Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2d87f15

Browse files
committedFeb 25, 2024·
adding unit test
1 parent eb3c4c0 commit 2d87f15

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed
 

‎.classpath

+2
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@
22
<classpath>
33
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
44
<classpathentry kind="src" path="src"/>
5+
<classpathentry kind="src" path="test"/>
6+
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
57
<classpathentry kind="output" path="bin"/>
68
</classpath>

‎.github/workflows/superlinter.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ jobs:
2525
env:
2626
DEFAULT_BRANCH: main
2727
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28-
VALIDATE_ALL_CODEBASE: true
28+
VALIDATE_ALL_CODEBASE: false
2929
JAVA_FILE_NAME: java.xml

‎.project

+11
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,15 @@
1414
<natures>
1515
<nature>org.eclipse.jdt.core.javanature</nature>
1616
</natures>
17+
<filteredResources>
18+
<filter>
19+
<id>1708804304551</id>
20+
<name></name>
21+
<type>30</type>
22+
<matcher>
23+
<id>org.eclipse.core.resources.regexFilterMatcher</id>
24+
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
25+
</matcher>
26+
</filter>
27+
</filteredResources>
1728
</projectDescription>

‎test/chapter01/TestExercise01.java

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package chapter01;
2+
3+
import static org.junit.jupiter.api.Assertions.*;
4+
5+
import java.io.ByteArrayOutputStream;
6+
import java.io.PrintStream;
7+
8+
import org.junit.jupiter.api.Test;
9+
10+
import com.github.jonathanbirkey.chapter01.Exercise01;
11+
12+
class TestExercise01 {
13+
14+
@Test
15+
public void testPrint() {
16+
ByteArrayOutputStream baos = new ByteArrayOutputStream();
17+
PrintStream ps = new PrintStream(baos);
18+
19+
PrintStream old = System.out;
20+
21+
System.setOut(ps);
22+
23+
// execute Exercise01 main method
24+
Exercise01.main(new String[0]);
25+
26+
System.out.flush();
27+
System.setOut(old);
28+
29+
// test method
30+
String expected = "Welcome to Java, Welcome to Computer Science, Programming is fun.";
31+
assertEquals(expected, baos.toString());
32+
}
33+
}

0 commit comments

Comments
 (0)
Please sign in to comment.