test: added test descriptions and resources for manually testing different project setup methods

This commit is contained in:
mlangkabel
2018-08-28 11:13:05 +02:00
parent 0f5548f5f9
commit 1ba843fbec
64 changed files with 1156 additions and 0 deletions
@@ -0,0 +1,7 @@
package hello;
public class Greeter {
public String sayHello() {
return "Hello world!";
}
}
@@ -0,0 +1,13 @@
package hello;
import org.joda.time.LocalTime;
public class HelloWorld {
public static void main(String[] args) {
LocalTime currentTime = new LocalTime();
System.out.println("The current local time is: " + currentTime);
Greeter greeter = new Greeter();
System.out.println(greeter.sayHello());
}
}
@@ -0,0 +1,40 @@
package hello;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.nio.charset.StandardCharsets;
import org.junit.Before;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertThat;
public class HelloWorldTests {
private ByteArrayOutputStream baos = new ByteArrayOutputStream();
private PrintStream ps = new PrintStream(baos);
@Before
public void setup() {
System.setOut(ps);
}
@Test
public void shouldPrintTimeToConsole() {
HelloWorld.main(new String[] { });
assertThat(output(), containsString("The current local time is"));
}
@Test
public void shouldPrintHelloWorldToConsole() {
HelloWorld.main(new String[] { });
assertThat(output(), containsString("Hello world!"));
}
private String output() {
return new String(baos.toByteArray(), StandardCharsets.UTF_8);
}
}