source: trunk/java-utils-test/src/test/java/de/ugoe/cs/util/console/FileOutputListenerTest.java @ 479

Last change on this file since 479 was 479, checked in by sherbold, 12 years ago
  • converted java-utils-test to Maven project
  • Property svn:mime-type set to text/plain
File size: 2.1 KB
Line 
1package de.ugoe.cs.util.console;
2
3import java.io.File;
4
5import junitx.framework.FileAssert;
6
7import org.junit.*;
8import 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 */
16public 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}
Note: See TracBrowser for help on using the repository browser.