Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[scale] fix NPE #8013

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[..10]=Kaltweiß
]10..90[=Gemischt
[90..100]=Warmweiß
NaN=Unbekannt
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public Object put(Object key, Object value) {
* The method transforms the input <code>source</code> by matching searching
* the range where it fits i.e. [min..max]=value or ]min..max]=value
*
* @param properties the list of properties defining all the available ranges
* @param data the list of properties defining all the available ranges
* @param source the input to transform
*
*/
Expand Down 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/spektrum.scale";
String source = "2409";
String transformedResponse = processor.transform(existingscale, source);
Assert.assertEquals("", transformedResponse);
}
}