File tree Expand file tree Collapse file tree 2 files changed +14
-4
lines changed
main/java/com/google/cloud/samples/test
test/java/com/google/cloud/samples/test Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change 2020 * A hello world app to test the parent pom.xml.
2121 */
2222public 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}
Original file line number Diff line number Diff line change 2222import org .junit .runner .RunWith ;
2323import 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 )
2932public 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}
You can’t perform that action at this time.
0 commit comments