From ebf19614810a2c1fdb2bc76a22dc45a87bc53e50 Mon Sep 17 00:00:00 2001 From: Paolo Bizzarri Date: Thu, 28 Nov 2024 16:29:54 +0100 Subject: [PATCH] [incubator-kie-drools-6136] Migrate drools test coverage to JUnit5 - #7 (#6175) * More tests migrated * Migrated tests to Junit5 * Migrated drools-core * Migrated alphanetwork compiler --- drools-alphanetwork-compiler/pom.xml | 6 +- .../ancompiler/AlphaNetworkCompilerTest.java | 139 +++++++++-------- .../ancompiler/AlphaNetworkInitTest.java | 38 +++-- .../org/drools/ancompiler/BaseModelTest.java | 63 ++++---- .../ancompiler/LargeAlphaNetworkTest.java | 14 +- .../ancompiler/MixedConstraintsTest.java | 18 +-- .../MultipleIndexableConstraintsTest.java | 14 +- .../drools/ancompiler/RangeIndexANCTest.java | 39 ++--- drools-core/pom.xml | 6 +- .../core/base/ClassTypeResolverTest.java | 2 +- .../org/drools/core/base/ValueTypeTest.java | 2 +- .../base/accumulators/VarianceNaNTest.java | 2 +- .../evaluators/TimeIntervalParserTest.java | 2 +- .../common/ClassAwareObjectStoreTest.java | 142 ++++++++++-------- .../core/common/DroolsObjectIOTest.java | 2 +- .../core/impl/KnowledgeBaseImplTest.java | 2 +- .../ByteArrayResourceSerializationTest.java | 2 +- .../impl/ByteArrayResourceToStringTest.java | 47 +++--- .../core/io/impl/ReaderResourceTest.java | 2 +- .../org/drools/core/reteoo/BaseNodeTest.java | 2 +- .../org/drools/core/reteoo/BetaNodeTest.java | 2 +- .../reteoo/DefaultFactHandleFactoryTest.java | 2 +- .../drools/core/reteoo/FactHandleTest.java | 2 +- .../drools/core/reteoo/MockLeftTupleSink.java | 2 - .../drools/core/reteoo/NodeTypeEnumTest.java | 2 +- .../drools/core/reteoo/ObjectSourceTest.java | 2 +- .../core/reteoo/ObjectTypeConfTest.java | 3 +- .../core/reteoo/TupleIterationTest.java | 6 +- .../drools/core/reteoo/TupleSourceTest.java | 2 +- .../reteoo/builder/ReteooRuleBuilderTest.java | 6 +- .../core/time/TemporalDistanceTest.java | 2 +- .../impl/CompositeMaxDurationTimerTest.java | 2 +- .../core/time/impl/CronExpressionTest.java | 7 +- .../drools/core/time/impl/CronJobTest.java | 3 +- .../core/time/impl/JDKTimerServiceTest.java | 2 +- .../time/impl/PseudoClockSchedulerTest.java | 14 +- .../drools/core/time/impl/Quartz601Test.java | 2 +- .../time/impl/SerializationTestSupport.java | 2 +- .../util/BinaryHeapPriorityQueueTest.java | 3 +- .../drools/core/util/BinaryHeapQueueTest.java | 7 +- .../org/drools/core/util/ClassUtilsTest.java | 2 +- .../util/IndexedHashtableIteratorTest.java | 2 +- .../org/drools/core/util/IoUtilsTest.java | 2 +- .../drools/core/util/KeyStoreHelperTest.java | 6 +- .../drools/core/util/KieFunctionsTest.java | 2 +- .../drools/core/util/LeftTupleRBTreeTest.java | 2 +- .../org/drools/core/util/LinkedListTest.java | 7 +- .../org/drools/core/util/MethodUtilsTest.java | 2 +- .../drools/core/util/RightTupleListTest.java | 3 +- .../drools/core/util/ScalablePoolTest.java | 2 +- .../drools/core/util/index/IndexUtilTest.java | 2 +- .../core/util/index/RangeIndexTest.java | 2 +- 52 files changed, 328 insertions(+), 323 deletions(-) diff --git a/drools-alphanetwork-compiler/pom.xml b/drools-alphanetwork-compiler/pom.xml index 3f1d6a7da7c..c3fe0de189e 100644 --- a/drools-alphanetwork-compiler/pom.xml +++ b/drools-alphanetwork-compiler/pom.xml @@ -82,10 +82,10 @@ test - org.kie - kie-test-util + org.junit.jupiter + junit-jupiter test - + org.assertj assertj-core diff --git a/drools-alphanetwork-compiler/src/test/java/org/drools/ancompiler/AlphaNetworkCompilerTest.java b/drools-alphanetwork-compiler/src/test/java/org/drools/ancompiler/AlphaNetworkCompilerTest.java index 4491f39eace..bee51fcf15f 100644 --- a/drools-alphanetwork-compiler/src/test/java/org/drools/ancompiler/AlphaNetworkCompilerTest.java +++ b/drools-alphanetwork-compiler/src/test/java/org/drools/ancompiler/AlphaNetworkCompilerTest.java @@ -27,7 +27,8 @@ import org.drools.core.reteoo.CompositeObjectSinkAdapter; import org.drools.core.reteoo.ObjectSinkPropagator; import org.drools.core.reteoo.ObjectTypeNode; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.KieServices; import org.kie.api.builder.ReleaseId; import org.kie.api.builder.model.KieModuleModel; @@ -39,9 +40,6 @@ public class AlphaNetworkCompilerTest extends BaseModelTest { - public AlphaNetworkCompilerTest(RUN_TYPE testRunType ) { - super( testRunType ); - } public class Message implements Serializable { private final String value; @@ -55,8 +53,9 @@ public String getValue() { } } - @Test - public void testNonHashedAlphaNode() { + @ParameterizedTest(name = "{0}") + @MethodSource("parameters") + public void testNonHashedAlphaNode(RUN_TYPE testRunType) { String str = "import " + Person.class.getCanonicalName() + ";" + "global java.util.List resultsM;\n" + @@ -75,7 +74,7 @@ public void testNonHashedAlphaNode() { final List resultsM = new ArrayList<>(); final List resultsL = new ArrayList<>(); - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(testRunType, str); ksession.setGlobal("resultsM", resultsM); ksession.setGlobal("resultsL", resultsL); @@ -95,8 +94,9 @@ public void testNonHashedAlphaNode() { assertThat(resultsL.iterator().next()).isEqualTo(luca); } - @Test - public void testNormalizationForAlphaIndexing() { + @ParameterizedTest(name = "{0}") + @MethodSource("parameters") + public void testNormalizationForAlphaIndexing(RUN_TYPE testRunType) { final String str = "package org.drools.test;\n" + "import " + Person.class.getCanonicalName() + ";\n" + @@ -113,7 +113,7 @@ public void testNormalizationForAlphaIndexing() { "then\n" + "end\n"; - final KieSession ksession = getKieSession(str); + final KieSession ksession = getKieSession(testRunType, str); ObjectTypeNode otn = ((NamedEntryPoint) ksession.getEntryPoint("DEFAULT")).getEntryPointNode().getObjectTypeNodes().entrySet() .stream() @@ -122,7 +122,7 @@ public void testNormalizationForAlphaIndexing() { .findFirst() .get(); ObjectSinkPropagator objectSinkPropagator = otn.getObjectSinkPropagator(); - if(this.testRunType.isAlphaNetworkCompiler()) { + if(testRunType.isAlphaNetworkCompiler()) { objectSinkPropagator = ((CompiledNetwork)objectSinkPropagator).getOriginalSinkPropagator(); } CompositeObjectSinkAdapter sinkAdaptor = (CompositeObjectSinkAdapter) objectSinkPropagator; @@ -135,8 +135,9 @@ public void testNormalizationForAlphaIndexing() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testNodeHashingWithMultipleConditions() { + @ParameterizedTest(name = "{0}") + @MethodSource("parameters") + public void testNodeHashingWithMultipleConditions(RUN_TYPE testRunType) { String str = "import " + Person.class.getCanonicalName() + ";" + "global java.util.List results;\n" + @@ -156,7 +157,7 @@ public void testNodeHashingWithMultipleConditions() { final List results = new ArrayList<>(); - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(testRunType, str); ksession.setGlobal("results", results); @@ -175,8 +176,9 @@ public void testNodeHashingWithMultipleConditions() { } - @Test - public void testHashedInteger() { + @ParameterizedTest(name = "{0}") + @MethodSource("parameters") + public void testHashedInteger(RUN_TYPE testRunType) { String str = "import " + Person.class.getCanonicalName() + ";" + "global java.util.List resultsM;\n" + @@ -195,7 +197,7 @@ public void testHashedInteger() { final List resultsM = new ArrayList<>(); final List resultsL = new ArrayList<>(); - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(testRunType, str); ksession.setGlobal("resultsM", resultsM); ksession.setGlobal("resultsL", resultsL); @@ -215,8 +217,9 @@ public void testHashedInteger() { assertThat(resultsL.iterator().next()).isEqualTo(luca); } - @Test - public void testAlphaConstraint() { + @ParameterizedTest(name = "{0}") + @MethodSource("parameters") + public void testAlphaConstraint(RUN_TYPE testRunType) { String str = "rule \"Bind\"\n" + "when\n" + @@ -224,7 +227,7 @@ public void testAlphaConstraint() { "then\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(testRunType, str); ksession.insert("Luca"); ksession.insert("Asdrubale"); @@ -232,8 +235,9 @@ public void testAlphaConstraint() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testAlphaConstraintsSwitchString() { + @ParameterizedTest(name = "{0}") + @MethodSource("parameters") + public void testAlphaConstraintsSwitchString(RUN_TYPE testRunType) { String str = "import " + Person.class.getCanonicalName() + ";" + "rule \"Bind1\"\n" + @@ -252,7 +256,7 @@ public void testAlphaConstraintsSwitchString() { "then\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(testRunType, str); ksession.insert(new Person("Luca")); ksession.insert(new Person("Asdrubale")); @@ -263,8 +267,9 @@ public void testAlphaConstraintsSwitchString() { /* This generates the switch but not the inlining */ - @Test - public void testAlphaConstraintsSwitchBigDecimal() { + @ParameterizedTest(name = "{0}") + @MethodSource("parameters") + public void testAlphaConstraintsSwitchBigDecimal(RUN_TYPE testRunType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + BigDecimal.class.getCanonicalName() + ";" + @@ -284,7 +289,7 @@ public void testAlphaConstraintsSwitchBigDecimal() { "then\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(testRunType, str); ksession.insert(new Person("Luca", new BigDecimal(0))); ksession.insert(new Person("Asdrubale", new BigDecimal(10))); @@ -292,8 +297,9 @@ public void testAlphaConstraintsSwitchBigDecimal() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testAlphaConstraintsSwitchPerson() { + @ParameterizedTest(name = "{0}") + @MethodSource("parameters") + public void testAlphaConstraintsSwitchPerson(RUN_TYPE testRunType) { String str = "import " + Person.class.getCanonicalName() + ";" + "rule \"Bind1\"\n" + @@ -312,7 +318,7 @@ public void testAlphaConstraintsSwitchPerson() { "then\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(testRunType, str); ksession.insert(new Person("Luca")); ksession.insert(new Person("Asdrubale")); @@ -320,8 +326,9 @@ public void testAlphaConstraintsSwitchPerson() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testAlphaConstraintsSwitchIntegers() { + @ParameterizedTest(name = "{0}") + @MethodSource("parameters") + public void testAlphaConstraintsSwitchIntegers(RUN_TYPE testRunType) { String str = "rule \"Bind1\"\n" + "when\n" + @@ -339,7 +346,7 @@ public void testAlphaConstraintsSwitchIntegers() { "then\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(testRunType, str); ksession.insert("Luca"); ksession.insert("Asdrubale"); @@ -347,8 +354,9 @@ public void testAlphaConstraintsSwitchIntegers() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testEnum() { + @ParameterizedTest(name = "{0}") + @MethodSource("parameters") + public void testEnum(RUN_TYPE testRunType) { String str = "import " + EnumFact1.class.getCanonicalName() + ";\n" + "import " + ChildFactWithEnum1.class.getCanonicalName() + ";\n" + @@ -365,14 +373,15 @@ public void testEnum() { "then\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(testRunType, str); ksession.insert(new ChildFactWithEnum1(1, 3, EnumFact1.FIRST)); ksession.insert(new ChildFactWithEnum1(1, 3, EnumFact1.SECOND)); assertThat(ksession.fireAllRules()).isEqualTo(2); } - @Test - public void testAlphaConstraintWithModification() { + @ParameterizedTest(name = "{0}") + @MethodSource("parameters") + public void testAlphaConstraintWithModification(RUN_TYPE testRunType) { String str = "global java.util.List results;\n" + "rule \"Bind\"\n" + @@ -382,7 +391,7 @@ public void testAlphaConstraintWithModification() { " results.add($s + \" is greater than 4 and smaller than 10\");\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(testRunType, str); ksession.insert("Luca"); ksession.insert("Asdrubale"); @@ -396,8 +405,9 @@ public void testAlphaConstraintWithModification() { assertThat(results.iterator().next()).isEqualTo("Asdrubale is greater than 4 and smaller than 10"); } - @Test - public void testModify() { + @ParameterizedTest(name = "{0}") + @MethodSource("parameters") + public void testModify(RUN_TYPE testRunType) { String str = "import " + Person.class.getCanonicalName() + ";" + "rule \"Modify\"\n" + @@ -407,7 +417,7 @@ public void testModify() { " modify($p) { setName($p.getName() + \"30\"); }" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(testRunType, str); final Person luca = new Person("Luca", 30); ksession.insert(luca); @@ -418,8 +428,9 @@ public void testModify() { assertThat(luca.getName()).isEqualTo("Luca30"); } - @Test - public void testModify2() { + @ParameterizedTest(name = "{0}") + @MethodSource("parameters") + public void testModify2(RUN_TYPE testRunType) { String str = "import " + Person.class.getCanonicalName() + ";" + "global java.util.List results;\n" + @@ -430,7 +441,7 @@ public void testModify2() { " modify($p) { setAge($p.getAge() + 1); }" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(testRunType, str); final Person luca = new Person("Luca", 30); ksession.insert(luca); @@ -444,8 +455,9 @@ public void testModify2() { assertThat(luca.getAge() == 40).isTrue(); } - @Test - public void testAlphaConstraintNagate() { + @ParameterizedTest(name = "{0}") + @MethodSource("parameters") + public void testAlphaConstraintNagate(RUN_TYPE testRunType) { final String str = "import " + Person.class.getCanonicalName() + ";\n" + "rule R1 when\n" + @@ -453,14 +465,15 @@ public void testAlphaConstraintNagate() { "then\n" + "end"; - try (KieSession ksession = getKieSession(str)) { + try (KieSession ksession = getKieSession(testRunType, str)) { ksession.insert(new Person("Mario", 45)); assertThat(ksession.fireAllRules()).isEqualTo(0); } } - @Test - public void testKJarUpgradeWithDeclaredType() throws Exception { + @ParameterizedTest(name = "{0}") + @MethodSource("parameters") + public void testKJarUpgradeWithDeclaredType(RUN_TYPE testRunType) throws Exception { String drl1 = "package org.drools.incremental\n" + "declare Message value : String end\n" + "rule Init when then insert(new Message( \"Hello World\" )); end\n" + @@ -495,30 +508,30 @@ public void testKJarUpgradeWithDeclaredType() throws Exception { ReleaseId releaseId1 = ks.newReleaseId( "org.kie", "test-upgrade", "1.0.0" ); KieModuleModel kieModuleModel = ks.newKieModuleModel(); - if(this.testRunType.isAlphaNetworkCompiler()) { + if(testRunType.isAlphaNetworkCompiler()) { kieModuleModel.setConfigurationProperty("drools.alphaNetworkCompiler", AlphaNetworkCompilerOption.INMEMORY.toString()); } - createAndDeployJar( ks, kieModuleModel, releaseId1, drl1, drl2_1 ); + createAndDeployJar(testRunType, ks, kieModuleModel, releaseId1, drl1, drl2_1); KieContainer kc = ks.newKieContainer( releaseId1 ); // Create a session and fire rules KieSession ksession = kc.newKieSession(); - if(this.testRunType.isAlphaNetworkCompiler()) { + if(testRunType.isAlphaNetworkCompiler()) { this.assertReteIsAlphaNetworkCompiled(ksession); } assertThat(ksession.fireAllRules()).isEqualTo(2); // Create a new jar for version 1.1.0 ReleaseId releaseId2 = ks.newReleaseId( "org.kie", "test-upgrade", "1.1.0" ); - createAndDeployJar( ks, kieModuleModel, releaseId2, drl1, drl2_2 ); + createAndDeployJar(testRunType, ks, kieModuleModel, releaseId2, drl1, drl2_2 ); // try to update the container to version 1.1.0 kc.updateToVersion( releaseId2 ); // try with a new session KieSession ksession2 = kc.newKieSession(); - if(this.testRunType.isAlphaNetworkCompiler()) { + if(testRunType.isAlphaNetworkCompiler()) { this.assertReteIsAlphaNetworkCompiled(ksession2); } @@ -526,12 +539,12 @@ public void testKJarUpgradeWithDeclaredType() throws Exception { // Create a new jar for version 1.2.0 ReleaseId releaseId3 = ks.newReleaseId( "org.kie", "test-upgrade", "1.2.0" ); - createAndDeployJar( ks, kieModuleModel, releaseId3, drl1, drl2_3 ); + createAndDeployJar(testRunType, ks, kieModuleModel, releaseId3, drl1, drl2_3); // try to update the container to version 1.2.0 kc.updateToVersion( releaseId3 ); KieSession kieSession3 = kc.newKieSession(); - if(this.testRunType.isAlphaNetworkCompiler()) { + if(testRunType.isAlphaNetworkCompiler()) { this.assertReteIsAlphaNetworkCompiled(kieSession3); } @@ -542,8 +555,9 @@ public void testKJarUpgradeWithDeclaredType() throws Exception { assertThat(list.get(0)).isEqualTo("Hello World"); } - @Test - public void testNodeHashingWith2LevelConditionsCheckFirstCondition() { + @ParameterizedTest(name = "{0}") + @MethodSource("parameters") + public void testNodeHashingWith2LevelConditionsCheckFirstCondition(RUN_TYPE testRunType) { // DROOLS-7137 String str = "import " + Person.class.getCanonicalName() + ";" + @@ -566,7 +580,7 @@ public void testNodeHashingWith2LevelConditionsCheckFirstCondition() { final List results = new ArrayList<>(); - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(testRunType, str); ksession.setGlobal("results", results); @@ -584,8 +598,9 @@ public void testNodeHashingWith2LevelConditionsCheckFirstCondition() { assertThat(results).containsExactlyInAnyOrder(luca20, luca18); } - @Test - public void testNodeHashingWith2LevelConditionsCheckFirstConditionWithLong() { + @ParameterizedTest(name = "{0}") + @MethodSource("parameters") + public void testNodeHashingWith2LevelConditionsCheckFirstConditionWithLong(RUN_TYPE testRunType) { // DROOLS-7137 String str = "import " + Person.class.getCanonicalName() + ";" + @@ -608,7 +623,7 @@ public void testNodeHashingWith2LevelConditionsCheckFirstConditionWithLong() { final List results = new ArrayList<>(); - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(testRunType, str); ksession.setGlobal("results", results); diff --git a/drools-alphanetwork-compiler/src/test/java/org/drools/ancompiler/AlphaNetworkInitTest.java b/drools-alphanetwork-compiler/src/test/java/org/drools/ancompiler/AlphaNetworkInitTest.java index 385b150935c..7ecce9c0510 100644 --- a/drools-alphanetwork-compiler/src/test/java/org/drools/ancompiler/AlphaNetworkInitTest.java +++ b/drools-alphanetwork-compiler/src/test/java/org/drools/ancompiler/AlphaNetworkInitTest.java @@ -20,41 +20,37 @@ import java.util.ArrayList; import java.util.List; +import java.util.stream.Stream; -import org.junit.Test; -import org.junit.runners.Parameterized; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.runtime.KieSession; import static org.assertj.core.api.Assertions.assertThat; public class AlphaNetworkInitTest extends BaseModelTest { - public AlphaNetworkInitTest(RUN_TYPE testRunType) { - super(testRunType); - } - // ANC is assembled manually - final static Object[] STANDARD = { - RUN_TYPE.STANDARD_FROM_DRL, - }; - - @Parameterized.Parameters(name = "{0}") - public static Object[] params() { - return STANDARD; + public static Stream parameters() { + return Stream.of(RUN_TYPE.STANDARD_FROM_DRL); } - @Test // DROOLS-6336 - public void testGenerateAndSetInMemoryANC() { + // DROOLS-6336 + @ParameterizedTest(name = "{0}") + @MethodSource("parameters") + public void testGenerateAndSetInMemoryANC(RUN_TYPE testRunType) { final List results = new ArrayList<>(); - KieSession kSession = setupKieSession(); + KieSession kSession = setupKieSession(testRunType); KieBaseUpdaterANC.generateAndSetInMemoryANC(kSession.getKieBase()); assertResult(results, kSession); } - @Test // DROOLS-6336 - public void testGenerateAndSetInMemoryANCCalledTwice() { + // DROOLS-6336 + @ParameterizedTest(name = "{0}") + @MethodSource("parameters") + public void testGenerateAndSetInMemoryANCCalledTwice(RUN_TYPE testRunType) { final List results = new ArrayList<>(); - KieSession kSession = setupKieSession(); + KieSession kSession = setupKieSession(testRunType); KieBaseUpdaterANC.generateAndSetInMemoryANC(kSession.getKieBase()); KieBaseUpdaterANC.generateAndSetInMemoryANC(kSession.getKieBase()); assertResult(results, kSession); @@ -69,7 +65,7 @@ private void assertResult(List results, KieSession ksession) { assertThat(results).containsExactly(jamesBond); } - private KieSession setupKieSession() { + private KieSession setupKieSession(RUN_TYPE testRunType) { String str = "import " + Person.class.getCanonicalName() + ";" + "global java.util.List results;\n" + @@ -80,7 +76,7 @@ private KieSession setupKieSession() { " results.add($p);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(testRunType, str); return ksession; } } diff --git a/drools-alphanetwork-compiler/src/test/java/org/drools/ancompiler/BaseModelTest.java b/drools-alphanetwork-compiler/src/test/java/org/drools/ancompiler/BaseModelTest.java index a12810095f0..7407ad43947 100644 --- a/drools-alphanetwork-compiler/src/test/java/org/drools/ancompiler/BaseModelTest.java +++ b/drools-alphanetwork-compiler/src/test/java/org/drools/ancompiler/BaseModelTest.java @@ -21,6 +21,7 @@ import java.util.List; import java.util.UUID; import java.util.stream.Collectors; +import java.util.stream.Stream; import org.drools.compiler.kie.builder.impl.DrlProject; import org.drools.compiler.kie.builder.impl.InternalKieModule; @@ -28,9 +29,6 @@ import org.drools.core.reteoo.Rete; import org.drools.kiesession.rulebase.InternalKnowledgeBase; import org.drools.model.codegen.ExecutableModelProject; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; import org.kie.api.KieServices; import org.kie.api.builder.KieBuilder; import org.kie.api.builder.KieFileSystem; @@ -46,7 +44,6 @@ import static org.assertj.core.api.Assertions.fail; // Copied from org.drools.modelcompiler.BaseModelTest. To be removed after https://issues.redhat.com/browse/DROOLS-5485 -@RunWith(Parameterized.class) public abstract class BaseModelTest { public enum RUN_TYPE { PATTERN_DSL( false ), @@ -66,61 +63,59 @@ public boolean isAlphaNetworkCompiler() { } - final static Object[] WITH_ALPHA_NETWORK = { + final static RUN_TYPE[] WITH_ALPHA_NETWORK = { RUN_TYPE.STANDARD_FROM_DRL, RUN_TYPE.PATTERN_DSL, RUN_TYPE.STANDARD_WITH_ALPHA_NETWORK, RUN_TYPE.PATTERN_WITH_ALPHA_NETWORK, }; - @Parameters(name = "{0}") public static Object[] params() { return WITH_ALPHA_NETWORK; } - - protected final RUN_TYPE testRunType; - - public BaseModelTest(RUN_TYPE testRunType ) { - this.testRunType = testRunType; + + public static Stream parameters() { + return Stream.of(WITH_ALPHA_NETWORK); } - protected KieSession getKieSession(String... rules) { + + protected KieSession getKieSession(RUN_TYPE testRunType, String... rules) { KieModuleModel model = testRunType.isAlphaNetworkCompiler() ? getKieModuleModelWithAlphaNetworkCompiler() : null; - return getKieSession(model, rules); + return getKieSession(testRunType, model, rules); } - protected KieSession getKieSession(KieModuleModel model, String... stringRules) { - return getKieContainer( model, stringRules ).newKieSession(); + protected KieSession getKieSession(RUN_TYPE testRunType, KieModuleModel model, String... stringRules) { + return getKieContainer(testRunType, model, stringRules ).newKieSession(); } - protected KieContainer getKieContainer( String... stringRules ) { + protected KieContainer getKieContainer(RUN_TYPE testRunType, String... stringRules ) { KieModuleModel model = testRunType.isAlphaNetworkCompiler() ? getKieModuleModelWithAlphaNetworkCompiler() : null; - return getKieContainer( model, toKieFiles( stringRules ) ); + return getKieContainer(testRunType, model, toKieFiles( stringRules ) ); } - protected KieContainer getKieContainer( KieModuleModel model, String... stringRules ) { - return getKieContainer( model, toKieFiles( stringRules ) ); + protected KieContainer getKieContainer(RUN_TYPE testRunType, KieModuleModel model, String... stringRules ) { + return getKieContainer(testRunType, model, toKieFiles( stringRules ) ); } - protected KieContainer getKieContainer( KieModuleModel model, KieFile... stringRules ) { + protected KieContainer getKieContainer(RUN_TYPE testRunType, KieModuleModel model, KieFile... stringRules ) { KieServices ks = KieServices.get(); ReleaseId releaseId = ks.newReleaseId( "org.kie", "kjar-test-" + UUID.randomUUID(), "1.0" ); - KieBuilder kieBuilder = createKieBuilder( ks, model, releaseId, stringRules ); + KieBuilder kieBuilder = createKieBuilder(testRunType, ks, model, releaseId, stringRules ); return ks.newKieContainer( releaseId ); } - protected KieBuilder createKieBuilder( String... stringRules ) { + protected KieBuilder createKieBuilder(RUN_TYPE testRunType, String... stringRules ) { KieServices ks = KieServices.get(); ReleaseId releaseId = ks.newReleaseId( "org.kie", "kjar-test-" + UUID.randomUUID(), "1.0" ); - return createKieBuilder( ks, null, releaseId, false, toKieFiles( stringRules ) ); + return createKieBuilder(testRunType, ks, null, releaseId, false, toKieFiles( stringRules ) ); } - protected KieBuilder createKieBuilder( KieServices ks, KieModuleModel model, ReleaseId releaseId, KieFile... stringRules ) { - return createKieBuilder( ks, model, releaseId, true, stringRules ); + protected KieBuilder createKieBuilder(RUN_TYPE testRunType, KieServices ks, KieModuleModel model, ReleaseId releaseId, KieFile... stringRules ) { + return createKieBuilder(testRunType, ks, model, releaseId, true, stringRules ); } - protected KieBuilder createKieBuilder( KieServices ks, KieModuleModel model, ReleaseId releaseId, boolean failIfBuildError, KieFile... stringRules ) { + protected KieBuilder createKieBuilder(RUN_TYPE testRunType, KieServices ks, KieModuleModel model, ReleaseId releaseId, boolean failIfBuildError, KieFile... stringRules ) { ks.getRepository().removeKieModule( releaseId ); KieFileSystem kfs = ks.newKieFileSystem(); @@ -159,20 +154,20 @@ public static List getObjectsIntoList(KieSession ksession, Class clazz return ksession.getInstancesOf(clazz).stream().collect(Collectors.toList()); } - protected void createAndDeployJar( KieServices ks, ReleaseId releaseId, String... drls ) { - createAndDeployJar( ks, null, releaseId, drls ); + protected void createAndDeployJar(RUN_TYPE testRunType, KieServices ks, ReleaseId releaseId, String... drls ) { + createAndDeployJar(testRunType, ks, null, releaseId, drls ); } - protected void createAndDeployJar( KieServices ks, ReleaseId releaseId, KieFile... ruleFiles ) { - createAndDeployJar( ks, null, releaseId, ruleFiles ); + protected void createAndDeployJar(RUN_TYPE testRunType, KieServices ks, ReleaseId releaseId, KieFile... ruleFiles ) { + createAndDeployJar(testRunType, ks, null, releaseId, ruleFiles ); } - protected void createAndDeployJar( KieServices ks, KieModuleModel model, ReleaseId releaseId, String... drls ) { - createAndDeployJar( ks, model, releaseId, toKieFiles( drls ) ); + protected void createAndDeployJar(RUN_TYPE testRunType, KieServices ks, KieModuleModel model, ReleaseId releaseId, String... drls ) { + createAndDeployJar(testRunType, ks, model, releaseId, toKieFiles( drls ) ); } - protected void createAndDeployJar( KieServices ks, KieModuleModel model, ReleaseId releaseId, KieFile... ruleFiles ) { - KieBuilder kieBuilder = createKieBuilder( ks, model, releaseId, ruleFiles ); + protected void createAndDeployJar(RUN_TYPE testRunType, KieServices ks, KieModuleModel model, ReleaseId releaseId, KieFile... ruleFiles ) { + KieBuilder kieBuilder = createKieBuilder(testRunType, ks, model, releaseId, ruleFiles ); InternalKieModule kieModule = (InternalKieModule) kieBuilder.getKieModule(); ks.getRepository().addKieModule( kieModule ); } diff --git a/drools-alphanetwork-compiler/src/test/java/org/drools/ancompiler/LargeAlphaNetworkTest.java b/drools-alphanetwork-compiler/src/test/java/org/drools/ancompiler/LargeAlphaNetworkTest.java index ce1bb10992a..326891e966a 100644 --- a/drools-alphanetwork-compiler/src/test/java/org/drools/ancompiler/LargeAlphaNetworkTest.java +++ b/drools-alphanetwork-compiler/src/test/java/org/drools/ancompiler/LargeAlphaNetworkTest.java @@ -20,20 +20,18 @@ import java.util.ArrayList; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.runtime.KieSession; import static org.assertj.core.api.Assertions.assertThat; public class LargeAlphaNetworkTest extends BaseModelTest { - public LargeAlphaNetworkTest(RUN_TYPE testRunType) { - super(testRunType); - } - - @Test - public void testLargeCompiledAlphaNetwork() { + @ParameterizedTest(name = "{0}") + @MethodSource("parameters") + public void testLargeCompiledAlphaNetwork(RUN_TYPE testRunType) { final StringBuilder rule = new StringBuilder("global java.util.List results;\n" + "import " + Person.class.getCanonicalName() + ";\n"); @@ -43,7 +41,7 @@ public void testLargeCompiledAlphaNetwork() { rule.append(ruleWithIndex(i)); } - try (KieSession ksession = getKieSession(rule.toString())) { + try (KieSession ksession = getKieSession(testRunType, rule.toString())) { ArrayList results = new ArrayList<>(); ksession.setGlobal("results", results); Person a = new Person("a", 1); diff --git a/drools-alphanetwork-compiler/src/test/java/org/drools/ancompiler/MixedConstraintsTest.java b/drools-alphanetwork-compiler/src/test/java/org/drools/ancompiler/MixedConstraintsTest.java index ac6321acca5..26cce445d9f 100644 --- a/drools-alphanetwork-compiler/src/test/java/org/drools/ancompiler/MixedConstraintsTest.java +++ b/drools-alphanetwork-compiler/src/test/java/org/drools/ancompiler/MixedConstraintsTest.java @@ -20,23 +20,21 @@ import java.util.ArrayList; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.runtime.KieSession; import static org.assertj.core.api.Assertions.assertThat; public class MixedConstraintsTest extends BaseModelTest { - public MixedConstraintsTest(RUN_TYPE testRunType) { - super(testRunType); - } - // When we have the startsWith constraint before the indexed constraint age == index the compiled alpha network // generation is wrong see DROOLS-5948 - @Test - @Ignore - public void testMixedConstraints() { + @Disabled + @ParameterizedTest(name = "{0}") + @MethodSource("parameters") + public void testMixedConstraints(RUN_TYPE testRunType) { final StringBuilder rule = new StringBuilder("global java.util.List results;\n" + "import " + Person.class.getCanonicalName() + ";\n"); @@ -46,7 +44,7 @@ public void testMixedConstraints() { rule.append(ruleWithIndex(i)); } - try (KieSession ksession = getKieSession(rule.toString())) { + try (KieSession ksession = getKieSession(testRunType, rule.toString())) { ArrayList results = new ArrayList<>(); ksession.setGlobal("results", results); Person a = new Person("a", 1); diff --git a/drools-alphanetwork-compiler/src/test/java/org/drools/ancompiler/MultipleIndexableConstraintsTest.java b/drools-alphanetwork-compiler/src/test/java/org/drools/ancompiler/MultipleIndexableConstraintsTest.java index 431c4bce881..49c6e350b9e 100644 --- a/drools-alphanetwork-compiler/src/test/java/org/drools/ancompiler/MultipleIndexableConstraintsTest.java +++ b/drools-alphanetwork-compiler/src/test/java/org/drools/ancompiler/MultipleIndexableConstraintsTest.java @@ -20,22 +20,20 @@ import java.util.ArrayList; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.runtime.KieSession; import static org.assertj.core.api.Assertions.assertThat; public class MultipleIndexableConstraintsTest extends BaseModelTest { - public MultipleIndexableConstraintsTest(RUN_TYPE testRunType) { - super(testRunType); - } - /* Currently we don't support multiple indexable constraints in the ANC, so this test will pass because it disables the switch generation and the inlining. See DROOLS-5947 */ - @Test - public void testMultipleIndexedConstraintTest() { + @ParameterizedTest(name = "{0}") + @MethodSource("parameters") + public void testMultipleIndexedConstraintTest(RUN_TYPE testRunType) { final StringBuilder rule = new StringBuilder("global java.util.List results;\n" + "import " + Person.class.getCanonicalName() + ";\n"); @@ -45,7 +43,7 @@ public void testMultipleIndexedConstraintTest() { rule.append(ruleWithIndex(i)); } - try (KieSession ksession = getKieSession(rule.toString())) { + try (KieSession ksession = getKieSession(testRunType, rule.toString())) { ArrayList results = new ArrayList<>(); ksession.setGlobal("results", results); Person a = new Person("a", 1); diff --git a/drools-alphanetwork-compiler/src/test/java/org/drools/ancompiler/RangeIndexANCTest.java b/drools-alphanetwork-compiler/src/test/java/org/drools/ancompiler/RangeIndexANCTest.java index fe64111579f..cd33f39d09d 100644 --- a/drools-alphanetwork-compiler/src/test/java/org/drools/ancompiler/RangeIndexANCTest.java +++ b/drools-alphanetwork-compiler/src/test/java/org/drools/ancompiler/RangeIndexANCTest.java @@ -21,7 +21,8 @@ import java.util.ArrayList; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.KieBase; import org.kie.api.KieBaseConfiguration; import org.kie.api.KieServices; @@ -33,12 +34,9 @@ public class RangeIndexANCTest extends BaseModelTest { - public RangeIndexANCTest(RUN_TYPE testRunType) { - super(testRunType); - } - - @Test - public void testInteger() { + @ParameterizedTest(name = "{0}") + @MethodSource("parameters") + public void testInteger(RUN_TYPE testRunType) { final String drl = "package org.drools.compiler.test\n" + "import " + Person.class.getCanonicalName() + "\n" + @@ -52,7 +50,7 @@ public void testInteger() { " Person( age > 8 )\n" + "then\n end\n"; - final KieBase kbase = createKieBaseWithRangeIndexThresholdValue(drl, 3); + final KieBase kbase = createKieBaseWithRangeIndexThresholdValue(testRunType, drl, 3); final KieSession ksession = kbase.newKieSession(); ksession.insert(new Person("John", 18)); @@ -64,15 +62,16 @@ public void testInteger() { assertThat(fired).isEqualTo(2); } - private KieBase createKieBaseWithRangeIndexThresholdValue(String drl, int rangeIndexThresholdValue) { - final KieContainer kieContainer = getKieContainer(drl); + private KieBase createKieBaseWithRangeIndexThresholdValue(RUN_TYPE testRunType, String drl, int rangeIndexThresholdValue) { + final KieContainer kieContainer = getKieContainer(testRunType, drl); final KieBaseConfiguration kieBaseConfiguration = KieServices.get().newKieBaseConfiguration(); kieBaseConfiguration.setOption(AlphaRangeIndexThresholdOption.get(rangeIndexThresholdValue)); // for test convenience. Default value is AlphaRangeIndexThresholdOption.DEFAULT_VALUE return kieContainer.newKieBase(kieBaseConfiguration); } - @Test - public void testMixedRangeHashAndOther() { + @ParameterizedTest(name = "{0}") + @MethodSource("parameters") + public void testMixedRangeHashAndOther(RUN_TYPE testRunType) { final String drl = "package org.drools.compiler.test\n" + "import " + Person.class.getCanonicalName() + "\n" + "global java.util.List results;\n" + @@ -112,7 +111,7 @@ public void testMixedRangeHashAndOther() { " results.add(drools.getRule().getName());" + "end\n"; - final KieBase kbase = createKieBaseWithRangeIndexThresholdValue(drl, 3); + final KieBase kbase = createKieBaseWithRangeIndexThresholdValue(testRunType, drl, 3); final KieSession ksession = kbase.newKieSession(); List results = new ArrayList<>(); @@ -128,8 +127,9 @@ public void testMixedRangeHashAndOther() { assertThat(results).containsOnly("test1", "test3", "test4", "test7"); } - @Test - public void testChainRange() { + @ParameterizedTest(name = "{0}") + @MethodSource("parameters") + public void testChainRange(RUN_TYPE testRunType) { final String drl = "package com.sample\n" + "import " + Person.class.getCanonicalName() + "\n" + "global java.util.List results;\n" + @@ -164,7 +164,7 @@ public void testChainRange() { " results.add(drools.getRule().getName());" + "end"; - final KieBase kbase = createKieBaseWithRangeIndexThresholdValue(drl, 3); + final KieBase kbase = createKieBaseWithRangeIndexThresholdValue(testRunType, drl, 3); final KieSession ksession = kbase.newKieSession(); List results = new ArrayList<>(); @@ -181,8 +181,9 @@ public void testChainRange() { results.clear(); } - @Test - public void testRangeWithBeta() { + @ParameterizedTest(name = "{0}") + @MethodSource("parameters") + public void testRangeWithBeta(RUN_TYPE testRunType) { final String drl = "package com.sample\n" + "import " + Person.class.getCanonicalName() + "\n" + "global java.util.List results;\n" + @@ -214,7 +215,7 @@ public void testRangeWithBeta() { " results.add(drools.getRule().getName());" + "end"; - final KieBase kbase = createKieBaseWithRangeIndexThresholdValue(drl, 3); + final KieBase kbase = createKieBaseWithRangeIndexThresholdValue(testRunType, drl, 3); final KieSession ksession = kbase.newKieSession(); List results = new ArrayList<>(); diff --git a/drools-core/pom.xml b/drools-core/pom.xml index 098b30fa9ab..f97f1681d1d 100644 --- a/drools-core/pom.xml +++ b/drools-core/pom.xml @@ -136,10 +136,10 @@ - junit - junit + org.junit.jupiter + junit-jupiter test - + org.assertj assertj-core diff --git a/drools-core/src/test/java/org/drools/core/base/ClassTypeResolverTest.java b/drools-core/src/test/java/org/drools/core/base/ClassTypeResolverTest.java index 55cfd83dc62..e49599985f6 100644 --- a/drools-core/src/test/java/org/drools/core/base/ClassTypeResolverTest.java +++ b/drools-core/src/test/java/org/drools/core/base/ClassTypeResolverTest.java @@ -25,7 +25,7 @@ import org.drools.core.test.model.SecondClass; import org.drools.util.ClassTypeResolver; import org.drools.util.TypeResolver; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; diff --git a/drools-core/src/test/java/org/drools/core/base/ValueTypeTest.java b/drools-core/src/test/java/org/drools/core/base/ValueTypeTest.java index f40d67e35b8..93214e55311 100755 --- a/drools-core/src/test/java/org/drools/core/base/ValueTypeTest.java +++ b/drools-core/src/test/java/org/drools/core/base/ValueTypeTest.java @@ -19,7 +19,7 @@ package org.drools.core.base; import org.drools.base.base.ValueType; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/drools-core/src/test/java/org/drools/core/base/accumulators/VarianceNaNTest.java b/drools-core/src/test/java/org/drools/core/base/accumulators/VarianceNaNTest.java index a17cb635787..23624d15ff3 100644 --- a/drools-core/src/test/java/org/drools/core/base/accumulators/VarianceNaNTest.java +++ b/drools-core/src/test/java/org/drools/core/base/accumulators/VarianceNaNTest.java @@ -19,7 +19,7 @@ package org.drools.core.base.accumulators; import org.drools.core.base.accumulators.VarianceAccumulateFunction.VarianceData; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.within; diff --git a/drools-core/src/test/java/org/drools/core/base/evaluators/TimeIntervalParserTest.java b/drools-core/src/test/java/org/drools/core/base/evaluators/TimeIntervalParserTest.java index c4a79c1d8ff..eaf46b7555f 100644 --- a/drools-core/src/test/java/org/drools/core/base/evaluators/TimeIntervalParserTest.java +++ b/drools-core/src/test/java/org/drools/core/base/evaluators/TimeIntervalParserTest.java @@ -19,7 +19,7 @@ package org.drools.core.base.evaluators; import org.drools.base.util.TimeIntervalParser; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/drools-core/src/test/java/org/drools/core/common/ClassAwareObjectStoreTest.java b/drools-core/src/test/java/org/drools/core/common/ClassAwareObjectStoreTest.java index 16fa5b0cfc1..6d8d618304a 100644 --- a/drools-core/src/test/java/org/drools/core/common/ClassAwareObjectStoreTest.java +++ b/drools-core/src/test/java/org/drools/core/common/ClassAwareObjectStoreTest.java @@ -26,46 +26,49 @@ import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.locks.ReentrantLock; +import java.util.stream.Stream; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import static org.assertj.core.api.Assertions.assertThat; -@RunWith(Parameterized.class) public class ClassAwareObjectStoreTest { - private final ClassAwareObjectStore underTest; - @Test - public void iterateObjectsReturnsObjectsOfAllTypes() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void iterateObjectsReturnsObjectsOfAllTypes(ClassAwareObjectStore underTest) throws Exception { String aStringValue = "a string"; BigDecimal bigDecimalValue = new BigDecimal("1"); - insertObjectWithFactHandle(aStringValue); - insertObjectWithFactHandle(bigDecimalValue); + underTest.addHandle(handleFor(aStringValue), aStringValue); + underTest.addHandle(handleFor(bigDecimalValue), bigDecimalValue); Collection result = collect(underTest.iterateObjects()); assertThat(result).hasSize(2); } - @Test - public void iterateByClassFiltersByClass() { + @ParameterizedTest + @MethodSource("parameters") + public void iterateByClassFiltersByClass(ClassAwareObjectStore underTest) { SimpleClass object = new SimpleClass(); - insertObjectWithFactHandle("some string"); - insertObjectWithFactHandle(object); + underTest.addHandle(handleFor("some string"), "some string"); + underTest.addHandle(handleFor(object), object); Collection results = collect(underTest.iterateObjects(SimpleClass.class)); assertThat(results).hasSize(1); assertThat(results).contains(object); } - @Test - public void queryBySuperTypeFindsSubType() throws Exception { - insertObjectWithFactHandle(new SubClass()); - insertObjectWithFactHandle(new SuperClass()); + @ParameterizedTest + @MethodSource("parameters") + public void queryBySuperTypeFindsSubType(ClassAwareObjectStore underTest) throws Exception { + Object objectToInsert = new SubClass(); + underTest.addHandle(handleFor(objectToInsert), objectToInsert); + Object objectToInsert1 = new SuperClass(); + underTest.addHandle(handleFor(objectToInsert1), objectToInsert1); Collection result = collect(underTest.iterateObjects(SuperClass.class)); @@ -74,10 +77,13 @@ public void queryBySuperTypeFindsSubType() throws Exception { assertThat(result).hasAtLeastOneElementOfType(SuperClass.class); } - @Test - public void queryBySubtypeDoesNotReturnSuperType() throws Exception { - insertObjectWithFactHandle(new SubClass()); - insertObjectWithFactHandle(new SuperClass()); + @ParameterizedTest + @MethodSource("parameters") + public void queryBySubtypeDoesNotReturnSuperType(ClassAwareObjectStore underTest) throws Exception { + Object objectToInsert = new SubClass(); + underTest.addHandle(handleFor(objectToInsert), objectToInsert); + Object objectToInsert1 = new SuperClass(); + underTest.addHandle(handleFor(objectToInsert1), objectToInsert1); Collection result = collect(underTest.iterateObjects(SubClass.class)); @@ -88,11 +94,14 @@ public void queryBySubtypeDoesNotReturnSuperType() throws Exception { /** * Should have identical results to {@link #queryBySuperTypeFindsSubType()} */ - @Test - public void queryBySubTypeDoesNotPreventInsertionsBeingPropogatedToSuperTypeQueries() throws Exception { - insertObjectWithFactHandle(new SuperClass()); + @ParameterizedTest + @MethodSource("parameters") + public void queryBySubTypeDoesNotPreventInsertionsBeingPropogatedToSuperTypeQueries(ClassAwareObjectStore underTest) throws Exception { + Object objectToInsert = new SuperClass(); + underTest.addHandle(handleFor(objectToInsert), objectToInsert); collect(underTest.iterateObjects(SubClass.class)); - insertObjectWithFactHandle(new SubClass()); + Object objectToInsert1 = new SubClass(); + underTest.addHandle(handleFor(objectToInsert1), objectToInsert1); Collection result = collect(underTest.iterateObjects(SuperClass.class)); @@ -101,9 +110,11 @@ public void queryBySubTypeDoesNotPreventInsertionsBeingPropogatedToSuperTypeQuer assertThat(result).hasAtLeastOneElementOfType(SuperClass.class); } - @Test - public void queryBySuperTypeCanFindSubTypeWhenNoSuperTypeInstancesAreInStore() throws Exception { - insertObjectWithFactHandle(new SubClass()); + @ParameterizedTest + @MethodSource("parameters") + public void queryBySuperTypeCanFindSubTypeWhenNoSuperTypeInstancesAreInStore(ClassAwareObjectStore underTest) throws Exception { + Object objectToInsert = new SubClass(); + underTest.addHandle(handleFor(objectToInsert), objectToInsert); Collection result = collect(underTest.iterateObjects(SuperClass.class)); @@ -111,10 +122,13 @@ public void queryBySuperTypeCanFindSubTypeWhenNoSuperTypeInstancesAreInStore() t assertThat(result).hasAtLeastOneElementOfType(SubClass.class); } - @Test - public void isOkayToReinsertSameTypeThenQuery() throws Exception { - insertObjectWithFactHandle(new SubClass()); - insertObjectWithFactHandle(new SubClass()); + @ParameterizedTest + @MethodSource("parameters") + public void isOkayToReinsertSameTypeThenQuery(ClassAwareObjectStore underTest) throws Exception { + Object objectToInsert = new SubClass(); + underTest.addHandle(handleFor(objectToInsert), objectToInsert); + Object objectToInsert1 = new SubClass(); + underTest.addHandle(handleFor(objectToInsert1), objectToInsert1); Collection result = collect(underTest.iterateObjects(SuperClass.class)); @@ -124,12 +138,15 @@ public void isOkayToReinsertSameTypeThenQuery() throws Exception { assertThat(new HashSet(result)).hasSize(2); } - @Test - public void onceSuperClassIsSetUpForReadingItCanBecomeSetUpForWritingWithoutGettingDuplicateQueryReturns() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void onceSuperClassIsSetUpForReadingItCanBecomeSetUpForWritingWithoutGettingDuplicateQueryReturns(ClassAwareObjectStore underTest) throws Exception { assertThat(collect(underTest.iterateObjects(SuperClass.class)).isEmpty()).isTrue(); + Object objectToInsert = new SubClass(); - insertObjectWithFactHandle(new SubClass()); - insertObjectWithFactHandle(new SuperClass()); + underTest.addHandle(handleFor(objectToInsert), objectToInsert); + Object objectToInsert1 = new SuperClass(); + underTest.addHandle(handleFor(objectToInsert1), objectToInsert1); Collection result = collect(underTest.iterateObjects(SuperClass.class)); @@ -139,9 +156,11 @@ public void onceSuperClassIsSetUpForReadingItCanBecomeSetUpForWritingWithoutGett assertThat(new HashSet(result)).hasSize(2); } - @Test - public void clearRemovesInsertedObjects() throws Exception { - insertObjectWithFactHandle(new SimpleClass()); + @ParameterizedTest + @MethodSource("parameters") + public void clearRemovesInsertedObjects(ClassAwareObjectStore underTest) throws Exception { + Object objectToInsert = new SimpleClass(); + underTest.addHandle(handleFor(objectToInsert), objectToInsert); assertThat(collect(underTest.iterateObjects())).hasSize(1); underTest.clear(); @@ -149,10 +168,13 @@ public void clearRemovesInsertedObjects() throws Exception { assertThat(collect(underTest.iterateObjects())).hasSize(0); } - @Test - public void canIterateOverObjectsUsingCustomFilter() throws Exception { - insertObjectWithFactHandle(new SuperClass()); - insertObjectWithFactHandle(new SubClass()); + @ParameterizedTest + @MethodSource("parameters") + public void canIterateOverObjectsUsingCustomFilter(ClassAwareObjectStore underTest) throws Exception { + Object objectToInsert = new SuperClass(); + underTest.addHandle(handleFor(objectToInsert), objectToInsert); + Object objectToInsert1 = new SubClass(); + underTest.addHandle(handleFor(objectToInsert1), objectToInsert1); Collection result = collect(underTest.iterateObjects(SubClass.class::isInstance)); @@ -160,24 +182,19 @@ public void canIterateOverObjectsUsingCustomFilter() throws Exception { assertThat(result).hasAtLeastOneElementOfType(SubClass.class); } - @Test - public void iteratingOverFactHandlesHasSameNumberOfResultsAsIteratingOverObjects() throws Exception { - insertObjectWithFactHandle(new SuperClass()); - insertObjectWithFactHandle(new SubClass()); + @ParameterizedTest + @MethodSource("parameters") + public void iteratingOverFactHandlesHasSameNumberOfResultsAsIteratingOverObjects(ClassAwareObjectStore underTest) throws Exception { + Object objectToInsert = new SuperClass(); + underTest.addHandle(handleFor(objectToInsert), objectToInsert); + Object objectToInsert1 = new SubClass(); + underTest.addHandle(handleFor(objectToInsert1), objectToInsert1); assertThat(collect(underTest.iterateFactHandles(SubClass.class))).hasSize(1); assertThat(collect(underTest.iterateFactHandles(SuperClass.class))).hasSize(2); } - private void insertObjectWithFactHandle(Object objectToInsert) { - underTest.addHandle(handleFor(objectToInsert), objectToInsert); - } - - public ClassAwareObjectStore getUnderTest() { - return underTest; - } - private static Collection collect(Iterator objects) { List result = new ArrayList(); while (objects.hasNext()) { @@ -185,17 +202,10 @@ private static Collection collect(Iterator objects) { } return result; } - - public ClassAwareObjectStoreTest(boolean isEqualityBehaviour) { - underTest = new ClassAwareObjectStore(isEqualityBehaviour, new ReentrantLock()); - } - - @Parameterized.Parameters - public static Collection ruleBaseConfigurations() { - List configurations = new ArrayList(2); - configurations.add(new Object[]{true}); - configurations.add(new Object[]{false}); - return configurations; + + public static Stream parameters() { + return Stream.of(new ClassAwareObjectStore(true, new ReentrantLock()), + new ClassAwareObjectStore(false, new ReentrantLock())); } private static final AtomicInteger factCounter = new AtomicInteger(0); diff --git a/drools-core/src/test/java/org/drools/core/common/DroolsObjectIOTest.java b/drools-core/src/test/java/org/drools/core/common/DroolsObjectIOTest.java index b396ff02dcf..55a4306b6f1 100644 --- a/drools-core/src/test/java/org/drools/core/common/DroolsObjectIOTest.java +++ b/drools-core/src/test/java/org/drools/core/common/DroolsObjectIOTest.java @@ -39,7 +39,7 @@ import org.drools.base.rule.GroupElement; import org.drools.core.reteoo.CoreComponentFactory; import org.drools.core.util.DroolsStreamUtils; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/drools-core/src/test/java/org/drools/core/impl/KnowledgeBaseImplTest.java b/drools-core/src/test/java/org/drools/core/impl/KnowledgeBaseImplTest.java index da961ccf59a..691fd782281 100644 --- a/drools-core/src/test/java/org/drools/core/impl/KnowledgeBaseImplTest.java +++ b/drools-core/src/test/java/org/drools/core/impl/KnowledgeBaseImplTest.java @@ -22,7 +22,7 @@ import org.drools.base.definitions.InternalKnowledgePackage; import org.drools.core.reteoo.CoreComponentFactory; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.kie.internal.conf.CompositeBaseConfiguration; import static org.assertj.core.api.Assertions.assertThat; diff --git a/drools-core/src/test/java/org/drools/core/io/impl/ByteArrayResourceSerializationTest.java b/drools-core/src/test/java/org/drools/core/io/impl/ByteArrayResourceSerializationTest.java index 1d26ecd2f01..dee1ec86caa 100644 --- a/drools-core/src/test/java/org/drools/core/io/impl/ByteArrayResourceSerializationTest.java +++ b/drools-core/src/test/java/org/drools/core/io/impl/ByteArrayResourceSerializationTest.java @@ -26,7 +26,7 @@ import java.nio.charset.StandardCharsets; import org.drools.io.ByteArrayResource; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/drools-core/src/test/java/org/drools/core/io/impl/ByteArrayResourceToStringTest.java b/drools-core/src/test/java/org/drools/core/io/impl/ByteArrayResourceToStringTest.java index 2bb1143a0ad..adde0442cff 100644 --- a/drools-core/src/test/java/org/drools/core/io/impl/ByteArrayResourceToStringTest.java +++ b/drools-core/src/test/java/org/drools/core/io/impl/ByteArrayResourceToStringTest.java @@ -18,62 +18,53 @@ */ package org.drools.core.io.impl; -import java.util.ArrayList; import java.util.Arrays; -import java.util.Collection; import java.util.List; +import java.util.stream.Stream; import org.apache.commons.lang3.ArrayUtils; import org.drools.io.ByteArrayResource; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.params.provider.Arguments.arguments; -@RunWith(Parameterized.class) public class ByteArrayResourceToStringTest { - @Parameterized.Parameters(name = "{index}: bytes={0}, encoding={1}") - public static Collection data() { - return new ArrayList(Arrays.asList(new Object[][]{ - { + public static Stream parameters() { + List parameters = List.of( + arguments( Arrays.asList(new Byte[]{10, 20, 30, 40}), null, "ByteArrayResource[bytes=[10, 20, 30, 40], encoding=null]" - }, - { + ), + arguments( Arrays.asList(new Byte[]{10, 20, 30, 40, 50, 60, 70, 80, 90, 100}), null, "ByteArrayResource[bytes=[10, 20, 30, 40, 50, 60, 70, 80, 90, 100], encoding=null]" - }, - { + ), + arguments( Arrays.asList(new Byte[]{10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120}), null, "ByteArrayResource[bytes=[10, 20, 30, 40, 50, 60, 70, 80, 90, 100, ...], encoding=null]" - }, + ), // non-null encoding - { + arguments( Arrays.asList(new Byte[]{10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120}), "UTF-8", "ByteArrayResource[bytes=[10, 20, 30, 40, 50, 60, 70, 80, 90, 100, ...], encoding=UTF-8]" - }, - })); + )); + return parameters.stream(); } // using List instead of directly byte[] to make sure the bytes are printed as part of the test name // see above ({index}: bytes[{0}], encoding[{1}]) -- Array.toString only return object id - @Parameterized.Parameter(0) - public List bytes; - @Parameterized.Parameter(1) - public String encoding; - - @Parameterized.Parameter(2) - public String expectedString; - - @Test - public void testToString() { + @ParameterizedTest(name = "{index}: bytes={0}, encoding={1}") + @MethodSource("parameters") + public void testToString(List bytes, String encoding, String expectedString) { byte[] byteArray = ArrayUtils.toPrimitive(bytes.toArray(new Byte[0])); ByteArrayResource byteArrayResource = new ByteArrayResource(byteArray, encoding); assertThat(byteArrayResource.toString()).isEqualTo(expectedString); diff --git a/drools-core/src/test/java/org/drools/core/io/impl/ReaderResourceTest.java b/drools-core/src/test/java/org/drools/core/io/impl/ReaderResourceTest.java index 976c0947df0..8ffcf52fdfd 100644 --- a/drools-core/src/test/java/org/drools/core/io/impl/ReaderResourceTest.java +++ b/drools-core/src/test/java/org/drools/core/io/impl/ReaderResourceTest.java @@ -25,7 +25,7 @@ import java.nio.charset.Charset; import org.drools.io.ReaderResource; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/drools-core/src/test/java/org/drools/core/reteoo/BaseNodeTest.java b/drools-core/src/test/java/org/drools/core/reteoo/BaseNodeTest.java index dabc5b72d8b..c29bd76c5d9 100644 --- a/drools-core/src/test/java/org/drools/core/reteoo/BaseNodeTest.java +++ b/drools-core/src/test/java/org/drools/core/reteoo/BaseNodeTest.java @@ -24,7 +24,7 @@ import org.drools.core.common.PropagationContext; import org.drools.core.common.UpdateContext; import org.drools.core.reteoo.builder.BuildContext; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/drools-core/src/test/java/org/drools/core/reteoo/BetaNodeTest.java b/drools-core/src/test/java/org/drools/core/reteoo/BetaNodeTest.java index f416955594e..6623a2184e4 100755 --- a/drools-core/src/test/java/org/drools/core/reteoo/BetaNodeTest.java +++ b/drools-core/src/test/java/org/drools/core/reteoo/BetaNodeTest.java @@ -24,7 +24,7 @@ import org.drools.core.impl.InternalRuleBase; import org.drools.core.impl.RuleBaseFactory; import org.drools.core.reteoo.builder.BuildContext; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/drools-core/src/test/java/org/drools/core/reteoo/DefaultFactHandleFactoryTest.java b/drools-core/src/test/java/org/drools/core/reteoo/DefaultFactHandleFactoryTest.java index 9344e08a906..e0f6c40f1c3 100644 --- a/drools-core/src/test/java/org/drools/core/reteoo/DefaultFactHandleFactoryTest.java +++ b/drools-core/src/test/java/org/drools/core/reteoo/DefaultFactHandleFactoryTest.java @@ -19,7 +19,7 @@ package org.drools.core.reteoo; import org.drools.core.common.DefaultFactHandle; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/drools-core/src/test/java/org/drools/core/reteoo/FactHandleTest.java b/drools-core/src/test/java/org/drools/core/reteoo/FactHandleTest.java index a2fae1cadfd..8069df27261 100644 --- a/drools-core/src/test/java/org/drools/core/reteoo/FactHandleTest.java +++ b/drools-core/src/test/java/org/drools/core/reteoo/FactHandleTest.java @@ -20,7 +20,7 @@ import org.drools.core.common.DefaultFactHandle; import org.drools.core.common.DisconnectedFactHandle; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/drools-core/src/test/java/org/drools/core/reteoo/MockLeftTupleSink.java b/drools-core/src/test/java/org/drools/core/reteoo/MockLeftTupleSink.java index c086a27578e..c84d574d6dd 100644 --- a/drools-core/src/test/java/org/drools/core/reteoo/MockLeftTupleSink.java +++ b/drools-core/src/test/java/org/drools/core/reteoo/MockLeftTupleSink.java @@ -23,10 +23,8 @@ import org.drools.base.reteoo.NodeTypeEnums; import org.drools.core.RuleBaseConfiguration; -import org.drools.core.common.InternalFactHandle; import org.drools.core.common.Memory; import org.drools.core.common.MemoryFactory; -import org.drools.core.common.PropagationContext; import org.drools.core.common.ReteEvaluator; import org.drools.core.common.UpdateContext; import org.drools.core.reteoo.builder.BuildContext; diff --git a/drools-core/src/test/java/org/drools/core/reteoo/NodeTypeEnumTest.java b/drools-core/src/test/java/org/drools/core/reteoo/NodeTypeEnumTest.java index 719e49f436c..26c524a37db 100644 --- a/drools-core/src/test/java/org/drools/core/reteoo/NodeTypeEnumTest.java +++ b/drools-core/src/test/java/org/drools/core/reteoo/NodeTypeEnumTest.java @@ -18,7 +18,7 @@ */ package org.drools.core.reteoo; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.drools.base.reteoo.NodeTypeEnums.isBetaNode; diff --git a/drools-core/src/test/java/org/drools/core/reteoo/ObjectSourceTest.java b/drools-core/src/test/java/org/drools/core/reteoo/ObjectSourceTest.java index 5839b12a0fd..23b41c6cbf0 100644 --- a/drools-core/src/test/java/org/drools/core/reteoo/ObjectSourceTest.java +++ b/drools-core/src/test/java/org/drools/core/reteoo/ObjectSourceTest.java @@ -20,7 +20,7 @@ import java.lang.reflect.Field; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/drools-core/src/test/java/org/drools/core/reteoo/ObjectTypeConfTest.java b/drools-core/src/test/java/org/drools/core/reteoo/ObjectTypeConfTest.java index 12bf7384ea7..1cae9c18aa0 100644 --- a/drools-core/src/test/java/org/drools/core/reteoo/ObjectTypeConfTest.java +++ b/drools-core/src/test/java/org/drools/core/reteoo/ObjectTypeConfTest.java @@ -18,8 +18,7 @@ */ package org.drools.core.reteoo; - -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/drools-core/src/test/java/org/drools/core/reteoo/TupleIterationTest.java b/drools-core/src/test/java/org/drools/core/reteoo/TupleIterationTest.java index 4142f3b2672..a0dc9e6176c 100644 --- a/drools-core/src/test/java/org/drools/core/reteoo/TupleIterationTest.java +++ b/drools-core/src/test/java/org/drools/core/reteoo/TupleIterationTest.java @@ -24,13 +24,13 @@ import org.drools.core.common.PropagationContext; import org.drools.core.reteoo.TupleIterator.OnLeaf; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; - public class TupleIterationTest { - @Test + + @Test public void testRootTraversal() { LeftTuple t0 = new LeftTuple(); LeftTuple t1 = new LeftTuple(t0, null, (PropagationContext) null, true); diff --git a/drools-core/src/test/java/org/drools/core/reteoo/TupleSourceTest.java b/drools-core/src/test/java/org/drools/core/reteoo/TupleSourceTest.java index acfdf31990b..9319bc87e32 100644 --- a/drools-core/src/test/java/org/drools/core/reteoo/TupleSourceTest.java +++ b/drools-core/src/test/java/org/drools/core/reteoo/TupleSourceTest.java @@ -24,7 +24,7 @@ import org.drools.core.impl.InternalRuleBase; import org.drools.core.impl.RuleBaseFactory; import org.drools.core.reteoo.builder.BuildContext; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.kie.api.KieBaseConfiguration; import static org.assertj.core.api.Assertions.assertThat; diff --git a/drools-core/src/test/java/org/drools/core/reteoo/builder/ReteooRuleBuilderTest.java b/drools-core/src/test/java/org/drools/core/reteoo/builder/ReteooRuleBuilderTest.java index 9a670077dc8..f6ce4a540fa 100755 --- a/drools-core/src/test/java/org/drools/core/reteoo/builder/ReteooRuleBuilderTest.java +++ b/drools-core/src/test/java/org/drools/core/reteoo/builder/ReteooRuleBuilderTest.java @@ -35,8 +35,8 @@ import org.drools.core.impl.RuleBaseFactory; import org.drools.core.reteoo.RuleTerminalNode; import org.drools.core.rule.consequence.KnowledgeHelper; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.kie.internal.conf.CompositeBaseConfiguration; import static org.assertj.core.api.Assertions.assertThat; @@ -48,7 +48,7 @@ public class ReteooRuleBuilderTest { /* (non-Javadoc) * @see junit.framework.TestCase#setUp() */ - @Before + @BeforeEach public void setUp() throws Exception { this.builder = new ReteooRuleBuilder(); rulebase = new KnowledgeBaseImpl("default", (CompositeBaseConfiguration) RuleBaseFactory.newKnowledgeBaseConfiguration()); diff --git a/drools-core/src/test/java/org/drools/core/time/TemporalDistanceTest.java b/drools-core/src/test/java/org/drools/core/time/TemporalDistanceTest.java index 8ec95a3e9a5..b3ae6f6e221 100644 --- a/drools-core/src/test/java/org/drools/core/time/TemporalDistanceTest.java +++ b/drools-core/src/test/java/org/drools/core/time/TemporalDistanceTest.java @@ -20,7 +20,7 @@ import org.drools.base.time.Interval; import org.drools.base.time.TimeUtils; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/drools-core/src/test/java/org/drools/core/time/impl/CompositeMaxDurationTimerTest.java b/drools-core/src/test/java/org/drools/core/time/impl/CompositeMaxDurationTimerTest.java index e8e44f66469..0066656619b 100644 --- a/drools-core/src/test/java/org/drools/core/time/impl/CompositeMaxDurationTimerTest.java +++ b/drools-core/src/test/java/org/drools/core/time/impl/CompositeMaxDurationTimerTest.java @@ -21,7 +21,7 @@ import java.util.Date; import org.drools.base.time.Trigger; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/drools-core/src/test/java/org/drools/core/time/impl/CronExpressionTest.java b/drools-core/src/test/java/org/drools/core/time/impl/CronExpressionTest.java index f4dd05968ce..4d7adc60ca8 100644 --- a/drools-core/src/test/java/org/drools/core/time/impl/CronExpressionTest.java +++ b/drools-core/src/test/java/org/drools/core/time/impl/CronExpressionTest.java @@ -27,8 +27,8 @@ import java.util.Date; import java.util.TimeZone; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; @@ -183,7 +183,8 @@ public void testQuartz640() throws ParseException { } } - @Test @Ignore + @Test + @Disabled public void testSerialization() { // TODO as we don't want to worry about this for now } diff --git a/drools-core/src/test/java/org/drools/core/time/impl/CronJobTest.java b/drools-core/src/test/java/org/drools/core/time/impl/CronJobTest.java index 530c8f19d83..0f6cb7d5687 100644 --- a/drools-core/src/test/java/org/drools/core/time/impl/CronJobTest.java +++ b/drools-core/src/test/java/org/drools/core/time/impl/CronJobTest.java @@ -25,11 +25,12 @@ import org.drools.core.impl.RuleBaseFactory; import org.drools.core.time.impl.JDKTimerServiceTest.HelloWorldJob; import org.drools.core.time.impl.JDKTimerServiceTest.HelloWorldJobContext; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; public class CronJobTest { + @Test public void testCronTriggerJob() throws Exception { SessionConfiguration config = RuleBaseFactory.newKnowledgeSessionConfiguration().as(SessionConfiguration.KEY); diff --git a/drools-core/src/test/java/org/drools/core/time/impl/JDKTimerServiceTest.java b/drools-core/src/test/java/org/drools/core/time/impl/JDKTimerServiceTest.java index 66854a69c2a..ac38fe59322 100644 --- a/drools-core/src/test/java/org/drools/core/time/impl/JDKTimerServiceTest.java +++ b/drools-core/src/test/java/org/drools/core/time/impl/JDKTimerServiceTest.java @@ -40,7 +40,7 @@ import org.drools.core.time.Job; import org.drools.core.time.JobContext; import org.drools.core.time.TimerService; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/drools-core/src/test/java/org/drools/core/time/impl/PseudoClockSchedulerTest.java b/drools-core/src/test/java/org/drools/core/time/impl/PseudoClockSchedulerTest.java index 4295f434578..f0ec5b022e5 100644 --- a/drools-core/src/test/java/org/drools/core/time/impl/PseudoClockSchedulerTest.java +++ b/drools-core/src/test/java/org/drools/core/time/impl/PseudoClockSchedulerTest.java @@ -26,7 +26,7 @@ import org.drools.base.time.Trigger; import org.drools.core.time.Job; import org.drools.core.time.JobContext; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.atLeast; @@ -48,7 +48,8 @@ public class PseudoClockSchedulerTest { private PseudoClockScheduler scheduler = new PseudoClockScheduler(); - @Test public void removeExistingJob() { + @Test + public void removeExistingJob() { final Date triggerTime = new Date(1000); when( mockTrigger_1.hasNextFireTime() ).thenReturn(triggerTime); @@ -62,7 +63,8 @@ public class PseudoClockSchedulerTest { } - @Test public void removeExistingJobWhenMultipleQueued() { + @Test + public void removeExistingJobWhenMultipleQueued() { final Date triggerTime_1 = new Date(1000); final Date triggerTime_2 = new Date(2000); when( mockTrigger_1.hasNextFireTime() ).thenReturn(triggerTime_1); @@ -82,7 +84,8 @@ public class PseudoClockSchedulerTest { verify( mockTrigger_2, atLeastOnce()).hasNextFireTime(); } - @Test public void timerIsSetToJobTriggerTimeForExecution() { + @Test + public void timerIsSetToJobTriggerTimeForExecution() { final Date triggerTime = new Date(1000); when( mockTrigger_1.hasNextFireTime() ).thenReturn(triggerTime, triggerTime, triggerTime, null); when( mockTrigger_1.nextFireTime() ).thenReturn(triggerTime); @@ -107,7 +110,8 @@ public void execute(JobContext ctx) { verify( mockTrigger_1, times(1) ).nextFireTime(); } - @Test public void timerIsResetWhenJobThrowsExceptions() { + @Test + public void timerIsResetWhenJobThrowsExceptions() { final Date triggerTime = new Date(1000); when( mockTrigger_1.hasNextFireTime() ).thenReturn(triggerTime, triggerTime, triggerTime, null); when( mockTrigger_1.nextFireTime() ).thenReturn(triggerTime); diff --git a/drools-core/src/test/java/org/drools/core/time/impl/Quartz601Test.java b/drools-core/src/test/java/org/drools/core/time/impl/Quartz601Test.java index 344f29e3e83..5206f94d427 100644 --- a/drools-core/src/test/java/org/drools/core/time/impl/Quartz601Test.java +++ b/drools-core/src/test/java/org/drools/core/time/impl/Quartz601Test.java @@ -21,7 +21,7 @@ import java.text.ParseException; import java.util.Set; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.fail; diff --git a/drools-core/src/test/java/org/drools/core/time/impl/SerializationTestSupport.java b/drools-core/src/test/java/org/drools/core/time/impl/SerializationTestSupport.java index eb41e46bf1f..426ff2be46c 100644 --- a/drools-core/src/test/java/org/drools/core/time/impl/SerializationTestSupport.java +++ b/drools-core/src/test/java/org/drools/core/time/impl/SerializationTestSupport.java @@ -23,7 +23,7 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Base class for unit tests that wish to verify diff --git a/drools-core/src/test/java/org/drools/core/util/BinaryHeapPriorityQueueTest.java b/drools-core/src/test/java/org/drools/core/util/BinaryHeapPriorityQueueTest.java index 4eb1d745356..a4a743bff91 100644 --- a/drools-core/src/test/java/org/drools/core/util/BinaryHeapPriorityQueueTest.java +++ b/drools-core/src/test/java/org/drools/core/util/BinaryHeapPriorityQueueTest.java @@ -24,9 +24,10 @@ import java.util.Random; import org.drools.core.util.Queue.QueueEntry; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class BinaryHeapPriorityQueueTest { + @Test public void testOptimised() { final Random random = new Random(); diff --git a/drools-core/src/test/java/org/drools/core/util/BinaryHeapQueueTest.java b/drools-core/src/test/java/org/drools/core/util/BinaryHeapQueueTest.java index 471a6ba5c14..14bf362c58c 100644 --- a/drools-core/src/test/java/org/drools/core/util/BinaryHeapQueueTest.java +++ b/drools-core/src/test/java/org/drools/core/util/BinaryHeapQueueTest.java @@ -33,11 +33,10 @@ import org.drools.core.common.PropagationContext; import org.drools.core.phreak.RuleAgendaItem; import org.drools.core.reteoo.TerminalNode; -import org.drools.core.reteoo.Tuple; import org.drools.core.reteoo.TupleImpl; import org.drools.core.rule.consequence.InternalMatch; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.kie.api.runtime.rule.FactHandle; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; @@ -115,7 +114,7 @@ public void testShuffled() { System.out.println("time:" + (System.currentTimeMillis() - time)); } - @Before + @BeforeEach public void setup() { System.out.println( "Running setup" ); Integer[] a = new Integer[max]; diff --git a/drools-core/src/test/java/org/drools/core/util/ClassUtilsTest.java b/drools-core/src/test/java/org/drools/core/util/ClassUtilsTest.java index 7339f04d88d..bd2bf40593b 100644 --- a/drools-core/src/test/java/org/drools/core/util/ClassUtilsTest.java +++ b/drools-core/src/test/java/org/drools/core/util/ClassUtilsTest.java @@ -19,7 +19,7 @@ package org.drools.core.util; import org.drools.util.ClassUtils; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/drools-core/src/test/java/org/drools/core/util/IndexedHashtableIteratorTest.java b/drools-core/src/test/java/org/drools/core/util/IndexedHashtableIteratorTest.java index 1f4c75102f2..334ee044212 100644 --- a/drools-core/src/test/java/org/drools/core/util/IndexedHashtableIteratorTest.java +++ b/drools-core/src/test/java/org/drools/core/util/IndexedHashtableIteratorTest.java @@ -26,7 +26,7 @@ import org.drools.core.reteoo.RightTuple; import org.drools.core.util.index.TupleIndexHashTable; import org.drools.core.util.index.TupleList; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/drools-core/src/test/java/org/drools/core/util/IoUtilsTest.java b/drools-core/src/test/java/org/drools/core/util/IoUtilsTest.java index b04f5d28d39..3c8b672a24d 100644 --- a/drools-core/src/test/java/org/drools/core/util/IoUtilsTest.java +++ b/drools-core/src/test/java/org/drools/core/util/IoUtilsTest.java @@ -23,7 +23,7 @@ import org.drools.io.ReaderInputStream; import org.drools.util.IoUtils; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/drools-core/src/test/java/org/drools/core/util/KeyStoreHelperTest.java b/drools-core/src/test/java/org/drools/core/util/KeyStoreHelperTest.java index 50868fc9997..cc147ebfa9f 100755 --- a/drools-core/src/test/java/org/drools/core/util/KeyStoreHelperTest.java +++ b/drools-core/src/test/java/org/drools/core/util/KeyStoreHelperTest.java @@ -36,8 +36,8 @@ import javax.crypto.SecretKeyFactory; import javax.crypto.spec.DESKeySpec; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; @@ -54,7 +54,7 @@ public class KeyStoreHelperTest { private static final String KEY_PASSWORD = "keypwd"; private static final String KEY_PHRASE = "secretkey"; - @AfterClass + @AfterAll public static void cleanup() { try { new File(KEYSTORE_JCEKS_FILENAME).delete(); diff --git a/drools-core/src/test/java/org/drools/core/util/KieFunctionsTest.java b/drools-core/src/test/java/org/drools/core/util/KieFunctionsTest.java index 75a9a77207a..94b15b8124c 100644 --- a/drools-core/src/test/java/org/drools/core/util/KieFunctionsTest.java +++ b/drools-core/src/test/java/org/drools/core/util/KieFunctionsTest.java @@ -21,7 +21,7 @@ import java.math.BigDecimal; import java.math.BigInteger; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/drools-core/src/test/java/org/drools/core/util/LeftTupleRBTreeTest.java b/drools-core/src/test/java/org/drools/core/util/LeftTupleRBTreeTest.java index 0942747f4c9..ada3eadc433 100644 --- a/drools-core/src/test/java/org/drools/core/util/LeftTupleRBTreeTest.java +++ b/drools-core/src/test/java/org/drools/core/util/LeftTupleRBTreeTest.java @@ -21,7 +21,7 @@ import java.util.Random; import org.drools.core.util.TupleRBTree.Node; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; diff --git a/drools-core/src/test/java/org/drools/core/util/LinkedListTest.java b/drools-core/src/test/java/org/drools/core/util/LinkedListTest.java index 9025cd40c5c..83d01a3f34f 100644 --- a/drools-core/src/test/java/org/drools/core/util/LinkedListTest.java +++ b/drools-core/src/test/java/org/drools/core/util/LinkedListTest.java @@ -18,12 +18,13 @@ */ package org.drools.core.util; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; + public class LinkedListTest { LinkedList list = null; @@ -31,7 +32,7 @@ public class LinkedListTest { DoubleLinkedEntry node2 = null; DoubleLinkedEntry node3 = null; - @Before + @BeforeEach public void setUp() throws Exception { this.list = new LinkedList(); this.node1 = new AbstractBaseLinkedListNodeMock(); diff --git a/drools-core/src/test/java/org/drools/core/util/MethodUtilsTest.java b/drools-core/src/test/java/org/drools/core/util/MethodUtilsTest.java index 8d0e8693b6d..3bef34c1f7d 100644 --- a/drools-core/src/test/java/org/drools/core/util/MethodUtilsTest.java +++ b/drools-core/src/test/java/org/drools/core/util/MethodUtilsTest.java @@ -26,7 +26,7 @@ import java.util.stream.Stream; import org.drools.util.MethodUtils; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/drools-core/src/test/java/org/drools/core/util/RightTupleListTest.java b/drools-core/src/test/java/org/drools/core/util/RightTupleListTest.java index b992a9b7e7f..856fb1c13aa 100644 --- a/drools-core/src/test/java/org/drools/core/util/RightTupleListTest.java +++ b/drools-core/src/test/java/org/drools/core/util/RightTupleListTest.java @@ -22,10 +22,9 @@ import org.drools.core.common.InternalFactHandle; import org.drools.core.reteoo.LeftTuple; import org.drools.core.reteoo.MockLeftTupleSink; -import org.drools.core.reteoo.MockObjectSink; import org.drools.core.test.model.Cheese; import org.drools.core.util.index.TupleList; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/drools-core/src/test/java/org/drools/core/util/ScalablePoolTest.java b/drools-core/src/test/java/org/drools/core/util/ScalablePoolTest.java index 34bc1e9f903..94b8effdae6 100644 --- a/drools-core/src/test/java/org/drools/core/util/ScalablePoolTest.java +++ b/drools-core/src/test/java/org/drools/core/util/ScalablePoolTest.java @@ -18,7 +18,7 @@ */ package org.drools.core.util; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/drools-core/src/test/java/org/drools/core/util/index/IndexUtilTest.java b/drools-core/src/test/java/org/drools/core/util/index/IndexUtilTest.java index 5d204db44b2..ebb5d93ef5d 100644 --- a/drools-core/src/test/java/org/drools/core/util/index/IndexUtilTest.java +++ b/drools-core/src/test/java/org/drools/core/util/index/IndexUtilTest.java @@ -43,7 +43,7 @@ import org.drools.core.reteoo.BetaMemory; import org.drools.core.util.AbstractHashTable.DoubleCompositeIndex; import org.drools.core.util.AbstractHashTable.Index; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.kie.api.KieBaseConfiguration; import org.kie.api.runtime.rule.FactHandle; import org.kie.internal.conf.CompositeConfiguration; diff --git a/drools-core/src/test/java/org/drools/core/util/index/RangeIndexTest.java b/drools-core/src/test/java/org/drools/core/util/index/RangeIndexTest.java index cc9b14c3282..dd5470d2a28 100644 --- a/drools-core/src/test/java/org/drools/core/util/index/RangeIndexTest.java +++ b/drools-core/src/test/java/org/drools/core/util/index/RangeIndexTest.java @@ -19,7 +19,7 @@ package org.drools.core.util.index; import org.drools.core.test.model.Person; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat;