Java 17 features (H-M) (#15520)
- add missing @override - Java style array syntax - remove redundant modifiers - always move String constants to left side in comparisons - simplify lambda expressions and return statements - use replace instead of replaceAll w/o regex - instanceof matching and multiline strings - remove null check before instanceof Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
This commit is contained in:
@@ -170,7 +170,6 @@ public class GatewayPayloadParser {
|
||||
if (payloadIntermediate == null) {
|
||||
throw new JsonSyntaxException("JSON parsing failed");
|
||||
}
|
||||
GatewayPayload payload = new GatewayPayload(payloadIntermediate);
|
||||
return payload;
|
||||
return new GatewayPayload(payloadIntermediate);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,18 +113,16 @@ public class RuuviGatewayDiscoveryTests {
|
||||
}));
|
||||
|
||||
assertTrue(//
|
||||
discoveryResults.stream().anyMatch(result -> {
|
||||
return "DE:EA:DB:BE:FF:00"
|
||||
.equals(result.getProperties().get(RuuviGatewayBindingConstants.PROPERTY_TAG_ID))
|
||||
&& "ruuvi/foo/bar/de:ea:DB:be:ff:00".equals(result.getProperties()
|
||||
.get(RuuviGatewayBindingConstants.CONFIGURATION_PROPERTY_TOPIC));
|
||||
}) && //
|
||||
discoveryResults.stream().anyMatch(result -> {
|
||||
return "DE:EA:DB:BE:FF:01"
|
||||
.equals(result.getProperties().get(RuuviGatewayBindingConstants.PROPERTY_TAG_ID))
|
||||
&& "ruuvi/foo/bar/de:ea:DB:be:ff:01".equals(result.getProperties()
|
||||
.get(RuuviGatewayBindingConstants.CONFIGURATION_PROPERTY_TOPIC));
|
||||
})
|
||||
discoveryResults.stream().anyMatch(result -> "DE:EA:DB:BE:FF:00"
|
||||
.equals(result.getProperties().get(RuuviGatewayBindingConstants.PROPERTY_TAG_ID))
|
||||
&& "ruuvi/foo/bar/de:ea:DB:be:ff:00".equals(
|
||||
result.getProperties().get(RuuviGatewayBindingConstants.CONFIGURATION_PROPERTY_TOPIC)))
|
||||
&& //
|
||||
discoveryResults.stream()
|
||||
.anyMatch(result -> "DE:EA:DB:BE:FF:01".equals(
|
||||
result.getProperties().get(RuuviGatewayBindingConstants.PROPERTY_TAG_ID))
|
||||
&& "ruuvi/foo/bar/de:ea:DB:be:ff:01".equals(result.getProperties()
|
||||
.get(RuuviGatewayBindingConstants.CONFIGURATION_PROPERTY_TOPIC)))
|
||||
|
||||
, "Failed to match: " + discoveryResults.toString());
|
||||
}
|
||||
|
||||
@@ -114,13 +114,16 @@ public class GatewayPayloadParserTests {
|
||||
public void testUnexpectedTypes3() {
|
||||
assertThrows(JsonSyntaxException.class, () -> {
|
||||
GatewayPayloadParser.parse(bytes(//
|
||||
"{\"gw_mac\": \"DE:AD:BE:EF:00:00\","//
|
||||
+ " \"rssi\": \"foobar\","// should be number
|
||||
+ " \"aoa\": [],"//
|
||||
+ " \"gwts\": \"1659365438\","//
|
||||
+ " \"ts\": \"1659365438\","//
|
||||
+ " \"data\": \"0201061BFF99040512FC5394C37C0004FFFC040CAC364200CDCBB8334C884F\","
|
||||
+ " \"coords\": \"\"" + "}"));
|
||||
"""
|
||||
{"gw_mac": "DE:AD:BE:EF:00:00",\
|
||||
"rssi": "foobar",\
|
||||
"aoa": [],\
|
||||
"gwts": "1659365438",\
|
||||
"ts": "1659365438",\
|
||||
"data": "0201061BFF99040512FC5394C37C0004FFFC040CAC364200CDCBB8334C884F",\
|
||||
"coords": ""\
|
||||
}\
|
||||
"""));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -141,14 +144,16 @@ public class GatewayPayloadParserTests {
|
||||
public void testUnexpectedManufacturer() {
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
GatewayPayloadParser.parse(bytes(//
|
||||
"{\"gw_mac\": \"DE:AD:BE:EF:00:00\","//
|
||||
+ " \"rssi\": -83,"//
|
||||
+ " \"aoa\": [],"//
|
||||
+ " \"gwts\": \"1659365438\","//
|
||||
+ " \"ts\": \"1659365438\","//
|
||||
// manufacturer is not 99 04 (Ruuvi) but 99 99
|
||||
+ " \"data\": \"0201061BFF99990512FC5394C37C0004FFFC040CAC364200CDCBB8334C884F\","
|
||||
+ " \"coords\": \"\"" + "}"));
|
||||
"""
|
||||
{"gw_mac": "DE:AD:BE:EF:00:00",\
|
||||
"rssi": -83,\
|
||||
"aoa": [],\
|
||||
"gwts": "1659365438",\
|
||||
"ts": "1659365438",\
|
||||
"data": "0201061BFF99990512FC5394C37C0004FFFC040CAC364200CDCBB8334C884F",\
|
||||
"coords": ""\
|
||||
}\
|
||||
"""));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -156,14 +161,16 @@ public class GatewayPayloadParserTests {
|
||||
public void testDataNotBluetoothAdvertisement() {
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
GatewayPayloadParser.parse(bytes(//
|
||||
"{\"gw_mac\": \"DE:AD:BE:EF:00:00\","//
|
||||
+ " \"rssi\": -83,"//
|
||||
+ " \"aoa\": [],"//
|
||||
+ " \"gwts\": \"1659365438\","//
|
||||
+ " \"ts\": \"1659365438\","//
|
||||
// not advertisement (FF) but AA
|
||||
+ " \"data\": \"0201061BAA99040512FC5394C37C0004FFFC040CAC364200CDCBB8334C884F\","
|
||||
+ " \"coords\": \"\"" + "}"));
|
||||
"""
|
||||
{"gw_mac": "DE:AD:BE:EF:00:00",\
|
||||
"rssi": -83,\
|
||||
"aoa": [],\
|
||||
"gwts": "1659365438",\
|
||||
"ts": "1659365438",\
|
||||
"data": "0201061BAA99040512FC5394C37C0004FFFC040CAC364200CDCBB8334C884F",\
|
||||
"coords": ""\
|
||||
}\
|
||||
"""));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user