Skip to content

Commit 7866331

Browse files
committed
Simplify tests
1 parent 635d3f8 commit 7866331

File tree

2 files changed

+10
-37
lines changed

2 files changed

+10
-37
lines changed

src/main/java/com/mycompany/app/App.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@
55
*/
66
public class App {
77

8-
private final String message = "Hello World!";
8+
private static final String MESSAGE = "Hello World!";
99

1010
public App() {}
1111

1212
public static void main(String[] args) {
13-
System.out.println(new App().getMessage());
13+
System.out.println(MESSAGE);
1414
}
1515

16-
private final String getMessage() {
17-
return message;
16+
public String getMessage() {
17+
return MESSAGE;
1818
}
19-
2019
}
Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,25 @@
11
package com.mycompany.app;
22

3-
import org.junit.jupiter.api.AfterEach;
4-
import org.junit.jupiter.api.BeforeEach;
53
import org.junit.jupiter.api.Test;
64

7-
import java.io.ByteArrayOutputStream;
8-
import java.io.PrintStream;
9-
105
import static org.junit.jupiter.api.Assertions.assertEquals;
11-
import static org.junit.jupiter.api.Assertions.fail;
126

137
/**
148
* Unit test for simple App.
159
*/
1610
public class AppTest
1711
{
18-
19-
private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
20-
21-
@BeforeEach
22-
public void setUpStreams() {
23-
System.setOut(new PrintStream(outContent));
24-
}
25-
2612
@Test
2713
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());
3317
}
3418

3519
@Test
36-
public void testAppMain()
20+
public void testAppMessage()
3721
{
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());
4924
}
50-
5125
}

0 commit comments

Comments
 (0)