From 0f32ba8b15d94697023563362b0992f0cbd68356 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Pie=C5=82a?= Date: Sat, 9 Mar 2024 22:30:29 +0100 Subject: [PATCH] Working helloworld with test --- .gitignore | 2 + pom.xml | 45 +++++++++++++++++++ .../java/eu/mateuszpiela/helloworld/Main.java | 8 ++++ .../eu/mateuszpiela/helloworld/MainTest.java | 37 +++++++++++++++ 4 files changed, 92 insertions(+) create mode 100644 .gitignore create mode 100644 pom.xml create mode 100644 src/main/java/eu/mateuszpiela/helloworld/Main.java create mode 100644 src/test/java/eu/mateuszpiela/helloworld/MainTest.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c507849 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +target +.idea diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..5437672 --- /dev/null +++ b/pom.xml @@ -0,0 +1,45 @@ + + 4.0.0 + + eu.mateuszpiela.helloworld + helloworld + 1.0-SNAPSHOT + + helloworld + https://mateuszpiela.eu + + + UTF-8 + 17 + 17 + + + + + junit + junit + 4.13.2 + test + + + + + + + org.apache.maven.plugins + maven-jar-plugin + 3.3.0 + + + true + + true + eu.mateuszpiela.helloworld.Main + + + + + + + \ No newline at end of file diff --git a/src/main/java/eu/mateuszpiela/helloworld/Main.java b/src/main/java/eu/mateuszpiela/helloworld/Main.java new file mode 100644 index 0000000..b2e4623 --- /dev/null +++ b/src/main/java/eu/mateuszpiela/helloworld/Main.java @@ -0,0 +1,8 @@ +package eu.mateuszpiela.helloworld; + +public class Main { + public static void main(String[] args) { + + System.out.println("Hello world from java"); + } +} \ No newline at end of file diff --git a/src/test/java/eu/mateuszpiela/helloworld/MainTest.java b/src/test/java/eu/mateuszpiela/helloworld/MainTest.java new file mode 100644 index 0000000..f384433 --- /dev/null +++ b/src/test/java/eu/mateuszpiela/helloworld/MainTest.java @@ -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); + } +}