diff --git a/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/channel/KNXChannelFactory.java b/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/channel/KNXChannelFactory.java index 826ed573d00..b29a1f1c8ec 100644 --- a/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/channel/KNXChannelFactory.java +++ b/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/channel/KNXChannelFactory.java @@ -56,6 +56,7 @@ public final class KNXChannelFactory { .map(Map.Entry::getValue).findFirst() .orElseThrow(() -> new IllegalArgumentException(channelTypeUID + " is not a valid channel type ID")); - return supplier.apply(channel); + // typecast to avoid warning about unsafe return type; we know that the lookup returns non null values + return (KNXChannel) supplier.apply(channel); } } diff --git a/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/client/SerialTransportAdapter.java b/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/client/SerialTransportAdapter.java index 7028d4b668f..d80b5f3ee09 100644 --- a/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/client/SerialTransportAdapter.java +++ b/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/client/SerialTransportAdapter.java @@ -156,7 +156,9 @@ public class SerialTransportAdapter implements SerialCom { if (tmpSerialPortManager == null) { return Collections.emptyList(); } - return tmpSerialPortManager.getIdentifiers().map(SerialPortIdentifier::getName).collect(Collectors.toList()); + // typecast only required to avoid warning about less-annotated type + return (List) tmpSerialPortManager.getIdentifiers().map(SerialPortIdentifier::getName) + .collect(Collectors.toList()); } @Override diff --git a/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/dpt/DPTUnits.java b/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/dpt/DPTUnits.java index c6a06dda511..a550f2027bf 100644 --- a/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/dpt/DPTUnits.java +++ b/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/dpt/DPTUnits.java @@ -116,7 +116,7 @@ public class DPTUnits { DPT_UNIT_MAP.put(DPTXlator2ByteUnsigned.DPT_TIMEPERIOD_100.getID(), "ms"); // according to spec, it is ms // two byte signed (DPT 8) - DPT_UNIT_MAP.remove(DptXlator2ByteSigned.DptValueCount.getID()); // pulses habe no unit + DPT_UNIT_MAP.remove(DptXlator2ByteSigned.DptValueCount.getID()); // pulses have no unit // 4 byte unsigned (DPT 12) DPT_UNIT_MAP.remove(DPTXlator4ByteUnsigned.DPT_VALUE_4_UCOUNT.getID()); // counts have no unit diff --git a/bundles/org.openhab.binding.knx/src/test/java/org/openhab/binding/knx/internal/channel/KNXChannelFactoryTest.java b/bundles/org.openhab.binding.knx/src/test/java/org/openhab/binding/knx/internal/channel/KNXChannelFactoryTest.java index 78aa0586de0..e6bf0a50ccb 100644 --- a/bundles/org.openhab.binding.knx/src/test/java/org/openhab/binding/knx/internal/channel/KNXChannelFactoryTest.java +++ b/bundles/org.openhab.binding.knx/src/test/java/org/openhab/binding/knx/internal/channel/KNXChannelFactoryTest.java @@ -18,6 +18,7 @@ import static org.mockito.Mockito.when; import static org.openhab.binding.knx.internal.KNXBindingConstants.*; import java.util.Map; +import java.util.Objects; import org.eclipse.jdt.annotation.NonNullByDefault; import org.junit.jupiter.api.Test; @@ -42,7 +43,7 @@ class KNXChannelFactoryTest { */ @Test public void testNullChannelUidFails() { - Channel channel = mock(Channel.class); + Channel channel = Objects.requireNonNull(mock(Channel.class)); assertThrows(IllegalArgumentException.class, () -> { KNXChannelFactory.createKnxChannel(channel); @@ -51,7 +52,7 @@ class KNXChannelFactoryTest { @Test public void testInvalidChannelUidFails() { - Channel channel = mock(Channel.class); + Channel channel = Objects.requireNonNull(mock(Channel.class)); when(channel.getChannelTypeUID()).thenReturn(new ChannelTypeUID("a:b:c")); assertThrows(IllegalArgumentException.class, () -> { @@ -65,7 +66,7 @@ class KNXChannelFactoryTest { CHANNEL_NUMBER_CONTROL, CHANNEL_ROLLERSHUTTER, CHANNEL_ROLLERSHUTTER_CONTROL, CHANNEL_STRING, CHANNEL_STRING_CONTROL, CHANNEL_SWITCH, CHANNEL_SWITCH_CONTROL }) public void testSuccess(String channeltype) { - Channel channel = mock(Channel.class); + Channel channel = Objects.requireNonNull(mock(Channel.class)); Configuration configuration = new Configuration( Map.of("key1", "5.001:<1/2/3+4/5/6+1/5/6", "key2", "1.001:7/1/9+1/1/2")); when(channel.getChannelTypeUID()).thenReturn(new ChannelTypeUID("knx:" + channeltype)); diff --git a/bundles/org.openhab.binding.knx/src/test/java/org/openhab/binding/knx/internal/channel/KNXChannelTest.java b/bundles/org.openhab.binding.knx/src/test/java/org/openhab/binding/knx/internal/channel/KNXChannelTest.java index 866a1410f1c..560fbe09fce 100644 --- a/bundles/org.openhab.binding.knx/src/test/java/org/openhab/binding/knx/internal/channel/KNXChannelTest.java +++ b/bundles/org.openhab.binding.knx/src/test/java/org/openhab/binding/knx/internal/channel/KNXChannelTest.java @@ -18,6 +18,7 @@ import static org.mockito.Mockito.when; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -139,7 +140,7 @@ class KNXChannelTest { @Test public void testChannelGaParsing() throws KNXFormatException { - Channel channel = mock(Channel.class); + Channel channel = Objects.requireNonNull(mock(Channel.class)); Configuration configuration = new Configuration( Map.of("key1", "5.001:<1/2/3+4/5/6+1/5/6", "key2", "1.001:7/1/9+1/1/2")); when(channel.getChannelTypeUID()).thenReturn(new ChannelTypeUID("a:b:c")); diff --git a/bundles/org.openhab.binding.knx/src/test/java/org/openhab/binding/knx/internal/dpt/DPTTest.java b/bundles/org.openhab.binding.knx/src/test/java/org/openhab/binding/knx/internal/dpt/DPTTest.java index 71c3b7ab56d..cda7f4c796c 100644 --- a/bundles/org.openhab.binding.knx/src/test/java/org/openhab/binding/knx/internal/dpt/DPTTest.java +++ b/bundles/org.openhab.binding.knx/src/test/java/org/openhab/binding/knx/internal/dpt/DPTTest.java @@ -59,17 +59,16 @@ class DPTTest { } @Test - @SuppressWarnings("null") void testToDPT5ValueFromQuantityType() { assertEquals("80", ValueEncoder.encode(new QuantityType<>("80 %"), "5.001")); assertEquals("180", ValueEncoder.encode(new QuantityType<>("180 °"), "5.003")); - assertTrue(ValueEncoder.encode(new QuantityType<>("3.14 rad"), "5.003").startsWith("179.")); + assertTrue(Objects.requireNonNullElse(ValueEncoder.encode(new QuantityType<>("3.14 rad"), "5.003"), "") + .startsWith("179.")); assertEquals("80", ValueEncoder.encode(new QuantityType<>("80 %"), "5.004")); } @Test - @SuppressWarnings("null") void testToDPT7ValueFromQuantityType() { assertEquals("1000", ValueEncoder.encode(new QuantityType<>("1000 ms"), "7.002")); assertEquals("1000", ValueEncoder.encode(new QuantityType<>("1000 ms"), "7.003")); @@ -86,7 +85,6 @@ class DPTTest { } @Test - @SuppressWarnings("null") void testToDPT8ValueFromQuantityType() { assertEquals("1000", ValueEncoder.encode(new QuantityType<>("1000 ms"), "8.002")); assertEquals("1000", ValueEncoder.encode(new QuantityType<>("1000 ms"), "8.003")); @@ -100,7 +98,6 @@ class DPTTest { } @Test - @SuppressWarnings("null") void testToDPT9ValueFromQuantityType() { assertEquals("23.1", ValueEncoder.encode(new QuantityType<>("23.1 °C"), "9.001")); assertEquals(5.0, @@ -109,14 +106,16 @@ class DPTTest { assertEquals("1", ValueEncoder.encode(new QuantityType<>("1 K"), "9.002")); assertEquals("1", ValueEncoder.encode(new QuantityType<>("1000 mK"), "9.002")); assertEquals("1", ValueEncoder.encode(new QuantityType<>("1 °C"), "9.002")); - assertTrue(ValueEncoder.encode(new QuantityType<>("1 °F"), "9.002").startsWith("0.55")); + assertTrue(Objects.requireNonNullElse(ValueEncoder.encode(new QuantityType<>("1 °F"), "9.002"), "") + .startsWith("0.55")); assertEquals("1", ValueEncoder.encode(new QuantityType<>("1 K/h"), "9.003")); assertEquals("1", ValueEncoder.encode(new QuantityType<>("1 °C/h"), "9.003")); assertEquals("1", ValueEncoder.encode(new QuantityType<>("1000 mK/h"), "9.003")); assertEquals("600", ValueEncoder.encode(new QuantityType<>("10 K/min"), "9.003")); assertEquals("100", ValueEncoder.encode(new QuantityType<>("100 lx"), "9.004")); assertEquals("1", ValueEncoder.encode(new QuantityType<>("1 m/s"), "9.005")); - assertTrue(ValueEncoder.encode(new QuantityType<>("1.94 kn"), "9.005").startsWith("0.99")); + assertTrue(Objects.requireNonNullElse(ValueEncoder.encode(new QuantityType<>("1.94 kn"), "9.005"), "") + .startsWith("0.99")); assertEquals(1.0, Double .parseDouble(Objects.requireNonNull(ValueEncoder.encode(new QuantityType<>("3.6 km/h"), "9.005")))); assertEquals("456", ValueEncoder.encode(new QuantityType<>("456 Pa"), "9.006")); @@ -133,34 +132,33 @@ class DPTTest { assertEquals("12", ValueEncoder.encode(new QuantityType<>("12 W/m²"), "9.022")); assertEquals("1", ValueEncoder.encode(new QuantityType<>("1 K/%"), "9.023")); assertEquals("1", ValueEncoder.encode(new QuantityType<>("1 °C/%"), "9.023")); - assertTrue(ValueEncoder.encode(new QuantityType<>("1 °F/%"), "9.023").startsWith("0.55")); + assertTrue(Objects.requireNonNullElse(ValueEncoder.encode(new QuantityType<>("1 °F/%"), "9.023"), "") + .startsWith("0.55")); assertEquals("1", ValueEncoder.encode(new QuantityType<>("1 kW"), "9.024")); assertEquals("1", ValueEncoder.encode(new QuantityType<>("1 l/h"), "9.025")); assertEquals("60", ValueEncoder.encode(new QuantityType<>("1 l/min"), "9.025")); assertEquals("1", ValueEncoder.encode(new QuantityType<>("1 l/m²"), "9.026")); assertEquals("1", ValueEncoder.encode(new QuantityType<>("1 °F"), "9.027")); - assertTrue(ValueEncoder.encode(new QuantityType<>("-12 °C"), "9.027").startsWith("10.")); + assertTrue(Objects.requireNonNullElse(ValueEncoder.encode(new QuantityType<>("-12 °C"), "9.027"), "") + .startsWith("10.")); assertEquals("10", ValueEncoder.encode(new QuantityType<>("10 km/h"), "9.028")); assertEquals("1", ValueEncoder.encode(new QuantityType<>("1 g/m³"), "9.029")); assertEquals("1", ValueEncoder.encode(new QuantityType<>("1 µg/m³"), "9.030")); } @Test - @SuppressWarnings("null") void testToDPT10ValueFromQuantityType() { - // DateTimeTyype, not QuantityType + // DateTimeType, not QuantityType assertEquals("Wed, 17:30:00", ValueEncoder.encode(new DateTimeType("2019-06-12T17:30:00Z"), "10.001")); } @Test - @SuppressWarnings("null") void testToDPT11ValueFromQuantityType() { - // DateTimeTyype, not QuantityType + // DateTimeType, not QuantityType assertEquals("2019-06-12", ValueEncoder.encode(new DateTimeType("2019-06-12T17:30:00Z"), "11.001")); } @Test - @SuppressWarnings("null") void testToDPT12ValueFromQuantityType() { // 12.001: dimensionless @@ -174,7 +172,6 @@ class DPTTest { } @Test - @SuppressWarnings("null") void testToDPT13ValueFromQuantityType() { // 13.001 dimensionless assertEquals("24", ValueEncoder.encode(new QuantityType<>("24 m³/h"), "13.002")); @@ -195,7 +192,6 @@ class DPTTest { } @Test - @SuppressWarnings("null") void testToDPT14ValueFromQuantityType() { assertEquals("1", ValueEncoder.encode(new QuantityType<>("1 m/s²"), "14.000")); assertEquals("1", ValueEncoder.encode(new QuantityType<>("1 rad/s²"), "14.001")); @@ -287,9 +283,8 @@ class DPTTest { } @Test - @SuppressWarnings("null") void testToDPT19ValueFromQuantityType() { - // DateTimeTyype, not QuantityType + // DateTimeType, not QuantityType assertEquals("2019-06-12 17:30:00", ValueEncoder.encode(new DateTimeType("2019-06-12T17:30:00Z"), "19.001")); } @@ -358,7 +353,7 @@ class DPTTest { assertNotEquals(DPTXlator2ByteUnsigned.DPT_TIMEPERIOD_100.getUnit(), "ms"); // according to spec, it is ms // two byte signed (DPT 8, DPTXlator is missing in calimero 2.5-M1) - assertNotEquals("", DptXlator2ByteSigned.DptValueCount.getUnit()); // pulses habe no unit + assertNotEquals("", DptXlator2ByteSigned.DptValueCount.getUnit()); // pulses have no unit // 4 byte unsigned (DPT 12) assertNotEquals("", DPTXlator4ByteUnsigned.DPT_VALUE_4_UCOUNT.getUnit()); // counts have no unit