File tree Expand file tree Collapse file tree 2 files changed +10
-37
lines changed
main/java/com/mycompany/app
test/java/com/mycompany/app Expand file tree Collapse file tree 2 files changed +10
-37
lines changed Original file line number Diff line number Diff line change 5
5
*/
6
6
public class App {
7
7
8
- private final String message = "Hello World!" ;
8
+ private static final String MESSAGE = "Hello World!" ;
9
9
10
10
public App () {}
11
11
12
12
public static void main (String [] args ) {
13
- System .out .println (new App (). getMessage () );
13
+ System .out .println (MESSAGE );
14
14
}
15
15
16
- private final String getMessage () {
17
- return message ;
16
+ public String getMessage () {
17
+ return MESSAGE ;
18
18
}
19
-
20
19
}
Original file line number Diff line number Diff line change 1
1
package com .mycompany .app ;
2
2
3
- import org .junit .jupiter .api .AfterEach ;
4
- import org .junit .jupiter .api .BeforeEach ;
5
3
import org .junit .jupiter .api .Test ;
6
4
7
- import java .io .ByteArrayOutputStream ;
8
- import java .io .PrintStream ;
9
-
10
5
import static org .junit .jupiter .api .Assertions .assertEquals ;
11
- import static org .junit .jupiter .api .Assertions .fail ;
12
6
13
7
/**
14
8
* Unit test for simple App.
15
9
*/
16
10
public class AppTest
17
11
{
18
-
19
- private final ByteArrayOutputStream outContent = new ByteArrayOutputStream ();
20
-
21
- @ BeforeEach
22
- public void setUpStreams () {
23
- System .setOut (new PrintStream (outContent ));
24
- }
25
-
26
12
@ Test
27
13
public void testAppConstructor () {
28
- try {
29
- new App ();
30
- } catch (Exception e ) {
31
- fail ("Construction failed." );
32
- }
14
+ App app1 = new App ();
15
+ App app2 = new App ();
16
+ assertEquals (app1 .getMessage (), app2 .getMessage ());
33
17
}
34
18
35
19
@ Test
36
- public void testAppMain ()
20
+ public void testAppMessage ()
37
21
{
38
- App .main (null );
39
- try {
40
- assertEquals ("Hello World!" + System .getProperty ("line.separator" ), outContent .toString ());
41
- } catch (AssertionError e ) {
42
- fail ("\" message\" is not \" Hello World!\" " );
43
- }
44
- }
45
-
46
- @ AfterEach
47
- public void cleanUpStreams () {
48
- System .setOut (null );
22
+ App app = new App ();
23
+ assertEquals ("Hello World!" , app .getMessage ());
49
24
}
50
-
51
25
}
You can’t perform that action at this time.
0 commit comments