1 | // Copyright 2012 Georg-August-Universität Göttingen, Germany
|
---|
2 | //
|
---|
3 | // Licensed under the Apache License, Version 2.0 (the "License");
|
---|
4 | // you may not use this file except in compliance with the License.
|
---|
5 | // You may obtain a copy of the License at
|
---|
6 | //
|
---|
7 | // http://www.apache.org/licenses/LICENSE-2.0
|
---|
8 | //
|
---|
9 | // Unless required by applicable law or agreed to in writing, software
|
---|
10 | // distributed under the License is distributed on an "AS IS" BASIS,
|
---|
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
12 | // See the License for the specific language governing permissions and
|
---|
13 | // limitations under the License.
|
---|
14 |
|
---|
15 | package de.ugoe.cs.util.console;
|
---|
16 |
|
---|
17 | import java.io.File;
|
---|
18 |
|
---|
19 | import junitx.framework.FileAssert;
|
---|
20 |
|
---|
21 | import org.junit.*;
|
---|
22 | import static org.junit.Assert.*;
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * The class <code>FileOutputListenerTest</code> contains tests for the class <code>{@link FileOutputListener}</code>.
|
---|
26 | *
|
---|
27 | * @author Steffen Herbold
|
---|
28 | * @version 1.0
|
---|
29 | */
|
---|
30 | public class FileOutputListenerTest {
|
---|
31 |
|
---|
32 | String expectedOutputFilename = "testdata/de.ugoe.cs.util.FileOutputListenerTest/expected.log";
|
---|
33 | String testOutputPath = "testoutput/";
|
---|
34 | String testFilename = testOutputPath + "listener.log";
|
---|
35 |
|
---|
36 | FileOutputListener listener;
|
---|
37 |
|
---|
38 | @Test
|
---|
39 | public void testFileOutputListener_1()
|
---|
40 | throws Exception {
|
---|
41 | String filename = "filename";
|
---|
42 |
|
---|
43 | FileOutputListener result = new FileOutputListener(filename);
|
---|
44 |
|
---|
45 | assertNotNull(result);
|
---|
46 | assertEquals(filename, result.getFilename());
|
---|
47 | }
|
---|
48 |
|
---|
49 | @Test
|
---|
50 | public void testOutputMsg_1()
|
---|
51 | throws Exception {
|
---|
52 | String message = "test";
|
---|
53 |
|
---|
54 | listener.start();
|
---|
55 | listener.outputMsg(message);
|
---|
56 | listener.stop();
|
---|
57 |
|
---|
58 | FileAssert.assertEquals(new File(expectedOutputFilename), new File(testFilename));
|
---|
59 | }
|
---|
60 |
|
---|
61 | @Test
|
---|
62 | public void testStart_1()
|
---|
63 | throws Exception {
|
---|
64 | FileOutputListener fixture = new FileOutputListener(testFilename);
|
---|
65 |
|
---|
66 | fixture.start();
|
---|
67 |
|
---|
68 | File file = new File(testFilename);
|
---|
69 | assertTrue(file.exists());
|
---|
70 | }
|
---|
71 |
|
---|
72 | @Test
|
---|
73 | public void testStart_2()
|
---|
74 | throws Exception {
|
---|
75 | FileOutputListener fixture = new FileOutputListener("");
|
---|
76 |
|
---|
77 | fixture.start();
|
---|
78 |
|
---|
79 | assertNull(fixture.writer);
|
---|
80 | }
|
---|
81 |
|
---|
82 | @Test
|
---|
83 | public void testStop_1()
|
---|
84 | throws Exception {
|
---|
85 | listener.stop();
|
---|
86 | assertNull(listener.writer);
|
---|
87 | }
|
---|
88 |
|
---|
89 | @Before
|
---|
90 | public void setUp()
|
---|
91 | throws Exception {
|
---|
92 | // add additional set up code here
|
---|
93 | Console.reset();
|
---|
94 | listener = new FileOutputListener(testFilename);
|
---|
95 | File file = new File(testFilename);
|
---|
96 | if( file.exists() ) {
|
---|
97 | file.delete();
|
---|
98 | }
|
---|
99 | }
|
---|
100 |
|
---|
101 | @After
|
---|
102 | public void tearDown()
|
---|
103 | throws Exception {
|
---|
104 | if( listener.writer!=null ) {
|
---|
105 | listener.writer.close();
|
---|
106 | }
|
---|
107 | }
|
---|
108 |
|
---|
109 | public static void main(String[] args) {
|
---|
110 | new org.junit.runner.JUnitCore().run(FileOutputListenerTest.class);
|
---|
111 | }
|
---|
112 | } |
---|