File tree 2 files changed +14
-4
lines changed
main/java/com/google/cloud/samples/test
test/java/com/google/cloud/samples/test
2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change 20
20
* A hello world app to test the parent pom.xml.
21
21
*/
22
22
public class App {
23
- public static String greeting () {
23
+ public String greeting () {
24
24
return "Hello World!" ;
25
25
}
26
26
27
27
public static void main (String [] args ) {
28
- System .out .println (App .greeting ());
28
+ App app = new App ();
29
+ System .out .println (app .greeting ());
29
30
}
30
31
}
Original file line number Diff line number Diff line change 22
22
import org .junit .runner .RunWith ;
23
23
import org .junit .runners .JUnit4 ;
24
24
25
+ import java .io .ByteArrayOutputStream ;
26
+ import java .io .PrintStream ;
27
+
25
28
/**
26
29
* Unit tests for {@link App}.
27
30
*/
28
31
@ RunWith (JUnit4 .class )
29
32
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!" );
32
41
}
33
42
}
You can’t perform that action at this time.
0 commit comments