| 1 | package tmcsim.cadsimulator; |
|---|
| 2 | |
|---|
| 3 | import java.io.ByteArrayOutputStream; |
|---|
| 4 | import java.io.PrintStream; |
|---|
| 5 | import java.rmi.RemoteException; |
|---|
| 6 | import static junit.framework.Assert.assertEquals; |
|---|
| 7 | import org.uispec4j.*; |
|---|
| 8 | import tmcsim.common.SimulationException; |
|---|
| 9 | |
|---|
| 10 | /** |
|---|
| 11 | * Test of Byte Output Stream and redirection |
|---|
| 12 | * |
|---|
| 13 | * @author jdalbey |
|---|
| 14 | */ |
|---|
| 15 | public class BOStest extends UISpecTestCase |
|---|
| 16 | { |
|---|
| 17 | |
|---|
| 18 | public BOStest(String testName) |
|---|
| 19 | { |
|---|
| 20 | super(testName); |
|---|
| 21 | } |
|---|
| 22 | /** |
|---|
| 23 | * Test of main method, of class CADSimulator. |
|---|
| 24 | */ |
|---|
| 25 | ByteArrayOutputStream bos; |
|---|
| 26 | |
|---|
| 27 | public void setUp() throws SimulationException, RemoteException |
|---|
| 28 | { |
|---|
| 29 | // Declare a stream to the output |
|---|
| 30 | bos = new ByteArrayOutputStream(); |
|---|
| 31 | PrintStream ps = new PrintStream(bos); |
|---|
| 32 | // Redirect the standard output |
|---|
| 33 | System.setOut(ps); |
|---|
| 34 | } |
|---|
| 35 | |
|---|
| 36 | @Override |
|---|
| 37 | public void tearDown() throws java.io.IOException |
|---|
| 38 | { |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | public void testConstructor() |
|---|
| 42 | { |
|---|
| 43 | System.out.println("Mary had a little lamb."); |
|---|
| 44 | // Convert the output stream into a string we can test. |
|---|
| 45 | String result = bos.toString(); |
|---|
| 46 | assertEquals(expected1, result); |
|---|
| 47 | |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | public void testLoad() throws RemoteException |
|---|
| 51 | { |
|---|
| 52 | System.out.print(expected2); |
|---|
| 53 | // Convert the output stream into a string we can test. |
|---|
| 54 | String result = bos.toString(); |
|---|
| 55 | assertEquals(expected2, result); |
|---|
| 56 | |
|---|
| 57 | } |
|---|
| 58 | String expected1 = "Mary had a little lamb.\n"; |
|---|
| 59 | String expected2 = "Fleece white as snow.\n"; |
|---|
| 60 | } |
|---|