Skip to content

Commit a3cd9c4

Browse files
authored
Merge pull request #25 from GoogleCloudPlatform/tswast-coverage
Improve code coverage.
2 parents e70092c + f95f02e commit a3cd9c4

File tree

2 files changed

+14
-4
lines changed
  • test/src

2 files changed

+14
-4
lines changed

test/src/main/java/com/google/cloud/samples/test/App.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@
2020
* A hello world app to test the parent pom.xml.
2121
*/
2222
public class App {
23-
public static String greeting() {
23+
public String greeting() {
2424
return "Hello World!";
2525
}
2626

2727
public static void main(String[] args) {
28-
System.out.println(App.greeting());
28+
App app = new App();
29+
System.out.println(app.greeting());
2930
}
3031
}

test/src/test/java/com/google/cloud/samples/test/AppTest.java

+11-2
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,21 @@
2222
import org.junit.runner.RunWith;
2323
import org.junit.runners.JUnit4;
2424

25+
import java.io.ByteArrayOutputStream;
26+
import java.io.PrintStream;
27+
2528
/**
2629
* Unit tests for {@link App}.
2730
*/
2831
@RunWith(JUnit4.class)
2932
public class AppTest {
30-
@Test public void greeting_returnsHelloWorld() {
31-
assertThat(App.greeting()).named("greeting").isEqualTo("Hello World!");
33+
@Test public void main_printsHelloWorld() {
34+
ByteArrayOutputStream out = new ByteArrayOutputStream();
35+
System.setOut(new PrintStream(out));
36+
37+
App.main(new String[0]);
38+
39+
String greeting = out.toString();
40+
assertThat(greeting).named("greeting").contains("Hello World!");
3241
}
3342
}

0 commit comments

Comments
 (0)