diff --git a/src/test/java/fr/inra/oresing/checker/GroovyLineCheckerTest.java b/src/test/java/fr/inra/oresing/checker/GroovyLineCheckerTest.java index 89f9842c1cc9961bd99c69c5397490dffbe99baf..47ce879aa85871564cbf5f13af44e6d53d5744c8 100644 --- a/src/test/java/fr/inra/oresing/checker/GroovyLineCheckerTest.java +++ b/src/test/java/fr/inra/oresing/checker/GroovyLineCheckerTest.java @@ -3,6 +3,7 @@ package fr.inra.oresing.checker; import com.google.common.collect.ImmutableMap; import fr.inra.oresing.OreSiTechnicalException; import fr.inra.oresing.model.VariableComponentKey; +import fr.inra.oresing.rest.ValidationCheckResult; import jdk.jshell.JShell; import jdk.jshell.SnippetEvent; import lombok.extern.slf4j.Slf4j; @@ -67,6 +68,33 @@ public class GroovyLineCheckerTest { } } + @Test + public void testCheckerWithNonBooleanValue() { + String expression = String.join("\n" + , "Integer température = Integer.parseInt(datum.get(\"temperature\").get(\"valeur\"));" + , "String unité = datum.get(\"temperature\").get(\"unité\");" + , "if (\"°C\".equals(unité)) {" + , " return température +273.15;" + , "} else if (\"kelvin\".equals(unité)) {" + , " return température;" + , "}" + , "throw new IllegalArgumentException(\"unité inconnue, \" + unité);" + ); + + GroovyLineChecker groovyLineChecker = GroovyLineChecker.forExpression(expression); + ImmutableMap<VariableComponentKey, String> validDatum = + ImmutableMap.of( + new VariableComponentKey("temperature", "valeur"), "-12", + new VariableComponentKey("temperature", "unité"), "°C" + ); + try { + ValidationCheckResult validation = groovyLineChecker.check(validDatum); + Assert.fail("une exception aurait dû être levée"); + } catch (OreSiTechnicalException e) { + Assert.assertTrue(e.getMessage().contains("L'évaluation de l’expression n'a pas retourné une valeur booléenne mais 261.15.")); + } + } + @Test @Ignore("juste un essai") public void testJShell() {