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.
Refactor App and made AppTest properly test App.
* Update version of junit dependency in 'pom.xml' file (to 4.11) so that org.junit dependencies in AppTest could be imported.
- Loading branch information
Showing
3 changed files
with
48 additions
and
30 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
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,38 +1,48 @@ | ||
package com.mycompany.app; | ||
|
||
import junit.framework.Test; | ||
import junit.framework.TestCase; | ||
import junit.framework.TestSuite; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.PrintStream; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.After; | ||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Unit test for simple App. | ||
*/ | ||
public class AppTest | ||
extends TestCase | ||
public class AppTest | ||
{ | ||
/** | ||
* Create the test case | ||
* | ||
* @param testName name of the test case | ||
*/ | ||
public AppTest( String testName ) | ||
{ | ||
super( testName ); | ||
|
||
private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); | ||
|
||
@Before | ||
public void setUpStreams() { | ||
System.setOut(new PrintStream(outContent)); | ||
} | ||
|
||
/** | ||
* @return the suite of tests being tested | ||
*/ | ||
public static Test suite() | ||
{ | ||
return new TestSuite( AppTest.class ); | ||
@Test | ||
public void testAppConstructor() { | ||
try { | ||
new App(); | ||
} catch (Exception e) { | ||
fail("Construction failed."); | ||
} | ||
} | ||
|
||
/** | ||
* Rigourous Test :-) | ||
*/ | ||
public void testApp() | ||
@Test | ||
public void testAppMain() | ||
{ | ||
assertTrue( true ); | ||
App.main(null); | ||
try { | ||
assertEquals("Hello World!" + System.getProperty("line.separator"), outContent.toString()); | ||
} catch (AssertionError e) { | ||
fail("\"message\" is not \"Hello World!\""); | ||
} | ||
} | ||
|
||
@After | ||
public void cleanUpStreams() { | ||
System.setOut(null); | ||
} | ||
|
||
} |