[boschshc] Code enhancements and Sonar issue fixes (#15160)

* replace call to deprecated HSBType::getRGB() with
ColorUtil::hsbTosRgb()
* make constructors of abstract classes protected
* use instanceof with pattern matching (JEP 305)
* enhance switches with combined cases using comma-separated case
expressions
* remove unnecessary public modifiers in unit tests

Signed-off-by: David Pace <dev@davidpace.de>
pull/15185/head
David Pace 2023-07-04 23:25:13 +02:00 committed by GitHub
parent 4775ad2a0d
commit 123982dcc6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
34 changed files with 140 additions and 144 deletions

View File

@ -37,7 +37,7 @@ public abstract class AbstractBatteryPoweredDeviceHandler extends BoschSHCDevice
*/
private final BatteryLevelService batteryLevelService;
public AbstractBatteryPoweredDeviceHandler(Thing thing) {
protected AbstractBatteryPoweredDeviceHandler(Thing thing) {
super(thing);
this.batteryLevelService = new BatteryLevelService();
}

View File

@ -74,8 +74,8 @@ public abstract class AbstractPowerSwitchHandler extends BoschSHCDeviceHandler {
switch (channelUID.getId()) {
case CHANNEL_POWER_SWITCH:
if (command instanceof OnOffType) {
updatePowerSwitchState((OnOffType) command);
if (command instanceof OnOffType onOffCommand) {
updatePowerSwitchState(onOffCommand);
}
break;
}

View File

@ -36,7 +36,7 @@ public abstract class AbstractSmokeDetectorHandler extends AbstractBatteryPowere
private SmokeDetectorCheckService smokeDetectorCheckService;
public AbstractSmokeDetectorHandler(Thing thing) {
protected AbstractSmokeDetectorHandler(Thing thing) {
super(thing);
this.smokeDetectorCheckService = new SmokeDetectorCheckService();
}

View File

@ -12,8 +12,7 @@
*/
package org.openhab.binding.boschshc.internal.devices.camera;
import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.CHANNEL_CAMERA_NOTIFICATION;
import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.CHANNEL_PRIVACY_MODE;
import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.*;
import java.util.List;
@ -35,18 +34,18 @@ import org.openhab.core.types.Command;
* Handler for security cameras.
* <p>
* This implementation handles services and commands that are common to all cameras, which are currently:
*
*
* <ul>
* <li><code>PrivacyMode</code> - Controls whether the camera records images</li>
* <li><code>CameraNotification</code> - Enables or disables notifications for the camera</li>
* </ul>
*
*
* <p>
* The Eyes outdoor camera advertises a <code>CameraLight</code> service, which unfortunately does not work properly.
* Valid states are <code>ON</code> and <code>OFF</code>.
* One of my two cameras returns <code>HTTP 204 (No Content)</code> when requesting the state.
* Once Bosch supports this service properly, a new subclass may be introduced for the Eyes outdoor camera.
*
*
* @author David Pace - Initial contribution
*
*/
@ -77,14 +76,14 @@ public class CameraHandler extends BoschSHCDeviceHandler {
switch (channelUID.getId()) {
case CHANNEL_PRIVACY_MODE:
if (command instanceof OnOffType) {
updatePrivacyModeState((OnOffType) command);
if (command instanceof OnOffType onOffCommand) {
updatePrivacyModeState(onOffCommand);
}
break;
case CHANNEL_CAMERA_NOTIFICATION:
if (command instanceof OnOffType) {
updateCameraNotificationState((OnOffType) command);
if (command instanceof OnOffType onOffCommand) {
updateCameraNotificationState(onOffCommand);
}
break;
}

View File

@ -71,31 +71,28 @@ public class ShutterControlHandler extends BoschSHCDeviceHandler {
public void handleCommand(ChannelUID channelUID, Command command) {
super.handleCommand(channelUID, command);
if (command instanceof UpDownType) {
if (command instanceof UpDownType upDownCommand) {
// Set full close/open as target state
UpDownType upDownType = (UpDownType) command;
ShutterControlServiceState state = new ShutterControlServiceState();
if (upDownType == UpDownType.UP) {
if (upDownCommand == UpDownType.UP) {
state.level = 1.0;
} else if (upDownType == UpDownType.DOWN) {
} else if (upDownCommand == UpDownType.DOWN) {
state.level = 0.0;
} else {
logger.warn("Received unknown UpDownType command: {}", upDownType);
logger.warn("Received unknown UpDownType command: {}", upDownCommand);
return;
}
this.updateServiceState(this.shutterControlService, state);
} else if (command instanceof StopMoveType) {
StopMoveType stopMoveType = (StopMoveType) command;
if (stopMoveType == StopMoveType.STOP) {
} else if (command instanceof StopMoveType stopMoveCommand) {
if (stopMoveCommand == StopMoveType.STOP) {
// Set STOPPED operation state
ShutterControlServiceState state = new ShutterControlServiceState();
state.operationState = OperationState.STOPPED;
this.updateServiceState(this.shutterControlService, state);
}
} else if (command instanceof PercentType) {
} else if (command instanceof PercentType percentCommand) {
// Set specific level
PercentType percentType = (PercentType) command;
double level = DataConversion.openPercentageToLevel(percentType.doubleValue());
double level = DataConversion.openPercentageToLevel(percentCommand.doubleValue());
this.updateServiceState(this.shutterControlService, new ShutterControlServiceState(level));
}
}

View File

@ -31,6 +31,7 @@ import org.openhab.core.library.types.PercentType;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.Thing;
import org.openhab.core.types.Command;
import org.openhab.core.util.ColorUtil;
/**
* Handler for smart light bulbs connected via Zigbee, e.g. Ledvance Smart+ bulbs
@ -68,38 +69,38 @@ public class SmartBulbHandler extends BoschSHCDeviceHandler {
switch (channelUID.getId()) {
case CHANNEL_POWER_SWITCH:
if (command instanceof OnOffType) {
updateBinarySwitchState((OnOffType) command);
if (command instanceof OnOffType onOffCommand) {
updateBinarySwitchState(onOffCommand);
}
break;
case CHANNEL_BRIGHTNESS:
if (command instanceof PercentType) {
updateMultiLevelSwitchState((PercentType) command);
if (command instanceof PercentType percentCommand) {
updateMultiLevelSwitchState(percentCommand);
}
break;
case CHANNEL_COLOR:
if (command instanceof HSBType) {
updateColorState((HSBType) command);
if (command instanceof HSBType hsbCommand) {
updateColorState(hsbCommand);
}
break;
}
}
private void updateBinarySwitchState(OnOffType command) {
private void updateBinarySwitchState(OnOffType onOffCommand) {
BinarySwitchServiceState serviceState = new BinarySwitchServiceState();
serviceState.on = command == OnOffType.ON;
serviceState.on = onOffCommand == OnOffType.ON;
this.updateServiceState(binarySwitchService, serviceState);
}
private void updateMultiLevelSwitchState(PercentType command) {
private void updateMultiLevelSwitchState(PercentType percentCommand) {
MultiLevelSwitchServiceState serviceState = new MultiLevelSwitchServiceState();
serviceState.level = command.intValue();
serviceState.level = percentCommand.intValue();
this.updateServiceState(multiLevelSwitchService, serviceState);
}
private void updateColorState(HSBType command) {
private void updateColorState(HSBType hsbCommand) {
HSBColorActuatorServiceState serviceState = new HSBColorActuatorServiceState();
serviceState.rgb = command.getRGB();
serviceState.rgb = ColorUtil.hsbTosRgb(hsbCommand);
this.updateServiceState(hsbColorActuatorService, serviceState);
}

View File

@ -88,8 +88,7 @@ public enum BatteryLevel {
switch (this) {
case LOW_BATTERY:
return new DecimalType(10);
case CRITICAL_LOW:
case CRITICALLY_LOW_BATTERY:
case CRITICAL_LOW, CRITICALLY_LOW_BATTERY:
return new DecimalType(1);
case NOT_AVAILABLE:
return UnDefType.UNDEF;
@ -108,9 +107,7 @@ public enum BatteryLevel {
*/
public OnOffType toLowBatteryState() {
switch (this) {
case LOW_BATTERY:
case CRITICAL_LOW:
case CRITICALLY_LOW_BATTERY:
case LOW_BATTERY, CRITICAL_LOW, CRITICALLY_LOW_BATTERY:
return OnOffType.ON;
default:
return OnOffType.OFF;

View File

@ -26,7 +26,7 @@ public enum SilentModeState {
MODE_NORMAL,
MODE_SILENT;
public static SilentModeState fromOnOffType(OnOffType onOffType) {
return onOffType == OnOffType.ON ? SilentModeState.MODE_SILENT : SilentModeState.MODE_NORMAL;
public static SilentModeState fromOnOffType(OnOffType onOffCommand) {
return onOffCommand == OnOffType.ON ? SilentModeState.MODE_SILENT : SilentModeState.MODE_NORMAL;
}
}

View File

@ -29,7 +29,7 @@ import org.openhab.core.thing.ThingTypeUID;
*
*/
@NonNullByDefault
public class BoschSHCHandlerFactoryTest {
class BoschSHCHandlerFactoryTest {
private @NonNullByDefault({}) BoschSHCHandlerFactory fixture;
@ -39,7 +39,7 @@ public class BoschSHCHandlerFactoryTest {
}
@Test
public void testSupportsThingType() {
void testSupportsThingType() {
assertTrue(fixture.supportsThingType(BoschSHCBindingConstants.THING_TYPE_SHC));
assertTrue(fixture.supportsThingType(BoschSHCBindingConstants.THING_TYPE_INWALL_SWITCH));
assertTrue(fixture.supportsThingType(BoschSHCBindingConstants.THING_TYPE_TWINGUARD));
@ -60,7 +60,7 @@ public class BoschSHCHandlerFactoryTest {
}
@Test
public void testCreateHandler() {
void testCreateHandler() {
Thing thing = mock(Thing.class);
when(thing.getThingTypeUID()).thenReturn(BoschSHCBindingConstants.THING_TYPE_SMART_PLUG_COMPACT);
assertTrue(fixture.createHandler(thing) instanceof PlugHandler);

View File

@ -24,7 +24,7 @@ import org.junit.jupiter.api.Test;
*
*/
@NonNullByDefault
public class BridgeConfigurationTest {
class BridgeConfigurationTest {
@Test
void testConstructor() {

View File

@ -25,7 +25,7 @@ import org.junit.jupiter.api.Test;
*
*/
@NonNullByDefault
public class JsonRpcRequestTest {
class JsonRpcRequestTest {
private @NonNullByDefault({}) JsonRpcRequest fixture;
@ -35,14 +35,14 @@ public class JsonRpcRequestTest {
}
@Test
public void testConstructor() {
void testConstructor() {
assertEquals("2.0", fixture.getJsonrpc());
assertEquals("RE/longPoll", fixture.getMethod());
assertArrayEquals(new String[] { "subscriptionId", "20" }, fixture.getParams());
}
@Test
public void testNoArgConstructor() {
void testNoArgConstructor() {
fixture = new JsonRpcRequest();
assertEquals("", fixture.getJsonrpc());
assertEquals("", fixture.getMethod());
@ -50,19 +50,19 @@ public class JsonRpcRequestTest {
}
@Test
public void testSetJsonrpc() {
void testSetJsonrpc() {
fixture.setJsonrpc("test");
assertEquals("test", fixture.getJsonrpc());
}
@Test
public void testSetMethod() {
void testSetMethod() {
fixture.setMethod("RE/subscribe");
assertEquals("RE/subscribe", fixture.getMethod());
}
@Test
public void testSetParams() {
void testSetParams() {
fixture.setParams(new String[] { "com/bosch/sh/remote/*", null });
assertArrayEquals(new String[] { "com/bosch/sh/remote/*", null }, fixture.getParams());
}

View File

@ -62,7 +62,7 @@ import com.google.gson.JsonObject;
*/
@NonNullByDefault
@ExtendWith(MockitoExtension.class)
public class LongPollingTest {
class LongPollingTest {
/**
* A dummy implementation of {@link ScheduledFuture}.

View File

@ -23,7 +23,7 @@ import org.junit.jupiter.api.Test;
* @author David Pace - Initial contribution
*
*/
public class DeviceServiceDataTest {
class DeviceServiceDataTest {
private DeviceServiceData fixture;
@ -34,7 +34,7 @@ public class DeviceServiceDataTest {
}
@Test
public void testToString() {
void testToString() {
assertEquals("64-da-a0-02-14-9b state: DeviceServiceData", fixture.toString());
}
}

View File

@ -60,7 +60,7 @@ public class DeviceTest {
}
@Test
public void testToString() {
void testToString() {
assertEquals(
"Type device; RootDeviceId: 64-da-a0-02-14-9b; Id: hdm:HomeMaticIP:3014F711A00004953859F31B; Device Service Ids: PowerMeter, PowerSwitch, PowerSwitchProgram, Routing; Manufacturer: BOSCH; Room Id: hz_3; Device Model: PSM; Serial: 3014F711A00004953859F31B; Profile: GENERIC; Name: Coffee Machine; Status: AVAILABLE; Child Device Ids: null ",
fixture.toString());

View File

@ -24,7 +24,7 @@ import org.openhab.binding.boschshc.internal.serialization.GsonUtils;
* @author Christian Oeing - Initial contribution
*/
@NonNullByDefault
public class LongPollResultTest {
class LongPollResultTest {
@Test
void noResultsForErrorResult() {

View File

@ -44,7 +44,7 @@ import com.google.gson.JsonParser;
*
*/
@NonNullByDefault
public class CameraHandlerTest extends AbstractBoschSHCDeviceHandlerTest<CameraHandler> {
class CameraHandlerTest extends AbstractBoschSHCDeviceHandlerTest<CameraHandler> {
private @Captor @NonNullByDefault({}) ArgumentCaptor<PrivacyModeServiceState> privacyModeServiceStateCaptor;
@ -66,7 +66,7 @@ public class CameraHandlerTest extends AbstractBoschSHCDeviceHandlerTest<CameraH
}
@Test
public void testHandleCommandPrivacyMode()
void testHandleCommandPrivacyMode()
throws InterruptedException, TimeoutException, ExecutionException, BoschSHCException {
getFixture().handleCommand(new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_PRIVACY_MODE),
OnOffType.ON);
@ -84,7 +84,7 @@ public class CameraHandlerTest extends AbstractBoschSHCDeviceHandlerTest<CameraH
}
@Test
public void testHandleCommandCameraNotification()
void testHandleCommandCameraNotification()
throws InterruptedException, TimeoutException, ExecutionException, BoschSHCException {
getFixture().handleCommand(
new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_CAMERA_NOTIFICATION),
@ -104,7 +104,7 @@ public class CameraHandlerTest extends AbstractBoschSHCDeviceHandlerTest<CameraH
}
@Test
public void testUpdateChannelsPrivacyModeState() {
void testUpdateChannelsPrivacyModeState() {
JsonElement jsonObject = JsonParser.parseString("{\"@type\":\"privacyModeState\",\"value\":\"ENABLED\"}");
getFixture().processUpdate("PrivacyMode", jsonObject);
verify(getCallback()).stateUpdated(
@ -117,7 +117,7 @@ public class CameraHandlerTest extends AbstractBoschSHCDeviceHandlerTest<CameraH
}
@Test
public void testUpdateChannelsCameraNotificationState() {
void testUpdateChannelsCameraNotificationState() {
JsonElement jsonObject = JsonParser
.parseString("{\"@type\":\"cameraNotificationState\",\"value\":\"ENABLED\"}");
getFixture().processUpdate("CameraNotification", jsonObject);

View File

@ -44,7 +44,7 @@ import com.google.gson.JsonParser;
*
*/
@NonNullByDefault
public class ClimateControlHandlerTest extends AbstractBoschSHCDeviceHandlerTest<ClimateControlHandler> {
class ClimateControlHandlerTest extends AbstractBoschSHCDeviceHandlerTest<ClimateControlHandler> {
private @Captor @NonNullByDefault({}) ArgumentCaptor<RoomClimateControlServiceState> roomClimateControlServiceStateCaptor;
@ -64,7 +64,7 @@ public class ClimateControlHandlerTest extends AbstractBoschSHCDeviceHandlerTest
}
@Test
public void testHandleCommandRoomClimateControlService()
void testHandleCommandRoomClimateControlService()
throws InterruptedException, TimeoutException, ExecutionException, BoschSHCException {
QuantityType<Temperature> temperature = new QuantityType<>(21.5, SIUnits.CELSIUS);
getFixture().handleCommand(
@ -77,7 +77,7 @@ public class ClimateControlHandlerTest extends AbstractBoschSHCDeviceHandlerTest
}
@Test
public void testUpdateChannelsTemperatureLevelService() {
void testUpdateChannelsTemperatureLevelService() {
JsonElement jsonObject = JsonParser.parseString(
"{\n" + " \"@type\": \"temperatureLevelState\",\n" + " \"temperature\": 21.5\n" + " }");
getFixture().processUpdate("TemperatureLevel", jsonObject);
@ -87,7 +87,7 @@ public class ClimateControlHandlerTest extends AbstractBoschSHCDeviceHandlerTest
}
@Test
public void testUpdateChannelsRoomClimateControlService() {
void testUpdateChannelsRoomClimateControlService() {
JsonElement jsonObject = JsonParser.parseString(
"{\n" + " \"@type\": \"climateControlState\",\n" + " \"setpointTemperature\": 21.5\n" + " }");
getFixture().processUpdate("RoomClimateControl", jsonObject);

View File

@ -41,7 +41,7 @@ import com.google.gson.JsonParser;
*
*/
@NonNullByDefault
public class IntrusionDetectionHandlerTest extends AbstractBoschSHCHandlerTest<IntrusionDetectionHandler> {
class IntrusionDetectionHandlerTest extends AbstractBoschSHCHandlerTest<IntrusionDetectionHandler> {
private @Captor @NonNullByDefault({}) ArgumentCaptor<ArmActionRequest> armActionRequestCaptor;
@ -56,7 +56,7 @@ public class IntrusionDetectionHandlerTest extends AbstractBoschSHCHandlerTest<I
}
@Test
public void testHandleCommandArmAction() throws InterruptedException, TimeoutException, ExecutionException {
void testHandleCommandArmAction() throws InterruptedException, TimeoutException, ExecutionException {
getFixture().handleCommand(new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_ARM_ACTION),
new StringType("0"));
verify(getBridgeHandler()).postAction(eq("intrusion/actions/arm"), armActionRequestCaptor.capture());
@ -65,21 +65,21 @@ public class IntrusionDetectionHandlerTest extends AbstractBoschSHCHandlerTest<I
}
@Test
public void testHandleCommandDisarmAction() throws InterruptedException, TimeoutException, ExecutionException {
void testHandleCommandDisarmAction() throws InterruptedException, TimeoutException, ExecutionException {
getFixture().handleCommand(new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_DISARM_ACTION),
OnOffType.ON);
verify(getBridgeHandler()).postAction("intrusion/actions/disarm");
}
@Test
public void testHandleCommandMuteAction() throws InterruptedException, TimeoutException, ExecutionException {
void testHandleCommandMuteAction() throws InterruptedException, TimeoutException, ExecutionException {
getFixture().handleCommand(new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_MUTE_ACTION),
OnOffType.ON);
verify(getBridgeHandler()).postAction("intrusion/actions/mute");
}
@Test
public void testUpdateChannelsIntrusionDetectionSystemState() {
void testUpdateChannelsIntrusionDetectionSystemState() {
JsonElement jsonObject = JsonParser.parseString("{\n" + " \"@type\": \"systemState\",\n"
+ " \"systemAvailability\": {\n" + " \"@type\": \"systemAvailabilityState\",\n"
+ " \"available\": true,\n" + " \"deleted\": false\n" + " },\n"
@ -108,7 +108,7 @@ public class IntrusionDetectionHandlerTest extends AbstractBoschSHCHandlerTest<I
}
@Test
public void testUpdateChannelsIntrusionDetectionControlState() {
void testUpdateChannelsIntrusionDetectionControlState() {
JsonElement jsonObject = JsonParser.parseString("{\n" + " \"@type\": \"intrusionDetectionControlState\",\n"
+ " \"activeProfile\": \"0\",\n" + " \"alarmActivationDelayTime\": 30,\n" + " \"actuators\": [\n"
+ " {\n" + " \"readonly\": false,\n" + " \"active\": true,\n"
@ -125,7 +125,7 @@ public class IntrusionDetectionHandlerTest extends AbstractBoschSHCHandlerTest<I
}
@Test
public void testUpdateChannelsSurveillanceAlarmState() {
void testUpdateChannelsSurveillanceAlarmState() {
JsonElement jsonObject = JsonParser.parseString("{\n" + " \"@type\": \"surveillanceAlarmState\",\n"
+ " \"incidents\": [\n" + " {\n" + " \"triggerName\": \"Motion Detector\",\n"
+ " \"locationId\": \"hz_5\",\n" + " \"location\": \"Living Room\",\n"

View File

@ -32,7 +32,7 @@ import com.google.gson.JsonParser;
*
*/
@NonNullByDefault
public class MotionDetectorHandlerTest extends AbstractBatteryPoweredDeviceHandlerTest<MotionDetectorHandler> {
class MotionDetectorHandlerTest extends AbstractBatteryPoweredDeviceHandlerTest<MotionDetectorHandler> {
@Override
protected MotionDetectorHandler createFixture() {
@ -50,7 +50,7 @@ public class MotionDetectorHandlerTest extends AbstractBatteryPoweredDeviceHandl
}
@Test
public void testUpdateChannelsLatestMotionService() {
void testUpdateChannelsLatestMotionService() {
JsonElement jsonObject = JsonParser.parseString("{\n" + " \"@type\": \"latestMotionState\",\n"
+ " \"latestMotionDetected\": \"2020-04-03T19:02:19.054Z\"\n" + " }");
getFixture().processUpdate("LatestMotion", jsonObject);

View File

@ -44,7 +44,7 @@ import com.google.gson.JsonParser;
*
*/
@NonNullByDefault
public class ShutterControlHandlerTest extends AbstractBoschSHCDeviceHandlerTest<ShutterControlHandler> {
class ShutterControlHandlerTest extends AbstractBoschSHCDeviceHandlerTest<ShutterControlHandler> {
private @Captor @NonNullByDefault({}) ArgumentCaptor<ShutterControlServiceState> shutterControlServiceStateCaptor;
@ -64,7 +64,7 @@ public class ShutterControlHandlerTest extends AbstractBoschSHCDeviceHandlerTest
}
@Test
public void testHandleCommandUpDownType()
void testHandleCommandUpDownType()
throws InterruptedException, TimeoutException, ExecutionException, BoschSHCException {
getFixture().handleCommand(new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_LEVEL),
UpDownType.UP);
@ -82,7 +82,7 @@ public class ShutterControlHandlerTest extends AbstractBoschSHCDeviceHandlerTest
}
@Test
public void testHandleCommandStopMoveType()
void testHandleCommandStopMoveType()
throws InterruptedException, TimeoutException, ExecutionException, BoschSHCException {
getFixture().handleCommand(new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_LEVEL),
StopMoveType.STOP);
@ -93,7 +93,7 @@ public class ShutterControlHandlerTest extends AbstractBoschSHCDeviceHandlerTest
}
@Test
public void testHandleCommandPercentType()
void testHandleCommandPercentType()
throws InterruptedException, TimeoutException, ExecutionException, BoschSHCException {
getFixture().handleCommand(new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_LEVEL),
new PercentType(42));
@ -104,7 +104,7 @@ public class ShutterControlHandlerTest extends AbstractBoschSHCDeviceHandlerTest
}
@Test
public void testUpdateChannelsShutterControlService() {
void testUpdateChannelsShutterControlService() {
JsonElement jsonObject = JsonParser
.parseString("{\n" + " \"@type\": \"shutterControlState\",\n" + " \"level\": 0.58\n" + " }");
getFixture().processUpdate("ShutterControl", jsonObject);

View File

@ -46,7 +46,7 @@ import com.google.gson.JsonParser;
*
*/
@NonNullByDefault
public class SmartBulbHandlerTest extends AbstractBoschSHCDeviceHandlerTest<SmartBulbHandler> {
class SmartBulbHandlerTest extends AbstractBoschSHCDeviceHandlerTest<SmartBulbHandler> {
private @Captor @NonNullByDefault({}) ArgumentCaptor<BinarySwitchServiceState> binarySwitchServiceStateCaptor;
@ -70,7 +70,7 @@ public class SmartBulbHandlerTest extends AbstractBoschSHCDeviceHandlerTest<Smar
}
@Test
public void testHandleCommandBinarySwitch()
void testHandleCommandBinarySwitch()
throws InterruptedException, TimeoutException, ExecutionException, BoschSHCException {
getFixture().handleCommand(new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_POWER_SWITCH),
OnOffType.ON);
@ -88,7 +88,7 @@ public class SmartBulbHandlerTest extends AbstractBoschSHCDeviceHandlerTest<Smar
}
@Test
public void testHandleCommandMultiLevelSwitch()
void testHandleCommandMultiLevelSwitch()
throws InterruptedException, TimeoutException, ExecutionException, BoschSHCException {
getFixture().handleCommand(new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_BRIGHTNESS),
new PercentType(42));
@ -99,7 +99,7 @@ public class SmartBulbHandlerTest extends AbstractBoschSHCDeviceHandlerTest<Smar
}
@Test
public void testHandleCommandHSBColorActuator()
void testHandleCommandHSBColorActuator()
throws InterruptedException, TimeoutException, ExecutionException, BoschSHCException {
getFixture().handleCommand(new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_COLOR),
HSBType.BLUE);
@ -110,7 +110,7 @@ public class SmartBulbHandlerTest extends AbstractBoschSHCDeviceHandlerTest<Smar
}
@Test
public void testUpdateChannelBinarySwitchState() {
void testUpdateChannelBinarySwitchState() {
JsonElement jsonObject = JsonParser.parseString("{\"@type\":\"binarySwitchState\",\"on\":true}");
getFixture().processUpdate("BinarySwitch", jsonObject);
verify(getCallback()).stateUpdated(
@ -123,7 +123,7 @@ public class SmartBulbHandlerTest extends AbstractBoschSHCDeviceHandlerTest<Smar
}
@Test
public void testUpdateChannelMultiLevelSwitchState() {
void testUpdateChannelMultiLevelSwitchState() {
JsonElement jsonObject = JsonParser.parseString("{\"@type\":\"multiLevelSwitchState\",\"level\":16}");
getFixture().processUpdate("MultiLevelSwitch", jsonObject);
verify(getCallback()).stateUpdated(
@ -131,7 +131,7 @@ public class SmartBulbHandlerTest extends AbstractBoschSHCDeviceHandlerTest<Smar
}
@Test
public void testUpdateChannelHSBColorActuatorState() {
void testUpdateChannelHSBColorActuatorState() {
JsonElement jsonObject = JsonParser.parseString("{\"colorTemperatureRange\": {\n" + " \"minCt\": 153,\n"
+ " \"maxCt\": 526\n" + " },\n" + " \"@type\": \"colorState\",\n"
+ " \"gamut\": \"LEDVANCE_GAMUT_A\",\n" + " \"rgb\": -12427}");

View File

@ -38,7 +38,7 @@ import com.google.gson.JsonParser;
*
*/
@NonNullByDefault
public class TwinguardHandlerTest extends AbstractSmokeDetectorHandlerTest<TwinguardHandler> {
class TwinguardHandlerTest extends AbstractSmokeDetectorHandlerTest<TwinguardHandler> {
@Override
protected TwinguardHandler createFixture() {
@ -56,7 +56,7 @@ public class TwinguardHandlerTest extends AbstractSmokeDetectorHandlerTest<Twing
}
@Test
public void testUpdateChannelsAirQualityLevelService() {
void testUpdateChannelsAirQualityLevelService() {
JsonElement jsonObject = JsonParser.parseString(
"{\"temperatureRating\":\"GOOD\",\"humidityRating\":\"MEDIUM\",\"purity\":620,\"@type\":\"airQualityLevelState\",\n"
+ " \"purityRating\":\"GOOD\",\"temperature\":23.77,\"description\":\"LITTLE_DRY\",\"humidity\":32.69,\"combinedRating\":\"MEDIUM\"}");

View File

@ -37,7 +37,7 @@ import com.google.gson.JsonParser;
*
*/
@NonNullByDefault
public class WallThermostatHandlerTest extends AbstractBatteryPoweredDeviceHandlerTest<WallThermostatHandler> {
class WallThermostatHandlerTest extends AbstractBatteryPoweredDeviceHandlerTest<WallThermostatHandler> {
@Override
protected WallThermostatHandler createFixture() {
@ -55,7 +55,7 @@ public class WallThermostatHandlerTest extends AbstractBatteryPoweredDeviceHandl
}
@Test
public void testUpdateChannelsTemperatureLevelService() {
void testUpdateChannelsTemperatureLevelService() {
JsonElement jsonObject = JsonParser.parseString(
"{\n" + " \"@type\": \"temperatureLevelState\",\n" + " \"temperature\": 21.5\n" + " }");
getFixture().processUpdate("TemperatureLevel", jsonObject);
@ -65,7 +65,7 @@ public class WallThermostatHandlerTest extends AbstractBatteryPoweredDeviceHandl
}
@Test
public void testUpdateChannelsHumidityLevelService() {
void testUpdateChannelsHumidityLevelService() {
JsonElement jsonObject = JsonParser
.parseString("{\n" + " \"@type\": \"humidityLevelState\",\n" + " \"humidity\": 42.5\n" + " }");
getFixture().processUpdate("HumidityLevel", jsonObject);

View File

@ -32,7 +32,7 @@ import com.google.gson.JsonParser;
*
*/
@NonNullByDefault
public class WindowContactHandlerTest extends AbstractBatteryPoweredDeviceHandlerTest<WindowContactHandler> {
class WindowContactHandlerTest extends AbstractBatteryPoweredDeviceHandlerTest<WindowContactHandler> {
@Override
protected WindowContactHandler createFixture() {
@ -50,7 +50,7 @@ public class WindowContactHandlerTest extends AbstractBatteryPoweredDeviceHandle
}
@Test
public void testUpdateChannelsShutterContactService() {
void testUpdateChannelsShutterContactService() {
JsonElement jsonObject = JsonParser
.parseString("{\n" + " \"@type\": \"shutterContactState\",\n" + " \"value\": \"OPEN\"\n" + " }");
getFixture().processUpdate("ShutterContact", jsonObject);

View File

@ -12,9 +12,10 @@
*/
package org.openhab.binding.boschshc.internal.discovery;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
import javax.jmdns.ServiceInfo;
@ -45,7 +46,7 @@ import org.openhab.core.thing.ThingUID;
@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.LENIENT)
@NonNullByDefault
public class BridgeDiscoveryParticipantTest {
class BridgeDiscoveryParticipantTest {
@Nullable
private BridgeDiscoveryParticipant fixture;
@ -76,30 +77,30 @@ public class BridgeDiscoveryParticipantTest {
}
/**
*
*
* Method: getSupportedThingTypeUIDs()
*
*
*/
@Test
public void testGetSupportedThingTypeUIDs() {
void testGetSupportedThingTypeUIDs() {
assert fixture != null;
assertTrue(fixture.getSupportedThingTypeUIDs().contains(BoschSHCBindingConstants.THING_TYPE_SHC));
}
/**
*
*
* Method: getServiceType()
*
*
*/
@Test
public void testGetServiceType() throws Exception {
void testGetServiceType() throws Exception {
assert fixture != null;
assertThat(fixture.getServiceType(), is("_http._tcp.local."));
}
@Test
public void testCreateResult() throws Exception {
void testCreateResult() throws Exception {
assert fixture != null;
DiscoveryResult result = fixture.createResult(shcBridge);
assertNotNull(result);
@ -110,14 +111,14 @@ public class BridgeDiscoveryParticipantTest {
}
@Test
public void testCreateResultOtherDevice() throws Exception {
void testCreateResultOtherDevice() throws Exception {
assert fixture != null;
DiscoveryResult result = fixture.createResult(otherDevice);
assertNull(result);
}
@Test
public void testGetThingUID() throws Exception {
void testGetThingUID() throws Exception {
assert fixture != null;
ThingUID thingUID = fixture.getThingUID(shcBridge);
assertNotNull(thingUID);
@ -126,32 +127,32 @@ public class BridgeDiscoveryParticipantTest {
}
@Test
public void testGetThingUIDOtherDevice() throws Exception {
void testGetThingUIDOtherDevice() throws Exception {
assert fixture != null;
assertNull(fixture.getThingUID(otherDevice));
}
@Test
public void testGetBridgeAddress() throws Exception {
void testGetBridgeAddress() throws Exception {
assert fixture != null;
assertThat(fixture.discoverBridge(shcBridge).shcIpAddress, is("192.168.0.123"));
}
@Test
public void testGetBridgeAddressOtherDevice() throws Exception {
void testGetBridgeAddressOtherDevice() throws Exception {
assert fixture != null;
assertThat(fixture.discoverBridge(otherDevice).shcIpAddress, is(""));
}
@Test
public void testGetPublicInformationFromPossibleBridgeAddress() throws Exception {
void testGetPublicInformationFromPossibleBridgeAddress() throws Exception {
assert fixture != null;
assertThat(fixture.getPublicInformationFromPossibleBridgeAddress("192.168.0.123").shcIpAddress,
is("192.168.0.123"));
}
@Test
public void testGetPublicInformationFromPossibleBridgeAddressInvalidContent() throws Exception {
void testGetPublicInformationFromPossibleBridgeAddressInvalidContent() throws Exception {
assert fixture != null;
ContentResponse contentResponse = mock(ContentResponse.class);
@ -170,7 +171,7 @@ public class BridgeDiscoveryParticipantTest {
}
@Test
public void testGetPublicInformationFromPossibleBridgeAddressInvalidStatus() throws Exception {
void testGetPublicInformationFromPossibleBridgeAddressInvalidStatus() throws Exception {
assert fixture != null;
ContentResponse contentResponse = mock(ContentResponse.class);

View File

@ -12,9 +12,10 @@
*/
package org.openhab.binding.boschshc.internal.discovery;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
import java.util.ArrayList;
@ -44,7 +45,7 @@ import org.openhab.core.thing.ThingUID;
*/
@ExtendWith(MockitoExtension.class)
@NonNullByDefault
public class ThingDiscoveryServiceTest {
class ThingDiscoveryServiceTest {
private @NonNullByDefault({}) ThingDiscoveryService fixture;
@ -69,7 +70,7 @@ public class ThingDiscoveryServiceTest {
}
@Test
public void testStartScan() throws InterruptedException {
void testStartScan() throws InterruptedException {
mockBridgeCalls();
fixture.activate();
@ -83,7 +84,7 @@ public class ThingDiscoveryServiceTest {
}
@Test
public void testStartScanWithoutBridgeHandler() {
void testStartScanWithoutBridgeHandler() {
mockBridgeCalls();
// No fixture.setThingHandler(bridgeHandler);
@ -96,13 +97,13 @@ public class ThingDiscoveryServiceTest {
}
@Test
public void testSetGetThingHandler() {
void testSetGetThingHandler() {
fixture.setThingHandler(bridgeHandler);
assertThat(fixture.getThingHandler(), is(bridgeHandler));
}
@Test
public void testAddDevices() {
void testAddDevices() {
mockBridgeCalls();
ArrayList<Device> devices = new ArrayList<>();
@ -128,7 +129,7 @@ public class ThingDiscoveryServiceTest {
}
@Test
public void testAddDevicesWithNoDevices() {
void testAddDevicesWithNoDevices() {
ArrayList<Device> emptyDevices = new ArrayList<>();
ArrayList<Room> emptyRooms = new ArrayList<>();
@ -141,7 +142,7 @@ public class ThingDiscoveryServiceTest {
}
@Test
public void testAddDevice() {
void testAddDevice() {
mockBridgeCalls();
Device device = new Device();
@ -159,26 +160,26 @@ public class ThingDiscoveryServiceTest {
assertThat(result.getThingUID().getId(), is("testDevice_ID"));
assertThat(result.getBridgeUID().getId(), is("testSHC"));
assertThat(result.getLabel(), is("Test Name"));
assertThat(result.getProperties().get("Location").toString(), is("TestRoom"));
assertThat(String.valueOf(result.getProperties().get("Location")), is("TestRoom"));
}
@Test
public void testAddDeviceWithNiceNameAndAppendedRoomName() {
void testAddDeviceWithNiceNameAndAppendedRoomName() {
assertDeviceNiceName("-RoomClimateControl-", "TestRoom", "Room Climate Control TestRoom");
}
@Test
public void testAddDeviceWithNiceNameWithEmtpyRoomName() {
void testAddDeviceWithNiceNameWithEmtpyRoomName() {
assertDeviceNiceName("-RoomClimateControl-", "", "Room Climate Control");
}
@Test
public void testAddDeviceWithNiceNameWithoutAppendingRoomName() {
void testAddDeviceWithNiceNameWithoutAppendingRoomName() {
assertDeviceNiceName("-SmokeDetectionSystem-", "TestRoom", "Smoke Detection System");
}
@Test
public void testAddDeviceWithNiceNameWithoutUsualName() {
void testAddDeviceWithNiceNameWithoutUsualName() {
assertDeviceNiceName("My other device", "TestRoom", "My other device");
}
@ -197,7 +198,7 @@ public class ThingDiscoveryServiceTest {
}
@Test
public void testGetRoomForDevice() {
void testGetRoomForDevice() {
Device device = new Device();
ArrayList<Room> rooms = new ArrayList<>();
@ -221,7 +222,7 @@ public class ThingDiscoveryServiceTest {
}
@Test
public void testGetThingTypeUID() {
void testGetThingTypeUID() {
Device device = new Device();
device.deviceModel = "invalid";

View File

@ -24,10 +24,10 @@ import org.junit.jupiter.api.Test;
*
*/
@NonNullByDefault
public class LongPollingFailedExceptionTest {
class LongPollingFailedExceptionTest {
@Test
public void testConstructor() {
void testConstructor() {
RuntimeException testException = new RuntimeException("test exception");
LongPollingFailedException longPollingFailedException = new LongPollingFailedException("message",
testException);

View File

@ -24,10 +24,10 @@ import org.junit.jupiter.api.Test;
*
*/
@NonNullByDefault
public class PairingFailedExceptionTest {
class PairingFailedExceptionTest {
@Test
public void testConstructor() {
void testConstructor() {
PairingFailedException fixture = new PairingFailedException();
assertNotNull(fixture);
assertNull(fixture.getMessage());
@ -35,7 +35,7 @@ public class PairingFailedExceptionTest {
}
@Test
public void testConstructorWithMessage() {
void testConstructorWithMessage() {
PairingFailedException fixture = new PairingFailedException("message");
assertNotNull(fixture);
assertEquals("message", fixture.getMessage());
@ -43,7 +43,7 @@ public class PairingFailedExceptionTest {
}
@Test
public void testConstructorWithMessageAndCause() {
void testConstructorWithMessageAndCause() {
RuntimeException testException = new RuntimeException("test exception");
PairingFailedException fixture = new PairingFailedException("message", testException);
assertNotNull(fixture);

View File

@ -23,7 +23,7 @@ import org.openhab.core.library.types.OnOffType;
* @author David Pace - Initial contribution
*
*/
public class BinarySwitchServiceStateTest {
class BinarySwitchServiceStateTest {
@Test
void testToOnOffType() {

View File

@ -48,10 +48,10 @@ class TestState2 extends BoschSHCServiceState {
* @author Christian Oeing - Initial contribution
*/
@NonNullByDefault
public class BoschSHCServiceStateTest {
class BoschSHCServiceStateTest {
@Test
public void fromJsonNullStateForDifferentType() {
void fromJsonNullStateForDifferentType() {
var state = BoschSHCServiceState.fromJson(
GsonUtils.DEFAULT_GSON_INSTANCE.fromJson("{\"@type\":\"differentState\"}", JsonObject.class),
TestState.class);
@ -59,7 +59,7 @@ public class BoschSHCServiceStateTest {
}
@Test
public void fromJsonStateObjectForValidJson() {
void fromJsonStateObjectForValidJson() {
var state = BoschSHCServiceState.fromJson(
GsonUtils.DEFAULT_GSON_INSTANCE.fromJson("{\"@type\":\"testState\"}", JsonObject.class),
TestState.class);
@ -70,7 +70,7 @@ public class BoschSHCServiceStateTest {
* This checks for a bug we had where the expected type stayed the same for different state classes
*/
@Test
public void fromJsonStateObjectForValidJsonAfterOtherState() {
void fromJsonStateObjectForValidJsonAfterOtherState() {
BoschSHCServiceState.fromJson(
GsonUtils.DEFAULT_GSON_INSTANCE.fromJson("{\"@type\":\"testState\"}", JsonObject.class),
TestState.class);

View File

@ -25,7 +25,7 @@ import org.junit.jupiter.api.Test;
*
*/
@NonNullByDefault
public class JsonRestExceptionResponseTest {
class JsonRestExceptionResponseTest {
private @NonNullByDefault({}) JsonRestExceptionResponse fixture;
@ -35,7 +35,7 @@ public class JsonRestExceptionResponseTest {
}
@Test
public void testIsValid() {
void testIsValid() {
assertFalse(JsonRestExceptionResponse.isValid(null));
assertTrue(JsonRestExceptionResponse.isValid(fixture));
fixture.errorCode = null;

View File

@ -23,7 +23,7 @@ import org.openhab.core.library.types.HSBType;
* @author David Pace - Initial contribution
*
*/
public class HSBColorActuatorServiceStateTest {
class HSBColorActuatorServiceStateTest {
@Test
void testToHSBType() {

View File

@ -23,7 +23,7 @@ import org.openhab.core.library.types.PercentType;
* @author David Pace - Initial contribution
*
*/
public class MultiLevelSwitchServiceStateTest {
class MultiLevelSwitchServiceStateTest {
@Test
void testToPercentType() {

View File

@ -19,12 +19,12 @@ import org.junit.jupiter.api.Test;
/**
* Unit tests for {@link SmokeDetectorCheckState}.
*
*
* @author David Pace - Initial contribution
*
*/
@NonNullByDefault
public class SmokeDetectorCheckStateTest {
class SmokeDetectorCheckStateTest {
@Test
void testFrom() {