forked from jenkins-docs/simple-java-maven-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
635d3f8
commit 7866331
Showing
2 changed files
with
10 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,25 @@ | ||
package com.mycompany.app; | ||
|
||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.PrintStream; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
/** | ||
* Unit test for simple App. | ||
*/ | ||
public class AppTest | ||
{ | ||
|
||
private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); | ||
|
||
@BeforeEach | ||
public void setUpStreams() { | ||
System.setOut(new PrintStream(outContent)); | ||
} | ||
|
||
@Test | ||
public void testAppConstructor() { | ||
try { | ||
new App(); | ||
} catch (Exception e) { | ||
fail("Construction failed."); | ||
} | ||
App app1 = new App(); | ||
App app2 = new App(); | ||
assertEquals(app1.getMessage(), app2.getMessage()); | ||
} | ||
|
||
@Test | ||
public void testAppMain() | ||
public void testAppMessage() | ||
{ | ||
App.main(null); | ||
try { | ||
assertEquals("Hello World!" + System.getProperty("line.separator"), outContent.toString()); | ||
} catch (AssertionError e) { | ||
fail("\"message\" is not \"Hello World!\""); | ||
} | ||
} | ||
|
||
@AfterEach | ||
public void cleanUpStreams() { | ||
System.setOut(null); | ||
App app = new App(); | ||
assertEquals("Hello World!", app.getMessage()); | ||
} | ||
|
||
} |