Skip to content

Commit

Permalink
[scale] fix NPE in transformation (openhab#8124)
Browse files Browse the repository at this point in the history
Signed-off-by: Johannes DerOetzi Ott <[email protected]>t>
Signed-off-by: Daan Meijer <[email protected]>
  • Loading branch information
DerOetzi authored and DaanMeijer committed Sep 1, 2020
1 parent 7a3c6a1 commit a045452
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
[38..45]=avoid exertion
[45..54]=dangerous
[54..100]=heat stroke imminent
NaN=unknown
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private String formatResult(Map<Range, String> data, String source, final BigDec

private String getScaleResult(Map<Range, String> data, String source, final BigDecimal value)
throws TransformationException {
return data.entrySet().stream().filter(entry -> entry.getKey().contains(value)).findFirst()
return data.entrySet().stream().filter(entry -> entry.getKey() != null && entry.getKey().contains(value)).findFirst()
.map(Map.Entry::getValue)
.orElseThrow(() -> new TransformationException("No matching range for '" + source + "'"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,12 @@ public void testTransformAndFormat() throws TransformationException {
String transformedResponse = processor.transform(existingscale, source);
Assert.assertEquals("Correcte (992) !", transformedResponse);
}

@Test
public void testValueExceedsRange() throws TransformationException {
String existingscale = "scale/humidex.scale";
String source = "200";
String transformedResponse = processor.transform(existingscale, source);
Assert.assertEquals("", transformedResponse);
}
}

0 comments on commit a045452

Please sign in to comment.