Working helloworld with test

This commit is contained in:
Mateusz Pieła 2024-03-09 22:30:29 +01:00
commit 0f32ba8b15
4 changed files with 92 additions and 0 deletions

View 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");
}
}

View 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);
}
}