Working helloworld with test
This commit is contained in:
commit
0f32ba8b15
4 changed files with 92 additions and 0 deletions
8
src/main/java/eu/mateuszpiela/helloworld/Main.java
Normal file
8
src/main/java/eu/mateuszpiela/helloworld/Main.java
Normal file
|
@ -0,0 +1,8 @@
|
|||
package eu.mateuszpiela.helloworld;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
|
||||
System.out.println("Hello world from java");
|
||||
}
|
||||
}
|
37
src/test/java/eu/mateuszpiela/helloworld/MainTest.java
Normal file
37
src/test/java/eu/mateuszpiela/helloworld/MainTest.java
Normal file
|
@ -0,0 +1,37 @@
|
|||
package eu.mateuszpiela.helloworld;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.lang.reflect.Array;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class MainTest {
|
||||
private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
|
||||
private final ByteArrayOutputStream errContent = new ByteArrayOutputStream();
|
||||
private final PrintStream originalOut = System.out;
|
||||
private final PrintStream originalErr = System.err;
|
||||
|
||||
@Before
|
||||
public void setUpStreams() {
|
||||
System.setOut(new PrintStream(outContent));
|
||||
System.setErr(new PrintStream(errContent));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void AssertConsoleOutputIsHelloWorld() {
|
||||
String[] args = {};
|
||||
eu.mateuszpiela.helloworld.Main.main(args);
|
||||
assertEquals("Hello world from java" + System.lineSeparator(), outContent.toString());
|
||||
}
|
||||
|
||||
@After
|
||||
public void restoreStreams() {
|
||||
System.setOut(originalOut);
|
||||
System.setErr(originalErr);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue