[255] | 1 | package de.ugoe.cs.util.console;
|
---|
| 2 |
|
---|
| 3 | import org.junit.*;
|
---|
[319] | 4 | import de.ugoe.cs.util.console.mock.MockCommandListener;
|
---|
| 5 | import de.ugoe.cs.util.console.mock.MockErrorListener;
|
---|
| 6 | import de.ugoe.cs.util.console.mock.MockExceptionListener;
|
---|
| 7 | import de.ugoe.cs.util.console.mock.MockObserver;
|
---|
| 8 | import de.ugoe.cs.util.console.mock.MockOutputListener;
|
---|
| 9 | import de.ugoe.cs.util.console.mock.MockTraceListener;
|
---|
[255] | 10 | import static org.junit.Assert.*;
|
---|
| 11 |
|
---|
| 12 | /**
|
---|
| 13 | * The class <code>ConsoleTest</code> contains tests for the class <code>{@link Console}</code>.
|
---|
| 14 | *
|
---|
| 15 | * @author Steffen Herbold
|
---|
| 16 | * @version 1.0
|
---|
| 17 | */
|
---|
| 18 | public class ConsoleTest {
|
---|
| 19 |
|
---|
| 20 | private static final String ENDLINE = System.getProperty("line.separator");
|
---|
| 21 |
|
---|
| 22 | @Test
|
---|
| 23 | public void testCommandNotification_1()
|
---|
| 24 | throws Exception {
|
---|
| 25 | String command = "test";
|
---|
| 26 |
|
---|
| 27 | MockCommandListener commandListener1 = new MockCommandListener();
|
---|
| 28 | MockCommandListener commandListener2 = new MockCommandListener();
|
---|
| 29 |
|
---|
| 30 | Console.getInstance().registerCommandListener(commandListener1);
|
---|
| 31 | Console.getInstance().registerCommandListener(commandListener2);
|
---|
| 32 | Console.commandNotification(command);
|
---|
| 33 |
|
---|
| 34 | assertEquals(command, commandListener1.getLastCommand());
|
---|
| 35 | assertEquals(command, commandListener2.getLastCommand());
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | @SuppressWarnings("deprecation")
|
---|
| 39 | @Test
|
---|
| 40 | public void testDeleteObserver_1()
|
---|
| 41 | throws Exception {
|
---|
| 42 | Console fixture = Console.getInstance();
|
---|
| 43 |
|
---|
| 44 | MockObserver mockObserver1 = new MockObserver();
|
---|
| 45 | MockObserver mockObserver2 = new MockObserver();
|
---|
| 46 | fixture.registerObserver(mockObserver1);
|
---|
| 47 | fixture.registerObserver(mockObserver2);
|
---|
| 48 |
|
---|
| 49 | fixture.deleteObserver(mockObserver1);
|
---|
| 50 |
|
---|
| 51 | assertFalse(fixture.hasCommandListener(mockObserver1));
|
---|
| 52 | assertFalse(fixture.hasErrorListener(mockObserver1));
|
---|
| 53 | assertFalse(fixture.hasExceptionListener(mockObserver1));
|
---|
| 54 | assertFalse(fixture.hasOutputListener(mockObserver1));
|
---|
| 55 | assertFalse(fixture.hasTraceListener(mockObserver1));
|
---|
| 56 |
|
---|
| 57 | assertTrue(fixture.hasCommandListener(mockObserver2));
|
---|
| 58 | assertTrue(fixture.hasErrorListener(mockObserver2));
|
---|
| 59 | assertTrue(fixture.hasExceptionListener(mockObserver2));
|
---|
| 60 | assertTrue(fixture.hasOutputListener(mockObserver2));
|
---|
| 61 | assertTrue(fixture.hasTraceListener(mockObserver2));
|
---|
| 62 |
|
---|
| 63 | // add additional test code here
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | @Test
|
---|
| 67 | public void testGetInstance()
|
---|
| 68 | throws Exception {
|
---|
| 69 |
|
---|
| 70 | Console result = Console.getInstance();
|
---|
| 71 | assertNotNull(result);
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | @Test
|
---|
| 75 | public void testLogException()
|
---|
| 76 | throws Exception {
|
---|
| 77 | Exception e = new Exception();
|
---|
| 78 | MockExceptionListener mockExceptionListener1 = new MockExceptionListener();
|
---|
| 79 | MockExceptionListener mockExceptionListener2 = new MockExceptionListener();
|
---|
| 80 |
|
---|
| 81 | Console.getInstance().registerExceptionListener(mockExceptionListener1);
|
---|
| 82 | Console.getInstance().registerExceptionListener(mockExceptionListener2);
|
---|
| 83 |
|
---|
| 84 | Console.logException(e);
|
---|
| 85 |
|
---|
| 86 | assertEquals(e, mockExceptionListener1.getLastException());
|
---|
| 87 | assertEquals(e, mockExceptionListener2.getLastException());
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | @Test
|
---|
| 91 | public void testPrint_1()
|
---|
| 92 | throws Exception {
|
---|
| 93 | String msg = "test";
|
---|
| 94 |
|
---|
| 95 | MockOutputListener mockOutputListener1 = new MockOutputListener();
|
---|
| 96 | MockOutputListener mockOutputListener2 = new MockOutputListener();
|
---|
| 97 |
|
---|
| 98 | Console.getInstance().registerOutputListener(mockOutputListener1);
|
---|
| 99 | Console.getInstance().registerOutputListener(mockOutputListener2);
|
---|
| 100 |
|
---|
| 101 | Console.print(msg);
|
---|
| 102 |
|
---|
| 103 | assertEquals(msg, mockOutputListener1.getLastOutput());
|
---|
| 104 | assertEquals(msg, mockOutputListener2.getLastOutput());
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | @Test
|
---|
| 108 | public void testPrinterr_1()
|
---|
| 109 | throws Exception {
|
---|
| 110 | String errMsg = "test";
|
---|
| 111 |
|
---|
| 112 | MockErrorListener mockErrorListener1 = new MockErrorListener();
|
---|
| 113 | MockErrorListener mockErrorListener2 = new MockErrorListener();
|
---|
| 114 |
|
---|
| 115 | Console.getInstance().registerErrorListener(mockErrorListener1);
|
---|
| 116 | Console.getInstance().registerErrorListener(mockErrorListener2);
|
---|
| 117 |
|
---|
| 118 | Console.printerr(errMsg);
|
---|
| 119 |
|
---|
| 120 | assertEquals(errMsg, mockErrorListener1.getLastError());
|
---|
| 121 | assertEquals(errMsg, mockErrorListener2.getLastError());
|
---|
| 122 | }
|
---|
| 123 |
|
---|
| 124 | @Test
|
---|
| 125 | public void testPrinterrln_1()
|
---|
| 126 | throws Exception {
|
---|
| 127 | String errMsg = "test";
|
---|
| 128 |
|
---|
| 129 | MockErrorListener mockErrorListener1 = new MockErrorListener();
|
---|
| 130 | MockErrorListener mockErrorListener2 = new MockErrorListener();
|
---|
| 131 |
|
---|
| 132 | Console.getInstance().registerErrorListener(mockErrorListener1);
|
---|
| 133 | Console.getInstance().registerErrorListener(mockErrorListener2);
|
---|
| 134 |
|
---|
| 135 | Console.printerrln(errMsg);
|
---|
| 136 |
|
---|
| 137 | assertEquals(errMsg+ENDLINE, mockErrorListener1.getLastError());
|
---|
| 138 | assertEquals(errMsg+ENDLINE, mockErrorListener2.getLastError());
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 |
|
---|
| 142 | @Test
|
---|
| 143 | public void testPrintln_1()
|
---|
| 144 | throws Exception {
|
---|
| 145 | String msg = "test";
|
---|
| 146 |
|
---|
| 147 | MockOutputListener mockOutputListener1 = new MockOutputListener();
|
---|
| 148 | MockOutputListener mockOutputListener2 = new MockOutputListener();
|
---|
| 149 |
|
---|
| 150 | Console.getInstance().registerOutputListener(mockOutputListener1);
|
---|
| 151 | Console.getInstance().registerOutputListener(mockOutputListener2);
|
---|
| 152 |
|
---|
| 153 | Console.println(msg);
|
---|
| 154 |
|
---|
| 155 | assertEquals(msg+ENDLINE, mockOutputListener1.getLastOutput());
|
---|
| 156 | assertEquals(msg+ENDLINE, mockOutputListener2.getLastOutput());
|
---|
| 157 | }
|
---|
| 158 |
|
---|
| 159 |
|
---|
| 160 | @Test
|
---|
| 161 | public void testRegisterCommandListener_1()
|
---|
| 162 | throws Exception {
|
---|
| 163 | Console fixture = Console.getInstance();
|
---|
| 164 | MockCommandListener mockCommandListener = new MockCommandListener();
|
---|
| 165 |
|
---|
| 166 | fixture.registerCommandListener(mockCommandListener);
|
---|
| 167 |
|
---|
| 168 | assertTrue(fixture.hasCommandListener(mockCommandListener));
|
---|
| 169 | }
|
---|
| 170 |
|
---|
| 171 | @Test
|
---|
| 172 | public void testRegisterErrorListener_1()
|
---|
| 173 | throws Exception {
|
---|
| 174 | Console fixture = Console.getInstance();
|
---|
| 175 |
|
---|
| 176 | MockErrorListener mockErrorListener = new MockErrorListener();
|
---|
| 177 |
|
---|
| 178 | fixture.registerErrorListener(mockErrorListener);
|
---|
| 179 |
|
---|
| 180 | assertTrue(fixture.hasErrorListener(mockErrorListener));
|
---|
| 181 | }
|
---|
| 182 |
|
---|
| 183 | @Test
|
---|
| 184 | public void testRegisterExceptionListener_1()
|
---|
| 185 | throws Exception {
|
---|
| 186 | Console fixture = Console.getInstance();
|
---|
| 187 |
|
---|
| 188 | MockExceptionListener mockExceptionListener = new MockExceptionListener();
|
---|
| 189 |
|
---|
| 190 | fixture.registerExceptionListener(mockExceptionListener);
|
---|
| 191 |
|
---|
| 192 | assertTrue(fixture.hasExceptionListener(mockExceptionListener));
|
---|
| 193 | }
|
---|
| 194 |
|
---|
| 195 | @SuppressWarnings("deprecation")
|
---|
| 196 | @Test
|
---|
| 197 | public void testRegisterObserver_1()
|
---|
| 198 | throws Exception {
|
---|
| 199 | Console fixture = Console.getInstance();
|
---|
| 200 |
|
---|
| 201 | MockObserver mockObserver = new MockObserver();
|
---|
| 202 |
|
---|
| 203 | fixture.registerObserver(mockObserver);
|
---|
| 204 |
|
---|
| 205 | assertTrue(fixture.hasCommandListener(mockObserver));
|
---|
| 206 | assertTrue(fixture.hasErrorListener(mockObserver));
|
---|
| 207 | assertTrue(fixture.hasExceptionListener(mockObserver));
|
---|
| 208 | assertTrue(fixture.hasOutputListener(mockObserver));
|
---|
| 209 | assertTrue(fixture.hasTraceListener(mockObserver));
|
---|
| 210 | }
|
---|
| 211 |
|
---|
| 212 | @Test
|
---|
| 213 | public void testRegisterOutputListener_1()
|
---|
| 214 | throws Exception {
|
---|
| 215 | Console fixture = Console.getInstance();
|
---|
| 216 |
|
---|
| 217 | MockOutputListener mockOutputListener = new MockOutputListener();
|
---|
| 218 |
|
---|
| 219 | fixture.registerOutputListener(mockOutputListener);
|
---|
| 220 |
|
---|
| 221 | assertTrue(fixture.hasOutputListener(mockOutputListener));
|
---|
| 222 | }
|
---|
| 223 |
|
---|
| 224 | @Test
|
---|
| 225 | public void testRegisterTraceListener_1()
|
---|
| 226 | throws Exception {
|
---|
| 227 | Console fixture = Console.getInstance();
|
---|
| 228 |
|
---|
| 229 | MockTraceListener mockTraceListener = new MockTraceListener();
|
---|
| 230 |
|
---|
| 231 | fixture.registerTraceListener(mockTraceListener);
|
---|
| 232 |
|
---|
| 233 | assertTrue(fixture.hasTraceListener(mockTraceListener));
|
---|
| 234 | }
|
---|
| 235 |
|
---|
| 236 | @Test
|
---|
| 237 | public void testRemoveCommandListener_1()
|
---|
| 238 | throws Exception {
|
---|
| 239 | Console fixture = Console.getInstance();
|
---|
| 240 |
|
---|
| 241 | MockCommandListener mockCommandListener1 = new MockCommandListener();
|
---|
| 242 | MockCommandListener mockCommandListener2 = new MockCommandListener();
|
---|
| 243 | fixture.registerCommandListener(mockCommandListener1);
|
---|
| 244 | fixture.registerCommandListener(mockCommandListener2);
|
---|
| 245 |
|
---|
| 246 | fixture.removeCommandListener(mockCommandListener1);
|
---|
| 247 |
|
---|
| 248 | assertFalse(fixture.hasCommandListener(mockCommandListener1));
|
---|
| 249 | assertTrue(fixture.hasCommandListener(mockCommandListener2));
|
---|
| 250 | }
|
---|
| 251 |
|
---|
| 252 | @Test
|
---|
| 253 | public void testRemoveErrorListener_1()
|
---|
| 254 | throws Exception {
|
---|
| 255 | Console fixture = Console.getInstance();
|
---|
| 256 |
|
---|
| 257 | MockErrorListener mockErrorListener1 = new MockErrorListener();
|
---|
| 258 | MockErrorListener mockErrorListener2 = new MockErrorListener();
|
---|
| 259 | fixture.registerErrorListener(mockErrorListener1);
|
---|
| 260 | fixture.registerErrorListener(mockErrorListener2);
|
---|
| 261 |
|
---|
| 262 | fixture.removeErrorListener(mockErrorListener1);
|
---|
| 263 |
|
---|
| 264 | assertFalse(fixture.hasErrorListener(mockErrorListener1));
|
---|
| 265 | assertTrue(fixture.hasErrorListener(mockErrorListener2));
|
---|
| 266 | }
|
---|
| 267 |
|
---|
| 268 | @Test
|
---|
| 269 | public void testRemoveExceptionListener_1()
|
---|
| 270 | throws Exception {
|
---|
| 271 | Console fixture = Console.getInstance();
|
---|
| 272 |
|
---|
| 273 | MockExceptionListener mockExceptionListener1 = new MockExceptionListener();
|
---|
| 274 | MockExceptionListener mockExceptionListener2 = new MockExceptionListener();
|
---|
| 275 |
|
---|
| 276 | fixture.registerExceptionListener(mockExceptionListener1);
|
---|
| 277 | fixture.registerExceptionListener(mockExceptionListener2);
|
---|
| 278 |
|
---|
| 279 | fixture.removeExceptionListener(mockExceptionListener1);
|
---|
| 280 |
|
---|
| 281 | assertFalse(fixture.hasExceptionListener(mockExceptionListener1));
|
---|
| 282 | assertTrue(fixture.hasExceptionListener(mockExceptionListener2));
|
---|
| 283 | }
|
---|
| 284 |
|
---|
| 285 | @Test
|
---|
| 286 | public void testRemoveOutputListener_1()
|
---|
| 287 | throws Exception {
|
---|
| 288 | Console fixture = Console.getInstance();
|
---|
| 289 |
|
---|
| 290 | MockOutputListener mockOutputListener1 = new MockOutputListener();
|
---|
| 291 | MockOutputListener mockOutputListener2 = new MockOutputListener();
|
---|
| 292 |
|
---|
| 293 | fixture.registerOutputListener(mockOutputListener1);
|
---|
| 294 | fixture.registerOutputListener(mockOutputListener2);
|
---|
| 295 |
|
---|
| 296 | fixture.removeOutputListener(mockOutputListener1);
|
---|
| 297 |
|
---|
| 298 | assertFalse(fixture.hasOutputListener(mockOutputListener1));
|
---|
| 299 | assertTrue(fixture.hasOutputListener(mockOutputListener2));
|
---|
| 300 | }
|
---|
| 301 |
|
---|
| 302 | @Test
|
---|
| 303 | public void testRemoveTraceListener_1()
|
---|
| 304 | throws Exception {
|
---|
| 305 | Console fixture = Console.getInstance();
|
---|
| 306 |
|
---|
| 307 | MockTraceListener mockTraceListener1 = new MockTraceListener();
|
---|
| 308 | MockTraceListener mockTraceListener2 = new MockTraceListener();
|
---|
| 309 |
|
---|
| 310 | fixture.registerTraceListener(mockTraceListener1);
|
---|
| 311 | fixture.registerTraceListener(mockTraceListener2);
|
---|
| 312 |
|
---|
| 313 | fixture.removeTraceListener(mockTraceListener1);
|
---|
| 314 |
|
---|
| 315 | assertFalse(fixture.hasTraceListener(mockTraceListener1));
|
---|
| 316 | assertTrue(fixture.hasTraceListener(mockTraceListener2));
|
---|
| 317 | }
|
---|
| 318 |
|
---|
| 319 | @Test
|
---|
| 320 | public void testTrace_1()
|
---|
| 321 | throws Exception {
|
---|
| 322 | String traceMsg = "test";
|
---|
| 323 |
|
---|
| 324 | MockTraceListener mockTraceListener1 = new MockTraceListener();
|
---|
| 325 | MockTraceListener mockTraceListener2 = new MockTraceListener();
|
---|
| 326 |
|
---|
| 327 | Console.getInstance().registerTraceListener(mockTraceListener1);
|
---|
| 328 | Console.getInstance().registerTraceListener(mockTraceListener2);
|
---|
| 329 |
|
---|
| 330 | Console.trace(traceMsg);
|
---|
| 331 |
|
---|
| 332 | assertEquals(traceMsg, mockTraceListener1.getLastTrace());
|
---|
| 333 | assertEquals(traceMsg, mockTraceListener2.getLastTrace());
|
---|
| 334 | }
|
---|
| 335 |
|
---|
| 336 | @Test
|
---|
| 337 | public void testTraceln_1()
|
---|
| 338 | throws Exception {
|
---|
| 339 | String traceMsg = "test";
|
---|
| 340 |
|
---|
| 341 | MockTraceListener mockTraceListener1 = new MockTraceListener();
|
---|
| 342 | MockTraceListener mockTraceListener2 = new MockTraceListener();
|
---|
| 343 |
|
---|
| 344 | Console.getInstance().registerTraceListener(mockTraceListener1);
|
---|
| 345 | Console.getInstance().registerTraceListener(mockTraceListener2);
|
---|
| 346 |
|
---|
| 347 | Console.traceln(traceMsg);
|
---|
| 348 |
|
---|
| 349 | assertEquals(traceMsg+ENDLINE, mockTraceListener1.getLastTrace());
|
---|
| 350 | assertEquals(traceMsg+ENDLINE, mockTraceListener2.getLastTrace());
|
---|
| 351 |
|
---|
| 352 | // add additional test code here
|
---|
| 353 | }
|
---|
| 354 |
|
---|
| 355 | @Before
|
---|
| 356 | public void setUp()
|
---|
| 357 | throws Exception {
|
---|
| 358 | Console.reset();
|
---|
| 359 | }
|
---|
| 360 |
|
---|
| 361 | public static void main(String[] args) {
|
---|
| 362 | new org.junit.runner.JUnitCore().run(ConsoleTest.class);
|
---|
| 363 | }
|
---|
| 364 | } |
---|