Skip to content

Commit

Permalink
Merge pull request #25 from GoogleCloudPlatform/tswast-coverage
Browse files Browse the repository at this point in the history
Improve code coverage.
  • Loading branch information
tswast authored Jun 28, 2016
2 parents e70092c + f95f02e commit a3cd9c4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
5 changes: 3 additions & 2 deletions test/src/main/java/com/google/cloud/samples/test/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@
* A hello world app to test the parent pom.xml.
*/
public class App {
public static String greeting() {
public String greeting() {
return "Hello World!";
}

public static void main(String[] args) {
System.out.println(App.greeting());
App app = new App();
System.out.println(app.greeting());
}
}
13 changes: 11 additions & 2 deletions test/src/test/java/com/google/cloud/samples/test/AppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,21 @@
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

/**
* Unit tests for {@link App}.
*/
@RunWith(JUnit4.class)
public class AppTest {
@Test public void greeting_returnsHelloWorld() {
assertThat(App.greeting()).named("greeting").isEqualTo("Hello World!");
@Test public void main_printsHelloWorld() {
ByteArrayOutputStream out = new ByteArrayOutputStream();
System.setOut(new PrintStream(out));

App.main(new String[0]);

String greeting = out.toString();
assertThat(greeting).named("greeting").contains("Hello World!");
}
}

0 comments on commit a3cd9c4

Please sign in to comment.