Working helloworld with test
This commit is contained in:
commit
0f32ba8b15
4 changed files with 92 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
target
|
||||||
|
.idea
|
45
pom.xml
Normal file
45
pom.xml
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>eu.mateuszpiela.helloworld</groupId>
|
||||||
|
<artifactId>helloworld</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
|
||||||
|
<name>helloworld</name>
|
||||||
|
<url>https://mateuszpiela.eu</url>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>4.13.2</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
<version>3.3.0</version>
|
||||||
|
<configuration>
|
||||||
|
<archive>
|
||||||
|
<index>true</index>
|
||||||
|
<manifest>
|
||||||
|
<addClasspath>true</addClasspath>
|
||||||
|
<mainClass>eu.mateuszpiela.helloworld.Main</mainClass>
|
||||||
|
</manifest>
|
||||||
|
</archive>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
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
Reference in a new issue