[255] | 1 | package de.ugoe.cs.util.console;
|
---|
| 2 |
|
---|
| 3 | import java.io.File;
|
---|
| 4 |
|
---|
| 5 | import junitx.framework.FileAssert;
|
---|
| 6 |
|
---|
| 7 | import org.junit.*;
|
---|
| 8 | import static org.junit.Assert.*;
|
---|
| 9 |
|
---|
| 10 | /**
|
---|
| 11 | * The class <code>FileOutputListenerTest</code> contains tests for the class <code>{@link FileOutputListener}</code>.
|
---|
| 12 | *
|
---|
| 13 | * @author Steffen Herbold
|
---|
| 14 | * @version 1.0
|
---|
| 15 | */
|
---|
| 16 | public class FileOutputListenerTest {
|
---|
| 17 |
|
---|
| 18 | String expectedOutputFilename = "testdata/de.ugoe.cs.util.FileOutputListenerTest/expected.log";
|
---|
| 19 | String testOutputPath = "testoutput/";
|
---|
| 20 | String testFilename = testOutputPath + "listener.log";
|
---|
| 21 |
|
---|
| 22 | FileOutputListener listener;
|
---|
| 23 |
|
---|
| 24 | @Test
|
---|
| 25 | public void testFileOutputListener_1()
|
---|
| 26 | throws Exception {
|
---|
| 27 | String filename = "filename";
|
---|
| 28 |
|
---|
| 29 | FileOutputListener result = new FileOutputListener(filename);
|
---|
| 30 |
|
---|
| 31 | assertNotNull(result);
|
---|
| 32 | assertEquals(filename, result.getFilename());
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | @Test
|
---|
| 36 | public void testOutputMsg_1()
|
---|
| 37 | throws Exception {
|
---|
| 38 | String message = "test";
|
---|
| 39 |
|
---|
| 40 | listener.start();
|
---|
| 41 | listener.outputMsg(message);
|
---|
| 42 | listener.stop();
|
---|
| 43 |
|
---|
| 44 | FileAssert.assertEquals(new File(expectedOutputFilename), new File(testFilename));
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | @Test
|
---|
| 48 | public void testStart_1()
|
---|
| 49 | throws Exception {
|
---|
| 50 | FileOutputListener fixture = new FileOutputListener(testFilename);
|
---|
| 51 |
|
---|
| 52 | fixture.start();
|
---|
| 53 |
|
---|
| 54 | File file = new File(testFilename);
|
---|
| 55 | assertTrue(file.exists());
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | @Test
|
---|
| 59 | public void testStart_2()
|
---|
| 60 | throws Exception {
|
---|
| 61 | FileOutputListener fixture = new FileOutputListener("");
|
---|
| 62 |
|
---|
| 63 | fixture.start();
|
---|
| 64 |
|
---|
| 65 | assertNull(fixture.writer);
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | @Test
|
---|
| 69 | public void testStop_1()
|
---|
| 70 | throws Exception {
|
---|
| 71 | listener.stop();
|
---|
| 72 | assertNull(listener.writer);
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | @Before
|
---|
| 76 | public void setUp()
|
---|
| 77 | throws Exception {
|
---|
| 78 | // add additional set up code here
|
---|
| 79 | Console.reset();
|
---|
| 80 | listener = new FileOutputListener(testFilename);
|
---|
| 81 | File file = new File(testFilename);
|
---|
| 82 | if( file.exists() ) {
|
---|
| 83 | file.delete();
|
---|
| 84 | }
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | @After
|
---|
| 88 | public void tearDown()
|
---|
| 89 | throws Exception {
|
---|
| 90 | if( listener.writer!=null ) {
|
---|
| 91 | listener.writer.close();
|
---|
| 92 | }
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | public static void main(String[] args) {
|
---|
| 96 | new org.junit.runner.JUnitCore().run(FileOutputListenerTest.class);
|
---|
| 97 | }
|
---|
| 98 | } |
---|