Skip to content

Commit

Permalink
Test clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
Cedric Liegeois committed Jul 11, 2020
1 parent 944a314 commit 52efa63
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
22 changes: 12 additions & 10 deletions wire-device/src/test/java/io/omam/wire/device/ScenarioRuntime.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,6 @@ private InstanceHolder() {

}

/** {@code true} if setup has been performed. */
private boolean setup;

/** the controller being tested. */
private CastDeviceController ctrl;

Expand Down Expand Up @@ -175,13 +172,22 @@ final void setup() throws GeneralSecurityException {
* Tears down the run time.
*/
final void tearDown() {
setup = false;
if (ctrl != null) {
ctrl.disconnect();
ctrl = null;
}
if (ecd != null) {
ecd.close();
ecd = null;
}
}

private void ensureNotSetup() {
if (ecd != null) {
throw new IllegalStateException("Emuated device already setup");
}
if (ctrl != null) {
throw new IllegalStateException("Controller already setup");
}
}

Expand All @@ -191,9 +197,7 @@ final void tearDown() {
* @throws GeneralSecurityException from controller
*/
private void setupEmulatedDevice() throws GeneralSecurityException {
if (setup) {
throw new IllegalStateException("Setup already done");
}
ensureNotSetup();
System.setProperty("io.omam.wire.device.heartbeatIntervalMs", "2000");
ecd = new EmulatedCastDevice();
final String deviceId = UUID.randomUUID().toString();
Expand All @@ -208,9 +212,7 @@ private void setupEmulatedDevice() throws GeneralSecurityException {
* @throws GeneralSecurityException from controller
*/
private void setupRealDevice() throws GeneralSecurityException {
if (setup) {
throw new IllegalStateException("Setup already done");
}
ensureNotSetup();
final String deviceId = UUID.randomUUID().toString();
final InetSocketAddress address = WireTestKit.realDeviceAddr();
ctrl = CastDeviceController.v2(deviceId, address, Optional.empty());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public final class EmulatedCastDevice implements AutoCloseable {
*/
private static final class AppAvailabilityReq extends Payload {

public static final String TYPE = "GET_APP_AVAILABILITY";
static final String TYPE = "GET_APP_AVAILABILITY";

/** ID of each application. */
private Collection<String> appId;
Expand Down

0 comments on commit 52efa63

Please sign in to comment.