|
18 | 18 | public class OBSRemoteControllerIT {
|
19 | 19 |
|
20 | 20 | /**
|
21 |
| - * - Set these two values before running these tests |
| 21 | + * - Setup OBS with the below address, and disable authentication |
22 | 22 | * - Make sure your OBS is running and available for connection
|
23 | 23 | */
|
24 | 24 | private final String obsAddress = "ws://localhost:4444";
|
@@ -324,50 +324,72 @@ void testConnectAndDisconnect() {
|
324 | 324 | }
|
325 | 325 |
|
326 | 326 | @Test
|
327 |
| - void testConnectWithNoCallbacksRegistered() { |
| 327 | + void disconnectShouldNotHaveErrorsWhenNoConnectDisconnectCallbacksRegistered() { |
328 | 328 | AtomicReference<String> testFailedReason = new AtomicReference<>();
|
329 | 329 |
|
| 330 | + // Given a controller that auto-connects...When connected |
330 | 331 | final OBSRemoteController controller = new OBSRemoteController(obsAddress, true,
|
331 | 332 | obsPassword, true);
|
332 | 333 |
|
| 334 | + // Then no errors should have occurred |
333 | 335 | if (controller.isFailed()) {
|
334 | 336 | fail("Failed to connect to websocket");
|
335 | 337 | }
|
336 | 338 |
|
| 339 | + // And given no callbacks registered for connect/disconnect |
337 | 340 | controller.registerDisconnectCallback(null);
|
338 | 341 | controller.registerConnectCallback(null);
|
339 |
| - controller.registerConnectionFailedCallback(message -> testFailedReason.set("ConnectionFailedCallback called unexpectedly")); |
340 |
| - controller.registerOnError((message, throwable) -> testFailedReason.set("OnError called unexpectedly")); |
341 | 342 |
|
| 343 | + // And given on connection failure and on error callbacks are set |
| 344 | + controller.registerConnectionFailedCallback(message -> |
| 345 | + testFailedReason.set("ConnectionFailedCallback called unexpectedly") |
| 346 | + ); |
| 347 | + controller.registerOnError((message, throwable) -> |
| 348 | + testFailedReason.set("OnError called unexpectedly") |
| 349 | + ); |
| 350 | + |
| 351 | + // When disconnected |
342 | 352 | controller.disconnect();
|
343 | 353 |
|
| 354 | + // Then the error or connection failure callbacks should not have been called |
344 | 355 | if (testFailedReason.get() != null) {
|
345 | 356 | fail(testFailedReason.get());
|
346 | 357 | }
|
347 | 358 | }
|
348 | 359 |
|
349 | 360 | @Test
|
350 |
| - void testConnectWithInvalidCallbacksRegistered() { |
| 361 | + void disconnectShouldNotHaveErrorsWhenConnectDisconnectCallbacksThrowErrors() { |
351 | 362 | AtomicReference<String> testFailedReason = new AtomicReference<>();
|
352 | 363 |
|
| 364 | + // Given controller that auto-connects...When connected |
353 | 365 | final OBSRemoteController controller = new OBSRemoteController(obsAddress, true,
|
354 | 366 | obsPassword, true);
|
355 | 367 |
|
| 368 | + // Then no failure was expected on connection |
356 | 369 | if (controller.isFailed()) {
|
357 | 370 | fail("Failed to connect to websocket");
|
358 | 371 | }
|
359 | 372 |
|
| 373 | + // And given (invalid) connect and disconnect callbacks are registered |
360 | 374 | controller.registerDisconnectCallback(response -> {
|
361 | 375 | throw new Error("Disconnect callback error");
|
362 | 376 | });
|
363 | 377 | controller.registerConnectCallback(response -> {
|
364 | 378 | throw new Error("Connect callback error");
|
365 | 379 | });
|
366 |
| - controller.registerConnectionFailedCallback(message -> testFailedReason.set("ConnectionFailedCallback called unexpectedly")); |
367 |
| - controller.registerOnError((message, throwable) -> testFailedReason.set("OnError called unexpectedly")); |
368 | 380 |
|
| 381 | + // And given on connection failure and on error callbacks are set |
| 382 | + controller.registerConnectionFailedCallback(message -> |
| 383 | + testFailedReason.set("ConnectionFailedCallback called unexpectedly") |
| 384 | + ); |
| 385 | + controller.registerOnError((message, throwable) -> |
| 386 | + testFailedReason.set("OnError called unexpectedly") |
| 387 | + ); |
| 388 | + |
| 389 | + // When the controller is disconnected |
369 | 390 | controller.disconnect();
|
370 | 391 |
|
| 392 | + // Then the connection failure and error callbacks should NOT have been called |
371 | 393 | if (testFailedReason.get() != null) {
|
372 | 394 | fail(testFailedReason.get());
|
373 | 395 | }
|
|
0 commit comments