It works with dependencies
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
package com.gitlesson;
|
||||
|
||||
import com.gitlesson.demolibrary.TestLibrary;
|
||||
|
||||
/**
|
||||
* Hello world!
|
||||
* Prints the string that gets from TestLibrary!
|
||||
*
|
||||
*/
|
||||
public class App
|
||||
{
|
||||
public static void main( String[] args )
|
||||
{
|
||||
System.out.println( "Hello World!" );
|
||||
public class App {
|
||||
public static void main(String[] args) {
|
||||
String test = TestLibrary.getText();
|
||||
System.out.print(test);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,49 @@
|
||||
package com.gitlesson;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.PrintStream;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import com.gitlesson.demolibrary.TestLibrary;
|
||||
|
||||
/**
|
||||
* Unit test for simple App.
|
||||
*/
|
||||
public class AppTest
|
||||
{
|
||||
public class AppTest {
|
||||
private final PrintStream stardardOut = System.out;
|
||||
private final ByteArrayOutputStream outputStreamCaptor = new ByteArrayOutputStream();
|
||||
|
||||
/**
|
||||
* substitute the standard output with
|
||||
* a new object because we need to check
|
||||
* if the method Main writes the correct string
|
||||
*/
|
||||
@Before
|
||||
public void setup() {
|
||||
System.setOut(new PrintStream(outputStreamCaptor));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the standard out to the system one
|
||||
*/
|
||||
@After
|
||||
public void restore() {
|
||||
System.setOut(stardardOut);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rigorous Test :-)
|
||||
*/
|
||||
@Test
|
||||
public void shouldAnswerWithTrue()
|
||||
{
|
||||
assertTrue( true );
|
||||
public void shouldAnswerWithTrue() {
|
||||
String[] args = new String[0];
|
||||
App.main(args);
|
||||
String result = outputStreamCaptor.toString();
|
||||
String expected = TestLibrary.getText();
|
||||
assertEquals("This strings should match", expected, result);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user