From c1162b1200114afcc404e144166ab53c7539d355 Mon Sep 17 00:00:00 2001 From: gs-rpant1729 Date: Mon, 8 Apr 2024 19:58:24 +0530 Subject: [PATCH] add more data types coercions (#2757) --- .../FunctionParametersNormalizer.java | 71 +++++- .../test/TestParametersValidation.java | 219 +++++++++--------- 2 files changed, 174 insertions(+), 116 deletions(-) diff --git a/legend-engine-core/legend-engine-core-base/legend-engine-core-executionPlan-execution/legend-engine-executionPlan-execution/src/main/java/org/finos/legend/engine/plan/execution/validation/FunctionParametersNormalizer.java b/legend-engine-core/legend-engine-core-base/legend-engine-core-executionPlan-execution/legend-engine-executionPlan-execution/src/main/java/org/finos/legend/engine/plan/execution/validation/FunctionParametersNormalizer.java index 6dc76645bb1..ed0b2184404 100644 --- a/legend-engine-core/legend-engine-core-base/legend-engine-core-executionPlan-execution/legend-engine-executionPlan-execution/src/main/java/org/finos/legend/engine/plan/execution/validation/FunctionParametersNormalizer.java +++ b/legend-engine-core/legend-engine-core-base/legend-engine-core-executionPlan-execution/legend-engine-executionPlan-execution/src/main/java/org/finos/legend/engine/plan/execution/validation/FunctionParametersNormalizer.java @@ -21,6 +21,7 @@ import org.finos.legend.engine.plan.execution.result.date.EngineDate; import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.Variable; +import java.math.BigDecimal; import java.time.Instant; import java.time.LocalDate; import java.time.LocalDateTime; @@ -79,6 +80,14 @@ public static Object normalizeParameterValue(Variable parameter, Object paramVal { return normalizeParameterValue(paramValue, FunctionParametersNormalizer::normalizeFloat); } + case "Decimal": + { + return normalizeParameterValue(paramValue, FunctionParametersNormalizer::normalizeDecimal); + } + case "Boolean": + { + return normalizeParameterValue(paramValue, FunctionParametersNormalizer::normalizeBoolean); + } default: { return paramValue; @@ -168,11 +177,69 @@ private static EngineDate normalizeDate(Object value) private static Object normalizeInteger(Object value) { - return (value instanceof Integer) ? ((Integer) value).longValue() : value; + if (value instanceof Long) + { + return value; + } + if (value instanceof Integer) + { + return ((Integer) value).longValue(); + } + if (value instanceof String) + { + return Long.parseLong((String) value); + } + throw new IllegalArgumentException("Invalid Integer value: " + value); } private static Object normalizeFloat(Object value) { - return (value instanceof Float) ? ((Float) value).doubleValue() : value; + if (value instanceof Float) + { + return ((Float) value).doubleValue(); + } + if (value instanceof Double) + { + return value; + } + if (value instanceof Integer) + { + return ((Integer) value).doubleValue(); + } + if (value instanceof Long) + { + return ((Long) value).doubleValue(); + } + if (value instanceof String) + { + return Double.parseDouble((String) value); + } + throw new IllegalArgumentException("Invalid Double value: " + value); + } + + private static Object normalizeDecimal(Object value) + { + if (value instanceof BigDecimal) + { + return value; + } + if (value instanceof String) + { + return new BigDecimal((String) value); + } + throw new IllegalArgumentException("Invalid Decimal value: " + value); + } + + private static Object normalizeBoolean(Object value) + { + if (value instanceof Boolean) + { + return value; + } + if (value instanceof String) + { + return Boolean.valueOf((String) value); + } + throw new IllegalArgumentException("Invalid Boolean value: " + value); } } \ No newline at end of file diff --git a/legend-engine-core/legend-engine-core-base/legend-engine-core-executionPlan-execution/legend-engine-executionPlan-execution/src/test/java/org/finos/legend/engine/plan/execution/validation/test/TestParametersValidation.java b/legend-engine-core/legend-engine-core-base/legend-engine-core-executionPlan-execution/legend-engine-executionPlan-execution/src/test/java/org/finos/legend/engine/plan/execution/validation/test/TestParametersValidation.java index dce99434b99..9422cad1154 100644 --- a/legend-engine-core/legend-engine-core-base/legend-engine-core-executionPlan-execution/legend-engine-executionPlan-execution/src/test/java/org/finos/legend/engine/plan/execution/validation/test/TestParametersValidation.java +++ b/legend-engine-core/legend-engine-core-base/legend-engine-core-executionPlan-execution/legend-engine-executionPlan-execution/src/test/java/org/finos/legend/engine/plan/execution/validation/test/TestParametersValidation.java @@ -14,6 +14,7 @@ package org.finos.legend.engine.plan.execution.validation.test; +import com.google.common.collect.Streams; import org.eclipse.collections.impl.factory.Lists; import org.finos.legend.engine.plan.execution.nodes.state.ExecutionState; import org.finos.legend.engine.plan.execution.result.ConstantResult; @@ -25,16 +26,17 @@ import org.junit.Assert; import org.junit.Test; +import java.math.BigDecimal; import java.time.Instant; import java.time.LocalDate; import java.time.LocalDateTime; +import java.time.ZoneOffset; import java.time.ZonedDateTime; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.function.Function; import java.util.stream.Collectors; public class TestParametersValidation @@ -42,177 +44,172 @@ public class TestParametersValidation @Test public void testStringParameter() { - Function normalizer = null; testRequiredToOneParameter( - "String", - Arrays.asList("the quick brown fox", "ABCDE", "5", "6.0", "true"), - Arrays.asList(5, 6.0, true, false, Instant.now(), LocalDate.now()), - normalizer + "String", + Arrays.asList("the quick brown fox", "ABCDE", "5", "6.0", "true"), + Arrays.asList("the quick brown fox", "ABCDE", "5", "6.0", "true"), + Arrays.asList(5, 6.0, true, false, Instant.now(), LocalDate.now()) ); testToManyParameter( - "String", - Arrays.asList(null, Collections.emptyList(), Arrays.asList("a", "b", "c"), Collections.singletonList("the quick brown fox")), - Arrays.asList(Arrays.asList("a", "b", true), Arrays.asList(5, 6.0, "string", false)), - normalizer + "String", + Arrays.asList(null, Collections.emptyList(), Arrays.asList("a", "b", "c"), Collections.singletonList("the quick brown fox")), + Arrays.asList(null, Collections.emptyList(), Arrays.asList("a", "b", "c"), Collections.singletonList("the quick brown fox")), + Arrays.asList(Arrays.asList("a", "b", true), Arrays.asList(5, 6.0, "string", false)) ); } @Test public void testBooleanParameter() { - Function normalizer = null; testRequiredToOneParameter( - "Boolean", - Arrays.asList(true, false, "true", "false"), - Arrays.asList(5, 6.0, "the quick brown fox", "jumped over the lazy dog", Instant.now(), LocalDate.now()), - normalizer + "Boolean", + Arrays.asList(true, false, "true", "false"), + Arrays.asList(true, false, true, false), + Arrays.asList(5, 6.0, "the quick brown fox", "jumped over the lazy dog", Instant.now(), LocalDate.now()) ); testToManyParameter( - "Boolean", - Arrays.asList(null, Collections.emptyList(), Arrays.asList(true, true), Arrays.asList(true, "false"), Collections.singletonList(false)), - Arrays.asList(Arrays.asList(true, "b"), Arrays.asList("c", 5, "e")), - normalizer + "Boolean", + Arrays.asList(null, Collections.emptyList(), Arrays.asList(true, true), Arrays.asList(true, "false"), Collections.singletonList(false)), + Arrays.asList(null, Collections.emptyList(), Arrays.asList(true, true), Arrays.asList(true, false), Collections.singletonList(false)), + Arrays.asList(Arrays.asList(true, "b"), Arrays.asList("c", 5, "e")) ); } @Test public void testIntegerParameter() { - Function normalizer = x -> (x instanceof Integer) ? ((Integer) x).longValue() : x; testRequiredToOneParameter( - "Integer", - Arrays.asList(5, 6L, -1L, Long.MAX_VALUE, Long.MIN_VALUE, Integer.MAX_VALUE, "-1", "5", "6"), - Arrays.asList(true, false, "the quick brown fox", "jumped over the lazy dog", Instant.now(), LocalDate.now()), - normalizer + "Integer", + Arrays.asList(5, 6L, -1L, Long.MAX_VALUE, Long.MIN_VALUE, Integer.MAX_VALUE, "-1", "5", "6"), + Arrays.asList(5L, 6L, -1L, Long.MAX_VALUE, Long.MIN_VALUE, ((Integer)(Integer.MAX_VALUE)).longValue(), -1L, 5L, 6L), + Arrays.asList(true, false, "the quick brown fox", "jumped over the lazy dog", Instant.now(), LocalDate.now()) ); testToManyParameter( - "Integer", - Arrays.asList(null, Collections.emptyList(), Arrays.asList(1, "2", 3L), Collections.singletonList(6L), Arrays.asList(Long.MAX_VALUE, Long.MIN_VALUE)), - Arrays.asList(Arrays.asList(1, 2, "b"), Arrays.asList("c", false)), - normalizer + "Integer", + Arrays.asList(null, Collections.emptyList(), Arrays.asList(1, "2", 3L), Collections.singletonList(6L), Arrays.asList(Long.MAX_VALUE, Long.MIN_VALUE)), + Arrays.asList(null, Collections.emptyList(), Arrays.asList(1L, 2L, 3L), Collections.singletonList(6L), Arrays.asList(Long.MAX_VALUE, Long.MIN_VALUE)), + Arrays.asList(Arrays.asList(1, 2, "b"), Arrays.asList("c", false)) + ); + } + + @Test + public void testDecimalParameter() + { + testRequiredToOneParameter( + "Decimal", + Arrays.asList(BigDecimal.valueOf(3.14d), BigDecimal.valueOf(5L), "-1.23", "2.73"), + Arrays.asList(BigDecimal.valueOf(3.14d), BigDecimal.valueOf(5L), BigDecimal.valueOf(-1.23), BigDecimal.valueOf(2.73)), + Arrays.asList(5L, 2.73d, 1.23f, true, false, "the quick brown fox", "jumped over the lazy dog", Instant.now(), LocalDate.now()) + ); + testToManyParameter( + "Decimal", + Arrays.asList(null, Collections.emptyList(), Collections.singletonList(BigDecimal.valueOf(3.14d)), Arrays.asList(BigDecimal.valueOf(5L), "-1.23")), + Arrays.asList(null, Collections.emptyList(), Collections.singletonList(BigDecimal.valueOf(3.14d)), Arrays.asList(BigDecimal.valueOf(5L), BigDecimal.valueOf(-1.23))), + Arrays.asList(Arrays.asList(1, 2, "b"), Arrays.asList("c", false, 5L)) ); } @Test public void testFloatParameter() { - Function normalizer = x -> (x instanceof Float) ? ((Float) x).doubleValue() : x; testRequiredToOneParameter( - "Float", - Arrays.asList(5.0, 6.12d, -2.71f, Double.MAX_VALUE, Double.MIN_VALUE, Float.MAX_VALUE, "-1.0", "5.234", "678978678", 5, 4, Long.MAX_VALUE), - Arrays.asList(true, false, "the quick brown fox", "jumped over the lazy dog", Instant.now(), LocalDate.now()), - normalizer + "Float", + Arrays.asList(5.0, 6.12d, Double.MAX_VALUE, Double.MIN_VALUE, "-1.0", "5.234", "678978678", 5, 4, Long.MAX_VALUE), + Arrays.asList(5.0d, 6.12d, Double.MAX_VALUE, Double.MIN_VALUE, -1.0d, 5.234d, 678978678d, 5d, 4d, ((Long) Long.MAX_VALUE).doubleValue()), + Arrays.asList(true, false, "the quick brown fox", "jumped over the lazy dog", Instant.now(), LocalDate.now()) ); testToManyParameter( - "Float", - Arrays.asList(null, Collections.emptyList(), Arrays.asList("5.0", 6.12d, -2.71f), Collections.singletonList(0.0), Arrays.asList(Double.MAX_VALUE, Double.MIN_VALUE)), - Arrays.asList(Arrays.asList(5.0, 6.12d, "c"), Arrays.asList(false, true, "a", "B")), - normalizer + "Float", + Arrays.asList(null, Collections.emptyList(), Arrays.asList("5.0", 6.12d, -2.71), Collections.singletonList(0.0), Arrays.asList(Double.MAX_VALUE, Double.MIN_VALUE)), + Arrays.asList(null, Collections.emptyList(), Arrays.asList(5.0d, 6.12d, -2.71d), Collections.singletonList(0.0d), Arrays.asList(Double.MAX_VALUE, Double.MIN_VALUE)), + Arrays.asList(Arrays.asList(5.0, 6.12d, "c"), Arrays.asList(false, true, "a", "B")) ); } @Test public void testDateParameter() { + LocalDate today = LocalDate.now(); + EngineDate engineToday = EngineDate.fromLocalDate(today); + Instant now = Instant.now(); + ZonedDateTime zonedNow = ZonedDateTime.ofInstant(now, ZoneOffset.UTC); + EngineDate engineNow = EngineDate.fromInstant(now); + testRequiredToOneParameter( - "Date", - Arrays.asList(Instant.now(), LocalDate.now(), LocalDateTime.now(), ZonedDateTime.now(), "2020-07-14", "2020-07-14 15:18:23", "2020-07-14T15:18:23", "2020-07-14 15:18:23.992", "2020-07-14T15:18:23.123", "2020-07-14T15:18:23-0300"), - Arrays.asList(true, false, "the quick brown fox", "jumped over the lazy dog", 4.2, -3.14, 5, 4, 3), - this::normalizeDate, - "Expected formats: [yyyy-MM-dd,yyyy-MM-dd'T'HH:mm:ss,yyyy-MM-dd'T'HH:mm:ss.SSS,yyyy-MM-dd HH:mm:ss.SSS,yyyy-MM-dd HH:mm:ss,yyyy-MM-dd'T'HH:mm:ss.SSSZ,yyyy-MM-dd'T'HH:mm:ssZ]" + "Date", + Arrays.asList(now, today, LocalDateTime.ofInstant(now, ZoneOffset.UTC), zonedNow, "2020-07-14", "2020-07-14 15:18:23", "2020-07-14T15:18:23", "2020-07-14 15:18:23.992", "2020-07-14T15:18:23.123", "2020-07-14T15:18:23-0300"), + Arrays.asList(engineNow, engineToday, engineNow, engineNow, EngineDate.fromDateString("2020-07-14"), EngineDate.fromDateTimeString("2020-07-14 15:18:23"), EngineDate.fromDateTimeString("2020-07-14 15:18:23"), EngineDate.fromDateTimeString("2020-07-14 15:18:23.992"), EngineDate.fromDateTimeString("2020-07-14 15:18:23.123"), EngineDate.fromDateTimeString("2020-07-14 18:18:23")), + Arrays.asList(true, false, "the quick brown fox", "jumped over the lazy dog", 4.2, -3.14, 5, 4, 3), + "Expected formats: [yyyy-MM-dd,yyyy-MM-dd'T'HH:mm:ss,yyyy-MM-dd'T'HH:mm:ss.SSS,yyyy-MM-dd HH:mm:ss.SSS,yyyy-MM-dd HH:mm:ss,yyyy-MM-dd'T'HH:mm:ss.SSSZ,yyyy-MM-dd'T'HH:mm:ssZ]" ); testToManyParameter( - "Date", - Arrays.asList(null, Collections.emptyList(), Collections.singletonList(Instant.now()), Arrays.asList(Instant.now(), LocalDate.now()), Arrays.asList(ZonedDateTime.now(), "2020-07-14")), - Arrays.asList(Arrays.asList(5, 2, 3), Arrays.asList(Instant.now(), 2)), - this::normalizeDate + "Date", + Arrays.asList(null, Collections.emptyList(), Collections.singletonList(now), Arrays.asList(now, today), Arrays.asList(zonedNow, "2020-07-14")), + Arrays.asList(null, Collections.emptyList(), Collections.singletonList(engineNow), Arrays.asList(engineNow, engineToday), Arrays.asList(engineNow, EngineDate.fromDateString("2020-07-14"))), + Arrays.asList(Arrays.asList(5, 2, 3), Arrays.asList(Instant.now(), 2)) ); } @Test public void testStrictDateParameter() { + LocalDate today = LocalDate.now(); + EngineDate engineToday = EngineDate.fromLocalDate(today); + testRequiredToOneParameter( - "StrictDate", - Arrays.asList(LocalDate.now(), "2020-07-14"), - Arrays.asList(Instant.now(), LocalDateTime.now(), ZonedDateTime.now(), true, false, "the quick brown fox", "jumped over the lazy dog", 4.2, -3.14, 5, 4, 3, "2020-07-14 15:18:23", "2020-07-14T15:18:23", "2020-07-14 15:18:23.992", "2020-07-14T15:18:23.123"), - this::normalizeDate, - "Expected formats: [yyyy-MM-dd]" + "StrictDate", + Arrays.asList(today, "2020-07-14"), + Arrays.asList(engineToday, EngineDate.fromDateString("2020-07-14")), + Arrays.asList(Instant.now(), LocalDateTime.now(), ZonedDateTime.now(), true, false, "the quick brown fox", "jumped over the lazy dog", 4.2, -3.14, 5, 4, 3, "2020-07-14 15:18:23", "2020-07-14T15:18:23", "2020-07-14 15:18:23.992", "2020-07-14T15:18:23.123"), + "Expected formats: [yyyy-MM-dd]" ); testToManyParameter( - "StrictDate", - Arrays.asList(null, Collections.emptyList(), Collections.singletonList(LocalDate.now()), Arrays.asList(LocalDate.now(), "2020-07-14"), Arrays.asList("2020-07-14", "2020-08-06")), - Arrays.asList(Arrays.asList(5, 2, "c", false), Arrays.asList(LocalDate.now(), ZonedDateTime.now())), - this::normalizeDate + "StrictDate", + Arrays.asList(null, Collections.emptyList(), Collections.singletonList(today), Arrays.asList(today, "2020-07-14"), Arrays.asList("2020-07-14", "2020-08-06")), + Arrays.asList(null, Collections.emptyList(), Collections.singletonList(engineToday), Arrays.asList(engineToday, EngineDate.fromDateString("2020-07-14")), Arrays.asList(EngineDate.fromDateString("2020-07-14"),EngineDate.fromDateString("2020-08-06"))), + Arrays.asList(Arrays.asList(5, 2, "c", false), Arrays.asList(LocalDate.now(), ZonedDateTime.now())) ); } @Test public void testDateTimeParameter() { + Instant now = Instant.now(); + ZonedDateTime zonedNow = ZonedDateTime.ofInstant(now, ZoneOffset.UTC); + EngineDate engineNow = EngineDate.fromInstant(now); + testRequiredToOneParameter( - "DateTime", - Arrays.asList(Instant.now(), LocalDateTime.now(), ZonedDateTime.now(), "2020-07-14 15:18:23", "2020-07-14T15:18:23", "2020-07-14 15:18:23.992", "2020-07-14T15:18:23.123", "2020-07-14T15:18:23.123-0300", "2020-07-14T15:18:23.123+0500"), - Arrays.asList(LocalDate.now(), true, false, "the quick brown fox", "jumped over the lazy dog", 4.2, -3.14, 5, 4, 3, "2020-07-14"), - this::normalizeDate, - "Expected formats: [yyyy-MM-dd'T'HH:mm:ss,yyyy-MM-dd'T'HH:mm:ss.SSS,yyyy-MM-dd HH:mm:ss.SSS,yyyy-MM-dd HH:mm:ss,yyyy-MM-dd'T'HH:mm:ss.SSSZ,yyyy-MM-dd'T'HH:mm:ssZ]" + "DateTime", + Arrays.asList(now, LocalDateTime.ofInstant(now, ZoneOffset.UTC), zonedNow, "2020-07-14 15:18:23", "2020-07-14T15:18:23", "2020-07-14 15:18:23.992", "2020-07-14T15:18:23.123", "2020-07-14T15:18:23.123-0300", "2020-07-14T15:18:23.123+0500"), + Arrays.asList(engineNow, engineNow, engineNow, EngineDate.fromDateTimeString("2020-07-14 15:18:23"), EngineDate.fromDateTimeString("2020-07-14 15:18:23"), EngineDate.fromDateTimeString("2020-07-14 15:18:23.992"), EngineDate.fromDateTimeString("2020-07-14 15:18:23.123"), EngineDate.fromDateTimeString("2020-07-14 18:18:23.123"), EngineDate.fromDateTimeString("2020-07-14 10:18:23.123")), + Arrays.asList(LocalDate.now(), true, false, "the quick brown fox", "jumped over the lazy dog", 4.2, -3.14, 5, 4, 3, "2020-07-14"), + "Expected formats: [yyyy-MM-dd'T'HH:mm:ss,yyyy-MM-dd'T'HH:mm:ss.SSS,yyyy-MM-dd HH:mm:ss.SSS,yyyy-MM-dd HH:mm:ss,yyyy-MM-dd'T'HH:mm:ss.SSSZ,yyyy-MM-dd'T'HH:mm:ssZ]" ); testToManyParameter( - "DateTime", - Arrays.asList(null, Collections.emptyList(), Arrays.asList(ZonedDateTime.now(), Instant.now()), Collections.singletonList(ZonedDateTime.now()), Arrays.asList("2020-07-14T15:18:23", "2020-07-14 15:18:23.992", "2020-07-14T15:18:23.123", "2020-07-14T15:18:23.123-0300", "2020-07-14T15:18:23.123+0500")), - Arrays.asList(Arrays.asList(5, "b", 3), Arrays.asList(ZonedDateTime.now(), "b"), Arrays.asList(LocalDate.now(), ZonedDateTime.now())), - this::normalizeDate + "DateTime", + Arrays.asList(null, Collections.emptyList(), Arrays.asList(zonedNow, now), Collections.singletonList(zonedNow), Arrays.asList("2020-07-14T15:18:23", "2020-07-14 15:18:23.992", "2020-07-14T15:18:23.123", "2020-07-14T15:18:23.123-0300", "2020-07-14T15:18:23.123+0500")), + Arrays.asList(null, Collections.emptyList(), Arrays.asList(engineNow, engineNow), Collections.singletonList(engineNow), Arrays.asList(EngineDate.fromDateTimeString("2020-07-14T15:18:23"), EngineDate.fromDateTimeString("2020-07-14 15:18:23.992"), EngineDate.fromDateTimeString("2020-07-14T15:18:23.123"), EngineDate.fromDateTimeString("2020-07-14T15:18:23.123-0300"), EngineDate.fromDateTimeString("2020-07-14T15:18:23.123+0500"))), + Arrays.asList(Arrays.asList(5, "b", 3), Arrays.asList(ZonedDateTime.now(), "b"), Arrays.asList(LocalDate.now(), ZonedDateTime.now())) ); } - private EngineDate normalizeDate(Object value) - { - if (value instanceof LocalDateTime) - { - return EngineDate.fromLocalDateTime((LocalDateTime) value); - } - if (value instanceof LocalDate) - { - return EngineDate.fromLocalDate((LocalDate) value); - } - if (value instanceof ZonedDateTime) - { - return EngineDate.fromZonedDateTime((ZonedDateTime) value); - } - if (value instanceof Instant) - { - return EngineDate.fromInstant((Instant) value); - } - if (value instanceof String) - { - return EngineDate.fromDateString((String) value); - } - throw new IllegalArgumentException(String.valueOf(value)); - } - - private void testRequiredToOneParameter(String cls, List validValues, List invalidValues, Function normalizer) + private void testRequiredToOneParameter(String cls, List validValues, List expectedValues, List invalidValues) { - testRequiredToOneParameter(cls, validValues, invalidValues, normalizer, null); + testRequiredToOneParameter(cls, validValues, expectedValues, invalidValues, null); } - private void testRequiredToOneParameter(String cls, List validValues, List invalidValues, Function normalizer, String exceptionSuffix) + private void testRequiredToOneParameter(String cls, List validValues, List expectedValues, List invalidValues, String exceptionSuffix) { Variable parameter = newVariable("p", cls, 1, 1); - for (Object validValue : validValues) + Streams.zip(validValues.stream(), expectedValues.stream(), (validValue, expectedValue) -> { ExecutionState state = newExecutionState(parameter.name, validValue); FunctionParametersParametersValidation.validate(Lists.immutable.with(parameter), Collections.emptyList(), state); Object actualValue = ((ConstantResult) state.getResult(parameter.name)).getValue(); - if (normalizer == null) - { - Assert.assertSame(String.valueOf(validValue), validValue, actualValue); - } - else - { - Assert.assertEquals(String.valueOf(validValue), normalizer.apply(validValue), actualValue); - } - } + Assert.assertEquals(String.valueOf(validValue), expectedValue, actualValue); + return true; + }).collect(Collectors.toList()); for (Object invalidValue : invalidValues) { @@ -220,25 +217,19 @@ private void testRequiredToOneParameter(String cls, List validValues, List Assert.assertEquals(getExpectedExceptionMessage(cls, invalidValue, exceptionSuffix), e.getMessage()); } } - - private void testToManyParameter(String cls, List> validValues, List invalidValues, Function normalizer) + + private void testToManyParameter(String cls, List> validValues, List> expectedValues, List invalidValues) { Variable parameter = newVariable("p", cls, 0, null); - for (List validValue : validValues) + Streams.zip(validValues.stream(), expectedValues.stream(), (validValue, expectedValue) -> { ExecutionState state = newExecutionState(parameter.name, validValue); FunctionParametersParametersValidation.validate(Lists.immutable.with(parameter), Collections.emptyList(), state); Object actualValue = ((ConstantResult) state.getResult(parameter.name)).getValue(); - if ((normalizer == null) || (validValue == null)) - { - Assert.assertSame(String.valueOf(validValue), validValue, actualValue); - } - else - { - Assert.assertEquals(String.valueOf(validValue), validValue.stream().map(normalizer).collect(Collectors.toList()), actualValue); - } - } + Assert.assertEquals(String.valueOf(validValue), expectedValue, actualValue); + return null; + }).collect(Collectors.toList()); for (Object invalidValue : invalidValues) {