From 8cb3c96057b63a3a989279b4a7a5f7290ddf2d31 Mon Sep 17 00:00:00 2001 From: Toshiya Kobayashi Date: Thu, 29 Aug 2024 15:20:55 +0900 Subject: [PATCH 1/6] [incubator-kie-drools-6053] MetricLogUtils forcibly uses Micrometer when available in classpath (#6054) - Add drools.metric.micrometer.disabled switch --- .../_performance-tuning-drl-ref.adoc | 3 ++ .../drools/metric/util/MetricLogUtils.java | 15 +++++- .../org/drools/metric/AbstractMetricTest.java | 2 - .../org/drools/metric/MetricLogUtilsTest.java | 51 ++++++++++++++----- .../src/test/resources/logback-test.xml | 2 +- 5 files changed, 55 insertions(+), 18 deletions(-) diff --git a/drools-docs/src/modules/ROOT/pages/language-reference/_performance-tuning-drl-ref.adoc b/drools-docs/src/modules/ROOT/pages/language-reference/_performance-tuning-drl-ref.adoc index ac5f4627fd3..a4368270773 100644 --- a/drools-docs/src/modules/ROOT/pages/language-reference/_performance-tuning-drl-ref.adoc +++ b/drools-docs/src/modules/ROOT/pages/language-reference/_performance-tuning-drl-ref.adoc @@ -143,6 +143,9 @@ Alternatively, you can use `drools-metric` to expose the data using https://asci Metrics.addRegitry(new JmxMeterRegistry(s -> null, Clock.SYSTEM)); ---- ++ +If you want to use logging instead of Micrometer even though Micrometer is available in classpath, you can disable it by setting the system property `drools.metric.micrometer.disabled` to `true`. + + Regardless of whether you want to use logging or Micrometer, you need to enable `MetricLogUtils` by setting the system property `drools.metric.logger.enabled` to `true`. Optionally, you can change the microseconds threshold of metric reporting by setting the `drools.metric.logger.threshold` system property. diff --git a/drools-metric/src/main/java/org/drools/metric/util/MetricLogUtils.java b/drools-metric/src/main/java/org/drools/metric/util/MetricLogUtils.java index 5eef523bf5b..a66bdd83efd 100644 --- a/drools-metric/src/main/java/org/drools/metric/util/MetricLogUtils.java +++ b/drools-metric/src/main/java/org/drools/metric/util/MetricLogUtils.java @@ -30,6 +30,11 @@ public class MetricLogUtils { public static final String METRIC_LOGGER_ENABLED = "drools.metric.logger.enabled"; private boolean enabled = Boolean.parseBoolean(getConfig(METRIC_LOGGER_ENABLED, "false")); + + // Set true when you want to disable Micrometer even if it is available. + public static final String METRIC_MICROMETER_DISABLED = "drools.metric.micrometer.disabled"; + private boolean micrometerDisabled = Boolean.parseBoolean(getConfig(METRIC_MICROMETER_DISABLED, "false")); + private boolean micrometerAvailable = isMicrometerAvailable(); public static final String METRIC_LOGGER_THRESHOLD = "drools.metric.logger.threshold"; @@ -37,7 +42,7 @@ public class MetricLogUtils { private final ThreadLocal nodeStats = new ThreadLocal<>(); - private static final MetricLogUtils INSTANCE = new MetricLogUtils(); + private static MetricLogUtils INSTANCE = new MetricLogUtils(); private static boolean isMicrometerAvailable() { try { @@ -92,7 +97,7 @@ public void logAndEndMetrics() { long elapsedTimeInNanos = (System.nanoTime() - stats.getStartTime()); long elapsedTimeInMicro = elapsedTimeInNanos / 1000; if (evalCount > 0 && elapsedTimeInMicro > threshold) { - if (micrometerAvailable) { + if (micrometerAvailable && !micrometerDisabled) { MicrometerUtils.INSTANCE.triggerMicrometer(stats.getNode(), evalCount, elapsedTimeInNanos); } else { // Only log when Micrometer is not enabled. logger.trace("{}, evalCount:{}, elapsedMicro:{}", stats.getNode(), evalCount, elapsedTimeInMicro); @@ -105,4 +110,10 @@ public void logAndEndMetrics() { } } + /* + * This method is only used for testing purposes. + */ + public static void recreateInstance() { + MetricLogUtils.INSTANCE = new MetricLogUtils(); + } } diff --git a/drools-metric/src/test/java/org/drools/metric/AbstractMetricTest.java b/drools-metric/src/test/java/org/drools/metric/AbstractMetricTest.java index e09541f5ec3..94afb25f899 100644 --- a/drools-metric/src/test/java/org/drools/metric/AbstractMetricTest.java +++ b/drools-metric/src/test/java/org/drools/metric/AbstractMetricTest.java @@ -47,6 +47,4 @@ public void clearMeters() { // Remove meters we inserted without affecting those MicrometerUtils.INSTANCE.clear(); registry = null; } - - } diff --git a/drools-metric/src/test/java/org/drools/metric/MetricLogUtilsTest.java b/drools-metric/src/test/java/org/drools/metric/MetricLogUtilsTest.java index fc9c9edd275..3262031bbec 100644 --- a/drools-metric/src/test/java/org/drools/metric/MetricLogUtilsTest.java +++ b/drools-metric/src/test/java/org/drools/metric/MetricLogUtilsTest.java @@ -26,6 +26,7 @@ import io.micrometer.core.instrument.Counter; import io.micrometer.core.instrument.Timer; import io.micrometer.core.instrument.search.Search; +import org.drools.metric.util.MetricLogUtils; import org.drools.mvel.compiler.Address; import org.drools.mvel.compiler.Person; import org.junit.Test; @@ -39,6 +40,24 @@ public class MetricLogUtilsTest extends AbstractMetricTest { @Test public void testJoin() { + runJoinRules(); + + // 2 nodes expected + Collection timers = Search.in(registry) + .name("org.drools.metric.elapsed.time.per.evaluation") + .timers(); + assertThat(timers).hasSize(2); + Collection timers2 = Search.in(registry) + .name("org.drools.metric.elapsed.time") + .timers(); + assertThat(timers2).hasSize(2); + Collection counters = Search.in(registry) + .name("org.drools.metric.evaluation.count") + .counters(); + assertThat(counters).hasSize(2); + } + + private void runJoinRules() { String str = "import " + Address.class.getCanonicalName() + "\n" + "import " + Person.class.getCanonicalName() + "\n" + @@ -67,20 +86,26 @@ public void testJoin() { int fired = ksession.fireAllRules(); ksession.dispose(); assertThat(fired).isEqualTo(36); + } - // 2 nodes expected - Collection timers = Search.in(registry) - .name("org.drools.metric.elapsed.time.per.evaluation") - .timers(); - assertThat(timers).hasSize(2); - Collection timers2 = Search.in(registry) - .name("org.drools.metric.elapsed.time") - .timers(); - assertThat(timers2).hasSize(2); - Collection counters = Search.in(registry) - .name("org.drools.metric.evaluation.count") - .counters(); - assertThat(counters).hasSize(2); + @Test + public void micrometerDisabled() { + + try { + System.setProperty(MetricLogUtils.METRIC_MICROMETER_DISABLED, "true"); + MetricLogUtils.recreateInstance(); + + runJoinRules(); + + // Micrometer is disabled + Collection timers = Search.in(registry) + .name("org.drools.metric.elapsed.time.per.evaluation") + .timers(); + assertThat(timers).isEmpty(); + } finally { + System.clearProperty(MetricLogUtils.METRIC_MICROMETER_DISABLED); // default is false + MetricLogUtils.recreateInstance(); + } } @Test diff --git a/drools-metric/src/test/resources/logback-test.xml b/drools-metric/src/test/resources/logback-test.xml index 87319242399..90bb41ab1db 100644 --- a/drools-metric/src/test/resources/logback-test.xml +++ b/drools-metric/src/test/resources/logback-test.xml @@ -30,7 +30,7 @@ - + From 7498b3d254e43ee3079ee4fc44457e5348b9cbe2 Mon Sep 17 00:00:00 2001 From: Paolo Bizzarri Date: Tue, 3 Sep 2024 14:43:53 +0200 Subject: [PATCH 2/6] Replaces junit assertions with assertj assertions (#6057) --- .../dmn/openapi/impl/DMNTypeSchemasTest.java | 60 +++++++++---------- .../openapi/impl/DMNUnaryTestsMapperTest.java | 53 +++++++--------- .../impl/FEELFunctionSchemaMapperTest.java | 6 +- .../impl/InfixOpNodeSchemaMapperTest.java | 7 ++- .../impl/RangeNodeSchemaMapperTest.java | 19 +++--- 5 files changed, 63 insertions(+), 82 deletions(-) diff --git a/kie-dmn/kie-dmn-openapi/src/test/java/org/kie/dmn/openapi/impl/DMNTypeSchemasTest.java b/kie-dmn/kie-dmn-openapi/src/test/java/org/kie/dmn/openapi/impl/DMNTypeSchemasTest.java index 1f6991ad8c6..90c94cb31bc 100644 --- a/kie-dmn/kie-dmn-openapi/src/test/java/org/kie/dmn/openapi/impl/DMNTypeSchemasTest.java +++ b/kie-dmn/kie-dmn-openapi/src/test/java/org/kie/dmn/openapi/impl/DMNTypeSchemasTest.java @@ -29,9 +29,7 @@ import org.kie.dmn.core.impl.SimpleTypeImpl; import org.kie.dmn.feel.lang.types.BuiltInType; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import static org.kie.dmn.openapi.impl.SchemaMapperTestUtils.FEEL_NUMBER; import static org.kie.dmn.openapi.impl.SchemaMapperTestUtils.FEEL_STRING; import static org.kie.dmn.openapi.impl.SchemaMapperTestUtils.getSchemaForSimpleType; @@ -49,25 +47,23 @@ void populateSchemaWithConstraintsForAllowedValues() { SimpleTypeImpl toRead = getSimpleType(allowedValuesString, null, FEEL_STRING, BuiltInType.STRING); AtomicReference toPopulate = new AtomicReference<>(getSchemaForSimpleType(toRead)); DMNTypeSchemas.populateSchemaWithConstraints(toPopulate.get(), toRead); - assertEquals(enumBase.size(), toPopulate.get().getEnumeration().size()); - enumBase.forEach(en -> assertTrue(toPopulate.get().getEnumeration().contains(en))); - assertTrue(toPopulate.get().getExtensions().containsKey(DMNOASConstants.X_DMN_ALLOWED_VALUES)); + assertThat(toPopulate.get().getEnumeration()).hasSameSizeAs(enumBase).containsAll(enumBase); + assertThat(toPopulate.get().getExtensions()).containsKey(DMNOASConstants.X_DMN_ALLOWED_VALUES); String retrieved = ((String) toPopulate.get().getExtensions().get(DMNOASConstants.X_DMN_ALLOWED_VALUES)).replace(" ", ""); - assertEquals(allowedValuesString, retrieved); + assertThat(retrieved).isEqualTo(allowedValuesString); - toEnum = Arrays.asList(1, 3, 6, 78); + toEnum = Arrays.asList(BigDecimal.valueOf(1), BigDecimal.valueOf(3), BigDecimal.valueOf(6), BigDecimal.valueOf(78)); allowedValuesString = String.join(",", toEnum.stream().map(toMap -> String.format("%s", toMap)).toList()); toRead = getSimpleType(allowedValuesString, null, FEEL_NUMBER, BuiltInType.NUMBER); toPopulate.set(getSchemaForSimpleType(toRead)); DMNTypeSchemas.populateSchemaWithConstraints(toPopulate.get(), toRead); - assertEquals(toEnum.size(), toPopulate.get().getEnumeration().size()); - toEnum.stream().map(i -> BigDecimal.valueOf((int) i)).forEach(en -> assertTrue(toPopulate.get().getEnumeration().contains(en))); - assertTrue(toPopulate.get().getExtensions().containsKey(DMNOASConstants.X_DMN_ALLOWED_VALUES)); + assertThat(toPopulate.get().getEnumeration()).hasSameSizeAs(toEnum).containsAll(toEnum); + assertThat(toPopulate.get().getExtensions()).containsKey(DMNOASConstants.X_DMN_ALLOWED_VALUES); retrieved = ((String) toPopulate.get().getExtensions().get(DMNOASConstants.X_DMN_ALLOWED_VALUES)).replace(" " , ""); - assertEquals(allowedValuesString, retrieved); + assertThat(retrieved).isEqualTo(allowedValuesString); } @Test @@ -80,26 +76,24 @@ void populateSchemaWithConstraintsForTypeConstraints() { SimpleTypeImpl toRead = getSimpleType(null, typeConstraintsString, FEEL_STRING, BuiltInType.STRING); AtomicReference toPopulate = new AtomicReference<>(getSchemaForSimpleType(toRead)); DMNTypeSchemas.populateSchemaWithConstraints(toPopulate.get(), toRead); - assertEquals(enumBase.size(), toPopulate.get().getEnumeration().size()); - enumBase.forEach(en -> assertTrue(toPopulate.get().getEnumeration().contains(en))); - assertTrue(toPopulate.get().getExtensions().containsKey(DMNOASConstants.X_DMN_TYPE_CONSTRAINTS)); + assertThat(toPopulate.get().getEnumeration()).hasSameSizeAs(enumBase).containsAll(enumBase); + assertThat(toPopulate.get().getExtensions()).containsKey(DMNOASConstants.X_DMN_TYPE_CONSTRAINTS); String retrieved = ((String) toPopulate.get().getExtensions().get(DMNOASConstants.X_DMN_TYPE_CONSTRAINTS)).replace(" ", ""); - assertEquals(typeConstraintsString, retrieved); + assertThat(retrieved).isEqualTo(typeConstraintsString); - toEnum = Arrays.asList(1, 3, 6, 78); + toEnum = Arrays.asList(BigDecimal.valueOf(1), BigDecimal.valueOf(3), BigDecimal.valueOf(6), BigDecimal.valueOf(78)); typeConstraintsString = String.join(",", toEnum.stream().map(toMap -> String.format("%s", toMap)).toList()); toRead = getSimpleType(null, typeConstraintsString, FEEL_NUMBER, BuiltInType.NUMBER); toPopulate.set(getSchemaForSimpleType(toRead)); DMNTypeSchemas.populateSchemaWithConstraints(toPopulate.get(), toRead); - assertEquals(toEnum.size(), toPopulate.get().getEnumeration().size()); - toEnum.stream().map(i -> BigDecimal.valueOf((int) i)).forEach(en -> assertTrue(toPopulate.get().getEnumeration().contains(en))); - assertTrue(toPopulate.get().getExtensions().containsKey(DMNOASConstants.X_DMN_TYPE_CONSTRAINTS)); + assertThat(toPopulate.get().getEnumeration()).hasSameSizeAs(toEnum).containsAll(toEnum); + assertThat(toPopulate.get().getExtensions()).containsKey(DMNOASConstants.X_DMN_TYPE_CONSTRAINTS); retrieved = ((String) toPopulate.get().getExtensions().get(DMNOASConstants.X_DMN_TYPE_CONSTRAINTS)).replace( " ", ""); - assertEquals(typeConstraintsString, retrieved); + assertThat(retrieved).isEqualTo(typeConstraintsString); } @Test @@ -110,15 +104,15 @@ void populateSchemaWithRangesForAllowedValues() { SimpleTypeImpl toRead = getSimpleType(allowedValuesString, null, FEEL_STRING, BuiltInType.STRING); AtomicReference toPopulate = new AtomicReference<>(getSchemaForSimpleType(toRead)); DMNTypeSchemas.populateSchemaWithConstraints(toPopulate.get(), toRead); - assertEquals(BigDecimal.ONE, toPopulate.get().getMinimum()); - assertTrue(toPopulate.get().getExclusiveMinimum()); - assertEquals(BigDecimal.TEN, toPopulate.get().getMaximum()); - assertFalse(toPopulate.get().getExclusiveMaximum()); - assertTrue(toPopulate.get().getExtensions().containsKey(DMNOASConstants.X_DMN_ALLOWED_VALUES)); + assertThat(toPopulate.get().getMinimum()).isEqualTo(BigDecimal.ONE); + assertThat(toPopulate.get().getExclusiveMinimum()).isTrue(); + assertThat(toPopulate.get().getMaximum()).isEqualTo(BigDecimal.TEN); + assertThat(toPopulate.get().getExclusiveMaximum()).isFalse(); + assertThat(toPopulate.get().getExtensions()).containsKey(DMNOASConstants.X_DMN_ALLOWED_VALUES); String retrieved = ((String) toPopulate.get().getExtensions().get(DMNOASConstants.X_DMN_ALLOWED_VALUES)).replace(" ", ""); String expected = allowedValuesString.replace("(", "").replace(")", ""); - assertEquals(expected, retrieved); + assertThat(retrieved).isEqualTo(expected); } @Test @@ -129,15 +123,15 @@ void populateSchemaWithRangesForTypeConstraints() { SimpleTypeImpl toRead = getSimpleType(null, typeConstraintsString, FEEL_STRING, BuiltInType.STRING); AtomicReference toPopulate = new AtomicReference<>(getSchemaForSimpleType(toRead)); DMNTypeSchemas.populateSchemaWithConstraints(toPopulate.get(), toRead); - assertEquals(BigDecimal.ONE, toPopulate.get().getMinimum()); - assertTrue(toPopulate.get().getExclusiveMinimum()); - assertEquals(BigDecimal.TEN, toPopulate.get().getMaximum()); - assertFalse(toPopulate.get().getExclusiveMaximum()); - assertTrue(toPopulate.get().getExtensions().containsKey(DMNOASConstants.X_DMN_TYPE_CONSTRAINTS)); + assertThat(toPopulate.get().getMinimum()).isEqualTo(BigDecimal.ONE); + assertThat(toPopulate.get().getExclusiveMinimum()).isTrue(); + assertThat(toPopulate.get().getMaximum()).isEqualTo(BigDecimal.TEN); + assertThat(toPopulate.get().getExclusiveMaximum()).isFalse(); + assertThat(toPopulate.get().getExtensions().containsKey(DMNOASConstants.X_DMN_TYPE_CONSTRAINTS)).isTrue(); String retrieved = ((String) toPopulate.get().getExtensions().get(DMNOASConstants.X_DMN_TYPE_CONSTRAINTS)).replace(" ", ""); String expected = typeConstraintsString.replace("(", "").replace(")", ""); - assertEquals(expected, retrieved); + assertThat(retrieved).isEqualTo(expected); } } \ No newline at end of file diff --git a/kie-dmn/kie-dmn-openapi/src/test/java/org/kie/dmn/openapi/impl/DMNUnaryTestsMapperTest.java b/kie-dmn/kie-dmn-openapi/src/test/java/org/kie/dmn/openapi/impl/DMNUnaryTestsMapperTest.java index c0951f69bde..90885ba04c0 100644 --- a/kie-dmn/kie-dmn-openapi/src/test/java/org/kie/dmn/openapi/impl/DMNUnaryTestsMapperTest.java +++ b/kie-dmn/kie-dmn-openapi/src/test/java/org/kie/dmn/openapi/impl/DMNUnaryTestsMapperTest.java @@ -22,7 +22,6 @@ import java.time.LocalDate; import java.util.Arrays; import java.util.List; -import java.util.Objects; import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; @@ -33,12 +32,8 @@ import org.kie.dmn.feel.lang.ast.BaseNode; import org.kie.dmn.feel.lang.types.BuiltInType; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.kie.dmn.openapi.impl.DMNUnaryTestsMapper.getUnaryEvaluationNodesFromUnaryTests; import static org.kie.dmn.openapi.impl.SchemaMapperTestUtils.FEEL_NUMBER; import static org.kie.dmn.openapi.impl.SchemaMapperTestUtils.FEEL_STRING; @@ -56,10 +51,9 @@ void populateSchemaFromUnaryTestsForEnumsWithoutNull() { expression += ", count (?) > 1"; List unaryTests = feel.evaluateUnaryTests(expression).stream().map(DMNUnaryTest.class::cast).toList(); DMNUnaryTestsMapper.populateSchemaFromUnaryTests(toPopulate, unaryTests); - assertFalse(toPopulate.getNullable()); - assertNotNull(toPopulate.getEnumeration()); - assertEquals(expectedStrings.size(), toPopulate.getEnumeration().size()); - expectedStrings.forEach(expectedString -> assertTrue(toPopulate.getEnumeration().contains(expectedString))); + assertThat(toPopulate.getNullable()).isFalse(); + assertThat(toPopulate.getEnumeration()).isNotNull(); + assertThat(toPopulate.getEnumeration()).hasSameSizeAs(expectedStrings).containsAll(expectedStrings); } @Test @@ -70,10 +64,9 @@ void populateSchemaFromUnaryTestsForEnumsWithNull() { String expression = String.join(",", toEnum.stream().map(toMap -> String.format("%s", toMap.toString())).toList()); List unaryTests = feel.evaluateUnaryTests(expression).stream().map(DMNUnaryTest.class::cast).toList(); DMNUnaryTestsMapper.populateSchemaFromUnaryTests(toPopulate, unaryTests); - assertTrue(toPopulate.getNullable()); - assertNotNull(toPopulate.getEnumeration()); - assertEquals(expectedStrings.size(), toPopulate.getEnumeration().size()); - expectedStrings.stream().filter(Objects::nonNull).forEach(expectedString -> assertTrue(toPopulate.getEnumeration().contains(expectedString))); + assertThat(toPopulate.getNullable()).isTrue(); + assertThat(toPopulate.getEnumeration()).isNotNull(); + assertThat(toPopulate.getEnumeration()).hasSameSizeAs(expectedStrings).containsAll(expectedStrings); } @Test @@ -83,19 +76,17 @@ void populateSchemaFromUnaryTestsForEnumSucceed() { String expression = String.join(",", toEnum.stream().map(toMap -> String.format("%s", toMap)).toList()); List toCheck = feel.evaluateUnaryTests(expression).stream().map(DMNUnaryTest.class::cast).toList(); AtomicReference toPopulate = new AtomicReference<>(getSchemaForSimpleType(null, expression, FEEL_STRING, BuiltInType.STRING)); - assertNull(toPopulate.get().getEnumeration()); + assertThat(toPopulate.get().getEnumeration()).isNull();; DMNUnaryTestsMapper.populateSchemaFromUnaryTests(toPopulate.get(), toCheck); - assertEquals(enumBase.size(), toPopulate.get().getEnumeration().size()); - enumBase.forEach(en -> assertTrue(toPopulate.get().getEnumeration().contains(en))); + assertThat(toPopulate.get().getEnumeration()).hasSameSizeAs(enumBase).containsAll(enumBase); - toEnum = Arrays.asList(1, 3, 6, 78); - expression = String.join(",", toEnum.stream().map(toMap -> String.format("%s", toMap)).toList()); + ListtoEnum1 = Arrays.asList(BigDecimal.valueOf(1L), BigDecimal.valueOf(3), BigDecimal.valueOf(6), BigDecimal.valueOf(78)); + expression = String.join(",", toEnum1.stream().map(toMap -> String.format("%s", toMap)).toList()); toCheck = feel.evaluateUnaryTests(expression).stream().map(DMNUnaryTest.class::cast).toList(); toPopulate.set(getSchemaForSimpleType(null, expression, FEEL_NUMBER, BuiltInType.NUMBER)); - assertNull(toPopulate.get().getEnumeration()); + assertThat(toPopulate.get().getEnumeration()).isNull(); DMNUnaryTestsMapper.populateSchemaFromUnaryTests(toPopulate.get(), toCheck); - assertEquals(toEnum.size(), toPopulate.get().getEnumeration().size()); - toEnum.stream().map(i -> BigDecimal.valueOf((int)i)).forEach(en -> assertTrue(toPopulate.get().getEnumeration().contains(en))); + assertThat(toPopulate.get().getEnumeration()).hasSameSizeAs(enumBase).extracting(value -> ((BigDecimal)value)).containsAll(toEnum1); toPopulate.set(OASFactory.createObject(Schema.class)); List expectedDates = Arrays.asList(LocalDate.of(2022, 1, 1), LocalDate.of(2024, 1, 1)); @@ -104,11 +95,10 @@ void populateSchemaFromUnaryTestsForEnumSucceed() { .toList(); expression = String.join(",", formattedDates.stream().map(toMap -> String.format("%s", toMap)).toList()); toCheck = feel.evaluateUnaryTests(expression).stream().map(DMNUnaryTest.class::cast).toList(); - assertNull(toPopulate.get().getNullable()); + assertThat(toPopulate.get().getNullable()).isNull(); DMNUnaryTestsMapper.populateSchemaFromUnaryTests(toPopulate.get(), toCheck); - assertNotNull(toPopulate.get().getEnumeration()); - assertEquals(expectedDates.size(), toPopulate.get().getEnumeration().size()); - expectedDates.forEach(expectedDate -> assertTrue(toPopulate.get().getEnumeration().contains(expectedDate))); + assertThat(toPopulate.get().getEnumeration()).isNotNull(); + assertThat(toPopulate.get().getEnumeration()).hasSameSizeAs(expectedDates).containsAll(expectedDates); } @Test @@ -117,9 +107,9 @@ void populateSchemaFromUnaryTestsFails() { String expression = String.join(",", toEnum.stream().map(toMap -> String.format("%s", toMap)).toList()); List toCheck = feel.evaluateUnaryTests(expression).stream().map(DMNUnaryTest.class::cast).toList(); - assertEquals(toEnum.size(), toCheck.size()); + assertThat(toCheck).hasSameSizeAs(toEnum); Schema toPopulate = getSchemaForSimpleType(null, expression, FEEL_STRING, BuiltInType.STRING); - assertThrows(IllegalArgumentException.class, () -> DMNUnaryTestsMapper.populateSchemaFromUnaryTests(toPopulate, toCheck)); + assertThatIllegalArgumentException().isThrownBy(() -> DMNUnaryTestsMapper.populateSchemaFromUnaryTests(toPopulate, toCheck)); } @Test @@ -130,11 +120,10 @@ void populateSchemaFromBaseNodeSucceed() { List dmnUnaryTests = feel.evaluateUnaryTests(expression).stream().map(DMNUnaryTest.class::cast).toList(); AtomicReference schemaRef = new AtomicReference<>(getSchemaForSimpleType(null, expression, FEEL_STRING, BuiltInType.STRING)); - assertNull(schemaRef.get().getEnumeration()); + assertThat(schemaRef.get().getEnumeration()).isNull(); BaseNode toCheck = getUnaryEvaluationNodesFromUnaryTests(dmnUnaryTests).get(0); DMNUnaryTestsMapper.populateSchemaFromBaseNode(schemaRef.get(), toCheck); - assertEquals(enumBase.size(), schemaRef.get().getEnumeration().size()); - enumBase.forEach(en -> assertTrue(schemaRef.get().getEnumeration().contains(en))); + assertThat(schemaRef.get().getEnumeration()).hasSameSizeAs(enumBase).containsAll(enumBase); } } \ No newline at end of file diff --git a/kie-dmn/kie-dmn-openapi/src/test/java/org/kie/dmn/openapi/impl/FEELFunctionSchemaMapperTest.java b/kie-dmn/kie-dmn-openapi/src/test/java/org/kie/dmn/openapi/impl/FEELFunctionSchemaMapperTest.java index 05b5566563f..03d90bf88e3 100644 --- a/kie-dmn/kie-dmn-openapi/src/test/java/org/kie/dmn/openapi/impl/FEELFunctionSchemaMapperTest.java +++ b/kie-dmn/kie-dmn-openapi/src/test/java/org/kie/dmn/openapi/impl/FEELFunctionSchemaMapperTest.java @@ -29,7 +29,7 @@ import org.kie.dmn.feel.lang.types.BuiltInType; import org.kie.dmn.feel.runtime.functions.CountFunction; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import static org.kie.dmn.openapi.impl.SchemaMapperTestUtils.FEEL_NUMBER; import static org.kie.dmn.openapi.impl.SchemaMapperTestUtils.getSchemaForSimpleType; @@ -55,8 +55,8 @@ void populateSchemaFromFEELFunction(InfixOperator operator) { expectedMaximum = rightValue; } } - assertEquals(expectedMinimum, toPopulate.getMinItems()); - assertEquals(expectedMaximum, toPopulate.getMaxItems()); + assertThat(toPopulate.getMinItems()).isEqualTo(expectedMinimum); + assertThat(toPopulate.getMaxItems()).isEqualTo(expectedMaximum); }); } } \ No newline at end of file diff --git a/kie-dmn/kie-dmn-openapi/src/test/java/org/kie/dmn/openapi/impl/InfixOpNodeSchemaMapperTest.java b/kie-dmn/kie-dmn-openapi/src/test/java/org/kie/dmn/openapi/impl/InfixOpNodeSchemaMapperTest.java index 42e8e136abe..084e7fc2c30 100644 --- a/kie-dmn/kie-dmn-openapi/src/test/java/org/kie/dmn/openapi/impl/InfixOpNodeSchemaMapperTest.java +++ b/kie-dmn/kie-dmn-openapi/src/test/java/org/kie/dmn/openapi/impl/InfixOpNodeSchemaMapperTest.java @@ -29,7 +29,8 @@ import org.kie.dmn.feel.lang.types.BuiltInType; import org.kie.dmn.feel.runtime.functions.CountFunction; -import static org.junit.jupiter.api.Assertions.assertEquals; + +import static org.assertj.core.api.Assertions.assertThat; import static org.kie.dmn.openapi.impl.SchemaMapperTestUtils.FEEL_NUMBER; import static org.kie.dmn.openapi.impl.SchemaMapperTestUtils.getBaseNode; import static org.kie.dmn.openapi.impl.SchemaMapperTestUtils.getSchemaForSimpleType; @@ -57,8 +58,8 @@ void populateSchemaFromFunctionInvocationNode(InfixOperator operator) { expectedMaximum = rightValue; } } - assertEquals(expectedMinimum, toPopulate.getMinItems()); - assertEquals(expectedMaximum, toPopulate.getMaxItems()); + assertThat(toPopulate.getMinItems()).isEqualTo(expectedMinimum); + assertThat(toPopulate.getMaxItems()).isEqualTo(expectedMaximum); }); } } \ No newline at end of file diff --git a/kie-dmn/kie-dmn-openapi/src/test/java/org/kie/dmn/openapi/impl/RangeNodeSchemaMapperTest.java b/kie-dmn/kie-dmn-openapi/src/test/java/org/kie/dmn/openapi/impl/RangeNodeSchemaMapperTest.java index a79c66b7ad3..d2c634f858b 100644 --- a/kie-dmn/kie-dmn-openapi/src/test/java/org/kie/dmn/openapi/impl/RangeNodeSchemaMapperTest.java +++ b/kie-dmn/kie-dmn-openapi/src/test/java/org/kie/dmn/openapi/impl/RangeNodeSchemaMapperTest.java @@ -33,9 +33,6 @@ import org.kie.dmn.feel.runtime.impl.RangeImpl; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; import static org.kie.dmn.openapi.impl.SchemaMapperTestUtils.getBaseNodes; class RangeNodeSchemaMapperTest { @@ -48,10 +45,10 @@ void evaluateUnaryTestsForNumberRange() { List ranges = getBaseNodes(toRange, RangeNode.class); Schema toPopulate = OASFactory.createObject(Schema.class); RangeNodeSchemaMapper.populateSchemaFromListOfRanges(toPopulate, ranges); - assertEquals(BigDecimal.ONE, toPopulate.getMinimum()); - assertTrue(toPopulate.getExclusiveMinimum()); - assertEquals(BigDecimal.TEN, toPopulate.getMaximum()); - assertFalse(toPopulate.getExclusiveMaximum()); + assertThat(toPopulate.getMinimum()).isEqualTo(BigDecimal.ONE); + assertThat(toPopulate.getExclusiveMinimum()).isTrue(); + assertThat(toPopulate.getMaximum()).isEqualTo(BigDecimal.TEN); + assertThat(toPopulate.getExclusiveMaximum()).isFalse(); } @Test @@ -66,10 +63,10 @@ void evaluateUnaryTestsForDateRange() { Schema toPopulate = OASFactory.createObject(Schema.class); RangeNodeSchemaMapper.populateSchemaFromListOfRanges(toPopulate, ranges); - assertEquals(expectedDates.get(0), toPopulate.getExtensions().get(DMNOASConstants.X_DMN_MINIMUM_VALUE)); - assertTrue(toPopulate.getExclusiveMinimum()); - assertEquals(expectedDates.get(1), toPopulate.getExtensions().get(DMNOASConstants.X_DMN_MAXIMUM_VALUE)); - assertFalse(toPopulate.getExclusiveMaximum()); + assertThat(toPopulate.getExtensions().get(DMNOASConstants.X_DMN_MINIMUM_VALUE)).isEqualTo(expectedDates.get(0)); + assertThat(toPopulate.getExclusiveMinimum()).isTrue(); + assertThat(toPopulate.getExtensions().get(DMNOASConstants.X_DMN_MAXIMUM_VALUE)).isEqualTo(expectedDates.get(1)); + assertThat(toPopulate.getExclusiveMaximum()).isFalse(); } @Test From c216212e38f3ac135ca9cd736de3081e878fd9af Mon Sep 17 00:00:00 2001 From: Paolo Bizzarri Date: Tue, 3 Sep 2024 14:50:27 +0200 Subject: [PATCH 3/6] Fixed build issue in Eclipse (#6059) --- kie-dmn/kie-dmn-feel/pom.xml | 2 +- kie-dmn/{ => kie-dmn-feel}/ref-dmn-feel-builtin-functions.adoc | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename kie-dmn/{ => kie-dmn-feel}/ref-dmn-feel-builtin-functions.adoc (100%) diff --git a/kie-dmn/kie-dmn-feel/pom.xml b/kie-dmn/kie-dmn-feel/pom.xml index 933dd442952..51fbef420b7 100644 --- a/kie-dmn/kie-dmn-feel/pom.xml +++ b/kie-dmn/kie-dmn-feel/pom.xml @@ -144,7 +144,7 @@ ${project.basedir}/src/test/resources - ${project.basedir}/../ + ${project.basedir}/ ref-dmn-feel-builtin-functions.adoc diff --git a/kie-dmn/ref-dmn-feel-builtin-functions.adoc b/kie-dmn/kie-dmn-feel/ref-dmn-feel-builtin-functions.adoc similarity index 100% rename from kie-dmn/ref-dmn-feel-builtin-functions.adoc rename to kie-dmn/kie-dmn-feel/ref-dmn-feel-builtin-functions.adoc From c2ad2faf39ce1a71120af18850bbbabdf9aa7517 Mon Sep 17 00:00:00 2001 From: Gabriele Cardosi Date: Wed, 4 Sep 2024 15:47:03 +0200 Subject: [PATCH 4/6] [incubator-kie-issues#1411] Ban usage of Junit assertions inside DMN (#6062) * [incubator-kie-issues#1411] Ban usage of Junit assertions inside DMN * [incubator-kie-issues#1411] Fixed as per PR suggestion --------- Co-authored-by: Gabriele-Cardosi --- kie-dmn/kie-dmn-api/pom.xml | 12 + .../org/kie/dmn/core/DMNMessagesAPITest.java | 4 +- .../java/org/kie/dmn/core/DMNRuntimeTest.java | 6 +- .../dmn/core/ast/DMNContextEvaluatorTest.java | 6 +- .../core/compiler/DMNCompilerImplTest.java | 4 +- .../core/compiler/UnnamedImportUtilsTest.java | 49 ++-- .../impl/DMNContextFEELCtxWrapperTest.java | 8 +- .../org/kie/dmn/core/util/CoerceUtilTest.java | 66 +++--- .../BigDecimalRangeIteratorTest.java | 20 +- .../ForIterationTest.java | 20 +- .../ForIterationUtilsTest.java | 29 +-- .../LocalDateRangeIteratorTest.java | 20 +- .../ZonedDateTimeRangeIteratorTest.java | 28 +-- .../dmn/feel/runtime/custom/ZoneTimeTest.java | 64 ++--- .../functions/BaseFEELFunctionHelperTest.java | 176 +++++++------- .../functions/BaseFEELFunctionTest.java | 224 +++++++++--------- .../functions/BuiltInFunctionsTest.java | 14 +- .../functions/MatchesFunctionTest.java | 48 ++-- .../runtime/functions/ScorerHelperTest.java | 145 ++++++------ .../runtime/functions/TimeFunctionTest.java | 12 +- .../org/kie/dmn/feel/util/CoerceUtilTest.java | 136 ++++++----- .../tests/core/v1_1/DMNRuntimeTest.java | 6 +- .../kie-dmn-ruleset2dmn-cli/pom.xml | 7 + kie-dmn/kie-dmn-test-resources/pom.xml | 12 + kie-dmn/kie-dmn-validation-bootstrap/pom.xml | 12 + .../org/kie/dmn/validation/ValidatorTest.java | 6 +- .../validation/v1_5/DMN15ValidationsTest.java | 6 +- kie-dmn/pom.xml | 42 ++++ 28 files changed, 615 insertions(+), 567 deletions(-) diff --git a/kie-dmn/kie-dmn-api/pom.xml b/kie-dmn/kie-dmn-api/pom.xml index f795af7a654..6f179cff3ac 100644 --- a/kie-dmn/kie-dmn-api/pom.xml +++ b/kie-dmn/kie-dmn-api/pom.xml @@ -62,6 +62,18 @@ + + + + com.societegenerale.commons + arch-unit-maven-plugin + + true + + + + + sonarcloud-analysis diff --git a/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/DMNMessagesAPITest.java b/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/DMNMessagesAPITest.java index 5f8bd501619..76397b486de 100644 --- a/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/DMNMessagesAPITest.java +++ b/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/DMNMessagesAPITest.java @@ -38,7 +38,7 @@ import org.slf4j.LoggerFactory; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; public class DMNMessagesAPITest { @@ -72,7 +72,7 @@ void apiUsage() { @Test void apiUsageSnippetForDocumentation() { - assertThrows(IllegalStateException.class, () -> { + assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> { KieServices ks = KieServices.Factory.get(); ReleaseId releaseId = ks.newReleaseId("org.kie", "dmn-test-" + UUID.randomUUID(), "1.0"); diff --git a/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/DMNRuntimeTest.java b/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/DMNRuntimeTest.java index 5ade865fb2f..89e261436f7 100644 --- a/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/DMNRuntimeTest.java +++ b/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/DMNRuntimeTest.java @@ -89,7 +89,7 @@ import org.slf4j.LoggerFactory; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; import static org.kie.dmn.core.util.DMNTestUtil.getAndAssertModelNoErrors; import static org.kie.dmn.core.util.DynamicTypeUtils.entry; import static org.kie.dmn.core.util.DynamicTypeUtils.mapOf; @@ -3136,7 +3136,7 @@ void functionDefinitionParameterTrailingSpace(boolean useExecModelCompiler) { @MethodSource("params") void evaluateByNameWithEmptyParam(boolean useExecModelCompiler) { init(useExecModelCompiler); - assertThrows(IllegalArgumentException.class, () -> { + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> { final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("simple-item-def.dmn", this.getClass()); final DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn/itemdef", "simple-item-def"); assertThat(dmnModel).isNotNull(); @@ -3154,7 +3154,7 @@ void evaluateByNameWithEmptyParam(boolean useExecModelCompiler) { @MethodSource("params") void evaluateByIdWithEmptyParam(boolean useExecModelCompiler) { init(useExecModelCompiler); - assertThrows(IllegalArgumentException.class, () -> { + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> { final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("simple-item-def.dmn", this.getClass()); final DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn/itemdef", "simple-item-def"); assertThat(dmnModel).isNotNull(); diff --git a/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/ast/DMNContextEvaluatorTest.java b/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/ast/DMNContextEvaluatorTest.java index 554631e2e7e..066c5439439 100644 --- a/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/ast/DMNContextEvaluatorTest.java +++ b/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/ast/DMNContextEvaluatorTest.java @@ -38,8 +38,6 @@ import org.kie.dmn.core.util.DMNRuntimeUtil; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; class DMNContextEvaluatorTest { @@ -74,8 +72,8 @@ void dateToDateTime() { DMNResultImpl result = createResult(dmnModel, context ); DMNExpressionEvaluator evaluator = ed.getEvaluator(); EvaluatorResult evaluated = evaluator.evaluate(runtime, result); - assertNotNull(evaluated); - assertEquals(EvaluatorResult.ResultType.SUCCESS, evaluated.getResultType()); + assertThat(evaluated).isNotNull(); + assertThat(evaluated.getResultType()).isEqualTo(EvaluatorResult.ResultType.SUCCESS); } private DMNResultImpl createResult(DMNModel model, DMNContext context) { diff --git a/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/compiler/DMNCompilerImplTest.java b/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/compiler/DMNCompilerImplTest.java index f67f8fc1557..bc11d10e568 100644 --- a/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/compiler/DMNCompilerImplTest.java +++ b/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/compiler/DMNCompilerImplTest.java @@ -28,7 +28,7 @@ import org.kie.dmn.model.v1_5.TInformationRequirement; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; class DMNCompilerImplTest { @@ -70,7 +70,7 @@ void getRootElement() { InformationRequirement informationRequirement = new TInformationRequirement(); elementReference.setParent(informationRequirement); - assertThrows(RuntimeException.class, () -> DMNCompilerImpl.getRootElement(elementReference)); + assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> DMNCompilerImpl.getRootElement(elementReference)); informationRequirement.setParent(parent); retrieved = DMNCompilerImpl.getRootElement(elementReference); diff --git a/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/compiler/UnnamedImportUtilsTest.java b/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/compiler/UnnamedImportUtilsTest.java index c3be2cb2fc2..f0a8e94a5a8 100644 --- a/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/compiler/UnnamedImportUtilsTest.java +++ b/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/compiler/UnnamedImportUtilsTest.java @@ -36,9 +36,6 @@ import org.kie.dmn.model.api.NamedElement; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; import static org.kie.dmn.core.compiler.UnnamedImportUtils.addIfNotPresent; import static org.kie.dmn.core.compiler.UnnamedImportUtils.isInUnnamedImport; @@ -68,26 +65,26 @@ void isInUnnamedImportFalse() { final DMNModelImpl importingModel = (DMNModelImpl)runtime.getModel("http://www.trisotech.com/dmn/definitions/_f79aa7a4-f9a3-410a-ac95-bea496edabgc", "Importing named Model"); assertThat(importingModel).isNotNull(); - importedModel.getDecisions().forEach(node -> assertFalse(isInUnnamedImport(node, importingModel))); - importedModel.getBusinessKnowledgeModels().forEach(node -> assertFalse(isInUnnamedImport(node, importingModel))); - importedModel.getDecisionServices().forEach(node -> assertFalse(isInUnnamedImport(node, importingModel))); - importedModel.getInputs().forEach(node -> assertFalse(isInUnnamedImport(node, importingModel))); - importedModel.getItemDefinitions().forEach(node -> assertFalse(isInUnnamedImport(node, importingModel))); + importedModel.getDecisions().forEach(node -> assertThat(isInUnnamedImport(node, importingModel)).isFalse()); + importedModel.getBusinessKnowledgeModels().forEach(node -> assertThat(isInUnnamedImport(node, importingModel)).isFalse()); + importedModel.getDecisionServices().forEach(node -> assertThat(isInUnnamedImport(node, importingModel)).isFalse()); + importedModel.getInputs().forEach(node -> assertThat(isInUnnamedImport(node, importingModel)).isFalse()); + importedModel.getItemDefinitions().forEach(node -> assertThat(isInUnnamedImport(node, importingModel)).isFalse()); } @Test void addIfNotPresentTrue() throws IOException { URL importedModelFileResource = Thread.currentThread().getContextClassLoader().getResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn"); - assertNotNull(importedModelFileResource); + assertThat(importedModelFileResource).isNotNull(); try (InputStream is = importedModelFileResource.openStream()) { String xml = new String(is.readAllBytes(), StandardCharsets.UTF_8); Definitions definitions = DMNMarshallerFactory.newDefaultMarshaller().unmarshal(xml); - definitions.getDecisionService().forEach(definition -> assertTrue(added(definition))); - definitions.getBusinessContextElement().forEach(definition -> assertTrue(added(definition))); - definitions.getDrgElement().forEach(definition -> assertTrue(added(definition))); - definitions.getImport().forEach(definition -> assertTrue(added(definition))); - definitions.getItemDefinition().forEach(definition -> assertTrue(added(definition))); + definitions.getDecisionService().forEach(definition -> assertThat(added(definition)).isTrue()); + definitions.getBusinessContextElement().forEach(definition -> assertThat(added(definition)).isTrue()); + definitions.getDrgElement().forEach(definition -> assertThat(added(definition)).isTrue()); + definitions.getImport().forEach(definition -> assertThat(added(definition)).isTrue()); + definitions.getItemDefinition().forEach(definition -> assertThat(added(definition)).isTrue()); } } @@ -117,11 +114,11 @@ private void commonIsInUnnamedImportTrue(String importingModelRef, String import "-f9a3-410a-ac95-bea496edabgc", "Importing empty-named Model"); assertThat(importingModel).isNotNull(); - importedModel.getDecisions().forEach(node -> assertTrue(isInUnnamedImport(node, importingModel))); - importedModel.getBusinessKnowledgeModels().forEach(node -> assertTrue(isInUnnamedImport(node, importingModel))); - importedModel.getDecisionServices().forEach(node -> assertTrue(isInUnnamedImport(node, importingModel))); - importedModel.getInputs().forEach(node -> assertTrue(isInUnnamedImport(node, importingModel))); - importedModel.getItemDefinitions().forEach(node -> assertTrue(isInUnnamedImport(node, importingModel))); + importedModel.getDecisions().forEach(node -> assertThat(isInUnnamedImport(node, importingModel)).isTrue()); + importedModel.getBusinessKnowledgeModels().forEach(node -> assertThat(isInUnnamedImport(node, importingModel)).isTrue()); + importedModel.getDecisionServices().forEach(node -> assertThat(isInUnnamedImport(node, importingModel)).isTrue()); + importedModel.getInputs().forEach(node -> assertThat(isInUnnamedImport(node, importingModel)).isTrue()); + importedModel.getItemDefinitions().forEach(node -> assertThat(isInUnnamedImport(node, importingModel)).isTrue()); } private void commonAddIfNotPresentFalse(String importingModelRef, String importedModelRef) throws IOException { @@ -135,16 +132,16 @@ private void commonAddIfNotPresentFalse(String importingModelRef, String importe Definitions importingDefinitions = importingModel.getDefinitions(); URL importedModelFileResource = Thread.currentThread().getContextClassLoader().getResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn"); - assertNotNull(importedModelFileResource); + assertThat(importedModelFileResource).isNotNull(); try (InputStream is = importedModelFileResource.openStream()) { String importedXml = new String(is.readAllBytes(), StandardCharsets.UTF_8); Definitions importedDefinitions = DMNMarshallerFactory.newDefaultMarshaller().unmarshal(importedXml); - importedDefinitions.getDecisionService().forEach(definition -> assertFalse(added(importingDefinitions.getDecisionService(), definition))); - importedDefinitions.getBusinessContextElement().forEach(definition -> assertFalse(added(importingDefinitions.getBusinessContextElement(), definition))); - importedDefinitions.getDrgElement().forEach(definition -> assertFalse(added(importingDefinitions.getDrgElement(), definition))); - importedDefinitions.getImport().forEach(definition -> assertFalse(added(importingDefinitions.getImport(), - definition))); - importedDefinitions.getItemDefinition().forEach(definition -> assertFalse(added(importingDefinitions.getItemDefinition(), definition))); + importedDefinitions.getDecisionService().forEach(definition -> assertThat(added(importingDefinitions.getDecisionService(), definition)).isFalse()); + importedDefinitions.getBusinessContextElement().forEach(definition -> assertThat(added(importingDefinitions.getBusinessContextElement(), definition)).isFalse()); + importedDefinitions.getDrgElement().forEach(definition -> assertThat(added(importingDefinitions.getDrgElement(), definition)).isFalse()); + importedDefinitions.getImport().forEach(definition -> assertThat(added(importingDefinitions.getImport(), + definition)).isFalse()); + importedDefinitions.getItemDefinition().forEach(definition -> assertThat(added(importingDefinitions.getItemDefinition(), definition)).isFalse()); } } diff --git a/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/impl/DMNContextFEELCtxWrapperTest.java b/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/impl/DMNContextFEELCtxWrapperTest.java index 3aa3a2553e7..cf9bdca07aa 100644 --- a/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/impl/DMNContextFEELCtxWrapperTest.java +++ b/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/impl/DMNContextFEELCtxWrapperTest.java @@ -32,7 +32,7 @@ import org.kie.dmn.feel.lang.EvaluationContext; import org.kie.dmn.feel.lang.FEELDialect; -import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; class DMNContextFEELCtxWrapperTest extends BaseDMNContextTest { @@ -56,7 +56,7 @@ void contextWithEntriesAndMetadata() { @Test void pushScopeException() { - assertThrows(UnsupportedOperationException.class, () -> { + assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> { DMNContextFEELCtxWrapper ctx = new DMNContextFEELCtxWrapper(new EvaluationContextMock(Collections.emptyMap())); ctx.pushScope("scopeName", "scopeNamespace"); }); @@ -64,7 +64,7 @@ void pushScopeException() { @Test void popScopeException() { - assertThrows(UnsupportedOperationException.class, () -> { + assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> { DMNContextFEELCtxWrapper ctx = new DMNContextFEELCtxWrapper(new EvaluationContextMock(Collections.emptyMap())); ctx.popScope(); }); @@ -72,7 +72,7 @@ void popScopeException() { @Test void scopeNamespaceException() { - assertThrows(UnsupportedOperationException.class, () -> { + assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> { DMNContextFEELCtxWrapper ctx = new DMNContextFEELCtxWrapper(new EvaluationContextMock(Collections.emptyMap())); ctx.scopeNamespace(); }); diff --git a/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/util/CoerceUtilTest.java b/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/util/CoerceUtilTest.java index 9dcec22375c..13e76e2bb3c 100644 --- a/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/util/CoerceUtilTest.java +++ b/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/util/CoerceUtilTest.java @@ -21,6 +21,7 @@ import java.math.BigDecimal; import java.time.LocalDate; +import java.time.LocalDateTime; import java.time.ZoneOffset; import java.time.ZonedDateTime; import java.util.Collections; @@ -30,9 +31,7 @@ import org.kie.dmn.core.impl.SimpleTypeImpl; import org.kie.dmn.feel.lang.types.BuiltInType; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; class CoerceUtilTest { @@ -49,8 +48,8 @@ void coerceValueCollectionToArrayConverted() { null, BuiltInType.STRING); Object retrieved = CoerceUtil.coerceValue(requiredType, value); - assertNotNull(retrieved); - assertEquals(item, retrieved); + assertThat(retrieved).isNotNull(); + assertThat(retrieved).isEqualTo(item); } @Test @@ -66,8 +65,8 @@ void coerceValueCollectionToArrayNotConverted() { null, BuiltInType.STRING); Object retrieved = CoerceUtil.coerceValue(requiredType, value); - assertNotNull(retrieved); - assertEquals(value, retrieved); + assertThat(retrieved).isNotNull(); + assertThat(retrieved).isEqualTo(value); value = "TESTED_OBJECT"; requiredType = new SimpleTypeImpl("http://www.omg.org/spec/DMN/20180521/FEEL/", @@ -79,12 +78,12 @@ void coerceValueCollectionToArrayNotConverted() { null, BuiltInType.STRING); retrieved = CoerceUtil.coerceValue(requiredType, value); - assertNotNull(retrieved); - assertEquals(value, retrieved); + assertThat(retrieved).isNotNull(); + assertThat(retrieved).isEqualTo(value); requiredType = null; retrieved = CoerceUtil.coerceValue(requiredType, value); - assertEquals(value, retrieved); + assertThat(retrieved).isEqualTo(value); value = null; requiredType = new SimpleTypeImpl("http://www.omg.org/spec/DMN/20180521/FEEL/", @@ -96,7 +95,7 @@ void coerceValueCollectionToArrayNotConverted() { null, BuiltInType.STRING); retrieved = CoerceUtil.coerceValue(requiredType, value); - assertEquals(value, retrieved); + assertThat(retrieved).isEqualTo(value); } @@ -112,14 +111,15 @@ void coerceValueDateToDateTimeConverted() { null, BuiltInType.DATE_TIME); Object retrieved = CoerceUtil.coerceValue(requiredType, value); - assertNotNull(retrieved); - assertTrue(retrieved instanceof ZonedDateTime); + assertThat(retrieved).isNotNull(); + assertThat(retrieved).isInstanceOf(ZonedDateTime.class); ZonedDateTime zdtRetrieved = (ZonedDateTime)retrieved; - assertEquals(value, zdtRetrieved.toLocalDate()); - assertEquals(ZoneOffset.UTC, zdtRetrieved.getOffset()); - assertEquals(0, zdtRetrieved.getHour()); - assertEquals(0, zdtRetrieved.getMinute()); - assertEquals(0, zdtRetrieved.getSecond()); + assertThat(zdtRetrieved.toLocalDate()).isEqualTo(value); + assertThat(zdtRetrieved.getOffset()).isEqualTo(ZoneOffset.UTC); + + assertThat(zdtRetrieved.getHour()).isEqualTo(0); + assertThat(zdtRetrieved.getMinute()).isEqualTo(0); + assertThat(zdtRetrieved.getSecond()).isEqualTo(0); } @Test @@ -134,8 +134,8 @@ void coerceValueDateToDateTimeNotConverted() { null, BuiltInType.DATE_TIME); Object retrieved = CoerceUtil.coerceValue(requiredType, value); - assertNotNull(retrieved); - assertEquals(value, retrieved); + assertThat(retrieved).isNotNull(); + assertThat(retrieved).isEqualTo(value); value = LocalDate.now(); requiredType = new SimpleTypeImpl("http://www.omg.org/spec/DMN/20180521/FEEL/", "date", @@ -146,8 +146,8 @@ void coerceValueDateToDateTimeNotConverted() { null, BuiltInType.DATE); retrieved = CoerceUtil.coerceValue(requiredType, value); - assertNotNull(retrieved); - assertEquals(value, retrieved); + assertThat(retrieved).isNotNull(); + assertThat(retrieved).isEqualTo(value); } @Test @@ -163,8 +163,8 @@ void actualCoerceValueCollectionToArray() { null, BuiltInType.STRING); Object retrieved = CoerceUtil.actualCoerceValue(requiredType, value); - assertNotNull(retrieved); - assertEquals(item, retrieved); + assertThat(retrieved).isNotNull(); + assertThat(retrieved).isEqualTo(item); } @Test @@ -179,14 +179,14 @@ void actualCoerceValueDateToDateTime() { null, BuiltInType.DATE_TIME); Object retrieved = CoerceUtil.actualCoerceValue(requiredType, value); - assertNotNull(retrieved); - assertTrue(retrieved instanceof ZonedDateTime); + assertThat(retrieved).isNotNull(); + assertThat(retrieved).isInstanceOf(ZonedDateTime.class); ZonedDateTime zdtRetrieved = (ZonedDateTime)retrieved; - assertEquals(value, zdtRetrieved.toLocalDate()); - assertEquals(ZoneOffset.UTC, zdtRetrieved.getOffset()); - assertEquals(0, zdtRetrieved.getHour()); - assertEquals(0, zdtRetrieved.getMinute()); - assertEquals(0, zdtRetrieved.getSecond()); + assertThat(zdtRetrieved.toLocalDate()).isEqualTo(value); + assertThat(zdtRetrieved.getOffset()).isEqualTo(ZoneOffset.UTC); + assertThat(zdtRetrieved.getHour()).isEqualTo(0); + assertThat(zdtRetrieved.getMinute()).isEqualTo(0); + assertThat(zdtRetrieved.getSecond()).isEqualTo(0); } @Test @@ -201,7 +201,7 @@ void actualCoerceValueNotConverted() { null, BuiltInType.NUMBER); Object retrieved = CoerceUtil.actualCoerceValue(requiredType, value); - assertNotNull(retrieved); - assertEquals(value, retrieved); + assertThat(retrieved).isNotNull(); + assertThat(retrieved).isEqualTo(value); } } \ No newline at end of file diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/forexpressioniterators/BigDecimalRangeIteratorTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/forexpressioniterators/BigDecimalRangeIteratorTest.java index 7264767ff0a..aec84884a5d 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/forexpressioniterators/BigDecimalRangeIteratorTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/forexpressioniterators/BigDecimalRangeIteratorTest.java @@ -25,9 +25,7 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; class BigDecimalRangeIteratorTest { @@ -36,13 +34,13 @@ void hasNextAscendantTest() { BigDecimal start = BigDecimal.valueOf(1); BigDecimal end = BigDecimal.valueOf(3); BigDecimalRangeIterator iterator = new BigDecimalRangeIterator(start, end); - assertTrue(iterator.hasNext()); + assertThat(iterator).hasNext(); BigDecimal next = iterator.next(); while (!next.equals(end)) { - assertTrue(iterator.hasNext()); + assertThat(iterator).hasNext(); next = iterator.next(); } - assertFalse(iterator.hasNext()); + assertThat(iterator).isExhausted(); } @Test @@ -50,13 +48,13 @@ void hasNextDescendantTest() { BigDecimal start = BigDecimal.valueOf(3); BigDecimal end = BigDecimal.valueOf(1); BigDecimalRangeIterator iterator = new BigDecimalRangeIterator(start, end); - assertTrue(iterator.hasNext()); + assertThat(iterator).hasNext(); BigDecimal next = iterator.next(); while (!next.equals(end)) { - assertTrue(iterator.hasNext()); + assertThat(iterator).hasNext(); next = iterator.next(); } - assertFalse(iterator.hasNext()); + assertThat(iterator).isExhausted(); } @Test @@ -65,7 +63,7 @@ void nextAscendantTest() { BigDecimal end = BigDecimal.valueOf(3); List expected = Arrays.asList(BigDecimal.valueOf(1), BigDecimal.valueOf(2), BigDecimal.valueOf(3)); BigDecimalRangeIterator iterator = new BigDecimalRangeIterator(start, end); - IntStream.range(0, 3).forEach(i -> assertEquals(expected.get(i), iterator.next())); + IntStream.range(0, 3).forEach(i -> assertThat(expected.get(i)).isEqualTo(iterator.next())); } @Test @@ -74,7 +72,7 @@ void nextDescendantTest() { BigDecimal end = BigDecimal.valueOf(1); List expected = Arrays.asList(BigDecimal.valueOf(3), BigDecimal.valueOf(2), BigDecimal.valueOf(1)); BigDecimalRangeIterator iterator = new BigDecimalRangeIterator(start, end); - IntStream.range(0, 3).forEach(i -> assertEquals(expected.get(i), iterator.next())); + IntStream.range(0, 3).forEach(i -> assertThat(expected.get(i)).isEqualTo(iterator.next())); } diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/forexpressioniterators/ForIterationTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/forexpressioniterators/ForIterationTest.java index 509cbcfe25f..b9980f6f119 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/forexpressioniterators/ForIterationTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/forexpressioniterators/ForIterationTest.java @@ -26,9 +26,7 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; class ForIterationTest { @@ -37,13 +35,13 @@ void hasNextValueBigDecimalTest() { BigDecimal start = BigDecimal.valueOf(1); BigDecimal end = BigDecimal.valueOf(3); ForIteration iteration = new ForIteration("iteration", start, end); - assertTrue(iteration.hasNextValue()); + assertThat(iteration.hasNextValue()).isTrue(); BigDecimal next = (BigDecimal) iteration.getNextValue(); while (!next.equals(end)) { - assertTrue(iteration.hasNextValue()); + assertThat(iteration.hasNextValue()).isTrue(); next = (BigDecimal) iteration.getNextValue(); } - assertFalse(iteration.hasNextValue()); + assertThat(iteration.hasNextValue()).isFalse(); } @Test @@ -51,13 +49,13 @@ void hasNextValueLocalDateTest() { LocalDate start = LocalDate.of(2021, 1, 1); LocalDate end = LocalDate.of(2021, 1, 3); ForIteration iteration = new ForIteration("iteration", start, end); - assertTrue(iteration.hasNextValue()); + assertThat(iteration.hasNextValue()).isTrue(); LocalDate next = (LocalDate) iteration.getNextValue(); while (!next.equals(end)) { - assertTrue(iteration.hasNextValue()); + assertThat(iteration.hasNextValue()).isTrue(); next = (LocalDate) iteration.getNextValue(); } - assertFalse(iteration.hasNextValue()); + assertThat(iteration.hasNextValue()).isFalse(); } @Test @@ -67,7 +65,7 @@ void getNextValueBigDecimalTest() { List expected = Arrays.asList(BigDecimal.valueOf(1), BigDecimal.valueOf(2), BigDecimal.valueOf(3)); ForIteration iteration = new ForIteration("iteration", start, end); iteration.hasNextValue(); - IntStream.range(0, 3).forEach(i -> assertEquals(expected.get(i), iteration.getNextValue())); + IntStream.range(0, 3).forEach(i -> assertThat(expected.get(i)).isEqualTo(iteration.getNextValue())); } @Test @@ -77,6 +75,6 @@ void getNextValueLocalDateTest() { List expected = Arrays.asList(LocalDate.of(2021, 1, 3), LocalDate.of(2021, 1, 2), LocalDate.of(2021, 1, 1)); ForIteration iteration = new ForIteration("iteration", start, end); iteration.hasNextValue(); - IntStream.range(0, 3).forEach(i -> assertEquals(expected.get(i), iteration.getNextValue())); + IntStream.range(0, 3).forEach(i -> assertThat(expected.get(i)).isEqualTo(iteration.getNextValue())); } } \ No newline at end of file diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/forexpressioniterators/ForIterationUtilsTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/forexpressioniterators/ForIterationUtilsTest.java index 0b4da928e6f..226d2e1797d 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/forexpressioniterators/ForIterationUtilsTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/forexpressioniterators/ForIterationUtilsTest.java @@ -6,9 +6,9 @@ * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

* Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -31,8 +31,7 @@ import org.kie.dmn.feel.lang.impl.FEELEventListenersManager; import org.mockito.ArgumentCaptor; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import static org.kie.dmn.feel.codegen.feel11.CodegenTestUtil.newEmptyEvaluationContext; import static org.kie.dmn.feel.lang.ast.forexpressioniterators.ForIterationUtils.getForIteration; import static org.kie.dmn.feel.lang.ast.forexpressioniterators.ForIterationUtils.validateValues; @@ -60,10 +59,10 @@ void setup() { @Test void getForIterationValidTest() { ForIteration retrieved = getForIteration(ctx, "iteration", BigDecimal.valueOf(1), BigDecimal.valueOf(3)); - assertNotNull(retrieved); + assertThat(retrieved).isNotNull(); verify(listener, never()).onEvent(any(FEELEvent.class)); retrieved = getForIteration(ctx, "iteration", LocalDate.of(2021, 1, 1), LocalDate.of(2021, 1, 3)); - assertNotNull(retrieved); + assertThat(retrieved).isNotNull(); verify(listener, never()).onEvent(any(FEELEvent.class)); } @@ -72,7 +71,7 @@ void getForIterationNotValidTest() { try { getForIteration(ctx, "iteration", "NOT", "VALID"); } catch (Exception e) { - assertTrue(e instanceof EndpointOfRangeNotValidTypeException); + assertThat(e).isInstanceOf(EndpointOfRangeNotValidTypeException.class); final ArgumentCaptor captor = ArgumentCaptor.forClass(FEELEvent.class); verify(listener, times(1)).onEvent(captor.capture()); reset(listener); @@ -80,7 +79,7 @@ void getForIterationNotValidTest() { try { getForIteration(ctx, "iteration", BigDecimal.valueOf(1), LocalDate.of(2021, 1, 1)); } catch (Exception e) { - assertTrue(e instanceof EndpointOfRangeOfDifferentTypeException); + assertThat(e).isInstanceOf(EndpointOfRangeOfDifferentTypeException.class); final ArgumentCaptor captor = ArgumentCaptor.forClass(FEELEvent.class); verify(listener, times(1)).onEvent(captor.capture()); reset(listener); @@ -88,7 +87,7 @@ void getForIterationNotValidTest() { try { getForIteration(ctx, "iteration", LocalDate.of(2021, 1, 1), BigDecimal.valueOf(1)); } catch (Exception e) { - assertTrue(e instanceof EndpointOfRangeOfDifferentTypeException); + assertThat(e).isInstanceOf(EndpointOfRangeOfDifferentTypeException.class); final ArgumentCaptor captor = ArgumentCaptor.forClass(FEELEvent.class); verify(listener, times(1)).onEvent(captor.capture()); reset(listener); @@ -108,7 +107,7 @@ void valueMustBeValidFalseTest() { try { valueMustBeValid(ctx, "INVALID"); } catch (Exception e) { - assertTrue(e instanceof EndpointOfRangeNotValidTypeException); + assertThat(e).isInstanceOf(EndpointOfRangeNotValidTypeException.class); final ArgumentCaptor captor = ArgumentCaptor.forClass(FEELEvent.class); verify(listener, times(1)).onEvent(captor.capture()); } @@ -127,7 +126,7 @@ void validateValuesFalseTest() { try { validateValues(ctx, "INVALID", "INVALID"); } catch (Exception e) { - assertTrue(e instanceof EndpointOfRangeNotValidTypeException); + assertThat(e).isInstanceOf(EndpointOfRangeNotValidTypeException.class); final ArgumentCaptor captor = ArgumentCaptor.forClass(FEELEvent.class); verify(listener, times(1)).onEvent(captor.capture()); reset(listener); @@ -135,7 +134,7 @@ void validateValuesFalseTest() { try { validateValues(ctx, BigDecimal.valueOf(1), LocalDate.of(2021, 1, 1)); } catch (Exception e) { - assertTrue(e instanceof EndpointOfRangeOfDifferentTypeException); + assertThat(e).isInstanceOf(EndpointOfRangeOfDifferentTypeException.class); final ArgumentCaptor captor = ArgumentCaptor.forClass(FEELEvent.class); verify(listener, times(1)).onEvent(captor.capture()); reset(listener); @@ -143,12 +142,10 @@ void validateValuesFalseTest() { try { validateValues(ctx, LocalDate.of(2021, 1, 1), BigDecimal.valueOf(1)); } catch (Exception e) { - assertTrue(e instanceof EndpointOfRangeOfDifferentTypeException); + assertThat(e).isInstanceOf(EndpointOfRangeOfDifferentTypeException.class); final ArgumentCaptor captor = ArgumentCaptor.forClass(FEELEvent.class); verify(listener, times(1)).onEvent(captor.capture()); reset(listener); } } - - } \ No newline at end of file diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/forexpressioniterators/LocalDateRangeIteratorTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/forexpressioniterators/LocalDateRangeIteratorTest.java index eaf378f26e7..4add411f7f5 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/forexpressioniterators/LocalDateRangeIteratorTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/forexpressioniterators/LocalDateRangeIteratorTest.java @@ -26,9 +26,7 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; class LocalDateRangeIteratorTest { @@ -44,39 +42,39 @@ static void setup() { @Test void hasNextAscendantTest() { LocalDateRangeIterator iterator = new LocalDateRangeIterator(before, after); - assertTrue(iterator.hasNext()); + assertThat(iterator).hasNext(); LocalDate next = iterator.next(); while (!next.equals(after)) { - assertTrue(iterator.hasNext()); + assertThat(iterator).hasNext(); next = iterator.next(); } - assertFalse(iterator.hasNext()); + assertThat(iterator).isExhausted(); } @Test void hasNextDescendantTest() { LocalDateRangeIterator iterator = new LocalDateRangeIterator(after, before); - assertTrue(iterator.hasNext()); + assertThat(iterator).hasNext(); LocalDate next = iterator.next(); while (!next.equals(before)) { - assertTrue(iterator.hasNext()); + assertThat(iterator).hasNext(); next = iterator.next(); } - assertFalse(iterator.hasNext()); + assertThat(iterator).isExhausted(); } @Test void nextAscendantTest() { List expected = Arrays.asList(LocalDate.of(2021, 1, 1), LocalDate.of(2021, 1, 2), LocalDate.of(2021, 1, 3)); LocalDateRangeIterator iterator = new LocalDateRangeIterator(before, after); - IntStream.range(0, 3).forEach(i -> assertEquals(expected.get(i), iterator.next())); + IntStream.range(0, 3).forEach(i -> assertThat(expected.get(i)).isEqualTo(iterator.next())); } @Test void nextDescendantTest() { List expected = Arrays.asList(LocalDate.of(2021, 1, 3), LocalDate.of(2021, 1, 2), LocalDate.of(2021, 1, 1)); LocalDateRangeIterator iterator = new LocalDateRangeIterator(after, before); - IntStream.range(0, 3).forEach(i -> assertEquals(expected.get(i), iterator.next())); + IntStream.range(0, 3).forEach(i -> assertThat(expected.get(i)).isEqualTo(iterator.next())); } diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/forexpressioniterators/ZonedDateTimeRangeIteratorTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/forexpressioniterators/ZonedDateTimeRangeIteratorTest.java index 9290ec8fa21..d8a1e8769ea 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/forexpressioniterators/ZonedDateTimeRangeIteratorTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/forexpressioniterators/ZonedDateTimeRangeIteratorTest.java @@ -28,9 +28,7 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; class ZonedDateTimeRangeIteratorTest { @@ -47,25 +45,25 @@ static void setup() { @Test void hasNextAscendantTest() { ZonedDateTimeRangeIterator iterator = new ZonedDateTimeRangeIterator(before, after); - assertTrue(iterator.hasNext()); + assertThat(iterator).hasNext(); ZonedDateTime next = iterator.next(); while (next.isBefore(after)) { - assertTrue(iterator.hasNext()); + assertThat(iterator).hasNext(); next = iterator.next(); } - assertFalse(iterator.hasNext()); + assertThat(iterator).isExhausted(); } @Test void hasNextDescendantTest() { ZonedDateTimeRangeIterator iterator = new ZonedDateTimeRangeIterator(after, before); - assertTrue(iterator.hasNext()); + assertThat(iterator).hasNext(); ZonedDateTime next = iterator.next(); while (!next.equals(before)) { - assertTrue(iterator.hasNext()); + assertThat(iterator).hasNext(); next = iterator.next(); } - assertFalse(iterator.hasNext()); + assertThat(iterator).isExhausted(); } @Test @@ -74,7 +72,7 @@ void nextAscendantTest() { getZonedDateTime(2021, 1, 2, 10, 15), getZonedDateTime(2021, 1, 3, 10, 15)); ZonedDateTimeRangeIterator iterator = new ZonedDateTimeRangeIterator(before, after); - IntStream.range(0, 3).forEach(i -> assertEquals(expected.get(i), iterator.next())); + IntStream.range(0, 3).forEach(i -> assertThat(expected.get(i)).isEqualTo(iterator.next())); } @Test @@ -83,7 +81,7 @@ void nextDescendantTest() { getZonedDateTime(2021, 1, 2, 10, 15), getZonedDateTime(2021, 1, 1, 10, 15)); ZonedDateTimeRangeIterator iterator = new ZonedDateTimeRangeIterator(after, before); - IntStream.range(0, 3).forEach(i -> assertEquals(expected.get(i), iterator.next())); + IntStream.range(0, 3).forEach(i -> assertThat(expected.get(i)).isEqualTo(iterator.next())); } @@ -93,8 +91,8 @@ void hasNotNextAscendantTest() { ZonedDateTime end = getZonedDateTime(2021, 1, 2, 10, 14); ZonedDateTimeRangeIterator iterator = new ZonedDateTimeRangeIterator(start, end); ZonedDateTime retrieved = iterator.next(); - assertEquals(start, retrieved); - assertFalse(iterator.hasNext()); + assertThat(retrieved).isEqualTo(start); + assertThat(iterator).isExhausted(); } @Test @@ -103,8 +101,8 @@ void hasNotNextDescendantTest() { ZonedDateTime end = getZonedDateTime(2021, 1, 1, 10, 15); ZonedDateTimeRangeIterator iterator = new ZonedDateTimeRangeIterator(start, end); ZonedDateTime retrieved = iterator.next(); - assertEquals(start, retrieved); - assertFalse(iterator.hasNext()); + assertThat(retrieved).isEqualTo(start); + assertThat(iterator).isExhausted(); } private static ZonedDateTime getZonedDateTime(int year, int month, int dayOfMonth, int hour, int minute) { diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/custom/ZoneTimeTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/custom/ZoneTimeTest.java index af286aad609..f602e091051 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/custom/ZoneTimeTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/custom/ZoneTimeTest.java @@ -35,7 +35,7 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; import static org.kie.dmn.feel.runtime.custom.ZoneTime.ZONED_OFFSET_WITH_SECONDS; import static org.kie.dmn.feel.runtime.custom.ZoneTime.ZONED_OFFSET_WITHOUT_SECONDS; @@ -59,29 +59,29 @@ static void setUpClass() { @Test void of() { ZoneTime retrieved = ZoneTime.of(localTime, zoneId, true); - assertNotNull(retrieved); - assertEquals(offsetTime, retrieved.getOffsetTime()); - assertEquals(zoneId, retrieved.getZoneId()); + assertThat(retrieved).isNotNull(); + assertThat(retrieved.getOffsetTime()).isEqualTo(offsetTime); + assertThat(retrieved.getZoneId()).isEqualTo(zoneId); } @Test void getTimezone() { - assertEquals(REFERENCED_ZONE, zoneTime.getTimezone()); + assertThat(zoneTime.getTimezone()).isEqualTo(REFERENCED_ZONE); } @Test void compareTo() { ZoneTime toCompare = ZoneTime.of(DateTimeFormatter.ISO_TIME.parse("09:34:31", LocalTime::from), zoneId, false); OffsetTime comparison = toCompare.getOffsetTime(); - assertEquals(offsetTime.compareTo(comparison), zoneTime.compareTo(toCompare)); + assertThat(zoneTime.compareTo(toCompare)).isEqualTo(offsetTime.compareTo(comparison)); } @Test void withTemporalField() { ZoneTime expected = new ZoneTime(offsetTime.with(ChronoField.HOUR_OF_DAY, 3), zoneId, false); - assertEquals(expected, zoneTime.with(ChronoField.HOUR_OF_DAY, 3)); + assertThat(zoneTime.with(ChronoField.HOUR_OF_DAY, 3)).isEqualTo(expected); } @Test @@ -89,37 +89,37 @@ void withTemporalAdjuster() { TemporalAdjuster adjuster = ZoneTime.of(DateTimeFormatter.ISO_TIME.parse("09:34:31", LocalTime::from), zoneId , false); ZoneTime expected = new ZoneTime(offsetTime.with(adjuster), zoneId, false); - assertEquals(expected, zoneTime.with(adjuster)); + assertThat(zoneTime.with(adjuster)).isEqualTo(expected); adjuster = DateTimeFormatter.ISO_TIME.parse("09:34:31", LocalTime::from ); expected = new ZoneTime(offsetTime.with(adjuster), zoneId, false); - assertEquals(expected, zoneTime.with(adjuster)); + assertThat(zoneTime.with(adjuster)).isEqualTo(expected); } @Test void plusLong() { ZoneTime expected = new ZoneTime(offsetTime.plus(3, ChronoUnit.HOURS), zoneId, false); - assertEquals(expected, zoneTime.plus(3, ChronoUnit.HOURS)); + assertThat(zoneTime.plus(3, ChronoUnit.HOURS)).isEqualTo(expected); } @Test void plusTemporalAmount() { TemporalAmount amount = Duration.of(23, ChronoUnit.MINUTES); ZoneTime expected = new ZoneTime(offsetTime.plus(amount), zoneId, false); - assertEquals(expected, zoneTime.plus(amount)); + assertThat(zoneTime.plus(amount)).isEqualTo(expected); } @Test void minusLong() { ZoneTime expected = new ZoneTime(offsetTime.minus(3, ChronoUnit.HOURS), zoneId, false); - assertEquals(expected, zoneTime.minus(3, ChronoUnit.HOURS)); + assertThat(zoneTime.minus(3, ChronoUnit.HOURS)).isEqualTo(expected); } @Test void minusTemporalAmount() { TemporalAmount amount = Duration.of(23, ChronoUnit.MINUTES); ZoneTime expected = new ZoneTime(offsetTime.minus(amount), zoneId, false); - assertEquals(expected, zoneTime.minus(amount)); + assertThat(zoneTime.minus(amount)).isEqualTo(expected); } @Test @@ -128,47 +128,47 @@ void until() { false); long expected = offsetTime.until(endExclusive, ChronoUnit.SECONDS); long retrieved = zoneTime.until(endExclusive, ChronoUnit.SECONDS); - assertEquals(expected, retrieved); + assertThat(retrieved).isEqualTo(expected); } @Test void isSupportedTemporalUnit() { for (ChronoUnit unit : ChronoUnit.values()) { - assertEquals(offsetTime.isSupported(unit), zoneTime.isSupported(unit)); + assertThat(zoneTime.isSupported(unit)).isEqualTo(offsetTime.isSupported(unit)); } } @Test void isSupportedTemporalField() { for (ChronoField field : ChronoField.values()) { - assertEquals(offsetTime.isSupported(field), zoneTime.isSupported(field)); + assertThat(zoneTime.isSupported(field)).isEqualTo(offsetTime.isSupported(field)); } } @Test void getLong() { Arrays.stream(ChronoField.values()).filter(offsetTime::isSupported) - .forEach(field -> assertEquals(offsetTime.getLong(field), zoneTime.getLong(field))); + .forEach(field -> assertThat(offsetTime.getLong(field)).isEqualTo(zoneTime.getLong(field))); } @Test void adjustInto() { ZoneTime temporal = ZoneTime.of(DateTimeFormatter.ISO_TIME.parse("09:34:31", LocalTime::from), zoneId, false); - assertEquals(offsetTime.adjustInto(temporal), zoneTime.adjustInto(temporal)); + assertThat(zoneTime.adjustInto(temporal)).isEqualTo(offsetTime.adjustInto(temporal)); } @Test void query() { - assertEquals(zoneId, zoneTime.query(TemporalQueries.zoneId())); - assertEquals(zoneId, zoneTime.query(TemporalQueries.zone())); - assertEquals(offsetTime.query(TemporalQueries.localTime()), zoneTime.query(TemporalQueries.localTime())); - assertEquals(offsetTime.query(TemporalQueries.offset()), zoneTime.query(TemporalQueries.offset())); + assertThat(zoneTime.query(TemporalQueries.zoneId())).isEqualTo(zoneId); + assertThat(zoneTime.query(TemporalQueries.zone())).isEqualTo(zoneId); + assertThat(zoneTime.query(TemporalQueries.localTime())).isEqualTo(offsetTime.query(TemporalQueries.localTime())); + assertThat(zoneTime.query(TemporalQueries.offset())).isEqualTo(offsetTime.query(TemporalQueries.offset())); } @Test void range() { Arrays.stream(ChronoField.values()).filter(offsetTime::isSupported) - .forEach(field -> assertEquals(offsetTime.range(field), zoneTime.range(field))); + .forEach(field -> assertThat(offsetTime.range(field)).isEqualTo(zoneTime.range(field))); } @Test @@ -176,15 +176,15 @@ void get() { Arrays.stream(ChronoField.values()) .filter(offsetTime::isSupported) .filter(field -> field != ChronoField.NANO_OF_DAY && field != ChronoField.MICRO_OF_DAY) // Unsupported by offsettime.get() - .forEach(field -> assertEquals(offsetTime.get(field), zoneTime.get(field))); + .forEach(field -> assertThat(offsetTime.get(field)).isEqualTo(zoneTime.get(field))); } @Test void testEquals() { ZoneTime toCompare = ZoneTime.of(DateTimeFormatter.ISO_TIME.parse("09:34:31", LocalTime::from), zoneId, false); - assertFalse(zoneTime.equals(toCompare)); + assertThat(toCompare).isNotEqualTo(zoneTime); toCompare = ZoneTime.of(localTime, zoneId, false); - assertTrue(zoneTime.equals(toCompare)); + assertThat(toCompare).isEqualTo(zoneTime); } @Test @@ -192,7 +192,7 @@ void testZONED_OFFSET_WITHOUT_SECONDS() { String timeString = "09:34"; ZoneTime toFormat = ZoneTime.of(DateTimeFormatter.ISO_TIME.parse(timeString, LocalTime::from), zoneId, false); String expected = String.format("%s@%s", timeString, REFERENCED_ZONE); - assertEquals(expected, ZONED_OFFSET_WITHOUT_SECONDS.format(toFormat)); + assertThat(ZONED_OFFSET_WITHOUT_SECONDS.format(toFormat)).isEqualTo(expected); } @Test @@ -200,12 +200,12 @@ void testZONED_OFFSET_WITH_SECONDS() { String timeString = "09:34:34"; ZoneTime toFormat = ZoneTime.of(DateTimeFormatter.ISO_TIME.parse(timeString, LocalTime::from), zoneId, true); String expected = String.format("%s@%s", timeString, REFERENCED_ZONE); - assertEquals(expected, ZONED_OFFSET_WITH_SECONDS.format(toFormat)); + assertThat(ZONED_OFFSET_WITH_SECONDS.format(toFormat)).isEqualTo(expected); timeString = "09:34:00"; toFormat = ZoneTime.of(DateTimeFormatter.ISO_TIME.parse(timeString, LocalTime::from), zoneId, true); expected = String.format("%s@%s", timeString, REFERENCED_ZONE); - assertEquals(expected, ZONED_OFFSET_WITH_SECONDS.format(toFormat)); + assertThat(ZONED_OFFSET_WITH_SECONDS.format(toFormat)).isEqualTo(expected); } @Test @@ -213,7 +213,7 @@ void testFormatWithoutSeconds() { String timeString = "09:34"; ZoneTime toFormat = ZoneTime.of(DateTimeFormatter.ISO_TIME.parse(timeString, LocalTime::from), zoneId, false); String expected = String.format("%s@%s", timeString, REFERENCED_ZONE); - assertEquals(expected, toFormat.format()); + assertThat(toFormat.format()).isEqualTo(expected); } @Test @@ -221,12 +221,12 @@ void testFormatWithSeconds() { String timeString = "09:34:00"; ZoneTime toFormat = ZoneTime.of(DateTimeFormatter.ISO_TIME.parse(timeString, LocalTime::from), zoneId, true); String expected = String.format("%s@%s", timeString, REFERENCED_ZONE); - assertEquals(expected, toFormat.format()); + assertThat(toFormat.format()).isEqualTo(expected); timeString = "09:34:34"; toFormat = ZoneTime.of(DateTimeFormatter.ISO_TIME.parse(timeString, LocalTime::from), zoneId, true); expected = String.format("%s@%s", timeString, REFERENCED_ZONE); - assertEquals(expected, toFormat.format()); + assertThat(toFormat.format()).isEqualTo(expected); } private static OffsetTime getCorrectOffsetTime() { diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/BaseFEELFunctionHelperTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/BaseFEELFunctionHelperTest.java index 39106d29d10..9143712030a 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/BaseFEELFunctionHelperTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/BaseFEELFunctionHelperTest.java @@ -37,13 +37,6 @@ import org.kie.dmn.feel.util.NumberEvalHelper; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertInstanceOf; -import static org.junit.jupiter.api.Assertions.assertNotEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertTrue; class BaseFEELFunctionHelperTest { @@ -58,14 +51,14 @@ public void setUp() { void getAdjustedParametersForMethod() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { // StddevFunction.invoke(@ParameterName( "list" ) List list) Method method = StddevFunction.class.getMethod("invoke", List.class); - assertNotNull(method); + assertThat(method).isNotNull(); Object actualValue = Arrays.asList(2, 4, 7, 5); Object[] parameters = {new NamedParameter("list", actualValue)}; Object[] retrieved = BaseFEELFunctionHelper.getAdjustedParametersForMethod(ctx, parameters, true, method); - assertNotNull(retrieved); - assertEquals(parameters.length, retrieved.length); - assertEquals(actualValue, retrieved[0]); + assertThat(retrieved).isNotNull(); + assertThat(retrieved.length).isEqualTo(parameters.length); + assertThat(retrieved[0]).isEqualTo(actualValue); } @Test @@ -75,103 +68,102 @@ void adjustByCoercion() { Class[] parameterTypes = new Class[]{List.class}; Object[] actualParams = {actualParam}; Object[] retrieved = BaseFEELFunctionHelper.adjustByCoercion(parameterTypes, actualParams); - assertEquals(actualParams, retrieved); + assertThat(retrieved).isEqualTo(actualParams); actualParam = "StringA"; parameterTypes = new Class[]{String.class}; actualParams = new Object[]{actualParam}; retrieved = BaseFEELFunctionHelper.adjustByCoercion(parameterTypes, actualParams); - assertEquals(actualParams, retrieved); + assertThat(retrieved).isEqualTo(actualParams); // coercing more objects to different types: fails parameterTypes = new Class[]{String.class, Integer.class}; actualParams = new Object[]{"String", 34 }; retrieved = BaseFEELFunctionHelper.adjustByCoercion(parameterTypes, actualParams); - assertEquals(actualParams, retrieved); + assertThat(retrieved).isEqualTo(actualParams); // not coercing null value to not-list type actualParam = null; actualParams = new Object[]{actualParam}; retrieved = BaseFEELFunctionHelper.adjustByCoercion(parameterTypes, actualParams); - assertEquals(actualParams, retrieved); + assertThat(retrieved).isEqualTo(actualParams); // not coercing null value to singleton list parameterTypes = new Class[]{List.class}; retrieved = BaseFEELFunctionHelper.adjustByCoercion(parameterTypes, actualParams); - assertEquals(actualParams, retrieved); + assertThat(retrieved).isEqualTo(actualParams); // coercing not-null value to singleton list actualParam = "StringA"; actualParams = new Object[]{actualParam}; retrieved = BaseFEELFunctionHelper.adjustByCoercion(parameterTypes, actualParams); - assertNotNull(retrieved); - assertNotEquals(actualParams, retrieved); - assertEquals(1, retrieved.length); - assertNotNull(retrieved[0]); + assertThat(retrieved).isNotNull(); + assertThat(retrieved).isNotEqualTo(actualParams); + assertThat(retrieved.length).isEqualTo(1); + assertThat(retrieved[0]).isNotNull(); assertThat(retrieved[0]).isInstanceOf(List.class); List retrievedList = (List) retrieved[0]; - assertEquals(1, retrievedList.size()); - assertEquals(actualParam, retrievedList.get(0)); + assertThat(retrievedList.size()).isEqualTo(1); + assertThat(retrievedList.get(0)).isEqualTo(actualParam); // coercing null value to array: fails parameterTypes = new Class[]{Object.class.arrayType()}; retrieved = BaseFEELFunctionHelper.adjustByCoercion(parameterTypes, actualParams); - assertNull(retrieved); + assertThat(retrieved).isNull(); // coercing one object to different type: fails actualParam = 45; parameterTypes = new Class[]{String.class}; actualParams = new Object[]{actualParam}; retrieved = BaseFEELFunctionHelper.adjustByCoercion(parameterTypes, actualParams); - assertNull(retrieved); + assertThat(retrieved).isNull(); // coercing more objects to different types: fails parameterTypes = new Class[]{String.class, Integer.class}; actualParams = new Object[]{"String", "34" }; retrieved = BaseFEELFunctionHelper.adjustByCoercion(parameterTypes, actualParams); - assertNull(retrieved); - + assertThat(retrieved).isNull(); } @Test void addCtxParamIfRequired() throws NoSuchMethodException { // AllFunction.invoke(@ParameterName( "list" ) List list) Method method = AllFunction.class.getMethod("invoke", List.class); - assertNotNull(method); + assertThat(method).isNotNull(); Object[] parameters = {List.of(true, false)}; Object[] retrieved = BaseFEELFunctionHelper.addCtxParamIfRequired(ctx, parameters, true, method); - assertNotNull(retrieved); - assertEquals(parameters.length, retrieved.length); + assertThat(retrieved).isNotNull(); + assertThat(retrieved.length).isEqualTo(parameters.length); for (int i = 0; i < parameters.length; i++) { - assertEquals(parameters[i], retrieved[i]); + assertThat(retrieved[i]).isEqualTo(parameters[i]); } // SortFunction.invoke(@ParameterName( "ctx" ) EvaluationContext ctx, // @ParameterName("list") List list, // @ParameterName("precedes") FEELFunction function) method = SortFunction.class.getMethod("invoke", EvaluationContext.class, List.class, FEELFunction.class); - assertNotNull(method); + assertThat(method).isNotNull(); parameters = new Object[]{List.of(1, 2), AllFunction.INSTANCE}; // direct reference to ctx retrieved = BaseFEELFunctionHelper.addCtxParamIfRequired(ctx, parameters, false, method); - assertNotNull(retrieved); - assertEquals(parameters.length + 1, retrieved.length); - assertEquals(ctx, retrieved[0]); + assertThat(retrieved).isNotNull(); + assertThat(retrieved.length).isEqualTo(parameters.length + 1); + assertThat(retrieved[0]).isEqualTo(ctx); for (int i = 0; i < parameters.length; i++) { - assertEquals(parameters[i], retrieved[i + 1]); + assertThat(retrieved[i + 1]).isEqualTo(parameters[i]); } // NamedParameter reference to ctx retrieved = BaseFEELFunctionHelper.addCtxParamIfRequired(ctx, parameters, true, method); - assertNotNull(retrieved); - assertEquals(parameters.length + 1, retrieved.length); - assertEquals(NamedParameter.class, retrieved[0].getClass()); + assertThat(retrieved).isNotNull(); + assertThat(retrieved.length).isEqualTo(parameters.length + 1); + assertThat(retrieved[0].getClass()).isEqualTo(NamedParameter.class); NamedParameter retrievedNamedParameter = (NamedParameter) retrieved[0]; - assertEquals("ctx", retrievedNamedParameter.getName()); - assertEquals(ctx, retrievedNamedParameter.getValue()); + assertThat(retrievedNamedParameter.getName()).isEqualTo("ctx"); + assertThat(retrievedNamedParameter.getValue()).isEqualTo(ctx); for (int i = 0; i < parameters.length; i++) { - assertEquals(parameters[i], retrieved[i + 1]); + assertThat(retrieved[i + 1]).isEqualTo(parameters[i]); } } @@ -179,16 +171,16 @@ void addCtxParamIfRequired() throws NoSuchMethodException { void calculateActualParams() throws NoSuchMethodException { // CeilingFunction.invoke(@ParameterName( "n" ) BigDecimal n) Method m = CeilingFunction.class.getMethod("invoke", BigDecimal.class); - assertNotNull(m); + assertThat(m).isNotNull(); NamedParameter[] parameters = {new NamedParameter("n", BigDecimal.valueOf(1.5))}; Object[] retrieved = BaseFEELFunctionHelper.calculateActualParams(m, parameters); - assertNotNull(retrieved); - assertEquals(parameters.length, retrieved.length); - assertEquals(parameters[0].getValue(), retrieved[0]); + assertThat(retrieved).isNotNull(); + assertThat(retrieved.length).isEqualTo(parameters.length); + assertThat(retrieved[0]).isEqualTo(parameters[0].getValue()); parameters = new NamedParameter[]{new NamedParameter("undefined", BigDecimal.class)}; retrieved = BaseFEELFunctionHelper.calculateActualParams(m, parameters); - assertNull(retrieved); + assertThat(retrieved).isNull(); } @Test @@ -200,14 +192,14 @@ void calculateActualParam() { boolean isVariableParameters = false; String variableParamPrefix = null; List variableParams = null; - assertTrue(BaseFEELFunctionHelper.calculateActualParam(np, names, actualParams, isVariableParameters, - variableParamPrefix, variableParams)); - assertEquals(np.getValue(), actualParams[0]); + assertThat(BaseFEELFunctionHelper.calculateActualParam(np, names, actualParams, isVariableParameters, + variableParamPrefix, variableParams)).isTrue(); + assertThat(actualParams[0]).isEqualTo(np.getValue()); np = new NamedParameter("undefined", BigDecimal.valueOf(1.5)); actualParams = new Object[1]; - assertFalse(BaseFEELFunctionHelper.calculateActualParam(np, names, actualParams, isVariableParameters, - variableParamPrefix, variableParams)); + assertThat(BaseFEELFunctionHelper.calculateActualParam(np, names, actualParams, isVariableParameters, + variableParamPrefix, variableParams)).isFalse(); // populate by variableparameters variableParamPrefix = "varPref"; @@ -217,13 +209,13 @@ void calculateActualParam() { actualParams = new Object[1]; isVariableParameters = true; variableParams = new ArrayList(); - assertTrue(BaseFEELFunctionHelper.calculateActualParam(np, names, actualParams, isVariableParameters, - variableParamPrefix, variableParams)); - assertEquals(varIndex, variableParams.size()); + assertThat(BaseFEELFunctionHelper.calculateActualParam(np, names, actualParams, isVariableParameters, + variableParamPrefix, variableParams)).isTrue(); + assertThat(variableParams.size()).isEqualTo(varIndex); for (int i = 0; i < varIndex - 1; i++) { - assertNull(variableParams.get(i)); + assertThat(variableParams.get(i)).isNull(); } - assertEquals(np.getValue(), variableParams.get(varIndex - 1)); + assertThat(variableParams.get(varIndex - 1)).isEqualTo(np.getValue()); } @Test @@ -233,33 +225,33 @@ void calculateActualParamVariableParameters() { int varIndex = 12; NamedParameter np = new NamedParameter(variableParamPrefix + varIndex, BigDecimal.valueOf(1.5)); List variableParams = new ArrayList<>(); - assertTrue(BaseFEELFunctionHelper.calculateActualParamVariableParameters(np, variableParamPrefix, - variableParams)); - assertEquals(varIndex, variableParams.size()); + assertThat(BaseFEELFunctionHelper.calculateActualParamVariableParameters(np, variableParamPrefix, + variableParams)).isTrue(); + assertThat(variableParams.size()).isEqualTo(varIndex); for (int i = 0; i < varIndex - 1; i++) { - assertNull(variableParams.get(i)); + assertThat(variableParams.get(i)).isNull(); } - assertEquals(np.getValue(), variableParams.get(varIndex - 1)); + assertThat(variableParams.get(varIndex - 1)).isEqualTo(np.getValue()); np = new NamedParameter("variableParamPrefix", BigDecimal.valueOf(1.5)); variableParams = new ArrayList<>(); - assertFalse(BaseFEELFunctionHelper.calculateActualParamVariableParameters(np, variableParamPrefix, - variableParams)); + assertThat(BaseFEELFunctionHelper.calculateActualParamVariableParameters(np, variableParamPrefix, + variableParams)).isFalse(); } @Test void getParametersNames() throws NoSuchMethodException { // SumFunction.invoke(@ParameterName("n") Object[] list) Method m = SumFunction.class.getMethod("invoke", Object.class.arrayType()); - assertNotNull(m); + assertThat(m).isNotNull(); List retrieved = BaseFEELFunctionHelper.getParametersNames(m); - assertNotNull(retrieved); + assertThat(retrieved).isNotNull(); int counter = 0; Annotation[][] pas = m.getParameterAnnotations(); for (Annotation[] annotations : pas) { for (Annotation annotation : annotations) { if (annotation instanceof ParameterName parameterName) { - assertEquals(parameterName.value(), retrieved.get(counter)); + assertThat(retrieved.get(counter)).isEqualTo(parameterName.value()); counter++; } } @@ -278,15 +270,15 @@ void getParametersNames() throws NoSuchMethodException { Number.class, Number.class, Number.class); - assertNotNull(m); + assertThat(m).isNotNull(); retrieved = BaseFEELFunctionHelper.getParametersNames(m); - assertNotNull(retrieved); + assertThat(retrieved).isNotNull(); counter = 0; pas = m.getParameterAnnotations(); for (Annotation[] annotations : pas) { for (Annotation annotation : annotations) { if (annotation instanceof ParameterName parameterName) { - assertEquals(parameterName.value(), retrieved.get(counter)); + assertThat(retrieved.get(counter)).isEqualTo(parameterName.value()); counter++; } } @@ -297,8 +289,8 @@ void getParametersNames() throws NoSuchMethodException { void rearrangeParameters() { NamedParameter[] params = {new NamedParameter("fake", new Object())}; Object[] retrieved = BaseFEELFunctionHelper.rearrangeParameters(params, Collections.emptyList()); - assertNotNull(retrieved); - assertEquals(params, retrieved); + assertThat(retrieved).isNotNull(); + assertThat(retrieved).isEqualTo(params); List pnames = IntStream.range(0, 3) .mapToObj(i -> "Parameter_" + i) @@ -307,26 +299,26 @@ void rearrangeParameters() { // single param in correct position params = new NamedParameter[]{new NamedParameter(pnames.get(0), new Object())}; retrieved = BaseFEELFunctionHelper.rearrangeParameters(params, pnames); - assertNotNull(retrieved); - assertEquals(pnames.size(), retrieved.length); + assertThat(retrieved).isNotNull(); + assertThat(retrieved.length).isEqualTo(pnames.size()); for (int i = 0; i < retrieved.length; i++) { if (i == 0) { - assertEquals(params[0].getValue(), retrieved[i]); + assertThat(retrieved[i]).isEqualTo(params[0].getValue()); } else { - assertNull(retrieved[i]); + assertThat(retrieved[i]).isNull(); } } // single param in wrong position params = new NamedParameter[]{new NamedParameter(pnames.get(2), new Object())}; retrieved = BaseFEELFunctionHelper.rearrangeParameters(params, pnames); - assertNotNull(retrieved); - assertEquals(pnames.size(), retrieved.length); + assertThat(retrieved).isNotNull(); + assertThat(retrieved.length).isEqualTo(pnames.size()); for (int i = 0; i < retrieved.length; i++) { if (i == 2) { - assertEquals(params[0].getValue(), retrieved[i]); + assertThat(retrieved[i]).isEqualTo(params[0].getValue()); } else { - assertNull(retrieved[i]); + assertThat(retrieved[i]).isNull(); } } @@ -335,18 +327,18 @@ void rearrangeParameters() { new NamedParameter(pnames.get(1), new Object()), new NamedParameter(pnames.get(0), new Object())}; retrieved = BaseFEELFunctionHelper.rearrangeParameters(params, pnames); - assertNotNull(retrieved); - assertEquals(pnames.size(), retrieved.length); + assertThat(retrieved).isNotNull(); + assertThat(retrieved.length).isEqualTo(pnames.size()); for (int i = 0; i < retrieved.length; i++) { switch (i) { case 0: - assertEquals(params[2].getValue(), retrieved[i]); + assertThat(retrieved[i]).isEqualTo(params[2].getValue()); break; case 1: - assertEquals(params[1].getValue(), retrieved[i]); + assertThat(retrieved[i]).isEqualTo(params[1].getValue()); break; case 2: - assertEquals(params[0].getValue(), retrieved[i]); + assertThat(retrieved[i]).isEqualTo(params[0].getValue()); break; } } @@ -357,22 +349,22 @@ void normalizeResult() { List originalResult = List.of(3, "4", 56); Object result = originalResult.toArray(); Object retrieved = BaseFEELFunctionHelper.normalizeResult(result); - assertNotNull(retrieved); - assertInstanceOf(List.class, retrieved); + assertThat(retrieved).isNotNull(); + assertThat(retrieved).isInstanceOf(List.class); List retrievedList = (List) retrieved; - assertEquals(originalResult.size(), retrievedList.size()); + assertThat(retrievedList.size()).isEqualTo(originalResult.size()); for (int i = 0; i < originalResult.size(); i++) { - assertEquals(NumberEvalHelper.coerceNumber(originalResult.get(i)), retrievedList.get(i)); + assertThat(retrievedList.get(i)).isEqualTo(NumberEvalHelper.coerceNumber(originalResult.get(i))); } result = 23; retrieved = BaseFEELFunctionHelper.normalizeResult(result); - assertNotNull(retrieved); - assertEquals(NumberEvalHelper.coerceNumber(result), retrieved); + assertThat(retrieved).isNotNull(); + assertThat(retrieved).isEqualTo(NumberEvalHelper.coerceNumber(result)); result = "23"; retrieved = BaseFEELFunctionHelper.normalizeResult(result); - assertNotNull(retrieved); - assertEquals(NumberEvalHelper.coerceNumber(result), retrieved); + assertThat(retrieved).isNotNull(); + assertThat(retrieved).isEqualTo(NumberEvalHelper.coerceNumber(result)); } } \ No newline at end of file diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/BaseFEELFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/BaseFEELFunctionTest.java index dde34f0d62b..6b221f7a30b 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/BaseFEELFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/BaseFEELFunctionTest.java @@ -43,11 +43,7 @@ import org.kie.dmn.feel.lang.types.BuiltInType; import org.kie.dmn.feel.runtime.FEELFunction; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertInstanceOf; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; class BaseFEELFunctionTest { @@ -79,16 +75,16 @@ void invokeReflectiveCustomFunction() { Object[] params = {new NamedParameter("foo", null), new NamedParameter("person's age", 16)}; Object retrieved = toTest.invokeReflectively(ctx, params); - assertNotNull(retrieved); - assertInstanceOf(Boolean.class, retrieved); - assertTrue((Boolean) retrieved); + assertThat(retrieved).isNotNull(); + assertThat(retrieved).isInstanceOf(Boolean.class); + assertThat((Boolean) retrieved).isTrue(); params = new Object[]{new NamedParameter("foo", null), new NamedParameter("person's age", 19)}; retrieved = toTest.invokeReflectively(ctx, params); - assertNotNull(retrieved); - assertInstanceOf(Boolean.class, retrieved); - assertFalse((Boolean) retrieved); + assertThat(retrieved).isNotNull(); + assertThat(retrieved).isInstanceOf(Boolean.class); + assertThat((Boolean) retrieved).isFalse(); } @Test @@ -98,28 +94,28 @@ void getAllFunctionCandidateMethod() { // invoke(@ParameterName( "list" ) List list) Object[] parameters = {List.of(true, false)}; BaseFEELFunction.CandidateMethod candidateMethodRetrieved = toTest.getCandidateMethod(ctx, parameters, false); - assertNotNull(candidateMethodRetrieved); + assertThat(candidateMethodRetrieved).isNotNull(); Method retrieved = candidateMethodRetrieved.getActualMethod(); - assertNotNull(retrieved); - assertTrue(Modifier.isPublic(retrieved.getModifiers())); - assertEquals("invoke", retrieved.getName()); + assertThat(retrieved).isNotNull(); + assertThat(Modifier.isPublic(retrieved.getModifiers())).isTrue(); + assertThat(retrieved.getName()).isEqualTo("invoke"); Parameter[] parametersRetrieved = retrieved.getParameters(); - assertNotNull(parametersRetrieved); - assertEquals(1, parametersRetrieved.length); - assertEquals(List.class, parametersRetrieved[0].getType()); + assertThat(parametersRetrieved).isNotNull(); + assertThat(parametersRetrieved.length).isEqualTo(1); + assertThat(parametersRetrieved[0].getType()).isEqualTo(List.class); // invoke(@ParameterName( "b" ) Object[] list) parameters = new Object[]{true, false}; candidateMethodRetrieved = toTest.getCandidateMethod(ctx, parameters, false); - assertNotNull(candidateMethodRetrieved); + assertThat(candidateMethodRetrieved).isNotNull(); retrieved = candidateMethodRetrieved.getActualMethod(); - assertNotNull(retrieved); - assertTrue(Modifier.isPublic(retrieved.getModifiers())); - assertEquals("invoke", retrieved.getName()); + assertThat(retrieved).isNotNull(); + assertThat(Modifier.isPublic(retrieved.getModifiers())).isTrue(); + assertThat(retrieved.getName()).isEqualTo("invoke"); parametersRetrieved = retrieved.getParameters(); - assertNotNull(parametersRetrieved); - assertEquals(1, parametersRetrieved.length); - assertEquals(Object.class.arrayType(), parametersRetrieved[0].getType()); + assertThat(parametersRetrieved).isNotNull(); + assertThat(parametersRetrieved.length).isEqualTo(1); + assertThat(parametersRetrieved[0].getType()).isEqualTo(Object.class.arrayType()); } @Test @@ -129,29 +125,29 @@ void getDateAndTimeFunctionCandidateMethod() { // invoke(@ParameterName( "from" ) String val) Object[] parameters = {"2017-09-07T10:20:30"}; BaseFEELFunction.CandidateMethod candidateMethodRetrieved = toTest.getCandidateMethod(ctx, parameters, false); - assertNotNull(candidateMethodRetrieved); + assertThat(candidateMethodRetrieved).isNotNull(); Method retrieved = candidateMethodRetrieved.getActualMethod(); - assertNotNull(retrieved); - assertTrue(Modifier.isPublic(retrieved.getModifiers())); - assertEquals("invoke", retrieved.getName()); + assertThat(retrieved).isNotNull(); + assertThat(Modifier.isPublic(retrieved.getModifiers())).isTrue(); + assertThat(retrieved.getName()).isEqualTo("invoke"); Parameter[] parametersRetrieved = retrieved.getParameters(); - assertNotNull(parametersRetrieved); - assertEquals(1, parametersRetrieved.length); - assertEquals(String.class, parametersRetrieved[0].getType()); + assertThat(parametersRetrieved).isNotNull(); + assertThat(parametersRetrieved.length).isEqualTo(1); + assertThat(parametersRetrieved[0].getType()).isEqualTo(String.class); // invoke(@ParameterName( "date" ) TemporalAccessor date, @ParameterName( "time" ) TemporalAccessor time) parameters = new Object[]{LocalDate.of(2017, 6, 12), LocalTime.of(10, 6, 20)}; candidateMethodRetrieved = toTest.getCandidateMethod(ctx, parameters, false); - assertNotNull(candidateMethodRetrieved); + assertThat(candidateMethodRetrieved).isNotNull(); retrieved = candidateMethodRetrieved.getActualMethod(); - assertNotNull(retrieved); - assertTrue(Modifier.isPublic(retrieved.getModifiers())); - assertEquals("invoke", retrieved.getName()); + assertThat(retrieved).isNotNull(); + assertThat(Modifier.isPublic(retrieved.getModifiers())).isTrue(); + assertThat(retrieved.getName()).isEqualTo("invoke"); parametersRetrieved = retrieved.getParameters(); - assertNotNull(parametersRetrieved); - assertEquals(2, parametersRetrieved.length); - Arrays.stream(parametersRetrieved).forEach(parameter -> assertEquals(TemporalAccessor.class, - parameter.getType())); + assertThat(parametersRetrieved).isNotNull(); + assertThat(parametersRetrieved.length).isEqualTo(2); + Arrays.stream(parametersRetrieved).forEach(parameter -> assertThat(TemporalAccessor.class).isEqualTo(parameter.getType())); + // invoke(@ParameterName( "year" ) Number year, @ParameterName( "month" ) Number month, @ParameterName( "day" // ) Number day, @@ -159,15 +155,15 @@ void getDateAndTimeFunctionCandidateMethod() { // "second" ) Number second ) parameters = new Object[]{2017, 6, 12, 10, 6, 20}; candidateMethodRetrieved = toTest.getCandidateMethod(ctx, parameters, false); - assertNotNull(candidateMethodRetrieved); + assertThat(candidateMethodRetrieved).isNotNull(); retrieved = candidateMethodRetrieved.getActualMethod(); - assertNotNull(retrieved); - assertTrue(Modifier.isPublic(retrieved.getModifiers())); - assertEquals("invoke", retrieved.getName()); + assertThat(retrieved).isNotNull(); + assertThat(Modifier.isPublic(retrieved.getModifiers())).isTrue(); + assertThat(retrieved.getName()).isEqualTo("invoke"); parametersRetrieved = retrieved.getParameters(); - assertNotNull(parametersRetrieved); - assertEquals(6, parametersRetrieved.length); - Arrays.stream(parametersRetrieved).forEach(parameter -> assertEquals(Number.class, parameter.getType())); + assertThat(parametersRetrieved).isNotNull(); + assertThat(parametersRetrieved.length).isEqualTo(6); + Arrays.stream(parametersRetrieved).forEach(parameter -> assertThat(Number.class).isEqualTo(parameter.getType())); // invoke(@ParameterName( "year" ) Number year, @ParameterName( "month" ) Number month, @ParameterName( "day" // ) Number day, @@ -176,15 +172,15 @@ void getDateAndTimeFunctionCandidateMethod() { // @ParameterName( "hour offset" ) Number hourOffset ) parameters = new Object[]{2017, 6, 12, 10, 6, 20, 2}; candidateMethodRetrieved = toTest.getCandidateMethod(ctx, parameters, false); - assertNotNull(candidateMethodRetrieved); + assertThat(candidateMethodRetrieved).isNotNull(); retrieved = candidateMethodRetrieved.getActualMethod(); - assertNotNull(retrieved); - assertTrue(Modifier.isPublic(retrieved.getModifiers())); - assertEquals("invoke", retrieved.getName()); + assertThat(retrieved).isNotNull(); + assertThat(Modifier.isPublic(retrieved.getModifiers())).isTrue(); + assertThat(retrieved.getName()).isEqualTo("invoke"); parametersRetrieved = retrieved.getParameters(); - assertNotNull(parametersRetrieved); - assertEquals(7, parametersRetrieved.length); - Arrays.stream(parametersRetrieved).forEach(parameter -> assertEquals(Number.class, parameter.getType())); + assertThat(parametersRetrieved).isNotNull(); + assertThat(parametersRetrieved.length).isEqualTo(7); + Arrays.stream(parametersRetrieved).forEach(parameter -> assertThat(Number.class).isEqualTo(parameter.getType())); // invoke(@ParameterName( "year" ) Number year, @ParameterName( "month" ) Number month, @ParameterName( "day" // ) Number day, @@ -193,18 +189,18 @@ void getDateAndTimeFunctionCandidateMethod() { // @ParameterName( "timezone" ) String timezone ) parameters = new Object[]{2017, 6, 12, 10, 6, 20, "Europe/Paris"}; candidateMethodRetrieved = toTest.getCandidateMethod(ctx, parameters, false); - assertNotNull(candidateMethodRetrieved); + assertThat(candidateMethodRetrieved).isNotNull(); retrieved = candidateMethodRetrieved.getActualMethod(); - assertNotNull(retrieved); - assertTrue(Modifier.isPublic(retrieved.getModifiers())); - assertEquals("invoke", retrieved.getName()); + assertThat(retrieved).isNotNull(); + assertThat(Modifier.isPublic(retrieved.getModifiers())).isTrue(); + assertThat(retrieved.getName()).isEqualTo("invoke"); parametersRetrieved = retrieved.getParameters(); - assertNotNull(parametersRetrieved); - assertEquals(7, parametersRetrieved.length); + assertThat(parametersRetrieved).isNotNull(); + assertThat(parametersRetrieved.length).isEqualTo(7); for (int i = 0; i < 6; i++) { - assertEquals(Number.class, parametersRetrieved[i].getType()); + assertThat(parametersRetrieved[i].getType()).isEqualTo(Number.class); } - assertEquals(String.class, parametersRetrieved[6].getType()); + assertThat(parametersRetrieved[6].getType()).isEqualTo(String.class); } @Test @@ -214,61 +210,61 @@ void getExtendedTimeFunctionCandidateMethod() { // invoke(@ParameterName( "from" ) String val) Object[] parameters = {"10:20:30"}; BaseFEELFunction.CandidateMethod candidateMethodRetrieved = toTest.getCandidateMethod(ctx, parameters, false); - assertNotNull(candidateMethodRetrieved); + assertThat(candidateMethodRetrieved).isNotNull(); Method retrieved = candidateMethodRetrieved.getActualMethod(); - assertNotNull(retrieved); - assertTrue(Modifier.isPublic(retrieved.getModifiers())); - assertEquals("invoke", retrieved.getName()); + assertThat(retrieved).isNotNull(); + assertThat(Modifier.isPublic(retrieved.getModifiers())).isTrue(); + assertThat(retrieved.getName()).isEqualTo("invoke"); Parameter[] parametersRetrieved = retrieved.getParameters(); - assertNotNull(parametersRetrieved); - assertEquals(1, parametersRetrieved.length); - assertEquals(String.class, parametersRetrieved[0].getType()); + assertThat(parametersRetrieved).isNotNull(); + assertThat(parametersRetrieved.length).isEqualTo(1); + assertThat(parametersRetrieved[0].getType()).isEqualTo(String.class); // invoke( // @ParameterName("hour") Number hour, @ParameterName("minute") Number minute, // @ParameterName("second") Number seconds) parameters = new Object[]{10, 6, 20}; candidateMethodRetrieved = toTest.getCandidateMethod(ctx, parameters, false); - assertNotNull(candidateMethodRetrieved); + assertThat(candidateMethodRetrieved).isNotNull(); retrieved = candidateMethodRetrieved.getActualMethod(); - assertNotNull(retrieved); - assertTrue(Modifier.isPublic(retrieved.getModifiers())); - assertEquals("invoke", retrieved.getName()); + assertThat(retrieved).isNotNull(); + assertThat(Modifier.isPublic(retrieved.getModifiers())).isTrue(); + assertThat(retrieved.getName()).isEqualTo("invoke"); parametersRetrieved = retrieved.getParameters(); - assertNotNull(parametersRetrieved); - assertEquals(3, parametersRetrieved.length); - Arrays.stream(parametersRetrieved).forEach(parameter -> assertEquals(Number.class, parameter.getType())); + assertThat(parametersRetrieved).isNotNull(); + assertThat(parametersRetrieved.length).isEqualTo(3); + Arrays.stream(parametersRetrieved).forEach(parameter -> assertThat(Number.class).isEqualTo(parameter.getType())); // invoke( // @ParameterName("hour") Number hour, @ParameterName("minute") Number minute, // @ParameterName("second") Number seconds, @ParameterName("offset") Duration offset) parameters = new Object[]{10, 6, 20, Duration.ofHours(3)}; candidateMethodRetrieved = toTest.getCandidateMethod(ctx, parameters, false); - assertNotNull(candidateMethodRetrieved); + assertThat(candidateMethodRetrieved).isNotNull(); retrieved = candidateMethodRetrieved.getActualMethod(); - assertNotNull(retrieved); - assertTrue(Modifier.isPublic(retrieved.getModifiers())); - assertEquals("invoke", retrieved.getName()); + assertThat(retrieved).isNotNull(); + assertThat(Modifier.isPublic(retrieved.getModifiers())).isTrue(); + assertThat(retrieved.getName()).isEqualTo("invoke"); parametersRetrieved = retrieved.getParameters(); - assertNotNull(parametersRetrieved); - assertEquals(4, parametersRetrieved.length); + assertThat(parametersRetrieved).isNotNull(); + assertThat(parametersRetrieved.length).isEqualTo(4); for (int i = 0; i < 3; i++) { - assertEquals(Number.class, parametersRetrieved[i].getType()); + assertThat(parametersRetrieved[i].getType()).isEqualTo(Number.class); } - assertEquals(Duration.class, parametersRetrieved[3].getType()); + assertThat(parametersRetrieved[3].getType()).isEqualTo(Duration.class); // invoke(@ParameterName("from") TemporalAccessor date parameters = new Object[]{LocalTime.of(10, 6, 20)}; candidateMethodRetrieved = toTest.getCandidateMethod(ctx, parameters, false); - assertNotNull(candidateMethodRetrieved); + assertThat(candidateMethodRetrieved).isNotNull(); retrieved = candidateMethodRetrieved.getActualMethod(); - assertNotNull(retrieved); - assertTrue(Modifier.isPublic(retrieved.getModifiers())); - assertEquals("invoke", retrieved.getName()); + assertThat(retrieved).isNotNull(); + assertThat(Modifier.isPublic(retrieved.getModifiers())).isTrue(); + assertThat(retrieved.getName()).isEqualTo("invoke"); parametersRetrieved = retrieved.getParameters(); - assertNotNull(parametersRetrieved); - assertEquals(1, parametersRetrieved.length); - assertEquals(TemporalAccessor.class, parametersRetrieved[0].getType()); + assertThat(parametersRetrieved).isNotNull(); + assertThat(parametersRetrieved.length).isEqualTo(1); + assertThat(parametersRetrieved[0].getType()).isEqualTo(TemporalAccessor.class); } @Test @@ -280,30 +276,30 @@ void getSortFunctionCandidateMethod() { // @ParameterName("precedes") FEELFunction function Object[] parameters = {List.of(1, 2), AllFunction.INSTANCE}; BaseFEELFunction.CandidateMethod candidateMethodRetrieved = toTest.getCandidateMethod(ctx, parameters, false); - assertNotNull(candidateMethodRetrieved); + assertThat(candidateMethodRetrieved).isNotNull(); Method retrieved = candidateMethodRetrieved.getActualMethod(); - assertNotNull(retrieved); - assertTrue(Modifier.isPublic(retrieved.getModifiers())); - assertEquals("invoke", retrieved.getName()); + assertThat(retrieved).isNotNull(); + assertThat(Modifier.isPublic(retrieved.getModifiers())).isTrue(); + assertThat(retrieved.getName()).isEqualTo("invoke"); Parameter[] parametersRetrieved = retrieved.getParameters(); - assertNotNull(parametersRetrieved); - assertEquals(3, parametersRetrieved.length); - assertEquals(EvaluationContext.class, parametersRetrieved[0].getType()); - assertEquals(List.class, parametersRetrieved[1].getType()); - assertEquals(FEELFunction.class, parametersRetrieved[2].getType()); + assertThat(parametersRetrieved).isNotNull(); + assertThat(parametersRetrieved.length).isEqualTo(3); + assertThat(parametersRetrieved[0].getType()).isEqualTo(EvaluationContext.class); + assertThat(parametersRetrieved[1].getType()).isEqualTo(List.class); + assertThat(parametersRetrieved[2].getType()).isEqualTo(FEELFunction.class); // invoke(@ParameterName("list") List list) parameters = new Object[]{List.of(1, 3, 5)}; candidateMethodRetrieved = toTest.getCandidateMethod(ctx, parameters, false); - assertNotNull(candidateMethodRetrieved); + assertThat(candidateMethodRetrieved).isNotNull(); retrieved = candidateMethodRetrieved.getActualMethod(); - assertNotNull(retrieved); - assertTrue(Modifier.isPublic(retrieved.getModifiers())); - assertEquals("invoke", retrieved.getName()); + assertThat(retrieved).isNotNull(); + assertThat(Modifier.isPublic(retrieved.getModifiers())).isTrue(); + assertThat(retrieved.getName()).isEqualTo("invoke"); parametersRetrieved = retrieved.getParameters(); - assertNotNull(parametersRetrieved); - assertEquals(1, parametersRetrieved.length); - assertEquals(List.class, parametersRetrieved[0].getType()); + assertThat(parametersRetrieved).isNotNull(); + assertThat(parametersRetrieved.length).isEqualTo(1); + assertThat(parametersRetrieved[0].getType()).isEqualTo(List.class); } @Test @@ -314,15 +310,15 @@ void getStddevFunctionCandidateMethod() { Object actualValue = Arrays.asList(2, 4, 7, 5); Object[] parameters = {new NamedParameter("list", actualValue)}; BaseFEELFunction.CandidateMethod candidateMethodRetrieved = toTest.getCandidateMethod(ctx, parameters, false); - assertNotNull(candidateMethodRetrieved); + assertThat(candidateMethodRetrieved).isNotNull(); Method retrieved = candidateMethodRetrieved.getActualMethod(); - assertNotNull(retrieved); - assertTrue(Modifier.isPublic(retrieved.getModifiers())); - assertEquals("invoke", retrieved.getName()); + assertThat(retrieved).isNotNull(); + assertThat(Modifier.isPublic(retrieved.getModifiers())).isTrue(); + assertThat(retrieved.getName()).isEqualTo("invoke"); Parameter[] parametersRetrieved = retrieved.getParameters(); - assertNotNull(parametersRetrieved); - assertEquals(1, parametersRetrieved.length); - assertEquals(List.class, parametersRetrieved[0].getType()); + assertThat(parametersRetrieved).isNotNull(); + assertThat(parametersRetrieved.length).isEqualTo(1); + assertThat(parametersRetrieved[0].getType()).isEqualTo(List.class); } } \ No newline at end of file diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/BuiltInFunctionsTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/BuiltInFunctionsTest.java index 286da3d7a25..f5f62c208b5 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/BuiltInFunctionsTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/BuiltInFunctionsTest.java @@ -30,9 +30,9 @@ import org.kie.dmn.feel.lang.Symbol; import org.kie.dmn.feel.runtime.FEELFunction; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; import static org.kie.dmn.feel.runtime.functions.BuiltInFunctions.FUNCTIONS; class BuiltInFunctionsTest { @@ -43,24 +43,24 @@ void getFunctions() { Set< Class> verifiedClasses = Stream.of(FUNCTIONS).map(this::validateFunction) .filter(Objects::nonNull) .collect(Collectors.toUnmodifiableSet()); - assertEquals(FUNCTIONS.length, verifiedClasses.size()); + assertThat(verifiedClasses).hasSameSizeAs(FUNCTIONS); } @Test void getFunctionsByClassFails() { - assertThrows(IllegalArgumentException.class, () -> BuiltInFunctions.getFunction(FakeFunction.class)); + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> BuiltInFunctions.getFunction(FakeFunction.class)); } @Test void getFunctionsByNameFails() { - assertThrows(IllegalArgumentException.class, () -> BuiltInFunctions.getFunction(FakeFunction.FAKE_NAME)); + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> BuiltInFunctions.getFunction(FakeFunction.FAKE_NAME)); } private Class validateFunction(FEELFunction toValidate) { Class aClass = toValidate.getClass(); try { Field instance = aClass.getDeclaredField("INSTANCE"); - assertEquals(aClass, instance.getDeclaringClass()); + assertThat(instance.getDeclaringClass()).isEqualTo(aClass); return aClass; } catch (NoSuchFieldException e) { fail("No INSTANCE field found for " + aClass); diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MatchesFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MatchesFunctionTest.java index eea47b17de6..b12612bb04a 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MatchesFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MatchesFunctionTest.java @@ -24,26 +24,26 @@ import java.security.InvalidParameterException; import java.util.regex.PatternSyntaxException; -import static org.junit.jupiter.api.Assertions.*; -import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatNoException; import static org.mockito.Mockito.*; class MatchesFunctionTest { @Test void invokeNull() { - assertThrows(InvalidParameterException.class, () -> MatchesFunction.matchFunctionWithFlags(null, null, null)); - assertThrows(InvalidParameterException.class, () -> MatchesFunction.matchFunctionWithFlags(null, "test",null)); - assertThrows(InvalidParameterException.class, () -> MatchesFunction.matchFunctionWithFlags("test", null,null)); + assertThatExceptionOfType(InvalidParameterException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags(null, null, null)); + assertThatExceptionOfType(InvalidParameterException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags(null, "test", null)); + assertThatExceptionOfType(InvalidParameterException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("test", null, null)); } @Test void invokeUnsupportedFlags() { - assertThrows(IllegalArgumentException.class, () -> MatchesFunction.matchFunctionWithFlags("foobar", "fo.bar", "g")); - assertThrows(IllegalArgumentException.class, () -> MatchesFunction.matchFunctionWithFlags("abracadabra", "bra", "p")); - assertThrows(IllegalArgumentException.class, () -> MatchesFunction.matchFunctionWithFlags("abracadabra", "bra", "X")); - assertThrows(IllegalArgumentException.class, () -> MatchesFunction.matchFunctionWithFlags("abracadabra", "bra", " ")); - assertThrows(IllegalArgumentException.class, () -> MatchesFunction.matchFunctionWithFlags("abracadabra", "bra", "iU")); + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("foobar", "fo.bar", "g")); + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("abracadabra", "bra", "p")); + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("abracadabra", "bra", "X")); + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("abracadabra", "bra", " ")); + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("abracadabra", "bra", "iU")); } @Test @@ -98,24 +98,24 @@ void invokeWithAllFlags() { @Test void checkForPatternTest() { - assertThrows(PatternSyntaxException.class, () -> MatchesFunction.matchFunctionWithFlags("foobar", "(abc|def(ghi", "i")); + assertThatExceptionOfType(PatternSyntaxException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("foobar", "(abc|def(ghi", "i")); } @Test void checkFlagsTest() { - assertDoesNotThrow(() -> MatchesFunction.checkFlags("s")); - assertDoesNotThrow(() -> MatchesFunction.checkFlags("i")); - assertDoesNotThrow(() -> MatchesFunction.checkFlags("sx")); - assertDoesNotThrow(() -> MatchesFunction.checkFlags("six")); - assertDoesNotThrow(() -> MatchesFunction.checkFlags("sixm")); - assertThrows(IllegalArgumentException.class, () -> MatchesFunction.checkFlags("a")); - assertThrows(IllegalArgumentException.class, () -> MatchesFunction.checkFlags("sa")); - assertThrows(IllegalArgumentException.class, () -> MatchesFunction.checkFlags("siU@")); - assertThrows(IllegalArgumentException.class, () -> MatchesFunction.checkFlags("siUxU")); - assertThrows(IllegalArgumentException.class, () -> MatchesFunction.checkFlags("ss")); - assertThrows(IllegalArgumentException.class, () -> MatchesFunction.checkFlags("siiU")); - assertThrows(IllegalArgumentException.class, () -> MatchesFunction.checkFlags("si U")); - assertThrows(IllegalArgumentException.class, () -> MatchesFunction.checkFlags("U")); + assertThatNoException().isThrownBy(() -> MatchesFunction.checkFlags("s")); + assertThatNoException().isThrownBy(() -> MatchesFunction.checkFlags("i")); + assertThatNoException().isThrownBy(() -> MatchesFunction.checkFlags("sx")); + assertThatNoException().isThrownBy(() -> MatchesFunction.checkFlags("six")); + assertThatNoException().isThrownBy(() -> MatchesFunction.checkFlags("sixm")); + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> MatchesFunction.checkFlags("a")); + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> MatchesFunction.checkFlags("sa")); + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> MatchesFunction.checkFlags("siU@")); + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> MatchesFunction.checkFlags("siUxU")); + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> MatchesFunction.checkFlags("ss")); + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> MatchesFunction.checkFlags("siiU")); + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> MatchesFunction.checkFlags("si U")); + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> MatchesFunction.checkFlags("U")); } @Test diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ScorerHelperTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ScorerHelperTest.java index 396e0a03560..71f4bf6934f 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ScorerHelperTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ScorerHelperTest.java @@ -29,7 +29,6 @@ import org.kie.dmn.feel.lang.impl.NamedParameter; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; import static org.kie.dmn.feel.runtime.functions.ScoreHelper.coercedToVarargsScore; import static org.kie.dmn.feel.runtime.functions.ScoreHelper.lastInputNotArrayNotArrayScore; import static org.kie.dmn.feel.runtime.functions.ScoreHelper.lastParameterNotArrayScore; @@ -47,7 +46,7 @@ void grossScore() { // 10000 (lastParameterNotArray) // 100000 (lastInputNotArray) int expected = lastInputNotArrayNotArrayScore + lastParameterNotArrayScore; - assertEquals(expected, retrieved); + assertThat(retrieved).isEqualTo(expected); originalInput = new Object[] { "String", "34" }; parameterTypes = new Class[] { String.class, Integer.class }; @@ -57,7 +56,7 @@ void grossScore() { // 10000 (lastParameterNotArray) // 100000 (lastInputNotArray) expected = lastInputNotArrayNotArrayScore + lastParameterNotArrayScore; - assertEquals(expected, retrieved); + assertThat(retrieved).isEqualTo(expected); originalInput = new Object[] { "String", "34" }; parameterTypes = new Class[] { String.class, Integer.class }; @@ -67,7 +66,7 @@ void grossScore() { // 10000 (lastParameterNotArray) // 100000 (lastInputNotArray) expected = lastInputNotArrayNotArrayScore + lastParameterNotArrayScore; - assertEquals(expected, retrieved); + assertThat(retrieved).isEqualTo(expected); originalInput = new Object[] { "StringA", "StringB" }; parameterTypes = new Class[] { String.class, String.class }; @@ -77,7 +76,7 @@ void grossScore() { // 10000 (lastParameterNotArray) // 100000 (lastInputNotArray) expected = lastInputNotArrayNotArrayScore + lastParameterNotArrayScore; - assertEquals(expected, retrieved); + assertThat(retrieved).isEqualTo(expected); originalInput = new Object[] { "StringA", "StringB" }; parameterTypes = new Class[] { Object.class.arrayType() }; @@ -87,7 +86,7 @@ void grossScore() { // 0 (lastParameterNotArray) // 0 (lastInputNotArray) expected = 0; - assertEquals( expected, retrieved); + assertThat(retrieved).isEqualTo(expected); originalInput = new Object[] { "StringA" }; @@ -98,7 +97,7 @@ void grossScore() { // 0 (lastParameterNotArray) // 0 (lastInputNotArray) expected = 0; - assertEquals( expected, retrieved); + assertThat(retrieved).isEqualTo(expected); originalInput = new Object[] { "StringA" }; parameterTypes = new Class[] { List.class }; @@ -108,7 +107,7 @@ void grossScore() { // 10000 (lastParameterNotArray) // 100000 (lastInputNotArray) expected = lastInputNotArrayNotArrayScore + lastParameterNotArrayScore; - assertEquals( expected, retrievedToCompare); + assertThat(retrievedToCompare).isEqualTo(expected); assertThat(retrievedToCompare).isGreaterThan(retrieved); @@ -120,7 +119,7 @@ void grossScore() { // 0 (lastParameterNotArray) // 100000 (lastInputNotArray) expected = lastInputNotArrayNotArrayScore; - assertEquals( expected, retrieved); + assertThat(retrieved).isEqualTo(expected); originalInput = new Object[] { null }; parameterTypes = new Class[] { List.class }; @@ -130,7 +129,7 @@ void grossScore() { // 10000 (lastParameterNotArray) // 100000 (lastInputNotArray) expected = lastInputNotArrayNotArrayScore + lastParameterNotArrayScore; - assertEquals( expected, retrievedToCompare); + assertThat(retrievedToCompare).isEqualTo(expected); assertThat(retrievedToCompare).isGreaterThan(retrieved); Object actualValue = Arrays.asList(2, 4, 7, 5); @@ -142,7 +141,7 @@ void grossScore() { // 10000 (lastParameterNotArray) // 100000 (lastInputNotArray) expected = lastInputNotArrayNotArrayScore + lastParameterNotArrayScore; - assertEquals( expected, retrieved); + assertThat(retrieved).isEqualTo(expected); parameterTypes = new Class[] { Object.class }; compares = new ScoreHelper.Compares(originalInput, adaptedInput, parameterTypes); @@ -150,7 +149,7 @@ void grossScore() { // 10000 (lastParameterNotArray) // 100000 (lastInputNotArray) expected = lastInputNotArrayNotArrayScore + lastParameterNotArrayScore; - assertEquals( expected, retrievedToCompare); + assertThat(retrievedToCompare).isEqualTo(expected); } @Test @@ -165,7 +164,7 @@ void fineScore() { // 1000 (typeIdentityOfParameters) // 1000 (numberOfParameters) int expected = numberOfParametersScore + 1000; - assertEquals(expected, retrieved); + assertThat(retrieved).isEqualTo(expected); originalInput = new Object[] { "String", "34" }; parameterTypes = new Class[] { String.class, Integer.class }; @@ -177,7 +176,7 @@ void fineScore() { // 500 (typeIdentityOfParameters) // 1000 (numberOfParameters) expected = numberOfParametersScore + 500 -1; - assertEquals(expected, retrieved); + assertThat(retrieved).isEqualTo(expected); originalInput = new Object[] { "String", "34" }; parameterTypes = new Class[] { String.class, Integer.class }; @@ -189,7 +188,7 @@ void fineScore() { // 750 (typeIdentityOfParameters) // 1000 (numberOfParameters) expected = numberOfParametersScore + 750; - assertEquals(expected, retrieved); + assertThat(retrieved).isEqualTo(expected); originalInput = new Object[] { "StringA", "StringB" }; parameterTypes = new Class[] { String.class, String.class }; @@ -201,7 +200,7 @@ void fineScore() { // 1000 (typeIdentityOfParameters) // 1000 (numberOfParameters) expected = numberOfParametersScore + 1000; - assertEquals(expected, retrieved); + assertThat(retrieved).isEqualTo(expected); originalInput = new Object[] { "StringA", "StringB" }; parameterTypes = new Class[] { Object.class.arrayType() }; @@ -213,7 +212,7 @@ void fineScore() { // 1000 (typeIdentityOfParameters) // 0 (numberOfParameters) expected = coercedToVarargsScore + 1000; - assertEquals( expected, retrieved); + assertThat(retrieved).isEqualTo(expected); originalInput = new Object[] { "StringA" }; @@ -226,7 +225,7 @@ void fineScore() { // 1000 (typeIdentityOfParameters) // 1000 (numberOfParameters) expected = numberOfParametersScore + coercedToVarargsScore + 1000; - assertEquals( expected, retrieved); + assertThat(retrieved).isEqualTo(expected); originalInput = new Object[] { "StringA" }; parameterTypes = new Class[] { List.class }; @@ -238,7 +237,7 @@ void fineScore() { // 1000 (typeIdentityOfParameters) // 1000 (numberOfParameters) expected = numberOfParametersScore + 1000; - assertEquals( expected, retrievedToCompare); + assertThat(retrievedToCompare).isEqualTo(expected); assertThat(retrievedToCompare).isGreaterThan(retrieved); @@ -252,7 +251,7 @@ void fineScore() { // 500 (typeIdentityOfParameters) // 1000 (numberOfParameters) expected = numberOfParametersScore + 500 -1; - assertEquals( expected, retrieved); + assertThat(retrieved).isEqualTo(expected); originalInput = new Object[] { null }; parameterTypes = new Class[] { List.class }; @@ -264,7 +263,7 @@ void fineScore() { // 500 (typeIdentityOfParameters) // 1000 (numberOfParameters) expected = numberOfParametersScore + 500 -1; - assertEquals( expected, retrieved); + assertThat(retrieved).isEqualTo(expected); Object actualValue = Arrays.asList(2, 4, 7, 5); originalInput = new Object[] {new NamedParameter("list", actualValue)}; @@ -277,7 +276,7 @@ void fineScore() { // 1000 (typeIdentityOfParameters) // 1000 (numberOfParameters) expected = numberOfParametersScore + 1000; - assertEquals( expected, retrieved); + assertThat(retrieved).isEqualTo(expected); parameterTypes = new Class[] { Object.class }; compares = new ScoreHelper.Compares(originalInput, adaptedInput, parameterTypes); @@ -287,7 +286,7 @@ void fineScore() { // 500 (typeIdentityOfParameters) // 1000 (numberOfParameters) expected = numberOfParametersScore + 500; - assertEquals( expected, retrieved); + assertThat(retrieved).isEqualTo(expected); } @Test @@ -295,27 +294,27 @@ void lastInputNotArray(){ Object[] adaptedInput = new Object[] { "String" }; ScoreHelper.Compares compares = new ScoreHelper.Compares(null, adaptedInput, null); int retrieved = ScoreHelper.lastInputNotArray.applyAsInt(compares); - assertEquals(lastInputNotArrayNotArrayScore, retrieved); + assertThat(retrieved).isEqualTo(lastInputNotArrayNotArrayScore); adaptedInput = new Object[] { "String", 34, new Object() }; compares = new ScoreHelper.Compares(null, adaptedInput, null); retrieved = ScoreHelper.lastInputNotArray.applyAsInt(compares); - assertEquals(lastInputNotArrayNotArrayScore, retrieved); + assertThat(retrieved).isEqualTo(lastInputNotArrayNotArrayScore); adaptedInput = new Object[] { null }; compares = new ScoreHelper.Compares(null, adaptedInput, null); retrieved = ScoreHelper.lastInputNotArray.applyAsInt(compares); - assertEquals(lastInputNotArrayNotArrayScore, retrieved); + assertThat(retrieved).isEqualTo(lastInputNotArrayNotArrayScore); adaptedInput = new Object[] { new Object[]{} }; compares = new ScoreHelper.Compares(null, adaptedInput, null); retrieved = ScoreHelper.lastInputNotArray.applyAsInt(compares); - assertEquals(0, retrieved); + assertThat(retrieved).isEqualTo(0); adaptedInput = new Object[] { "String", 34, new Object[]{} }; compares = new ScoreHelper.Compares(null, adaptedInput, null); retrieved = ScoreHelper.lastInputNotArray.applyAsInt(compares); - assertEquals(0, retrieved); + assertThat(retrieved).isEqualTo(0); } @Test @@ -323,47 +322,47 @@ void lastParameterNotArray(){ Class[] parameterTypes = new Class[] { String.class }; ScoreHelper.Compares compares = new ScoreHelper.Compares(null, null, parameterTypes); int retrieved = ScoreHelper.lastParameterNotArray.applyAsInt(compares); - assertEquals(lastParameterNotArrayScore, retrieved); + assertThat(retrieved).isEqualTo(lastParameterNotArrayScore); parameterTypes = new Class[] { String.class, Object.class }; compares = new ScoreHelper.Compares(null, null, parameterTypes); retrieved = ScoreHelper.lastParameterNotArray.applyAsInt(compares); - assertEquals(lastParameterNotArrayScore, retrieved); + assertThat(retrieved).isEqualTo(lastParameterNotArrayScore); parameterTypes = new Class[] { null }; compares = new ScoreHelper.Compares(null, null, parameterTypes); retrieved = ScoreHelper.lastParameterNotArray.applyAsInt(compares); - assertEquals(lastParameterNotArrayScore, retrieved); + assertThat(retrieved).isEqualTo(lastParameterNotArrayScore); parameterTypes = new Class[] { String.class, null }; compares = new ScoreHelper.Compares(null, null, parameterTypes); retrieved = ScoreHelper.lastParameterNotArray.applyAsInt(compares); - assertEquals(lastParameterNotArrayScore, retrieved); + assertThat(retrieved).isEqualTo(lastParameterNotArrayScore); parameterTypes = new Class[] { Object.class.arrayType(), String.class }; compares = new ScoreHelper.Compares(null, null, parameterTypes); retrieved = ScoreHelper.lastParameterNotArray.applyAsInt(compares); - assertEquals(lastParameterNotArrayScore, retrieved); + assertThat(retrieved).isEqualTo(lastParameterNotArrayScore); parameterTypes = new Class[] { Object.class.arrayType(), null }; compares = new ScoreHelper.Compares(null, null, parameterTypes); retrieved = ScoreHelper.lastParameterNotArray.applyAsInt(compares); - assertEquals(lastParameterNotArrayScore, retrieved); + assertThat(retrieved).isEqualTo(lastParameterNotArrayScore); parameterTypes = new Class[] { Object.class.arrayType() }; compares = new ScoreHelper.Compares(null, null, parameterTypes); retrieved = ScoreHelper.lastParameterNotArray.applyAsInt(compares); - assertEquals(0, retrieved); + assertThat(retrieved).isEqualTo(0); parameterTypes = new Class[] { String.class, Object.class.arrayType() }; compares = new ScoreHelper.Compares(null, null, parameterTypes); retrieved = ScoreHelper.lastParameterNotArray.applyAsInt(compares); - assertEquals(0, retrieved); + assertThat(retrieved).isEqualTo(0); parameterTypes = new Class[] { null, Object.class.arrayType() }; compares = new ScoreHelper.Compares(null, null, parameterTypes); retrieved = ScoreHelper.lastParameterNotArray.applyAsInt(compares); - assertEquals(0, retrieved); + assertThat(retrieved).isEqualTo(0); } @Test @@ -372,31 +371,31 @@ void numberOfParameters() { Class[] parameterTypes = new Class[] { String.class }; ScoreHelper.Compares compares = new ScoreHelper.Compares(originalInput, null, parameterTypes); int retrieved = ScoreHelper.numberOfParameters.applyAsInt(compares); - assertEquals(numberOfParametersScore, retrieved); + assertThat(retrieved).isEqualTo(numberOfParametersScore); originalInput = new Object[] { "String" }; parameterTypes = new Class[] { Object.class }; compares = new ScoreHelper.Compares(originalInput, null, parameterTypes); retrieved = ScoreHelper.numberOfParameters.applyAsInt(compares); - assertEquals(numberOfParametersScore, retrieved); + assertThat(retrieved).isEqualTo(numberOfParametersScore); originalInput = new Object[] { new Object[]{ "String", 34 } }; parameterTypes = new Class[] { Object.class.arrayType() }; compares = new ScoreHelper.Compares(originalInput, null, parameterTypes); retrieved = ScoreHelper.numberOfParameters.applyAsInt(compares); - assertEquals(numberOfParametersScore, retrieved); + assertThat(retrieved).isEqualTo(numberOfParametersScore); originalInput = new Object[] { "String", 34 }; parameterTypes = new Class[] { Object.class }; compares = new ScoreHelper.Compares(originalInput, null, parameterTypes); retrieved = ScoreHelper.numberOfParameters.applyAsInt(compares); - assertEquals(0, retrieved); + assertThat(retrieved).isEqualTo(0); originalInput = new Object[] { "String", 34 }; parameterTypes = new Class[] { Object.class.arrayType() }; compares = new ScoreHelper.Compares(originalInput, null, parameterTypes); retrieved = ScoreHelper.numberOfParameters.applyAsInt(compares); - assertEquals(0, retrieved); + assertThat(retrieved).isEqualTo(0); } @Test @@ -406,110 +405,110 @@ void typeIdentityOfParameters() { Class[] parameterTypes = new Class[] { String.class }; ScoreHelper.Compares compares = new ScoreHelper.Compares(originalInput, adaptedInput, parameterTypes); int retrieved = ScoreHelper.typeIdentityOfParameters.applyAsInt(compares); - assertEquals(1000, retrieved); + assertThat(retrieved).isEqualTo(1000); parameterTypes = new Class[] { Object.class }; compares = new ScoreHelper.Compares(originalInput, adaptedInput, parameterTypes); retrieved = ScoreHelper.typeIdentityOfParameters.applyAsInt(compares); - assertEquals(500, retrieved); + assertThat(retrieved).isEqualTo(500); originalInput = new Object[] { "String", 34 }; adaptedInput = originalInput; parameterTypes = new Class[] { String.class, Integer.class }; compares = new ScoreHelper.Compares(originalInput, adaptedInput, parameterTypes); retrieved = ScoreHelper.typeIdentityOfParameters.applyAsInt(compares); - assertEquals(1000, retrieved); + assertThat(retrieved).isEqualTo(1000); parameterTypes = new Class[] { String.class, Object.class }; compares = new ScoreHelper.Compares(originalInput, adaptedInput, parameterTypes); retrieved = ScoreHelper.typeIdentityOfParameters.applyAsInt(compares); - assertEquals(750, retrieved); + assertThat(retrieved).isEqualTo(750); originalInput = new Object[] { "String", "34" }; adaptedInput = null; parameterTypes = new Class[] { String.class, Integer.class }; compares = new ScoreHelper.Compares(originalInput, adaptedInput, parameterTypes); retrieved = ScoreHelper.typeIdentityOfParameters.applyAsInt(compares); - assertEquals(750, retrieved); + assertThat(retrieved).isEqualTo(750); originalInput = new Object[] { "StringA", "StringB", 40 }; parameterTypes = new Class[] { String.class, Integer.class, Integer.class }; compares = new ScoreHelper.Compares(originalInput, adaptedInput, parameterTypes); retrieved = ScoreHelper.typeIdentityOfParameters.applyAsInt(compares); - assertEquals(1000, retrieved); + assertThat(retrieved).isEqualTo(1000); originalInput = new Object[] { "StringA", "StringB", 40 }; parameterTypes = new Class[] { String.class, Integer.class, String.class }; compares = new ScoreHelper.Compares(originalInput, null, parameterTypes); retrieved = ScoreHelper.typeIdentityOfParameters.applyAsInt(compares); - assertEquals(500, retrieved); + assertThat(retrieved).isEqualTo(500); originalInput = new Object[] { CodegenTestUtil.newEmptyEvaluationContext(), "String" }; adaptedInput = originalInput; parameterTypes = new Class[] { EvaluationContext.class, String.class }; compares = new ScoreHelper.Compares(originalInput, adaptedInput, parameterTypes); retrieved = ScoreHelper.typeIdentityOfParameters.applyAsInt(compares); - assertEquals(1000, retrieved); + assertThat(retrieved).isEqualTo(1000); originalInput = new Object[] { "String" }; adaptedInput = new Object[] { CodegenTestUtil.newEmptyEvaluationContext(), "String" }; parameterTypes = new Class[] { EvaluationContext.class, String.class }; compares = new ScoreHelper.Compares(originalInput, adaptedInput, parameterTypes); retrieved = ScoreHelper.typeIdentityOfParameters.applyAsInt(compares); - assertEquals(1500, retrieved); + assertThat(retrieved).isEqualTo(1500); originalInput = new Object[] { "String" }; adaptedInput = null; parameterTypes = new Class[] { Integer.class }; compares = new ScoreHelper.Compares(originalInput, adaptedInput, parameterTypes); retrieved = ScoreHelper.typeIdentityOfParameters.applyAsInt(compares); - assertEquals(0, retrieved); + assertThat(retrieved).isEqualTo(0); originalInput = new Object[] { "String", 34 }; adaptedInput = new Object[] { CodegenTestUtil.newEmptyEvaluationContext(), "String", 34 }; parameterTypes = new Class[] { EvaluationContext.class, String.class, Integer.class }; compares = new ScoreHelper.Compares(originalInput, adaptedInput, parameterTypes); retrieved = ScoreHelper.typeIdentityOfParameters.applyAsInt(compares); - assertEquals(1500, retrieved); + assertThat(retrieved).isEqualTo(1500); originalInput = new Object[] { "String", "34" }; adaptedInput = originalInput; parameterTypes = new Class[] { EvaluationContext.class, String.class, Object.class }; compares = new ScoreHelper.Compares(originalInput, adaptedInput, parameterTypes); retrieved = ScoreHelper.typeIdentityOfParameters.applyAsInt(compares); - assertEquals(750, retrieved); + assertThat(retrieved).isEqualTo(750); originalInput = new Object[] { "String", "34" }; adaptedInput = null; parameterTypes = new Class[] { EvaluationContext.class, String.class, Integer.class }; compares = new ScoreHelper.Compares(originalInput, adaptedInput, parameterTypes); retrieved = ScoreHelper.typeIdentityOfParameters.applyAsInt(compares); - assertEquals(750, retrieved); + assertThat(retrieved).isEqualTo(750); originalInput = new Object[] { "String" }; parameterTypes = new Class[] { EvaluationContext.class, Integer.class }; compares = new ScoreHelper.Compares(originalInput, adaptedInput, parameterTypes); retrieved = ScoreHelper.typeIdentityOfParameters.applyAsInt(compares); - assertEquals(0, retrieved); + assertThat(retrieved).isEqualTo(0); originalInput = new Object[] { CodegenTestUtil.newEmptyEvaluationContext(), "String" }; parameterTypes = new Class[] { EvaluationContext.class, Integer.class }; compares = new ScoreHelper.Compares(originalInput, null, parameterTypes); retrieved = ScoreHelper.typeIdentityOfParameters.applyAsInt(compares); - assertEquals(0, retrieved); + assertThat(retrieved).isEqualTo(0); originalInput = new Object[] { null }; parameterTypes = new Class[] { Object.class.arrayType() }; compares = new ScoreHelper.Compares(originalInput, null, parameterTypes); retrieved = ScoreHelper.typeIdentityOfParameters.applyAsInt(compares); - assertEquals(500, retrieved); + assertThat(retrieved).isEqualTo(500); originalInput = new Object[] { "StringA", "StringB" }; parameterTypes = new Class[] { Object.class.arrayType() }; adaptedInput = new Object[] { new Object[] {"StringA", "StringB"} }; compares = new ScoreHelper.Compares(originalInput, adaptedInput, parameterTypes); retrieved = ScoreHelper.typeIdentityOfParameters.applyAsInt(compares); - assertEquals(1000, retrieved); + assertThat(retrieved).isEqualTo(1000); } @Test @@ -518,49 +517,49 @@ void coercedToVarargs() { Object[] adaptedInput = new Object[] { "String" }; ScoreHelper.Compares compares = new ScoreHelper.Compares(originalInput, adaptedInput, null); int retrieved = ScoreHelper.coercedToVarargs.applyAsInt(compares); - assertEquals(0, retrieved); + assertThat(retrieved).isEqualTo(0); originalInput = new Object[] { "String" }; adaptedInput = new Object[] { new Object[] {"String"} }; compares = new ScoreHelper.Compares(originalInput, adaptedInput, null); retrieved = ScoreHelper.coercedToVarargs.applyAsInt(compares); - assertEquals(coercedToVarargsScore, retrieved); + assertThat(retrieved).isEqualTo(coercedToVarargsScore); originalInput = new Object[] { "String", 34 }; adaptedInput = new Object[] { new Object[] {"String", 34} }; compares = new ScoreHelper.Compares(originalInput, adaptedInput, null); retrieved = ScoreHelper.coercedToVarargs.applyAsInt(compares); - assertEquals(coercedToVarargsScore, retrieved); + assertThat(retrieved).isEqualTo(coercedToVarargsScore); originalInput = new Object[] { CodegenTestUtil.newEmptyEvaluationContext(), "String", 34 }; adaptedInput = new Object[] { new Object[] {"String", 34} }; compares = new ScoreHelper.Compares(originalInput, adaptedInput, null); retrieved = ScoreHelper.coercedToVarargs.applyAsInt(compares); - assertEquals(coercedToVarargsScore, retrieved); + assertThat(retrieved).isEqualTo(coercedToVarargsScore); originalInput = new Object[] { "String", 34 }; adaptedInput = new Object[] { CodegenTestUtil.newEmptyEvaluationContext(), new Object[] {"String", 34} }; compares = new ScoreHelper.Compares(originalInput, adaptedInput, null); retrieved = ScoreHelper.coercedToVarargs.applyAsInt(compares); - assertEquals(coercedToVarargsScore, retrieved); + assertThat(retrieved).isEqualTo(coercedToVarargsScore); originalInput = new Object[] { CodegenTestUtil.newEmptyEvaluationContext(), "String", 34 }; adaptedInput = new Object[] { CodegenTestUtil.newEmptyEvaluationContext(), new Object[] {"String", 34} }; compares = new ScoreHelper.Compares(originalInput, adaptedInput, null); retrieved = ScoreHelper.coercedToVarargs.applyAsInt(compares); - assertEquals(coercedToVarargsScore, retrieved); + assertThat(retrieved).isEqualTo(coercedToVarargsScore); originalInput = new Object[] { new Object[] {"String", 34} }; adaptedInput = new Object[] { new Object[] {"String", 34} }; compares = new ScoreHelper.Compares(originalInput, adaptedInput, null); retrieved = ScoreHelper.coercedToVarargs.applyAsInt(compares); - assertEquals(0, retrieved); + assertThat(retrieved).isEqualTo(0); originalInput = new Object[] {BigDecimal.valueOf(10), null, BigDecimal.valueOf(20), BigDecimal.valueOf(40),null }; adaptedInput = new Object[] { new Object[] { BigDecimal.valueOf(10), null, BigDecimal.valueOf(20), BigDecimal.valueOf(40),null } }; compares = new ScoreHelper.Compares(originalInput, adaptedInput, null); retrieved = ScoreHelper.coercedToVarargs.applyAsInt(compares); - assertEquals(coercedToVarargsScore, retrieved); + assertThat(retrieved).isEqualTo(coercedToVarargsScore); } @Test @@ -568,27 +567,27 @@ void nullCounts() { Object[] adaptedInput = new Object[] { "String" }; ScoreHelper.Compares compares = new ScoreHelper.Compares(null, adaptedInput, null); int retrieved = ScoreHelper.nullCounts.applyAsInt(compares); - assertEquals(0, retrieved); + assertThat(retrieved).isEqualTo(0); adaptedInput = new Object[] { }; compares = new ScoreHelper.Compares(null, adaptedInput, null); retrieved = ScoreHelper.nullCounts.applyAsInt(compares); - assertEquals(0, retrieved); + assertThat(retrieved).isEqualTo(0); adaptedInput = new Object[] { "String", null }; compares = new ScoreHelper.Compares(null, adaptedInput, null); retrieved = ScoreHelper.nullCounts.applyAsInt(compares); - assertEquals(-1, retrieved); + assertThat(retrieved).isEqualTo(-1); adaptedInput = new Object[] { null }; compares = new ScoreHelper.Compares(null, adaptedInput, null); retrieved = ScoreHelper.nullCounts.applyAsInt(compares); - assertEquals(-1, retrieved); + assertThat(retrieved).isEqualTo(-1); adaptedInput = new Object[] { null, new Object(), null }; compares = new ScoreHelper.Compares(null, adaptedInput, null); retrieved = ScoreHelper.nullCounts.applyAsInt(compares); - assertEquals(-2, retrieved); + assertThat(retrieved).isEqualTo(-2); } @Test @@ -605,6 +604,6 @@ void nullCount() { params[i] = new Object(); } } - assertEquals(expectedCount, ScoreHelper.nullCount(params)); + assertThat(ScoreHelper.nullCount(params)).isEqualTo(expectedCount); } } \ No newline at end of file diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/TimeFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/TimeFunctionTest.java index 105ba640dd8..d22769d4197 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/TimeFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/TimeFunctionTest.java @@ -34,8 +34,6 @@ import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; class TimeFunctionTest { @@ -189,11 +187,11 @@ void invokeTimeUnitsParamsWithOffsetWithNanoseconds() { @Test void timeStringWithSeconds() { - assertTrue(TimeFunction.timeStringWithSeconds("10:10:00@Australia/Melbourne")); - assertTrue(TimeFunction.timeStringWithSeconds("10:10:00+10:00")); - assertTrue(TimeFunction.timeStringWithSeconds("10:10:00:123")); + assertThat(TimeFunction.timeStringWithSeconds("10:10:00@Australia/Melbourne")).isTrue(); + assertThat(TimeFunction.timeStringWithSeconds("10:10:00+10:00")).isTrue(); + assertThat(TimeFunction.timeStringWithSeconds("10:10:00:123")).isTrue(); - assertFalse(TimeFunction.timeStringWithSeconds("10:10@Australia/Melbourne")); - assertFalse(TimeFunction.timeStringWithSeconds("10:10+10:00")); + assertThat(TimeFunction.timeStringWithSeconds("10:10@Australia/Melbourne")).isFalse(); + assertThat(TimeFunction.timeStringWithSeconds("10:10+10:00")).isFalse(); } } \ No newline at end of file diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/util/CoerceUtilTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/util/CoerceUtilTest.java index 31cef2149d5..2bed3b5f7dd 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/util/CoerceUtilTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/util/CoerceUtilTest.java @@ -31,9 +31,7 @@ import org.junit.jupiter.api.Test; import org.kie.dmn.feel.lang.types.BuiltInType; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; class CoerceUtilTest { @@ -45,61 +43,61 @@ void coerceParam() { Object valueObject = 34; Object actualObject = List.of(valueObject); Optional retrieved = CoerceUtil.coerceParam(currentIdxActualParameterType, expectedParameterType, actualObject); - assertNotNull(retrieved); - assertTrue(retrieved.isPresent()); - assertEquals(valueObject, retrieved.get()); + assertThat(retrieved).isNotNull(); + assertThat(retrieved).isPresent(); + assertThat(retrieved.get()).isEqualTo(valueObject); // Coerce single element to singleton list currentIdxActualParameterType = Number.class; expectedParameterType = List.class; actualObject = 34; retrieved = CoerceUtil.coerceParam(currentIdxActualParameterType, expectedParameterType, actualObject); - assertNotNull(retrieved); - assertTrue(retrieved.isPresent()); - assertTrue(retrieved.get() instanceof List); + assertThat(retrieved).isNotNull(); + assertThat(retrieved).isPresent(); + assertThat(retrieved.get()).isInstanceOf(List.class); List lstRetrieved = (List) retrieved.get(); - assertEquals(1, lstRetrieved.size()); - assertEquals(actualObject, lstRetrieved.get(0)); + assertThat(lstRetrieved).hasSize(1); + assertThat(lstRetrieved.get(0)).isEqualTo(actualObject); // Coerce date to date and time actualObject = LocalDate.now(); currentIdxActualParameterType = LocalDate.class; expectedParameterType = ZonedDateTime.class; retrieved = CoerceUtil.coerceParam(currentIdxActualParameterType, expectedParameterType, actualObject); - assertNotNull(retrieved); - assertTrue(retrieved.isPresent()); - assertTrue(retrieved.get() instanceof ZonedDateTime); + assertThat(retrieved).isNotNull(); + assertThat(retrieved).isPresent(); + assertThat(retrieved.get() instanceof ZonedDateTime).isTrue(); ZonedDateTime zdtRetrieved = (ZonedDateTime) retrieved.get(); - assertEquals(actualObject, zdtRetrieved.toLocalDate()); - assertEquals(ZoneOffset.UTC, zdtRetrieved.getOffset()); - assertEquals(0, zdtRetrieved.getHour()); - assertEquals(0, zdtRetrieved.getMinute()); - assertEquals(0, zdtRetrieved.getSecond()); + assertThat(zdtRetrieved.toLocalDate()).isEqualTo(actualObject); + assertThat(zdtRetrieved.getOffset()).isEqualTo(ZoneOffset.UTC); + assertThat(zdtRetrieved.getHour()).isEqualTo(0); + assertThat(zdtRetrieved.getMinute()).isEqualTo(0); + assertThat(zdtRetrieved.getSecond()).isEqualTo(0); } @Test void coerceParameterDateToDateTimeConverted() { Object value = LocalDate.now(); Object retrieved = CoerceUtil.coerceParameter(BuiltInType.DATE_TIME, value); - assertNotNull(retrieved); - assertTrue(retrieved instanceof ZonedDateTime); + assertThat(retrieved).isNotNull(); + assertThat(retrieved).isInstanceOf(ZonedDateTime.class); ZonedDateTime zdtRetrieved = (ZonedDateTime) retrieved; - assertEquals(value, zdtRetrieved.toLocalDate()); - assertEquals(ZoneOffset.UTC, zdtRetrieved.getOffset()); - assertEquals(0, zdtRetrieved.getHour()); - assertEquals(0, zdtRetrieved.getMinute()); - assertEquals(0, zdtRetrieved.getSecond()); + assertThat(zdtRetrieved.toLocalDate()).isEqualTo(value); + assertThat(zdtRetrieved.getOffset()).isEqualTo(ZoneOffset.UTC); + assertThat(zdtRetrieved.getHour()).isEqualTo(0); + assertThat(zdtRetrieved.getMinute()).isEqualTo(0); + assertThat(zdtRetrieved.getSecond()).isEqualTo(0); } @Test void coerceParameterDateToDateTimeNotConverted() { Object value = "TEST_OBJECT"; Object retrieved = CoerceUtil.coerceParameter(null, value); - assertEquals(value, retrieved); + assertThat(retrieved).isEqualTo(value); value = null; retrieved = CoerceUtil.coerceParameter(BuiltInType.DATE, value); - assertEquals(value, retrieved); + assertThat(retrieved).isEqualTo(value); } @Test @@ -108,28 +106,28 @@ void coerceParamsCollectionToArrayConverted() { Object value = Collections.singleton(item); Object[] actualParams1 = {value, "NOT_DATE"}; Optional retrieved = CoerceUtil.coerceParams(Set.class, String.class, actualParams1, 0); - assertNotNull(retrieved); - assertTrue(retrieved.isPresent()); + assertThat(retrieved).isNotNull(); + assertThat(retrieved).isPresent(); Object[] retrievedObjects = retrieved.get(); - assertEquals(item, retrievedObjects[0]); - assertEquals(actualParams1[1], retrievedObjects[1]); + assertThat(retrievedObjects[0]).isEqualTo(item); + assertThat(retrievedObjects[1]).isEqualTo(actualParams1[1]); item = LocalDate.now(); value = Collections.singleton(item); Object[] actualParams2 = {value, "NOT_DATE"}; retrieved = CoerceUtil.coerceParams(Set.class, ZonedDateTime.class, actualParams2, 0); - assertNotNull(retrieved); - assertTrue(retrieved.isPresent()); + assertThat(retrieved).isNotNull(); + assertThat(retrieved).isPresent(); retrievedObjects = retrieved.get(); - assertTrue(retrievedObjects[0] instanceof ZonedDateTime); + assertThat(retrievedObjects[0]).isInstanceOf(ZonedDateTime.class); ZonedDateTime zdtRetrieved = (ZonedDateTime) retrievedObjects[0]; - assertEquals(item, zdtRetrieved.toLocalDate()); - assertEquals(ZoneOffset.UTC, zdtRetrieved.getOffset()); - assertEquals(0, zdtRetrieved.getHour()); - assertEquals(0, zdtRetrieved.getMinute()); - assertEquals(0, zdtRetrieved.getSecond()); - assertEquals(actualParams2[1], retrievedObjects[1]); + assertThat(zdtRetrieved.toLocalDate()).isEqualTo(item); + assertThat(zdtRetrieved.getOffset()).isEqualTo(ZoneOffset.UTC); + assertThat(zdtRetrieved.getHour()).isEqualTo(0); + assertThat(zdtRetrieved.getMinute()).isEqualTo(0); + assertThat(zdtRetrieved.getSecond()).isEqualTo(0); + assertThat(retrievedObjects[1]).isEqualTo(actualParams2[1]); } @Test @@ -137,17 +135,17 @@ void coerceParamsToDateTimeConverted() { Object value = LocalDate.now(); Object[] actualParams = {value, "NOT_DATE"}; Optional retrieved = CoerceUtil.coerceParams(LocalDate.class, ZonedDateTime.class, actualParams, 0); - assertNotNull(retrieved); - assertTrue(retrieved.isPresent()); + assertThat(retrieved).isNotNull(); + assertThat(retrieved).isPresent(); Object[] retrievedObjects = retrieved.get(); - assertTrue(retrievedObjects[0] instanceof ZonedDateTime); + assertThat(retrievedObjects[0]).isInstanceOf(ZonedDateTime.class); ZonedDateTime zdtRetrieved = (ZonedDateTime) retrievedObjects[0]; - assertEquals(value, zdtRetrieved.toLocalDate()); - assertEquals(ZoneOffset.UTC, zdtRetrieved.getOffset()); - assertEquals(0, zdtRetrieved.getHour()); - assertEquals(0, zdtRetrieved.getMinute()); - assertEquals(0, zdtRetrieved.getSecond()); - assertEquals(actualParams[1], retrievedObjects[1]); + assertThat(zdtRetrieved.toLocalDate()).isEqualTo(value); + assertThat(zdtRetrieved.getOffset()).isEqualTo(ZoneOffset.UTC); + assertThat(zdtRetrieved.getHour()).isEqualTo(0); + assertThat(zdtRetrieved.getMinute()).isEqualTo(0); + assertThat(zdtRetrieved.getSecond()).isEqualTo(0); + assertThat(retrievedObjects[1]).isEqualTo(actualParams[1]); } @Test @@ -156,41 +154,41 @@ void coerceParamsNotConverted() { Object value = Collections.singleton(item); Object[] actualParams1 = {value, "NOT_DATE"}; Optional retrieved = CoerceUtil.coerceParams(Set.class, BigDecimal.class, actualParams1, 0); - assertNotNull(retrieved); - assertTrue(retrieved.isEmpty()); + assertThat(retrieved).isNotNull(); + assertThat(retrieved).isEmpty(); value = LocalDate.now(); Object[] actualParams2 = {value, "NOT_DATE"}; retrieved = CoerceUtil.coerceParams(LocalDate.class, String.class, actualParams2, 0); - assertNotNull(retrieved); - assertTrue(retrieved.isEmpty()); + assertThat(retrieved).isNotNull(); + assertThat(retrieved).isEmpty(); } @Test void actualCoerceParameterToDateTimeConverted() { Object value = LocalDate.now(); Object retrieved = CoerceUtil.actualCoerceParameter(BuiltInType.DATE_TIME, value); - assertNotNull(retrieved); - assertTrue(retrieved instanceof ZonedDateTime); + assertThat(retrieved).isNotNull(); + assertThat(retrieved).isInstanceOf(ZonedDateTime.class); ZonedDateTime zdtRetrieved = (ZonedDateTime) retrieved; - assertEquals(value, zdtRetrieved.toLocalDate()); - assertEquals(ZoneOffset.UTC, zdtRetrieved.getOffset()); - assertEquals(0, zdtRetrieved.getHour()); - assertEquals(0, zdtRetrieved.getMinute()); - assertEquals(0, zdtRetrieved.getSecond()); + assertThat(zdtRetrieved.toLocalDate()).isEqualTo(value); + assertThat(zdtRetrieved.getOffset()).isEqualTo(ZoneOffset.UTC); + assertThat(zdtRetrieved.getHour()).isEqualTo(0); + assertThat(zdtRetrieved.getMinute()).isEqualTo(0); + assertThat(zdtRetrieved.getSecond()).isEqualTo(0); } @Test void actualCoerceParameterNotConverted() { Object value = "TEST_OBJECT"; Object retrieved = CoerceUtil.actualCoerceParameter(BuiltInType.DATE_TIME, value); - assertNotNull(retrieved); - assertEquals(value, retrieved); + assertThat(retrieved).isNotNull(); + assertThat(retrieved).isEqualTo(value); value = LocalDate.now(); retrieved = CoerceUtil.actualCoerceParameter(BuiltInType.DATE, value); - assertNotNull(retrieved); - assertEquals(value, retrieved); + assertThat(retrieved).isNotNull(); + assertThat(retrieved).isEqualTo(value); } @Test @@ -199,10 +197,10 @@ void actualCoerceParams() { Object[] actualParams = {value, "NOT_DATE"}; Object coercedValue = BigDecimal.valueOf(1L); Object[] retrieved = CoerceUtil.actualCoerceParams(actualParams, coercedValue, 0); - assertNotNull(retrieved); - assertEquals(actualParams.length, retrieved.length); - assertEquals(coercedValue, retrieved[0]); - assertEquals(actualParams[1], retrieved[1]); + assertThat(retrieved).isNotNull(); + assertThat(retrieved).hasSameSizeAs(actualParams); + assertThat(retrieved[0]).isEqualTo(coercedValue); + assertThat(retrieved[1]).isEqualTo(actualParams[1]); } } \ No newline at end of file diff --git a/kie-dmn/kie-dmn-legacy-tests/src/test/java/org/kie/dmn/legacy/tests/core/v1_1/DMNRuntimeTest.java b/kie-dmn/kie-dmn-legacy-tests/src/test/java/org/kie/dmn/legacy/tests/core/v1_1/DMNRuntimeTest.java index 550a7817e21..b5443e3e861 100644 --- a/kie-dmn/kie-dmn-legacy-tests/src/test/java/org/kie/dmn/legacy/tests/core/v1_1/DMNRuntimeTest.java +++ b/kie-dmn/kie-dmn-legacy-tests/src/test/java/org/kie/dmn/legacy/tests/core/v1_1/DMNRuntimeTest.java @@ -83,7 +83,7 @@ import org.slf4j.LoggerFactory; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; import static org.kie.dmn.core.util.DMNTestUtil.getAndAssertModelNoErrors; import static org.kie.dmn.core.util.DynamicTypeUtils.entry; import static org.kie.dmn.core.util.DynamicTypeUtils.mapOf; @@ -2539,7 +2539,7 @@ private void testDTinputExprCollectionWithAllowedValues(final DMNRuntime runtime @MethodSource("params") void evaluateByNameWithEmptyParam(VariantTestConf conf) { testConfig = conf; - assertThrows(IllegalArgumentException.class, () -> { + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> { final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("simple-item-def.dmn", this.getClass()); final DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn/itemdef", "simple-item" + "-def"); @@ -2558,7 +2558,7 @@ void evaluateByNameWithEmptyParam(VariantTestConf conf) { @MethodSource("params") void evaluateByIdWithEmptyParam(VariantTestConf conf) { testConfig = conf; - assertThrows(IllegalArgumentException.class, () -> { + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> { final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("simple-item-def.dmn", this.getClass()); final DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn/itemdef", "simple-item" + "-def"); diff --git a/kie-dmn/kie-dmn-ruleset2dmn-parent/kie-dmn-ruleset2dmn-cli/pom.xml b/kie-dmn/kie-dmn-ruleset2dmn-parent/kie-dmn-ruleset2dmn-cli/pom.xml index 26574c8bf64..b561e12e70b 100644 --- a/kie-dmn/kie-dmn-ruleset2dmn-parent/kie-dmn-ruleset2dmn-cli/pom.xml +++ b/kie-dmn/kie-dmn-ruleset2dmn-parent/kie-dmn-ruleset2dmn-cli/pom.xml @@ -110,6 +110,13 @@ + + com.societegenerale.commons + arch-unit-maven-plugin + + true + + \ No newline at end of file diff --git a/kie-dmn/kie-dmn-test-resources/pom.xml b/kie-dmn/kie-dmn-test-resources/pom.xml index bb3d105a5ba..88dcaf865fa 100644 --- a/kie-dmn/kie-dmn-test-resources/pom.xml +++ b/kie-dmn/kie-dmn-test-resources/pom.xml @@ -39,4 +39,16 @@ UTF-8 + + + + com.societegenerale.commons + arch-unit-maven-plugin + + true + + + + + \ No newline at end of file diff --git a/kie-dmn/kie-dmn-validation-bootstrap/pom.xml b/kie-dmn/kie-dmn-validation-bootstrap/pom.xml index 08e23433b78..9c44c43ac89 100644 --- a/kie-dmn/kie-dmn-validation-bootstrap/pom.xml +++ b/kie-dmn/kie-dmn-validation-bootstrap/pom.xml @@ -68,6 +68,18 @@ This is not an user dependency, hence is not added to the boms drools-wiring-dynamic + + + + + com.societegenerale.commons + arch-unit-maven-plugin + + true + + + + diff --git a/kie-dmn/kie-dmn-validation/src/test/java/org/kie/dmn/validation/ValidatorTest.java b/kie-dmn/kie-dmn-validation/src/test/java/org/kie/dmn/validation/ValidatorTest.java index 4099be40e0e..1a58820f607 100644 --- a/kie-dmn/kie-dmn-validation/src/test/java/org/kie/dmn/validation/ValidatorTest.java +++ b/kie-dmn/kie-dmn-validation/src/test/java/org/kie/dmn/validation/ValidatorTest.java @@ -56,8 +56,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; import static org.kie.dmn.validation.DMNValidator.Validation.VALIDATE_COMPILATION; import static org.kie.dmn.validation.DMNValidator.Validation.VALIDATE_MODEL; import static org.kie.dmn.validation.DMNValidator.Validation.VALIDATE_SCHEMA; @@ -558,9 +556,9 @@ private void testFiles(List modelFiles) { .map(ClassPathResource::new) .toArray(value -> new Resource[modelFiles.size()]); List dmnMessages = validatorBuilder.theseModels(resources); - assertNotNull(dmnMessages); + assertThat(dmnMessages).isNotNull(); dmnMessages.forEach(dmnMessage -> LOGGER.error(dmnMessage.toString())); - assertTrue(dmnMessages.isEmpty()); + assertThat(dmnMessages).isEmpty(); } diff --git a/kie-dmn/kie-dmn-validation/src/test/java/org/kie/dmn/validation/v1_5/DMN15ValidationsTest.java b/kie-dmn/kie-dmn-validation/src/test/java/org/kie/dmn/validation/v1_5/DMN15ValidationsTest.java index e8a27da03fd..62254f11ffc 100644 --- a/kie-dmn/kie-dmn-validation/src/test/java/org/kie/dmn/validation/v1_5/DMN15ValidationsTest.java +++ b/kie-dmn/kie-dmn-validation/src/test/java/org/kie/dmn/validation/v1_5/DMN15ValidationsTest.java @@ -39,8 +39,6 @@ import org.slf4j.LoggerFactory; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; import static org.kie.dmn.core.util.DynamicTypeUtils.entry; import static org.kie.dmn.core.util.DynamicTypeUtils.prototype; @@ -155,9 +153,9 @@ private void validate(String modelFileName, String... otherFileNames) { this.getClass())) .toArray(value -> new Resource[allModelsFileNames.size()]); List dmnMessages = validatorBuilder.theseModels(resources); - assertNotNull(dmnMessages); + assertThat(dmnMessages).isNotNull(); dmnMessages.forEach(dmnMessage -> LOG.error(dmnMessage.toString())); - assertTrue(dmnMessages.isEmpty()); + assertThat(dmnMessages).isEmpty(); } private void evaluate(String modelNamespace, String modelName, String modelFileName, diff --git a/kie-dmn/pom.xml b/kie-dmn/pom.xml index f65c0ea87a9..a9c4001341e 100644 --- a/kie-dmn/pom.xml +++ b/kie-dmn/pom.xml @@ -36,6 +36,10 @@ KIE :: Decision Model Notation Top level pom for the KIE DMN support implementation + + 2.9.1 + + kie-dmn-api kie-dmn-model @@ -70,6 +74,15 @@ + + + + com.societegenerale.commons + arch-unit-maven-plugin + ${archunit.maven.plugin.version} + + + org.apache.maven.plugins @@ -95,6 +108,35 @@ + + com.societegenerale.commons + arch-unit-maven-plugin + + + + + + + + + + + + + + com.societegenerale.commons.plugin.rules.NoJunitAssertRuleTest + + + + + + test + + arch-test + + + + From c7c74beadc7bcad0b188c18206b9d935a5ad8eb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tibor=20Zim=C3=A1nyi?= Date: Thu, 5 Sep 2024 09:34:24 +0200 Subject: [PATCH 5/6] [kie-issues#1465] Align with Quarkus 3.8.6. (#6067) --- build-parent/pom.xml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/build-parent/pom.xml b/build-parent/pom.xml index d4f77ee8527..eb2cdb36d1f 100644 --- a/build-parent/pom.xml +++ b/build-parent/pom.xml @@ -60,9 +60,9 @@ 1.1.1 2.15.1 1.11.0 - 2.16.1 - 2.16.1 - 2.16.1 + 2.17.2 + 2.17.2 + 2.17.2 4.31.0 3.7.4 1.0.1 @@ -74,7 +74,7 @@ 0.18.0 4.7.5 1.12.2 - 3.8.4 + 3.8.6 3.10.0 8.5.11 4.13.1 @@ -101,11 +101,11 @@ 2.3.0 14.0.25.Final 3.26.0-GA - 7.0.1.Final + 7.0.2.Final 3.5.3.Final 8.0.0.Final 3.1.6.Final - 3.0.3 + 3.1 4.0.1 2.0.1 2.1.2 From ee6a1956fd544e7fa11b79fd82adb52dbdfdf87a Mon Sep 17 00:00:00 2001 From: Paolo Bizzarri Date: Thu, 5 Sep 2024 16:20:49 +0200 Subject: [PATCH 6/6] NO ISSUE: Improving stream assertions in tests (#6068) * First cleanup for assertj assertions on streams * More stream assertions cleanup * Making the test behaves correctly --- .../org/kie/dmn/core/DMNCompilerTest.java | 12 ++-- .../core/compiler/UnnamedImportUtilsTest.java | 41 ++++++----- .../kie/dmn/core/impl/DMNModelImplTest.java | 12 ++-- .../stronglytyped/DMNRuntimeTypesTest.java | 4 +- .../BigDecimalRangeIteratorTest.java | 10 +-- .../ForIterationTest.java | 17 +++-- .../LocalDateRangeIteratorTest.java | 9 +-- .../ZonedDateTimeRangeIteratorTest.java | 13 ++-- .../dmn/feel/runtime/custom/ZoneTimeTest.java | 25 +++---- .../functions/BaseFEELFunctionTest.java | 69 +++++++++---------- .../kie/dmn/openapi/EnumGenerationTest.java | 18 ++--- 11 files changed, 102 insertions(+), 128 deletions(-) diff --git a/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/DMNCompilerTest.java b/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/DMNCompilerTest.java index daf7518dbb9..7e9874ef7da 100644 --- a/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/DMNCompilerTest.java +++ b/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/DMNCompilerTest.java @@ -339,8 +339,8 @@ void testNestedImports(VariantTestConf conf) { LOG.debug("{}", message); } LOG.debug("{}", evaluateModelCDecision); - assertThat(evaluateModelCDecision.getDecisionResults()).size().isEqualTo(3); - evaluateModelCDecision.getDecisionResults().forEach(dmnDecisionResult -> assertThat(dmnDecisionResult.getEvaluationStatus()).isEqualTo(SUCCEEDED)); + assertThat(evaluateModelCDecision.getDecisionResults()).hasSize(3); + assertThat(evaluateModelCDecision.getDecisionResults()).allMatch(dmnDecisionResult -> dmnDecisionResult.getEvaluationStatus().equals(SUCCEEDED)); } @ParameterizedTest @@ -415,13 +415,11 @@ void wrongComparisonOps(VariantTestConf conf) { assertThat(dmnModel.hasErrors()).as(DMNRuntimeUtil.formatMessages(dmnModel.getMessages())).isFalse(); assertThat(dmnModel.getMessages()).as(DMNRuntimeUtil.formatMessages(dmnModel.getMessages())).hasSize(4); assertThat(dmnModel.getMessages(DMNMessage.Severity.WARN)).as(DMNRuntimeUtil.formatMessages(dmnModel.getMessages())).hasSize(4); - assertThat(dmnModel.getMessages(DMNMessage.Severity.WARN) - .stream() - .filter(m -> m.getSourceId().equals("_d72d6fab-1e67-4fe7-9c12-54800d6fe294") || + assertThat(dmnModel.getMessages(DMNMessage.Severity.WARN)).as(DMNRuntimeUtil.formatMessages(dmnModel.getMessages())) + .filteredOn(m -> m.getSourceId().equals("_d72d6fab-1e67-4fe7-9c12-54800d6fe294") || m.getSourceId().equals("_2390dd99-094d-4f97-aecc-9cccb697ce05") || m.getSourceId().equals("_0c292d34-498e-4b08-ae99-3c694197b69f") || - m.getSourceId().equals("_21c7d800-b806-4b2e-9a10-00828de7f2d2")) - .count()).as(DMNRuntimeUtil.formatMessages(dmnModel.getMessages())).isEqualTo(4L); + m.getSourceId().equals("_21c7d800-b806-4b2e-9a10-00828de7f2d2")).hasSize(4); } @ParameterizedTest diff --git a/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/compiler/UnnamedImportUtilsTest.java b/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/compiler/UnnamedImportUtilsTest.java index f0a8e94a5a8..29d1ac343c1 100644 --- a/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/compiler/UnnamedImportUtilsTest.java +++ b/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/compiler/UnnamedImportUtilsTest.java @@ -65,11 +65,11 @@ void isInUnnamedImportFalse() { final DMNModelImpl importingModel = (DMNModelImpl)runtime.getModel("http://www.trisotech.com/dmn/definitions/_f79aa7a4-f9a3-410a-ac95-bea496edabgc", "Importing named Model"); assertThat(importingModel).isNotNull(); - importedModel.getDecisions().forEach(node -> assertThat(isInUnnamedImport(node, importingModel)).isFalse()); - importedModel.getBusinessKnowledgeModels().forEach(node -> assertThat(isInUnnamedImport(node, importingModel)).isFalse()); - importedModel.getDecisionServices().forEach(node -> assertThat(isInUnnamedImport(node, importingModel)).isFalse()); - importedModel.getInputs().forEach(node -> assertThat(isInUnnamedImport(node, importingModel)).isFalse()); - importedModel.getItemDefinitions().forEach(node -> assertThat(isInUnnamedImport(node, importingModel)).isFalse()); + assertThat(importedModel.getDecisions()).noneMatch(node -> isInUnnamedImport(node, importingModel)); + assertThat(importedModel.getBusinessKnowledgeModels()).noneMatch(node -> isInUnnamedImport(node, importingModel)); + assertThat(importedModel.getDecisionServices()).noneMatch(node -> isInUnnamedImport(node, importingModel)); + assertThat(importedModel.getInputs()).noneMatch(node -> isInUnnamedImport(node, importingModel)); + assertThat(importedModel.getItemDefinitions()).noneMatch(node -> isInUnnamedImport(node, importingModel)); } @Test @@ -80,11 +80,11 @@ void addIfNotPresentTrue() throws IOException { try (InputStream is = importedModelFileResource.openStream()) { String xml = new String(is.readAllBytes(), StandardCharsets.UTF_8); Definitions definitions = DMNMarshallerFactory.newDefaultMarshaller().unmarshal(xml); - definitions.getDecisionService().forEach(definition -> assertThat(added(definition)).isTrue()); - definitions.getBusinessContextElement().forEach(definition -> assertThat(added(definition)).isTrue()); - definitions.getDrgElement().forEach(definition -> assertThat(added(definition)).isTrue()); - definitions.getImport().forEach(definition -> assertThat(added(definition)).isTrue()); - definitions.getItemDefinition().forEach(definition -> assertThat(added(definition)).isTrue()); + assertThat(definitions.getDecisionService()).allMatch(definition -> added(definition)); + assertThat(definitions.getBusinessContextElement()).allMatch(definition -> added(definition)); + assertThat(definitions.getDrgElement()).allMatch(definition -> added(definition)); + assertThat(definitions.getImport()).allMatch(definition -> added(definition)); + assertThat(definitions.getItemDefinition()).allMatch(definition -> added(definition)); } } @@ -114,11 +114,11 @@ private void commonIsInUnnamedImportTrue(String importingModelRef, String import "-f9a3-410a-ac95-bea496edabgc", "Importing empty-named Model"); assertThat(importingModel).isNotNull(); - importedModel.getDecisions().forEach(node -> assertThat(isInUnnamedImport(node, importingModel)).isTrue()); - importedModel.getBusinessKnowledgeModels().forEach(node -> assertThat(isInUnnamedImport(node, importingModel)).isTrue()); - importedModel.getDecisionServices().forEach(node -> assertThat(isInUnnamedImport(node, importingModel)).isTrue()); - importedModel.getInputs().forEach(node -> assertThat(isInUnnamedImport(node, importingModel)).isTrue()); - importedModel.getItemDefinitions().forEach(node -> assertThat(isInUnnamedImport(node, importingModel)).isTrue()); + assertThat(importedModel.getDecisions()).allMatch(node -> isInUnnamedImport(node, importingModel)); + assertThat(importedModel.getBusinessKnowledgeModels()).allMatch(node -> isInUnnamedImport(node, importingModel)); + assertThat(importedModel.getDecisionServices()).allMatch(node -> isInUnnamedImport(node, importingModel)); + assertThat(importedModel.getInputs()).allMatch(node -> isInUnnamedImport(node, importingModel)); + assertThat(importedModel.getItemDefinitions()).allMatch(node -> isInUnnamedImport(node, importingModel)); } private void commonAddIfNotPresentFalse(String importingModelRef, String importedModelRef) throws IOException { @@ -136,12 +136,11 @@ private void commonAddIfNotPresentFalse(String importingModelRef, String importe try (InputStream is = importedModelFileResource.openStream()) { String importedXml = new String(is.readAllBytes(), StandardCharsets.UTF_8); Definitions importedDefinitions = DMNMarshallerFactory.newDefaultMarshaller().unmarshal(importedXml); - importedDefinitions.getDecisionService().forEach(definition -> assertThat(added(importingDefinitions.getDecisionService(), definition)).isFalse()); - importedDefinitions.getBusinessContextElement().forEach(definition -> assertThat(added(importingDefinitions.getBusinessContextElement(), definition)).isFalse()); - importedDefinitions.getDrgElement().forEach(definition -> assertThat(added(importingDefinitions.getDrgElement(), definition)).isFalse()); - importedDefinitions.getImport().forEach(definition -> assertThat(added(importingDefinitions.getImport(), - definition)).isFalse()); - importedDefinitions.getItemDefinition().forEach(definition -> assertThat(added(importingDefinitions.getItemDefinition(), definition)).isFalse()); + assertThat(importedDefinitions.getDecisionService()).noneMatch(definition -> added(importingDefinitions.getDecisionService(), definition)); + assertThat(importedDefinitions.getBusinessContextElement()).noneMatch(definition -> added(importingDefinitions.getBusinessContextElement(), definition)); + assertThat(importedDefinitions.getDrgElement()).noneMatch(definition -> added(importingDefinitions.getDrgElement(), definition)); + assertThat(importedDefinitions.getImport()).noneMatch(definition -> added(importingDefinitions.getImport(), definition)); + assertThat(importedDefinitions.getItemDefinition()).noneMatch(definition -> added(importingDefinitions.getItemDefinition(), definition)); } } diff --git a/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/impl/DMNModelImplTest.java b/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/impl/DMNModelImplTest.java index 7663612df49..8ec9697fa07 100644 --- a/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/impl/DMNModelImplTest.java +++ b/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/impl/DMNModelImplTest.java @@ -53,7 +53,7 @@ void addDecisionSameModel() { decisionNodeList.add(toAdd); }); - decisionNodeList.forEach(decisionNode -> { + assertThat(decisionNodeList).allSatisfy(decisionNode -> { assertThat(model.getDecisionByName(decisionNode.getName())) .isNotNull() .isEqualTo(decisionNode); @@ -72,7 +72,7 @@ void addDecisionWithoutIdSameModel() { decisionNodeList.add(toAdd); }); - decisionNodeList.forEach(decisionNode -> + assertThat(decisionNodeList).allSatisfy(decisionNode -> assertThat(model.getDecisionByName(decisionNode.getName())) .isNotNull() .isEqualTo(decisionNode)); @@ -86,7 +86,7 @@ void addDecisionWithoutNameSameModel() { model.addDecision(toAdd); decisionNodeList.add(toAdd); }); - decisionNodeList.forEach(decisionNode -> + assertThat(decisionNodeList).allSatisfy(decisionNode -> assertThat(model.getDecisionById(decisionNode.getId())) .isNotNull() .isEqualTo(decisionNode)); @@ -104,7 +104,7 @@ void addDecisionImportedModel() { decisionNodeList.add(toAdd); }); - decisionNodeList.forEach(decisionNode -> { + assertThat(decisionNodeList).allSatisfy(decisionNode -> { assertThat(model.getDecisionByName(String.format("%s.%s", importedNameSpace, decisionNode.getName()))) .isNotNull() .isEqualTo(decisionNode); @@ -126,7 +126,7 @@ void addDecisionWithoutIdImportedModel() { decisionNodeList.add(toAdd); }); - decisionNodeList.forEach(decisionNode -> + assertThat(decisionNodeList).allSatisfy(decisionNode -> assertThat(model.getDecisionByName(String.format("%s.%s", importedNameSpace, decisionNode.getName()))) .isNotNull() .isEqualTo(decisionNode)); @@ -143,7 +143,7 @@ void addDecisionWithoutNameImportedModel() { model.addDecision(toAdd); decisionNodeList.add(toAdd); }); - decisionNodeList.forEach(decisionNode -> + assertThat(decisionNodeList).allSatisfy(decisionNode -> assertThat(model.getDecisionById(String.format("%s#%s", importedNameSpace, decisionNode.getId()))) .isNotNull() .isEqualTo(decisionNode)); diff --git a/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/stronglytyped/DMNRuntimeTypesTest.java b/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/stronglytyped/DMNRuntimeTypesTest.java index 2e14a803bc3..f090219c183 100644 --- a/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/stronglytyped/DMNRuntimeTypesTest.java +++ b/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/stronglytyped/DMNRuntimeTypesTest.java @@ -1035,11 +1035,11 @@ void collectionOfCollectionOfCollection(VariantTestConf conf) { Map allProperties = outputSet.allFEELProperties(); List>> colCOut = (List>>) allProperties.get("Decision-1"); List personOutList = colCOut.stream().flatMap(colB -> colB.stream()).flatMap(colA -> colA.stream()).collect(Collectors.toList()); - personOutList.stream().forEach(person -> assertPersonInDeepCol(person)); + assertThat(personOutList).allSatisfy(person -> assertPersonInDeepCol(person)); } else { List>>> colCOut = (List>>>)dmnResult.getContext().get("Decision-1"); List> personOutList = colCOut.stream().flatMap(colB -> colB.stream()).flatMap(colA -> colA.stream()).collect(Collectors.toList()); - personOutList.stream().forEach(person -> assertPersonMapInDeepCol(person)); + assertThat(personOutList).allSatisfy(person -> assertPersonMapInDeepCol(person)); } } diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/forexpressioniterators/BigDecimalRangeIteratorTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/forexpressioniterators/BigDecimalRangeIteratorTest.java index aec84884a5d..261e10bd5f9 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/forexpressioniterators/BigDecimalRangeIteratorTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/forexpressioniterators/BigDecimalRangeIteratorTest.java @@ -19,9 +19,6 @@ package org.kie.dmn.feel.lang.ast.forexpressioniterators; import java.math.BigDecimal; -import java.util.Arrays; -import java.util.List; -import java.util.stream.IntStream; import org.junit.jupiter.api.Test; @@ -61,18 +58,17 @@ void hasNextDescendantTest() { void nextAscendantTest() { BigDecimal start = BigDecimal.valueOf(1); BigDecimal end = BigDecimal.valueOf(3); - List expected = Arrays.asList(BigDecimal.valueOf(1), BigDecimal.valueOf(2), BigDecimal.valueOf(3)); BigDecimalRangeIterator iterator = new BigDecimalRangeIterator(start, end); - IntStream.range(0, 3).forEach(i -> assertThat(expected.get(i)).isEqualTo(iterator.next())); + + assertThat(iterator).toIterable().containsExactly(BigDecimal.valueOf(1), BigDecimal.valueOf(2), BigDecimal.valueOf(3)); } @Test void nextDescendantTest() { BigDecimal start = BigDecimal.valueOf(3); BigDecimal end = BigDecimal.valueOf(1); - List expected = Arrays.asList(BigDecimal.valueOf(3), BigDecimal.valueOf(2), BigDecimal.valueOf(1)); BigDecimalRangeIterator iterator = new BigDecimalRangeIterator(start, end); - IntStream.range(0, 3).forEach(i -> assertThat(expected.get(i)).isEqualTo(iterator.next())); + assertThat(iterator).toIterable().containsExactly(BigDecimal.valueOf(3), BigDecimal.valueOf(2), BigDecimal.valueOf(1)); } diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/forexpressioniterators/ForIterationTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/forexpressioniterators/ForIterationTest.java index b9980f6f119..89ecdf56300 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/forexpressioniterators/ForIterationTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/forexpressioniterators/ForIterationTest.java @@ -20,9 +20,6 @@ import java.math.BigDecimal; import java.time.LocalDate; -import java.util.Arrays; -import java.util.List; -import java.util.stream.IntStream; import org.junit.jupiter.api.Test; @@ -62,19 +59,21 @@ void hasNextValueLocalDateTest() { void getNextValueBigDecimalTest() { BigDecimal start = BigDecimal.valueOf(1); BigDecimal end = BigDecimal.valueOf(3); - List expected = Arrays.asList(BigDecimal.valueOf(1), BigDecimal.valueOf(2), BigDecimal.valueOf(3)); ForIteration iteration = new ForIteration("iteration", start, end); - iteration.hasNextValue(); - IntStream.range(0, 3).forEach(i -> assertThat(expected.get(i)).isEqualTo(iteration.getNextValue())); + assertThat(iteration.hasNextValue()).isTrue(); + assertThat(iteration.getNextValue()).isEqualTo(BigDecimal.valueOf(1)); + assertThat(iteration.getNextValue()).isEqualTo(BigDecimal.valueOf(2)); + assertThat(iteration.getNextValue()).isEqualTo(BigDecimal.valueOf(3)); } @Test void getNextValueLocalDateTest() { LocalDate start = LocalDate.of(2021, 1, 3); LocalDate end = LocalDate.of(2021, 1, 1); - List expected = Arrays.asList(LocalDate.of(2021, 1, 3), LocalDate.of(2021, 1, 2), LocalDate.of(2021, 1, 1)); ForIteration iteration = new ForIteration("iteration", start, end); - iteration.hasNextValue(); - IntStream.range(0, 3).forEach(i -> assertThat(expected.get(i)).isEqualTo(iteration.getNextValue())); + assertThat(iteration.hasNextValue()).isTrue(); + assertThat(iteration.getNextValue()).isEqualTo(LocalDate.of(2021, 1, 3)); + assertThat(iteration.getNextValue()).isEqualTo(LocalDate.of(2021, 1, 2)); + assertThat(iteration.getNextValue()).isEqualTo(LocalDate.of(2021, 1, 1)); } } \ No newline at end of file diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/forexpressioniterators/LocalDateRangeIteratorTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/forexpressioniterators/LocalDateRangeIteratorTest.java index 4add411f7f5..6f932c15d24 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/forexpressioniterators/LocalDateRangeIteratorTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/forexpressioniterators/LocalDateRangeIteratorTest.java @@ -19,9 +19,6 @@ package org.kie.dmn.feel.lang.ast.forexpressioniterators; import java.time.LocalDate; -import java.util.Arrays; -import java.util.List; -import java.util.stream.IntStream; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -65,16 +62,14 @@ void hasNextDescendantTest() { @Test void nextAscendantTest() { - List expected = Arrays.asList(LocalDate.of(2021, 1, 1), LocalDate.of(2021, 1, 2), LocalDate.of(2021, 1, 3)); LocalDateRangeIterator iterator = new LocalDateRangeIterator(before, after); - IntStream.range(0, 3).forEach(i -> assertThat(expected.get(i)).isEqualTo(iterator.next())); + assertThat(iterator).toIterable().containsExactly(LocalDate.of(2021, 1, 1), LocalDate.of(2021, 1, 2), LocalDate.of(2021, 1, 3)); } @Test void nextDescendantTest() { - List expected = Arrays.asList(LocalDate.of(2021, 1, 3), LocalDate.of(2021, 1, 2), LocalDate.of(2021, 1, 1)); LocalDateRangeIterator iterator = new LocalDateRangeIterator(after, before); - IntStream.range(0, 3).forEach(i -> assertThat(expected.get(i)).isEqualTo(iterator.next())); + assertThat(iterator).toIterable().containsExactly(LocalDate.of(2021, 1, 3), LocalDate.of(2021, 1, 2), LocalDate.of(2021, 1, 1)); } diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/forexpressioniterators/ZonedDateTimeRangeIteratorTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/forexpressioniterators/ZonedDateTimeRangeIteratorTest.java index d8a1e8769ea..c11f203619a 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/forexpressioniterators/ZonedDateTimeRangeIteratorTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/forexpressioniterators/ZonedDateTimeRangeIteratorTest.java @@ -21,9 +21,6 @@ import java.time.LocalDateTime; import java.time.ZoneId; import java.time.ZonedDateTime; -import java.util.Arrays; -import java.util.List; -import java.util.stream.IntStream; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -68,20 +65,18 @@ void hasNextDescendantTest() { @Test void nextAscendantTest() { - List expected = Arrays.asList(getZonedDateTime(2021, 1, 1, 10, 15), + ZonedDateTimeRangeIterator iterator = new ZonedDateTimeRangeIterator(before, after); + assertThat(iterator).toIterable().containsExactly(getZonedDateTime(2021, 1, 1, 10, 15), getZonedDateTime(2021, 1, 2, 10, 15), getZonedDateTime(2021, 1, 3, 10, 15)); - ZonedDateTimeRangeIterator iterator = new ZonedDateTimeRangeIterator(before, after); - IntStream.range(0, 3).forEach(i -> assertThat(expected.get(i)).isEqualTo(iterator.next())); } @Test void nextDescendantTest() { - List expected = Arrays.asList(getZonedDateTime(2021, 1, 3, 10, 15), + ZonedDateTimeRangeIterator iterator = new ZonedDateTimeRangeIterator(after, before); + assertThat(iterator).toIterable().containsExactly(getZonedDateTime(2021, 1, 3, 10, 15), getZonedDateTime(2021, 1, 2, 10, 15), getZonedDateTime(2021, 1, 1, 10, 15)); - ZonedDateTimeRangeIterator iterator = new ZonedDateTimeRangeIterator(after, before); - IntStream.range(0, 3).forEach(i -> assertThat(expected.get(i)).isEqualTo(iterator.next())); } diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/custom/ZoneTimeTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/custom/ZoneTimeTest.java index f602e091051..26c49b8317c 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/custom/ZoneTimeTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/custom/ZoneTimeTest.java @@ -30,7 +30,6 @@ import java.time.temporal.TemporalAdjuster; import java.time.temporal.TemporalAmount; import java.time.temporal.TemporalQueries; -import java.util.Arrays; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -133,22 +132,18 @@ void until() { @Test void isSupportedTemporalUnit() { - for (ChronoUnit unit : ChronoUnit.values()) { - assertThat(zoneTime.isSupported(unit)).isEqualTo(offsetTime.isSupported(unit)); - } + assertThat(ChronoUnit.values()).allMatch(unit -> zoneTime.isSupported(unit) == offsetTime.isSupported(unit)); } @Test void isSupportedTemporalField() { - for (ChronoField field : ChronoField.values()) { - assertThat(zoneTime.isSupported(field)).isEqualTo(offsetTime.isSupported(field)); - } + assertThat(ChronoField.values()).allMatch(field -> zoneTime.isSupported(field) == offsetTime.isSupported(field)); } @Test void getLong() { - Arrays.stream(ChronoField.values()).filter(offsetTime::isSupported) - .forEach(field -> assertThat(offsetTime.getLong(field)).isEqualTo(zoneTime.getLong(field))); + assertThat(ChronoField.values()).filteredOn(offsetTime::isSupported) + .allMatch(field -> offsetTime.getLong(field) == (zoneTime.getLong(field))); } @Test @@ -167,16 +162,16 @@ void query() { @Test void range() { - Arrays.stream(ChronoField.values()).filter(offsetTime::isSupported) - .forEach(field -> assertThat(offsetTime.range(field)).isEqualTo(zoneTime.range(field))); + assertThat(ChronoField.values()).filteredOn(offsetTime::isSupported) + .allMatch(field -> offsetTime.range(field).equals(zoneTime.range(field))); } @Test void get() { - Arrays.stream(ChronoField.values()) - .filter(offsetTime::isSupported) - .filter(field -> field != ChronoField.NANO_OF_DAY && field != ChronoField.MICRO_OF_DAY) // Unsupported by offsettime.get() - .forEach(field -> assertThat(offsetTime.get(field)).isEqualTo(zoneTime.get(field))); + assertThat(ChronoField.values()) + .filteredOn(offsetTime::isSupported) + .filteredOn(field -> field != ChronoField.NANO_OF_DAY && field != ChronoField.MICRO_OF_DAY) // Unsupported by offsettime.get() + .allMatch(field -> offsetTime.get(field) == zoneTime.get(field)); } @Test diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/BaseFEELFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/BaseFEELFunctionTest.java index 6b221f7a30b..f5deff2214d 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/BaseFEELFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/BaseFEELFunctionTest.java @@ -101,8 +101,8 @@ void getAllFunctionCandidateMethod() { assertThat(retrieved.getName()).isEqualTo("invoke"); Parameter[] parametersRetrieved = retrieved.getParameters(); assertThat(parametersRetrieved).isNotNull(); - assertThat(parametersRetrieved.length).isEqualTo(1); - assertThat(parametersRetrieved[0].getType()).isEqualTo(List.class); + assertThat(parametersRetrieved).hasSize(1); + assertThat(parametersRetrieved).extracting("type").containsExactly(List.class); // invoke(@ParameterName( "b" ) Object[] list) parameters = new Object[]{true, false}; @@ -114,8 +114,8 @@ void getAllFunctionCandidateMethod() { assertThat(retrieved.getName()).isEqualTo("invoke"); parametersRetrieved = retrieved.getParameters(); assertThat(parametersRetrieved).isNotNull(); - assertThat(parametersRetrieved.length).isEqualTo(1); - assertThat(parametersRetrieved[0].getType()).isEqualTo(Object.class.arrayType()); + assertThat(parametersRetrieved).hasSize(1); + assertThat(parametersRetrieved).extracting("type").containsExactly(Object.class.arrayType()); } @Test @@ -132,8 +132,8 @@ void getDateAndTimeFunctionCandidateMethod() { assertThat(retrieved.getName()).isEqualTo("invoke"); Parameter[] parametersRetrieved = retrieved.getParameters(); assertThat(parametersRetrieved).isNotNull(); - assertThat(parametersRetrieved.length).isEqualTo(1); - assertThat(parametersRetrieved[0].getType()).isEqualTo(String.class); + assertThat(parametersRetrieved).hasSize(1); + assertThat(parametersRetrieved).extracting("type").containsExactly(String.class); // invoke(@ParameterName( "date" ) TemporalAccessor date, @ParameterName( "time" ) TemporalAccessor time) parameters = new Object[]{LocalDate.of(2017, 6, 12), LocalTime.of(10, 6, 20)}; @@ -145,8 +145,8 @@ void getDateAndTimeFunctionCandidateMethod() { assertThat(retrieved.getName()).isEqualTo("invoke"); parametersRetrieved = retrieved.getParameters(); assertThat(parametersRetrieved).isNotNull(); - assertThat(parametersRetrieved.length).isEqualTo(2); - Arrays.stream(parametersRetrieved).forEach(parameter -> assertThat(TemporalAccessor.class).isEqualTo(parameter.getType())); + assertThat(parametersRetrieved).hasSize(2); + assertThat(parametersRetrieved).extracting("type").containsExactly(TemporalAccessor.class, TemporalAccessor.class); // invoke(@ParameterName( "year" ) Number year, @ParameterName( "month" ) Number month, @ParameterName( "day" @@ -162,8 +162,9 @@ void getDateAndTimeFunctionCandidateMethod() { assertThat(retrieved.getName()).isEqualTo("invoke"); parametersRetrieved = retrieved.getParameters(); assertThat(parametersRetrieved).isNotNull(); - assertThat(parametersRetrieved.length).isEqualTo(6); - Arrays.stream(parametersRetrieved).forEach(parameter -> assertThat(Number.class).isEqualTo(parameter.getType())); + assertThat(parametersRetrieved).hasSize(6); + assertThat(parametersRetrieved).extracting("type").containsExactly(Number.class, Number.class, Number.class, + Number.class, Number.class, Number.class); // invoke(@ParameterName( "year" ) Number year, @ParameterName( "month" ) Number month, @ParameterName( "day" // ) Number day, @@ -179,8 +180,9 @@ void getDateAndTimeFunctionCandidateMethod() { assertThat(retrieved.getName()).isEqualTo("invoke"); parametersRetrieved = retrieved.getParameters(); assertThat(parametersRetrieved).isNotNull(); - assertThat(parametersRetrieved.length).isEqualTo(7); - Arrays.stream(parametersRetrieved).forEach(parameter -> assertThat(Number.class).isEqualTo(parameter.getType())); + assertThat(parametersRetrieved).hasSize(7); + assertThat(parametersRetrieved).extracting("type").containsExactly(Number.class, Number.class, Number.class, + Number.class, Number.class, Number.class, Number.class); // invoke(@ParameterName( "year" ) Number year, @ParameterName( "month" ) Number month, @ParameterName( "day" // ) Number day, @@ -196,11 +198,9 @@ void getDateAndTimeFunctionCandidateMethod() { assertThat(retrieved.getName()).isEqualTo("invoke"); parametersRetrieved = retrieved.getParameters(); assertThat(parametersRetrieved).isNotNull(); - assertThat(parametersRetrieved.length).isEqualTo(7); - for (int i = 0; i < 6; i++) { - assertThat(parametersRetrieved[i].getType()).isEqualTo(Number.class); - } - assertThat(parametersRetrieved[6].getType()).isEqualTo(String.class); + assertThat(parametersRetrieved).hasSize(7); + assertThat(parametersRetrieved).extracting("type").containsExactly(Number.class, Number.class, Number.class, + Number.class, Number.class, Number.class, String.class); } @Test @@ -217,8 +217,8 @@ void getExtendedTimeFunctionCandidateMethod() { assertThat(retrieved.getName()).isEqualTo("invoke"); Parameter[] parametersRetrieved = retrieved.getParameters(); assertThat(parametersRetrieved).isNotNull(); - assertThat(parametersRetrieved.length).isEqualTo(1); - assertThat(parametersRetrieved[0].getType()).isEqualTo(String.class); + assertThat(parametersRetrieved).hasSize(1); + assertThat(parametersRetrieved).extracting("type").containsExactly(String.class); // invoke( // @ParameterName("hour") Number hour, @ParameterName("minute") Number minute, @@ -232,8 +232,8 @@ void getExtendedTimeFunctionCandidateMethod() { assertThat(retrieved.getName()).isEqualTo("invoke"); parametersRetrieved = retrieved.getParameters(); assertThat(parametersRetrieved).isNotNull(); - assertThat(parametersRetrieved.length).isEqualTo(3); - Arrays.stream(parametersRetrieved).forEach(parameter -> assertThat(Number.class).isEqualTo(parameter.getType())); + assertThat(parametersRetrieved).hasSize(3); + assertThat(parametersRetrieved).extracting("type").containsExactly(Number.class, Number.class, Number.class); // invoke( // @ParameterName("hour") Number hour, @ParameterName("minute") Number minute, @@ -247,11 +247,10 @@ void getExtendedTimeFunctionCandidateMethod() { assertThat(retrieved.getName()).isEqualTo("invoke"); parametersRetrieved = retrieved.getParameters(); assertThat(parametersRetrieved).isNotNull(); - assertThat(parametersRetrieved.length).isEqualTo(4); - for (int i = 0; i < 3; i++) { - assertThat(parametersRetrieved[i].getType()).isEqualTo(Number.class); - } - assertThat(parametersRetrieved[3].getType()).isEqualTo(Duration.class); + assertThat(parametersRetrieved).hasSize(4); + + assertThat(parametersRetrieved).extracting("type").containsExactly(Number.class, Number.class, Number.class, Duration.class); + // invoke(@ParameterName("from") TemporalAccessor date parameters = new Object[]{LocalTime.of(10, 6, 20)}; @@ -263,8 +262,8 @@ void getExtendedTimeFunctionCandidateMethod() { assertThat(retrieved.getName()).isEqualTo("invoke"); parametersRetrieved = retrieved.getParameters(); assertThat(parametersRetrieved).isNotNull(); - assertThat(parametersRetrieved.length).isEqualTo(1); - assertThat(parametersRetrieved[0].getType()).isEqualTo(TemporalAccessor.class); + assertThat(parametersRetrieved).hasSize(1); + assertThat(parametersRetrieved).extracting("type").containsExactly(TemporalAccessor.class); } @Test @@ -283,10 +282,8 @@ void getSortFunctionCandidateMethod() { assertThat(retrieved.getName()).isEqualTo("invoke"); Parameter[] parametersRetrieved = retrieved.getParameters(); assertThat(parametersRetrieved).isNotNull(); - assertThat(parametersRetrieved.length).isEqualTo(3); - assertThat(parametersRetrieved[0].getType()).isEqualTo(EvaluationContext.class); - assertThat(parametersRetrieved[1].getType()).isEqualTo(List.class); - assertThat(parametersRetrieved[2].getType()).isEqualTo(FEELFunction.class); + assertThat(parametersRetrieved).hasSize(3); + assertThat(parametersRetrieved).extracting("type").containsExactly(EvaluationContext.class, List.class, FEELFunction.class); // invoke(@ParameterName("list") List list) parameters = new Object[]{List.of(1, 3, 5)}; @@ -298,8 +295,8 @@ void getSortFunctionCandidateMethod() { assertThat(retrieved.getName()).isEqualTo("invoke"); parametersRetrieved = retrieved.getParameters(); assertThat(parametersRetrieved).isNotNull(); - assertThat(parametersRetrieved.length).isEqualTo(1); - assertThat(parametersRetrieved[0].getType()).isEqualTo(List.class); + assertThat(parametersRetrieved).hasSize(1); + assertThat(parametersRetrieved).extracting("type").containsExactly(List.class); } @Test @@ -317,8 +314,8 @@ void getStddevFunctionCandidateMethod() { assertThat(retrieved.getName()).isEqualTo("invoke"); Parameter[] parametersRetrieved = retrieved.getParameters(); assertThat(parametersRetrieved).isNotNull(); - assertThat(parametersRetrieved.length).isEqualTo(1); - assertThat(parametersRetrieved[0].getType()).isEqualTo(List.class); + assertThat(parametersRetrieved).hasSize(1); + assertThat(parametersRetrieved).extracting("type").containsExactly(List.class); } } \ No newline at end of file diff --git a/kie-dmn/kie-dmn-openapi/src/test/java/org/kie/dmn/openapi/EnumGenerationTest.java b/kie-dmn/kie-dmn-openapi/src/test/java/org/kie/dmn/openapi/EnumGenerationTest.java index f0604cd5000..9c2c11accb8 100644 --- a/kie-dmn/kie-dmn-openapi/src/test/java/org/kie/dmn/openapi/EnumGenerationTest.java +++ b/kie-dmn/kie-dmn-openapi/src/test/java/org/kie/dmn/openapi/EnumGenerationTest.java @@ -60,7 +60,8 @@ void numberAllowedValues() { ArrayNode arrayNode = (ArrayNode) node.get("enum"); assertThat(arrayNode).isNotNull(); List expected = Arrays.asList(BigDecimal.ZERO, BigDecimal.ONE, BigDecimal.valueOf(2)); - arrayNode.iterator().forEachRemaining(e -> { + + assertThat(arrayNode).allSatisfy(e -> { assertThat(e).isInstanceOf(DecimalNode.class); assertThat(expected).contains(e.decimalValue()); }); @@ -75,7 +76,7 @@ void stringAllowedValues() { ArrayNode arrayNode = (ArrayNode) node.get("enum"); assertThat(arrayNode).isNotNull(); List expected = Arrays.asList("a", "b", "c"); - arrayNode.iterator().forEachRemaining(e -> { + assertThat(arrayNode).allSatisfy(e -> { assertThat(e).isInstanceOf(TextNode.class); assertThat(expected).contains(e.textValue()); }); @@ -90,7 +91,7 @@ void stringNullableAllowedValues() { ArrayNode arrayNode = (ArrayNode) node.get("enum"); assertThat(arrayNode).isNotNull(); List expected = Arrays.asList("a", "b", "c", null); - arrayNode.iterator().forEachRemaining(e -> { + assertThat(arrayNode).allSatisfy(e -> { assertThat(expected).contains(e.textValue()); }); assertThat(node.get("nullable")).isNotNull().isInstanceOf(BooleanNode.class); @@ -104,7 +105,7 @@ void numberTypeConstraint() { ArrayNode arrayNode = (ArrayNode) node.get("enum"); assertThat(arrayNode).isNotNull(); List expected = Arrays.asList(BigDecimal.ZERO, BigDecimal.ONE, BigDecimal.valueOf(2)); - arrayNode.iterator().forEachRemaining(e -> { + assertThat(arrayNode).allSatisfy(e -> { assertThat(e).isInstanceOf(DecimalNode.class); assertThat(expected).contains(e.decimalValue()); }); @@ -119,7 +120,7 @@ void stringTypeConstraint() { ArrayNode arrayNode = (ArrayNode) node.get("enum"); assertThat(arrayNode).isNotNull(); List expected = Arrays.asList("a", "b", "c"); - arrayNode.iterator().forEachRemaining(e -> { + assertThat(arrayNode).allSatisfy(e -> { assertThat(e).isInstanceOf(TextNode.class); assertThat(expected).contains(e.textValue()); }); @@ -133,10 +134,9 @@ void stringNullableTypeConstraint() { assertThat(node).isNotNull(); ArrayNode arrayNode = (ArrayNode) node.get("enum"); assertThat(arrayNode).isNotNull(); - List expected = Arrays.asList("a", "b", "c", null); - arrayNode.iterator().forEachRemaining(e -> { - assertThat(expected).contains(e.textValue()); - }); + + assertThat(arrayNode).extracting(node1 -> node1.textValue()).containsExactlyInAnyOrder("a", "b", "c", null); + assertThat(node.get("nullable")).isNotNull().isInstanceOf(BooleanNode.class); assertThat(node.get("nullable").asBoolean()).isTrue(); }