[mielecloud] Fix mockito concurrency issues in integration tests (#11742)

* Move bridge and thing setup into individual integration tests
* Ensure that mocks used by ThingHandlers are fully initialized prior to
creating the thing handlers
* Ensure that bridge and thing are linked together after thing creation in
integration tests

Signed-off-by: Björn Lange <bjoern.lange@tu-dortmund.de>
This commit is contained in:
Björn Lange 2022-01-03 16:16:01 +01:00 committed by GitHub
parent 167f8ebc49
commit 45ce201813
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 277 additions and 84 deletions

View File

@ -33,6 +33,7 @@ import org.openhab.binding.mielecloud.internal.MieleCloudBindingConstants;
import org.openhab.binding.mielecloud.internal.auth.OAuthTokenRefresher;
import org.openhab.binding.mielecloud.internal.auth.OpenHabOAuthTokenRefresher;
import org.openhab.binding.mielecloud.internal.util.MieleCloudBindingIntegrationTestConstants;
import org.openhab.binding.mielecloud.internal.util.ReflectionUtil;
import org.openhab.binding.mielecloud.internal.webservice.MieleWebservice;
import org.openhab.binding.mielecloud.internal.webservice.MieleWebserviceFactory;
import org.openhab.binding.mielecloud.internal.webservice.api.DeviceState;
@ -231,7 +232,18 @@ public abstract class AbstractMieleThingHandlerTest extends JavaOSGiTest {
ThingHandler handler = thing.getHandler();
assertNotNull(handler);
return (AbstractMieleThingHandler) Objects.requireNonNull(handler);
AbstractMieleThingHandler mieleThingHandler = (AbstractMieleThingHandler) Objects.requireNonNull(handler);
waitForAssert(() -> {
try {
assertNotNull(ReflectionUtil.invokePrivate(mieleThingHandler, "getBridge"));
} catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException e) {
throw new RuntimeException(e);
}
assertNotNull(getBridge().getThing(thingUid));
});
return mieleThingHandler;
}
private List<Channel> createChannelsForThingHandler(ThingTypeUID thingTypeUid, ThingUID thingUid) {
@ -319,6 +331,9 @@ public abstract class AbstractMieleThingHandlerTest extends JavaOSGiTest {
setUpThingRegistry();
setUpItemRegistry();
setUpWebservice();
}
protected void setUpBridgeAndThing() throws Exception {
setUpBridge();
thingHandler = setUpThingHandler();
}
@ -353,12 +368,18 @@ public abstract class AbstractMieleThingHandlerTest extends JavaOSGiTest {
@Test
public void testCachedStateIsQueriedOnInitialize() throws Exception {
// given:
setUpBridgeAndThing();
// then:
verify(getWebserviceMock()).dispatchDeviceState(SERIAL_NUMBER);
}
@Test
public void testThingStatusIsOfflineWithDetailGoneAndDetailMessageWhenDeviceIsRemoved() {
public void testThingStatusIsOfflineWithDetailGoneAndDetailMessageWhenDeviceIsRemoved() throws Exception {
// given:
setUpBridgeAndThing();
// when:
getBridgeHandler().onDeviceRemoved(SERIAL_NUMBER);
@ -379,8 +400,10 @@ public abstract class AbstractMieleThingHandlerTest extends JavaOSGiTest {
}
@Test
public void testStatusIsSetToOnlineWhenDeviceStateIsValid() {
public void testStatusIsSetToOnlineWhenDeviceStateIsValid() throws Exception {
// given:
setUpBridgeAndThing();
DeviceState deviceState = createDeviceStateMock(StateType.ON, "On");
// when:
@ -391,8 +414,10 @@ public abstract class AbstractMieleThingHandlerTest extends JavaOSGiTest {
}
@Test
public void testStatusIsSetToOfflineWhenDeviceIsNotConnected() {
public void testStatusIsSetToOfflineWhenDeviceIsNotConnected() throws Exception {
// given:
setUpBridgeAndThing();
DeviceState deviceState = createDeviceStateMock(StateType.NOT_CONNECTED, "Not connected");
// when:
@ -404,15 +429,17 @@ public abstract class AbstractMieleThingHandlerTest extends JavaOSGiTest {
}
@Test
public void testFailingPutProcessActionDoesNotSetTheDeviceToOffline() {
public void testFailingPutProcessActionDoesNotSetTheDeviceToOffline() throws Exception {
// given:
doThrow(MieleWebserviceException.class).when(getWebserviceMock()).putProcessAction(any(),
eq(ProcessAction.STOP));
setUpBridgeAndThing();
DeviceState deviceState = createDeviceStateMock(StateType.ON, "On");
getBridgeHandler().onDeviceStateUpdated(deviceState);
assertThingStatusIs(getThingHandler().getThing(), ThingStatus.ONLINE, ThingStatusDetail.NONE);
doThrow(MieleWebserviceException.class).when(getWebserviceMock()).putProcessAction(any(),
eq(ProcessAction.STOP));
// when:
getThingHandler().triggerProcessAction(ProcessAction.STOP);
@ -421,7 +448,10 @@ public abstract class AbstractMieleThingHandlerTest extends JavaOSGiTest {
}
@Test
public void testHandleCommandProgramStartToStartStopChannel() {
public void testHandleCommandProgramStartToStartStopChannel() throws Exception {
// given:
setUpBridgeAndThing();
// when:
getThingHandler().handleCommand(channel(PROGRAM_START_STOP),
new StringType(ProgramStatus.PROGRAM_STARTED.getState()));
@ -433,7 +463,10 @@ public abstract class AbstractMieleThingHandlerTest extends JavaOSGiTest {
}
@Test
public void testHandleCommandProgramStopToStartStopChannel() {
public void testHandleCommandProgramStopToStartStopChannel() throws Exception {
// given:
setUpBridgeAndThing();
// when:
getThingHandler().handleCommand(channel(PROGRAM_START_STOP),
new StringType(ProgramStatus.PROGRAM_STOPPED.getState()));
@ -445,7 +478,10 @@ public abstract class AbstractMieleThingHandlerTest extends JavaOSGiTest {
}
@Test
public void testHandleCommandProgramStartToStartStopPauseChannel() {
public void testHandleCommandProgramStartToStartStopPauseChannel() throws Exception {
// given:
setUpBridgeAndThing();
// when:
getThingHandler().handleCommand(channel(PROGRAM_START_STOP_PAUSE),
new StringType(ProgramStatus.PROGRAM_STARTED.getState()));
@ -457,7 +493,10 @@ public abstract class AbstractMieleThingHandlerTest extends JavaOSGiTest {
}
@Test
public void testHandleCommandProgramStopToStartStopPauseChannel() {
public void testHandleCommandProgramStopToStartStopPauseChannel() throws Exception {
// given:
setUpBridgeAndThing();
// when:
getThingHandler().handleCommand(channel(PROGRAM_START_STOP_PAUSE),
new StringType(ProgramStatus.PROGRAM_STOPPED.getState()));
@ -469,7 +508,10 @@ public abstract class AbstractMieleThingHandlerTest extends JavaOSGiTest {
}
@Test
public void testHandleCommandProgramPauseToStartStopPauseChannel() {
public void testHandleCommandProgramPauseToStartStopPauseChannel() throws Exception {
// given:
setUpBridgeAndThing();
// when:
getThingHandler().handleCommand(channel(PROGRAM_START_STOP_PAUSE),
new StringType(ProgramStatus.PROGRAM_PAUSED.getState()));
@ -481,14 +523,16 @@ public abstract class AbstractMieleThingHandlerTest extends JavaOSGiTest {
}
@Test
public void testFailingPutLightDoesNotSetTheDeviceToOffline() {
public void testFailingPutLightDoesNotSetTheDeviceToOffline() throws Exception {
// given:
doThrow(MieleWebserviceException.class).when(getWebserviceMock()).putLight(any(), eq(true));
setUpBridgeAndThing();
DeviceState deviceState = createDeviceStateMock(StateType.ON, "On");
getBridgeHandler().onDeviceStateUpdated(deviceState);
assertThingStatusIs(getThingHandler().getThing(), ThingStatus.ONLINE, ThingStatusDetail.NONE);
doThrow(MieleWebserviceException.class).when(getWebserviceMock()).putLight(any(), eq(true));
// when:
getThingHandler().triggerLight(true);
@ -497,7 +541,10 @@ public abstract class AbstractMieleThingHandlerTest extends JavaOSGiTest {
}
@Test
public void testHandleCommandLightOff() {
public void testHandleCommandLightOff() throws Exception {
// given:
setUpBridgeAndThing();
// when:
getThingHandler().handleCommand(channel(LIGHT_SWITCH), OnOffType.OFF);
@ -508,7 +555,10 @@ public abstract class AbstractMieleThingHandlerTest extends JavaOSGiTest {
}
@Test
public void testHandleCommandLightOn() {
public void testHandleCommandLightOn() throws Exception {
// given:
setUpBridgeAndThing();
// when:
getThingHandler().handleCommand(channel(LIGHT_SWITCH), OnOffType.ON);
@ -519,7 +569,10 @@ public abstract class AbstractMieleThingHandlerTest extends JavaOSGiTest {
}
@Test
public void testHandleCommandDoesNothingWhenCommandIsNotOfOnOffType() {
public void testHandleCommandDoesNothingWhenCommandIsNotOfOnOffType() throws Exception {
// given:
setUpBridgeAndThing();
// when:
getThingHandler().handleCommand(channel(LIGHT_SWITCH), new DecimalType(0));
@ -528,7 +581,10 @@ public abstract class AbstractMieleThingHandlerTest extends JavaOSGiTest {
}
@Test
public void testHandleCommandPowerOn() {
public void testHandleCommandPowerOn() throws Exception {
// given:
setUpBridgeAndThing();
// when:
getThingHandler().handleCommand(channel(POWER_ON_OFF), OnOffType.ON);
@ -539,7 +595,10 @@ public abstract class AbstractMieleThingHandlerTest extends JavaOSGiTest {
}
@Test
public void testHandleCommandPowerOff() {
public void testHandleCommandPowerOff() throws Exception {
// given:
setUpBridgeAndThing();
// when:
getThingHandler().handleCommand(channel(POWER_ON_OFF), OnOffType.OFF);
@ -550,7 +609,10 @@ public abstract class AbstractMieleThingHandlerTest extends JavaOSGiTest {
}
@Test
public void testHandleCommandDoesNothingWhenPowerCommandIsNotOfOnOffType() {
public void testHandleCommandDoesNothingWhenPowerCommandIsNotOfOnOffType() throws Exception {
// given:
setUpBridgeAndThing();
// when:
getThingHandler().handleCommand(channel(POWER_ON_OFF), new DecimalType(0));
@ -559,8 +621,10 @@ public abstract class AbstractMieleThingHandlerTest extends JavaOSGiTest {
}
@Test
public void testMissingPropertiesAreSetWhenAStateUpdateIsReceivedFromTheCloud() {
public void testMissingPropertiesAreSetWhenAStateUpdateIsReceivedFromTheCloud() throws Exception {
// given:
setUpBridgeAndThing();
assertFalse(getThingHandler().getThing().getProperties().containsKey(Thing.PROPERTY_SERIAL_NUMBER));
assertFalse(getThingHandler().getThing().getProperties().containsKey(Thing.PROPERTY_MODEL_ID));

View File

@ -46,8 +46,10 @@ public class CoffeeDeviceThingHandlerTest extends AbstractMieleThingHandlerTest
}
@Test
public void testChannelUpdatesForNullValues() {
public void testChannelUpdatesForNullValues() throws Exception {
// given:
setUpBridgeAndThing();
DeviceState deviceState = mock(DeviceState.class);
when(deviceState.getDeviceIdentifier()).thenReturn(COFFEE_SYSTEM_THING_UID.getId());
when(deviceState.isRemoteControlEnabled()).thenReturn(Optional.empty());
@ -79,8 +81,10 @@ public class CoffeeDeviceThingHandlerTest extends AbstractMieleThingHandlerTest
}
@Test
public void testChannelUpdatesForValidValues() {
public void testChannelUpdatesForValidValues() throws Exception {
// given:
setUpBridgeAndThing();
DeviceState deviceState = mock(DeviceState.class);
when(deviceState.getDeviceIdentifier()).thenReturn(COFFEE_SYSTEM_THING_UID.getId());
when(deviceState.isRemoteControlEnabled()).thenReturn(Optional.of(true));
@ -116,8 +120,10 @@ public class CoffeeDeviceThingHandlerTest extends AbstractMieleThingHandlerTest
}
@Test
public void testFinishStateChannelIsSetToOnWhenProgramHasFinished() {
public void testFinishStateChannelIsSetToOnWhenProgramHasFinished() throws Exception {
// given:
setUpBridgeAndThing();
DeviceState deviceStateBefore = mock(DeviceState.class);
when(deviceStateBefore.getDeviceIdentifier()).thenReturn(COFFEE_SYSTEM_THING_UID.getId());
when(deviceStateBefore.getStateType()).thenReturn(Optional.of(StateType.RUNNING));
@ -140,8 +146,10 @@ public class CoffeeDeviceThingHandlerTest extends AbstractMieleThingHandlerTest
}
@Test
public void testTransitionChannelUpdatesForNullValues() {
public void testTransitionChannelUpdatesForNullValues() throws Exception {
// given:
setUpBridgeAndThing();
DeviceState deviceStateBefore = mock(DeviceState.class);
when(deviceStateBefore.getDeviceIdentifier()).thenReturn(COFFEE_SYSTEM_THING_UID.getId());
when(deviceStateBefore.getStateType()).thenReturn(Optional.of(StateType.RUNNING));
@ -165,8 +173,10 @@ public class CoffeeDeviceThingHandlerTest extends AbstractMieleThingHandlerTest
}
@Test
public void testTransitionChannelUpdatesForValidValues() {
public void testTransitionChannelUpdatesForValidValues() throws Exception {
// given:
setUpBridgeAndThing();
DeviceState deviceStateBefore = mock(DeviceState.class);
when(deviceStateBefore.getDeviceIdentifier()).thenReturn(COFFEE_SYSTEM_THING_UID.getId());
when(deviceStateBefore.getStateType()).thenReturn(Optional.of(StateType.RUNNING));
@ -190,8 +200,10 @@ public class CoffeeDeviceThingHandlerTest extends AbstractMieleThingHandlerTest
}
@Test
public void testActionsChannelUpdatesForValidValues() {
public void testActionsChannelUpdatesForValidValues() throws Exception {
// given:
setUpBridgeAndThing();
ActionsState actionsState = mock(ActionsState.class);
when(actionsState.getDeviceIdentifier()).thenReturn(COFFEE_SYSTEM_THING_UID.getId());
when(actionsState.canBeSwitchedOn()).thenReturn(true);

View File

@ -49,8 +49,10 @@ public class CoolingDeviceThingHandlerTest extends AbstractMieleThingHandlerTest
}
@Test
public void testChannelUpdatesForNullValues() {
public void testChannelUpdatesForNullValues() throws Exception {
// given:
setUpBridgeAndThing();
DeviceState deviceState = mock(DeviceState.class);
when(deviceState.getDeviceIdentifier()).thenReturn(FRIDGE_FREEZER_DEVICE_THING_UID.getId());
when(deviceState.getRawType()).thenReturn(DeviceType.FRIDGE_FREEZER_COMBINATION);
@ -84,8 +86,10 @@ public class CoolingDeviceThingHandlerTest extends AbstractMieleThingHandlerTest
}
@Test
public void testChannelUpdatesForValidValues() {
public void testChannelUpdatesForValidValues() throws Exception {
// given:
setUpBridgeAndThing();
DeviceState deviceState = mock(DeviceState.class);
when(deviceState.getDeviceIdentifier()).thenReturn(FRIDGE_FREEZER_DEVICE_THING_UID.getId());
when(deviceState.getRawType()).thenReturn(DeviceType.FRIDGE_FREEZER_COMBINATION);
@ -121,8 +125,10 @@ public class CoolingDeviceThingHandlerTest extends AbstractMieleThingHandlerTest
}
@Test
public void testChannelUpdatesForSuperCooling() {
public void testChannelUpdatesForSuperCooling() throws Exception {
// given:
setUpBridgeAndThing();
DeviceState deviceState = mock(DeviceState.class);
when(deviceState.getDeviceIdentifier()).thenReturn(FRIDGE_FREEZER_DEVICE_THING_UID.getId());
when(deviceState.getRawType()).thenReturn(DeviceType.FRIDGE_FREEZER_COMBINATION);
@ -139,8 +145,10 @@ public class CoolingDeviceThingHandlerTest extends AbstractMieleThingHandlerTest
}
@Test
public void testChannelUpdatesForSuperFreezing() {
public void testChannelUpdatesForSuperFreezing() throws Exception {
// given:
setUpBridgeAndThing();
DeviceState deviceState = mock(DeviceState.class);
when(deviceState.getDeviceIdentifier()).thenReturn(FRIDGE_FREEZER_DEVICE_THING_UID.getId());
when(deviceState.getRawType()).thenReturn(DeviceType.FRIDGE_FREEZER_COMBINATION);
@ -157,8 +165,10 @@ public class CoolingDeviceThingHandlerTest extends AbstractMieleThingHandlerTest
}
@Test
public void testChannelUpdatesForSuperCollingSuperFreezing() {
public void testChannelUpdatesForSuperCollingSuperFreezing() throws Exception {
// given:
setUpBridgeAndThing();
DeviceState deviceState = mock(DeviceState.class);
when(deviceState.getDeviceIdentifier()).thenReturn(FRIDGE_FREEZER_DEVICE_THING_UID.getId());
when(deviceState.getRawType()).thenReturn(DeviceType.FRIDGE_FREEZER_COMBINATION);
@ -175,8 +185,10 @@ public class CoolingDeviceThingHandlerTest extends AbstractMieleThingHandlerTest
}
@Test
public void testActionsChannelUpdatesForValidValues() {
public void testActionsChannelUpdatesForValidValues() throws Exception {
// given:
setUpBridgeAndThing();
ActionsState actionsState = mock(ActionsState.class);
when(actionsState.getDeviceIdentifier()).thenReturn(FRIDGE_FREEZER_DEVICE_THING_UID.getId());
when(actionsState.canContolSupercooling()).thenReturn(true);
@ -194,7 +206,10 @@ public class CoolingDeviceThingHandlerTest extends AbstractMieleThingHandlerTest
@Override
@Test
public void testHandleCommandDoesNothingWhenCommandIsNotOfOnOffType() {
public void testHandleCommandDoesNothingWhenCommandIsNotOfOnOffType() throws Exception {
// given:
setUpBridgeAndThing();
// when:
getThingHandler().handleCommand(channel(FRIDGE_SUPER_COOL), new DecimalType(50));
@ -203,7 +218,10 @@ public class CoolingDeviceThingHandlerTest extends AbstractMieleThingHandlerTest
}
@Test
public void testHandleCommandStartsSupercoolingWhenRequested() {
public void testHandleCommandStartsSupercoolingWhenRequested() throws Exception {
// given:
setUpBridgeAndThing();
// when:
getThingHandler().handleCommand(channel(FRIDGE_SUPER_COOL), OnOffType.ON);
@ -215,7 +233,10 @@ public class CoolingDeviceThingHandlerTest extends AbstractMieleThingHandlerTest
}
@Test
public void testHandleCommandStopsSupercoolingWhenRequested() {
public void testHandleCommandStopsSupercoolingWhenRequested() throws Exception {
// given:
setUpBridgeAndThing();
// when:
getThingHandler().handleCommand(channel(FRIDGE_SUPER_COOL), OnOffType.OFF);
@ -227,7 +248,10 @@ public class CoolingDeviceThingHandlerTest extends AbstractMieleThingHandlerTest
}
@Test
public void testHandleCommandStartsSuperfreezingWhenRequested() {
public void testHandleCommandStartsSuperfreezingWhenRequested() throws Exception {
// given:
setUpBridgeAndThing();
// when:
getThingHandler().handleCommand(channel(FREEZER_SUPER_FREEZE), OnOffType.ON);
@ -239,7 +263,10 @@ public class CoolingDeviceThingHandlerTest extends AbstractMieleThingHandlerTest
}
@Test
public void testHandleCommandStopsSuperfreezingWhenRequested() {
public void testHandleCommandStopsSuperfreezingWhenRequested() throws Exception {
// given:
setUpBridgeAndThing();
// when:
getThingHandler().handleCommand(channel(FREEZER_SUPER_FREEZE), OnOffType.OFF);

View File

@ -46,8 +46,10 @@ public class DishWarmerDeviceThingHandlerTest extends AbstractMieleThingHandlerT
}
@Test
public void testChannelUpdatesForNullValues() {
public void testChannelUpdatesForNullValues() throws Exception {
// given:
setUpBridgeAndThing();
DeviceState deviceState = mock(DeviceState.class);
when(deviceState.getDeviceIdentifier())
.thenReturn(MieleCloudBindingIntegrationTestConstants.DISH_WARMER_DEVICE_THING_UID.getId());
@ -81,8 +83,10 @@ public class DishWarmerDeviceThingHandlerTest extends AbstractMieleThingHandlerT
}
@Test
public void testChannelUpdatesForValidValues() {
public void testChannelUpdatesForValidValues() throws Exception {
// given:
setUpBridgeAndThing();
DeviceState deviceState = mock(DeviceState.class);
when(deviceState.getDeviceIdentifier())
.thenReturn(MieleCloudBindingIntegrationTestConstants.DISH_WARMER_DEVICE_THING_UID.getId());
@ -115,8 +119,10 @@ public class DishWarmerDeviceThingHandlerTest extends AbstractMieleThingHandlerT
}
@Test
public void testFinishStateChannelIsSetToOnWhenProgramHasFinished() {
public void testFinishStateChannelIsSetToOnWhenProgramHasFinished() throws Exception {
// given:
setUpBridgeAndThing();
DeviceState deviceStateBefore = mock(DeviceState.class);
when(deviceStateBefore.getDeviceIdentifier())
.thenReturn(MieleCloudBindingIntegrationTestConstants.DISH_WARMER_DEVICE_THING_UID.getId());
@ -141,8 +147,10 @@ public class DishWarmerDeviceThingHandlerTest extends AbstractMieleThingHandlerT
}
@Test
public void testTransitionChannelUpdatesForNullValues() {
public void testTransitionChannelUpdatesForNullValues() throws Exception {
// given:
setUpBridgeAndThing();
DeviceState deviceStateBefore = mock(DeviceState.class);
when(deviceStateBefore.getDeviceIdentifier())
.thenReturn(MieleCloudBindingIntegrationTestConstants.DISH_WARMER_DEVICE_THING_UID.getId());
@ -171,8 +179,10 @@ public class DishWarmerDeviceThingHandlerTest extends AbstractMieleThingHandlerT
}
@Test
public void testTransitionChannelUpdatesForValidValues() {
public void testTransitionChannelUpdatesForValidValues() throws Exception {
// given:
setUpBridgeAndThing();
DeviceState deviceStateBefore = mock(DeviceState.class);
when(deviceStateBefore.getDeviceIdentifier())
.thenReturn(MieleCloudBindingIntegrationTestConstants.DISH_WARMER_DEVICE_THING_UID.getId());
@ -201,8 +211,10 @@ public class DishWarmerDeviceThingHandlerTest extends AbstractMieleThingHandlerT
}
@Test
public void testActionsChannelUpdatesForValidValues() {
public void testActionsChannelUpdatesForValidValues() throws Exception {
// given:
setUpBridgeAndThing();
ActionsState actionsState = mock(ActionsState.class);
when(actionsState.getDeviceIdentifier())
.thenReturn(MieleCloudBindingIntegrationTestConstants.DISH_WARMER_DEVICE_THING_UID.getId());
@ -220,7 +232,10 @@ public class DishWarmerDeviceThingHandlerTest extends AbstractMieleThingHandlerT
}
@Test
public void testHandleCommandDishWarmerProgramActive() {
public void testHandleCommandDishWarmerProgramActive() throws Exception {
// given:
setUpBridgeAndThing();
// when:
getThingHandler().handleCommand(channel(DISH_WARMER_PROGRAM_ACTIVE), new StringType("3"));

View File

@ -47,8 +47,10 @@ public class DishwasherDeviceThingHandlerTest extends AbstractMieleThingHandlerT
}
@Test
public void testChannelUpdatesForNullValues() {
public void testChannelUpdatesForNullValues() throws Exception {
// given:
setUpBridgeAndThing();
DeviceState deviceState = mock(DeviceState.class);
when(deviceState.getDeviceIdentifier()).thenReturn(DISHWASHER_DEVICE_THING_UID.getId());
when(deviceState.getStateType()).thenReturn(Optional.empty());
@ -83,8 +85,10 @@ public class DishwasherDeviceThingHandlerTest extends AbstractMieleThingHandlerT
}
@Test
public void testChannelUpdatesForValidValues() {
public void testChannelUpdatesForValidValues() throws Exception {
// given:
setUpBridgeAndThing();
DeviceState deviceState = mock(DeviceState.class);
when(deviceState.isInState(any())).thenCallRealMethod();
when(deviceState.getDeviceIdentifier()).thenReturn(DISHWASHER_DEVICE_THING_UID.getId());
@ -124,8 +128,10 @@ public class DishwasherDeviceThingHandlerTest extends AbstractMieleThingHandlerT
}
@Test
public void testFinishStateChannelIsSetToOnWhenProgramHasFinished() {
public void testFinishStateChannelIsSetToOnWhenProgramHasFinished() throws Exception {
// given:
setUpBridgeAndThing();
DeviceState deviceStateBefore = mock(DeviceState.class);
when(deviceStateBefore.getDeviceIdentifier()).thenReturn(DISHWASHER_DEVICE_THING_UID.getId());
when(deviceStateBefore.getStateType()).thenReturn(Optional.of(StateType.RUNNING));
@ -148,8 +154,10 @@ public class DishwasherDeviceThingHandlerTest extends AbstractMieleThingHandlerT
}
@Test
public void testTransitionChannelUpdatesForNullValues() {
public void testTransitionChannelUpdatesForNullValues() throws Exception {
// given:
setUpBridgeAndThing();
DeviceState deviceStateBefore = mock(DeviceState.class);
when(deviceStateBefore.getDeviceIdentifier()).thenReturn(DISHWASHER_DEVICE_THING_UID.getId());
when(deviceStateBefore.getStateType()).thenReturn(Optional.of(StateType.RUNNING));
@ -176,8 +184,10 @@ public class DishwasherDeviceThingHandlerTest extends AbstractMieleThingHandlerT
}
@Test
public void testTransitionChannelUpdatesForValidValues() {
public void testTransitionChannelUpdatesForValidValues() throws Exception {
// given:
setUpBridgeAndThing();
DeviceState deviceStateBefore = mock(DeviceState.class);
when(deviceStateBefore.getDeviceIdentifier()).thenReturn(DISHWASHER_DEVICE_THING_UID.getId());
when(deviceStateBefore.getStateType()).thenReturn(Optional.of(StateType.RUNNING));
@ -204,8 +214,10 @@ public class DishwasherDeviceThingHandlerTest extends AbstractMieleThingHandlerT
}
@Test
public void testActionsChannelUpdatesForValidValues() {
public void testActionsChannelUpdatesForValidValues() throws Exception {
// given:
setUpBridgeAndThing();
ActionsState actionsState = mock(ActionsState.class);
when(actionsState.getDeviceIdentifier()).thenReturn(DISHWASHER_DEVICE_THING_UID.getId());
when(actionsState.canBeStarted()).thenReturn(true);

View File

@ -47,8 +47,10 @@ public class DryerDeviceThingHandlerTest extends AbstractMieleThingHandlerTest {
}
@Test
public void testChannelUpdatesForNullValues() {
public void testChannelUpdatesForNullValues() throws Exception {
// given:
setUpBridgeAndThing();
DeviceState deviceState = mock(DeviceState.class);
when(deviceState.getDeviceIdentifier()).thenReturn(DRYER_DEVICE_THING_UID.getId());
when(deviceState.getStateType()).thenReturn(Optional.empty());
@ -89,8 +91,10 @@ public class DryerDeviceThingHandlerTest extends AbstractMieleThingHandlerTest {
}
@Test
public void testChannelUpdatesForValidValues() {
public void testChannelUpdatesForValidValues() throws Exception {
// given:
setUpBridgeAndThing();
DeviceState deviceState = mock(DeviceState.class);
when(deviceState.isInState(any())).thenCallRealMethod();
when(deviceState.getDeviceIdentifier()).thenReturn(DRYER_DEVICE_THING_UID.getId());
@ -136,8 +140,10 @@ public class DryerDeviceThingHandlerTest extends AbstractMieleThingHandlerTest {
}
@Test
public void testFinishStateChannelIsSetToOnWhenProgramHasFinished() {
public void testFinishStateChannelIsSetToOnWhenProgramHasFinished() throws Exception {
// given:
setUpBridgeAndThing();
DeviceState deviceStateBefore = mock(DeviceState.class);
when(deviceStateBefore.getDeviceIdentifier()).thenReturn(DRYER_DEVICE_THING_UID.getId());
when(deviceStateBefore.getStateType()).thenReturn(Optional.of(StateType.RUNNING));
@ -160,8 +166,10 @@ public class DryerDeviceThingHandlerTest extends AbstractMieleThingHandlerTest {
}
@Test
public void testTransitionChannelUpdatesForNullValues() {
public void testTransitionChannelUpdatesForNullValues() throws Exception {
// given:
setUpBridgeAndThing();
DeviceState deviceStateBefore = mock(DeviceState.class);
when(deviceStateBefore.getDeviceIdentifier()).thenReturn(DRYER_DEVICE_THING_UID.getId());
when(deviceStateBefore.getStateType()).thenReturn(Optional.of(StateType.RUNNING));
@ -188,8 +196,10 @@ public class DryerDeviceThingHandlerTest extends AbstractMieleThingHandlerTest {
}
@Test
public void testTransitionChannelUpdatesForValidValues() {
public void testTransitionChannelUpdatesForValidValues() throws Exception {
// given:
setUpBridgeAndThing();
DeviceState deviceStateBefore = mock(DeviceState.class);
when(deviceStateBefore.getDeviceIdentifier()).thenReturn(DRYER_DEVICE_THING_UID.getId());
when(deviceStateBefore.getStateType()).thenReturn(Optional.of(StateType.RUNNING));
@ -216,8 +226,10 @@ public class DryerDeviceThingHandlerTest extends AbstractMieleThingHandlerTest {
}
@Test
public void testActionsChannelUpdatesForValidValues() {
public void testActionsChannelUpdatesForValidValues() throws Exception {
// given:
setUpBridgeAndThing();
ActionsState actionsState = mock(ActionsState.class);
when(actionsState.getDeviceIdentifier()).thenReturn(DRYER_DEVICE_THING_UID.getId());
when(actionsState.canBeStarted()).thenReturn(true);

View File

@ -44,8 +44,10 @@ public class HobDeviceThingHandlerTest extends AbstractMieleThingHandlerTest {
}
@Test
public void testChannelUpdatesForNullValues() {
public void testChannelUpdatesForNullValues() throws Exception {
// given:
setUpBridgeAndThing();
DeviceState deviceState = mock(DeviceState.class);
when(deviceState.getDeviceIdentifier()).thenReturn(HOB_DEVICE_THING_UID.getId());
when(deviceState.getStateType()).thenReturn(Optional.empty());
@ -78,8 +80,10 @@ public class HobDeviceThingHandlerTest extends AbstractMieleThingHandlerTest {
}
@Test
public void testChannelUpdatesForValidValues() {
public void testChannelUpdatesForValidValues() throws Exception {
// given:
setUpBridgeAndThing();
DeviceState deviceState = mock(DeviceState.class);
when(deviceState.getDeviceIdentifier()).thenReturn(HOB_DEVICE_THING_UID.getId());
when(deviceState.getStateType()).thenReturn(Optional.of(StateType.RUNNING));

View File

@ -44,8 +44,10 @@ public class HoodDeviceThingHandlerTest extends AbstractMieleThingHandlerTest {
}
@Test
public void testChannelUpdatesForNullValues() {
public void testChannelUpdatesForNullValues() throws Exception {
// given:
setUpBridgeAndThing();
DeviceState deviceState = mock(DeviceState.class);
when(deviceState.getDeviceIdentifier()).thenReturn(HOOD_DEVICE_THING_UID.getId());
when(deviceState.getStateType()).thenReturn(Optional.empty());
@ -75,8 +77,10 @@ public class HoodDeviceThingHandlerTest extends AbstractMieleThingHandlerTest {
}
@Test
public void testChannelUpdatesForValidValues() {
public void testChannelUpdatesForValidValues() throws Exception {
// given:
setUpBridgeAndThing();
DeviceState deviceState = mock(DeviceState.class);
when(deviceState.getDeviceIdentifier()).thenReturn(HOOD_DEVICE_THING_UID.getId());
when(deviceState.getStateType()).thenReturn(Optional.of(StateType.RUNNING));
@ -110,8 +114,10 @@ public class HoodDeviceThingHandlerTest extends AbstractMieleThingHandlerTest {
}
@Test
public void testActionsChannelUpdatesForValidValues() {
public void testActionsChannelUpdatesForValidValues() throws Exception {
// given:
setUpBridgeAndThing();
ActionsState actionsState = mock(ActionsState.class);
when(actionsState.getDeviceIdentifier()).thenReturn(HOOD_DEVICE_THING_UID.getId());
when(actionsState.canBeSwitchedOn()).thenReturn(true);

View File

@ -50,8 +50,10 @@ public class OvenDeviceThingHandlerTest extends AbstractMieleThingHandlerTest {
}
@Test
public void testChannelUpdatesForNullValues() {
public void testChannelUpdatesForNullValues() throws Exception {
// given:
setUpBridgeAndThing();
DeviceState deviceState = mock(DeviceState.class);
when(deviceState.getDeviceIdentifier()).thenReturn(OVEN_DEVICE_THING_UID.getId());
when(deviceState.getStateType()).thenReturn(Optional.empty());
@ -94,8 +96,10 @@ public class OvenDeviceThingHandlerTest extends AbstractMieleThingHandlerTest {
}
@Test
public void testChannelUpdatesForValidValues() {
public void testChannelUpdatesForValidValues() throws Exception {
// given:
setUpBridgeAndThing();
DeviceState deviceState = mock(DeviceState.class);
when(deviceState.isInState(any())).thenCallRealMethod();
when(deviceState.getDeviceIdentifier()).thenReturn(OVEN_DEVICE_THING_UID.getId());
@ -143,8 +147,10 @@ public class OvenDeviceThingHandlerTest extends AbstractMieleThingHandlerTest {
}
@Test
public void testFinishStateChannelIsSetToOnWhenProgramHasFinished() {
public void testFinishStateChannelIsSetToOnWhenProgramHasFinished() throws Exception {
// given:
setUpBridgeAndThing();
DeviceState deviceStateBefore = mock(DeviceState.class);
when(deviceStateBefore.getDeviceIdentifier()).thenReturn(OVEN_DEVICE_THING_UID.getId());
when(deviceStateBefore.getStateType()).thenReturn(Optional.of(StateType.RUNNING));
@ -167,8 +173,10 @@ public class OvenDeviceThingHandlerTest extends AbstractMieleThingHandlerTest {
}
@Test
public void testTransitionChannelUpdatesForNullValues() {
public void testTransitionChannelUpdatesForNullValues() throws Exception {
// given:
setUpBridgeAndThing();
DeviceState deviceStateBefore = mock(DeviceState.class);
when(deviceStateBefore.getDeviceIdentifier()).thenReturn(OVEN_DEVICE_THING_UID.getId());
when(deviceStateBefore.getStateType()).thenReturn(Optional.of(StateType.RUNNING));
@ -195,8 +203,10 @@ public class OvenDeviceThingHandlerTest extends AbstractMieleThingHandlerTest {
}
@Test
public void testTransitionChannelUpdatesForValidValues() {
public void testTransitionChannelUpdatesForValidValues() throws Exception {
// given:
setUpBridgeAndThing();
DeviceState deviceStateBefore = mock(DeviceState.class);
when(deviceStateBefore.getDeviceIdentifier()).thenReturn(OVEN_DEVICE_THING_UID.getId());
when(deviceStateBefore.getStateType()).thenReturn(Optional.of(StateType.RUNNING));
@ -223,8 +233,10 @@ public class OvenDeviceThingHandlerTest extends AbstractMieleThingHandlerTest {
}
@Test
public void testActionsChannelUpdatesForValidValues() {
public void testActionsChannelUpdatesForValidValues() throws Exception {
// given:
setUpBridgeAndThing();
ActionsState actionsState = mock(ActionsState.class);
when(actionsState.getDeviceIdentifier()).thenReturn(OVEN_DEVICE_THING_UID.getId());
when(actionsState.canBeStarted()).thenReturn(true);

View File

@ -45,8 +45,10 @@ public class RoboticVacuumCleanerDeviceThingHandlerTest extends AbstractMieleThi
}
@Test
public void testChannelUpdatesForNullValues() {
public void testChannelUpdatesForNullValues() throws Exception {
// given:
setUpBridgeAndThing();
DeviceState deviceState = mock(DeviceState.class);
when(deviceState.getDeviceIdentifier())
.thenReturn(MieleCloudBindingIntegrationTestConstants.ROBOTIC_VACUUM_CLEANER_THING_UID.getId());
@ -76,8 +78,10 @@ public class RoboticVacuumCleanerDeviceThingHandlerTest extends AbstractMieleThi
}
@Test
public void testChannelUpdatesForValidValues() {
public void testChannelUpdatesForValidValues() throws Exception {
// given:
setUpBridgeAndThing();
DeviceState deviceState = mock(DeviceState.class);
when(deviceState.isInState(any())).thenCallRealMethod();
when(deviceState.getDeviceIdentifier())
@ -108,8 +112,10 @@ public class RoboticVacuumCleanerDeviceThingHandlerTest extends AbstractMieleThi
}
@Test
public void testFinishStateChannelIsSetToOnWhenProgramHasFinished() {
public void testFinishStateChannelIsSetToOnWhenProgramHasFinished() throws Exception {
// given:
setUpBridgeAndThing();
DeviceState deviceStateBefore = mock(DeviceState.class);
when(deviceStateBefore.getDeviceIdentifier())
.thenReturn(MieleCloudBindingIntegrationTestConstants.ROBOTIC_VACUUM_CLEANER_THING_UID.getId());
@ -134,8 +140,10 @@ public class RoboticVacuumCleanerDeviceThingHandlerTest extends AbstractMieleThi
}
@Test
public void testActionsChannelUpdatesForValidValues() {
public void testActionsChannelUpdatesForValidValues() throws Exception {
// given:
setUpBridgeAndThing();
ActionsState actionsState = mock(ActionsState.class);
when(actionsState.getDeviceIdentifier())
.thenReturn(MieleCloudBindingIntegrationTestConstants.ROBOTIC_VACUUM_CLEANER_THING_UID.getId());
@ -157,7 +165,10 @@ public class RoboticVacuumCleanerDeviceThingHandlerTest extends AbstractMieleThi
}
@Test
public void testHandleCommandVacuumCleanerProgramActive() {
public void testHandleCommandVacuumCleanerProgramActive() throws Exception {
// given:
setUpBridgeAndThing();
// when:
getThingHandler().handleCommand(channel(VACUUM_CLEANER_PROGRAM_ACTIVE), new StringType("1"));

View File

@ -50,8 +50,10 @@ public class WashingDeviceThingHandlerTest extends AbstractMieleThingHandlerTest
}
@Test
public void testChannelUpdatesForNullValues() {
public void testChannelUpdatesForNullValues() throws Exception {
// given:
setUpBridgeAndThing();
DeviceState deviceState = mock(DeviceState.class);
when(deviceState.getDeviceIdentifier()).thenReturn(WASHING_MACHINE_THING_UID.getId());
when(deviceState.getStateType()).thenReturn(Optional.empty());
@ -94,8 +96,10 @@ public class WashingDeviceThingHandlerTest extends AbstractMieleThingHandlerTest
}
@Test
public void testChannelUpdatesForValidValues() {
public void testChannelUpdatesForValidValues() throws Exception {
// given:
setUpBridgeAndThing();
DeviceState deviceState = mock(DeviceState.class);
when(deviceState.isInState(any())).thenCallRealMethod();
when(deviceState.getDeviceIdentifier()).thenReturn(WASHING_MACHINE_THING_UID.getId());
@ -143,8 +147,10 @@ public class WashingDeviceThingHandlerTest extends AbstractMieleThingHandlerTest
}
@Test
public void testFinishStateChannelIsSetToOnWhenProgramHasFinished() {
public void testFinishStateChannelIsSetToOnWhenProgramHasFinished() throws Exception {
// given:
setUpBridgeAndThing();
DeviceState deviceStateBefore = mock(DeviceState.class);
when(deviceStateBefore.getDeviceIdentifier()).thenReturn(WASHING_MACHINE_THING_UID.getId());
when(deviceStateBefore.getStateType()).thenReturn(Optional.of(StateType.RUNNING));
@ -167,8 +173,10 @@ public class WashingDeviceThingHandlerTest extends AbstractMieleThingHandlerTest
}
@Test
public void testTransitionChannelUpdatesForNullValues() {
public void testTransitionChannelUpdatesForNullValues() throws Exception {
// given:
setUpBridgeAndThing();
DeviceState deviceStateBefore = mock(DeviceState.class);
when(deviceStateBefore.getDeviceIdentifier()).thenReturn(WASHING_MACHINE_THING_UID.getId());
when(deviceStateBefore.getStateType()).thenReturn(Optional.of(StateType.RUNNING));
@ -195,8 +203,10 @@ public class WashingDeviceThingHandlerTest extends AbstractMieleThingHandlerTest
}
@Test
public void testTransitionChannelUpdatesForValidValues() {
public void testTransitionChannelUpdatesForValidValues() throws Exception {
// given:
setUpBridgeAndThing();
DeviceState deviceStateBefore = mock(DeviceState.class);
when(deviceStateBefore.getDeviceIdentifier()).thenReturn(WASHING_MACHINE_THING_UID.getId());
when(deviceStateBefore.getStateType()).thenReturn(Optional.of(StateType.RUNNING));
@ -223,8 +233,10 @@ public class WashingDeviceThingHandlerTest extends AbstractMieleThingHandlerTest
}
@Test
public void testActionsChannelUpdatesForValidValues() {
public void testActionsChannelUpdatesForValidValues() throws Exception {
// given:
setUpBridgeAndThing();
ActionsState actionsState = mock(ActionsState.class);
when(actionsState.getDeviceIdentifier()).thenReturn(WASHING_MACHINE_THING_UID.getId());
when(actionsState.canBeStarted()).thenReturn(true);

View File

@ -47,8 +47,10 @@ public class WineStorageDeviceThingHandlerTest extends AbstractMieleThingHandler
}
@Test
public void testChannelUpdatesForNullValues() {
public void testChannelUpdatesForNullValues() throws Exception {
// given:
setUpBridgeAndThing();
DeviceState deviceState = mock(DeviceState.class);
when(deviceState.getDeviceIdentifier()).thenReturn(WINE_STORAGE_DEVICE_THING_UID.getId());
when(deviceState.getRawType()).thenReturn(DeviceType.WINE_CONDITIONING_UNIT);
@ -83,8 +85,10 @@ public class WineStorageDeviceThingHandlerTest extends AbstractMieleThingHandler
}
@Test
public void testChannelUpdatesForValidValues() {
public void testChannelUpdatesForValidValues() throws Exception {
// given:
setUpBridgeAndThing();
DeviceState deviceState = mock(DeviceState.class);
when(deviceState.getDeviceIdentifier()).thenReturn(WINE_STORAGE_DEVICE_THING_UID.getId());
when(deviceState.getRawType()).thenReturn(DeviceType.WINE_CONDITIONING_UNIT);
@ -123,8 +127,10 @@ public class WineStorageDeviceThingHandlerTest extends AbstractMieleThingHandler
}
@Test
public void testActionsChannelUpdatesForValidValues() {
public void testActionsChannelUpdatesForValidValues() throws Exception {
// given:
setUpBridgeAndThing();
ActionsState actionsState = mock(ActionsState.class);
when(actionsState.getDeviceIdentifier()).thenReturn(WINE_STORAGE_DEVICE_THING_UID.getId());
when(actionsState.canBeSwitchedOn()).thenReturn(true);