diff --git a/drools-traits/pom.xml b/drools-traits/pom.xml
index f2c5f685fd1..70d75678a7b 100644
--- a/drools-traits/pom.xml
+++ b/drools-traits/pom.xml
@@ -184,10 +184,10 @@
- junit
- junit
+ org.junit.jupiter
+ junit-jupiter
test
-
+
org.mockito
mockito-core
diff --git a/drools-traits/src/test/java/org/drools/traits/UseOfRuleFlowGroupPlusLockOnTest.java b/drools-traits/src/test/java/org/drools/traits/UseOfRuleFlowGroupPlusLockOnTest.java
index 76a68c0a133..12460df4967 100644
--- a/drools-traits/src/test/java/org/drools/traits/UseOfRuleFlowGroupPlusLockOnTest.java
+++ b/drools-traits/src/test/java/org/drools/traits/UseOfRuleFlowGroupPlusLockOnTest.java
@@ -19,8 +19,8 @@
package org.drools.traits;
import org.drools.kiesession.agenda.DefaultAgenda;
+import org.junit.jupiter.api.Test;
import org.drools.core.reteoo.ReteDumper;
-import org.junit.Test;
import org.kie.api.KieBase;
import org.kie.api.event.rule.DebugAgendaEventListener;
import org.kie.api.io.ResourceType;
diff --git a/drools-traits/src/test/java/org/drools/traits/compiler/CommonTraitTest.java b/drools-traits/src/test/java/org/drools/traits/compiler/CommonTraitTest.java
index 7f42e4fd45e..efa4b0786d1 100644
--- a/drools-traits/src/test/java/org/drools/traits/compiler/CommonTraitTest.java
+++ b/drools-traits/src/test/java/org/drools/traits/compiler/CommonTraitTest.java
@@ -21,7 +21,7 @@
import org.drools.kiesession.rulebase.InternalKnowledgeBase;
import org.drools.kiesession.rulebase.KnowledgeBaseFactory;
import org.drools.traits.core.base.evaluators.IsAEvaluatorDefinition;
-import org.junit.BeforeClass;
+import org.junit.jupiter.api.BeforeAll;
import org.kie.api.KieBase;
import org.kie.api.io.ResourceType;
import org.kie.internal.builder.KnowledgeBuilder;
@@ -33,7 +33,7 @@
public class CommonTraitTest {
- @BeforeClass
+ @BeforeAll
public static void beforeClass() {
System.setProperty(EvaluatorOption.PROPERTY_NAME + "isA", IsAEvaluatorDefinition.class.getName());
}
diff --git a/drools-traits/src/test/java/org/drools/traits/compiler/factmodel/traits/LegacyTraitTest.java b/drools-traits/src/test/java/org/drools/traits/compiler/factmodel/traits/LegacyTraitTest.java
index 6b54b117bfa..47f7e41b0d7 100644
--- a/drools-traits/src/test/java/org/drools/traits/compiler/factmodel/traits/LegacyTraitTest.java
+++ b/drools-traits/src/test/java/org/drools/traits/compiler/factmodel/traits/LegacyTraitTest.java
@@ -19,21 +19,19 @@
package org.drools.traits.compiler.factmodel.traits;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collection;
+import java.util.List;
import org.drools.base.factmodel.traits.Trait;
import org.drools.base.factmodel.traits.Traitable;
import org.drools.kiesession.rulebase.InternalKnowledgeBase;
import org.drools.kiesession.rulebase.KnowledgeBaseFactory;
import org.drools.traits.compiler.CommonTraitTest;
-import org.drools.traits.core.factmodel.LogicalTypeInconsistencyException;
import org.drools.traits.core.factmodel.TraitFactoryImpl;
import org.drools.traits.core.factmodel.VirtualPropertyMode;
import org.drools.traits.core.util.StandaloneTraitFactory;
-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 org.kie.api.KieBase;
import org.kie.api.builder.Message;
import org.kie.api.definition.type.PropertyReactive;
@@ -47,41 +45,26 @@
import org.slf4j.LoggerFactory;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.fail;
import static org.drools.traits.compiler.factmodel.traits.TraitTestUtils.createStandaloneTraitFactory;
-@RunWith(Parameterized.class)
public class LegacyTraitTest extends CommonTraitTest {
private static final Logger LOGGER = LoggerFactory.getLogger(LegacyTraitTest.class);
- public VirtualPropertyMode mode;
-
- @Parameterized.Parameters
- public static Collection modes() {
- return Arrays.asList( new VirtualPropertyMode[][]
- {
- { VirtualPropertyMode.MAP },
- { VirtualPropertyMode.TRIPLES }
- } );
- }
-
- public LegacyTraitTest( VirtualPropertyMode m ) {
- this.mode = m;
+ public static Collection modes() {
+ return List.of(VirtualPropertyMode.MAP, VirtualPropertyMode.TRIPLES);
}
-
-
- private KieSession getSessionFromString( String drl ) {
+ private KieSession getSessionFromString(String drl) {
KnowledgeBuilder knowledgeBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
- knowledgeBuilder.add( ResourceFactory.newByteArrayResource( drl.getBytes() ),
- ResourceType.DRL );
+ knowledgeBuilder.add(ResourceFactory.newByteArrayResource(drl.getBytes()),
+ ResourceType.DRL);
if (knowledgeBuilder.hasErrors()) {
- throw new RuntimeException( knowledgeBuilder.getErrors().toString() );
+ throw new RuntimeException(knowledgeBuilder.getErrors().toString());
}
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
- kbase.addPackages( knowledgeBuilder.getKnowledgePackages() );
+ kbase.addPackages(knowledgeBuilder.getKnowledgePackages());
KieSession session = kbase.newKieSession();
return session;
@@ -149,8 +132,9 @@ public void setPers(Pers pers) {
}
- @Test
- public void traitWithPojoInterface() {
+ @ParameterizedTest
+ @MethodSource("modes")
+ public void traitWithPojoInterface(VirtualPropertyMode mode) {
String source = "package org.drools.compiler.test;\n" +
"import " + LegacyTraitTest.Procedure.class.getCanonicalName() + ";\n" +
"import " + LegacyTraitTest.class.getCanonicalName() + ";\n" +
@@ -160,7 +144,7 @@ public void traitWithPojoInterface() {
// enhanced so that declaration is not needed
// "declare ProcedureImpl end " +
"declare trait ExtendedProcedure " +
- " @role( event )" +
+ " @role(event)" +
"end " +
// Surgery must be declared as trait, since it does not extend Thing
@@ -174,54 +158,54 @@ public void traitWithPojoInterface() {
"when " +
" $p : ExtendedProcedure() " +
"then " +
- " don( $p, Surgery.class ); " +
+ " don($p, Surgery.class); " +
"end " +
"rule 'Test 1' " +
"dialect 'mvel' " +
"when " +
- " $s1 : ExtendedProcedure( $subject : subject ) " +
- " $s2 : ExtendedProcedure( subject == $subject ) " +
+ " $s1 : ExtendedProcedure($subject : subject) " +
+ " $s2 : ExtendedProcedure(subject == $subject) " +
"then " +
"end " +
"rule 'Test 2' " +
"dialect 'mvel' " +
"when " +
- " $s1 : ExtendedProcedure( $subject : subject.name ) " +
- " $s2 : ExtendedProcedure( subject.name == $subject ) " +
+ " $s1 : ExtendedProcedure($subject : subject.name) " +
+ " $s2 : ExtendedProcedure(subject.name == $subject) " +
"then " +
"end " +
"rule 'Test 3' " +
"dialect 'mvel' " +
"when " +
- " $s1 : ExtendedProcedure( ) " +
+ " $s1 : ExtendedProcedure() " +
"then " +
- " update( $s1 ); " +
+ " update($s1); " +
"end " +
"\n";
- KieSession ks = getSessionFromString( source );
- TraitFactoryImpl.setMode(mode, ks.getKieBase() );
+ KieSession ks = getSessionFromString(source);
+ TraitFactoryImpl.setMode(mode, ks.getKieBase());
ExtendedProcedureImpl procedure1 = new ExtendedProcedureImpl();
ExtendedProcedureImpl procedure2 = new ExtendedProcedureImpl();
PatientImpl patient1 = new PatientImpl();
patient1.setName("John");
- procedure1.setSubject( patient1 );
+ procedure1.setSubject(patient1);
procedure1.setPers(new PatientImpl());
PatientImpl patient2 = new PatientImpl();
patient2.setName("John");
- procedure2.setSubject( patient2 );
+ procedure2.setSubject(patient2);
procedure2.setPers(new PatientImpl());
- ks.insert( procedure1 );
- ks.insert( procedure2 );
+ ks.insert(procedure1);
+ ks.insert(procedure2);
- ks.fireAllRules( 500 );
+ ks.fireAllRules(500);
}
@@ -237,8 +221,9 @@ public static interface Trunk extends Root { }
@Trait
public static interface Foo extends Trunk { }
- @Test
- public void traitWithMixedInterfacesExtendingEachOther() {
+ @ParameterizedTest
+ @MethodSource("modes")
+ public void traitWithMixedInterfacesExtendingEachOther(VirtualPropertyMode mode) {
String source = "package org.drools.compiler.test;" +
"import " + BarImpl.class.getCanonicalName() + "; " +
"import " + Foo.class.getCanonicalName() + "; " +
@@ -256,67 +241,64 @@ public void traitWithMixedInterfacesExtendingEachOther() {
"rule 'Bar Don'" +
"when " +
- " $b : BarImpl( this isA Foo.class, this not isA Foo2.class )\n" +
+ " $b : BarImpl(this isA Foo.class, this not isA Foo2.class)\n" +
" String()\n" +
"then " +
- " list.add( 3 ); " +
- " retract( $b ); " +
+ " list.add(3); " +
+ " retract($b); " +
"end " +
"rule 'Don Bar' " +
"no-loop " +
"when " +
- " $b : Foo( ) " +
+ " $b : Foo() " +
"then " +
- " list.add( 1 ); " +
- " don( $b, Foo2.class ); " +
+ " list.add(1); " +
+ " don($b, Foo2.class); " +
"end " +
"rule 'Cant really shed Foo but Foo2' " +
"when " +
" $b : Foo2() " +
"then " +
- " list.add( 2 ); " +
- " shed( $b, Foo.class ); " +
- " insert( \"done\" );" +
+ " list.add(2); " +
+ " shed($b, Foo.class); " +
+ " insert(\"done\");" +
"end " +
"";
- KieSession ks = getSessionFromString( source );
+ KieSession ks = getSessionFromString(source);
KieBase kieBase = ks.getKieBase();
TraitFactoryImpl.setMode(mode, kieBase);
- ArrayList list = new ArrayList();
- ks.setGlobal( "list", list );
+ List list = new ArrayList<>();
+ ks.setGlobal("list", list);
- ks.insert( new BarImpl() );
+ ks.insert(new BarImpl());
int n = ks.fireAllRules();
- LOGGER.debug( list.toString() );
- assertThat(list).isEqualTo(Arrays.asList(1, 2, 3));
+ LOGGER.debug(list.toString());
+ assertThat(list).containsExactly(1, 2, 3);
assertThat(n).isEqualTo(3);
}
- @Test
- public void testTraitWithNonAccessorMethodShadowing() {
+ @ParameterizedTest
+ @MethodSource("modes")
+ public void testTraitWithNonAccessorMethodShadowing(VirtualPropertyMode mode) throws Exception {
StandaloneTraitFactory factory = createStandaloneTraitFactory();
- try {
- SomeInterface r = (SomeInterface) factory.don( new SomeClass(), SomeInterface.class );
- r.prepare();
- assertThat(r.getFoo()).isEqualTo(42);
- assertThat(r.doThis("that")).isEqualTo("I did that");
- } catch ( LogicalTypeInconsistencyException e ) {
- e.printStackTrace();
- fail( e.getMessage() );
- }
+ SomeInterface r = (SomeInterface) factory.don(new SomeClass(), SomeInterface.class);
+ r.prepare();
+ assertThat(r.getFoo()).isEqualTo(42);
+ assertThat(r.doThis("that")).isEqualTo("I did that");
}
- @Test()
- public void testPojoExtendInterface() {
+ @ParameterizedTest
+ @MethodSource("modes")
+ public void testPojoExtendInterface(VirtualPropertyMode mode) {
// DROOLS-697
// It is now allowed for a declared type to extend an interface
// The interface itself will be added to the implements part of the generated class
@@ -331,9 +313,9 @@ public void testPojoExtendInterface() {
"";
KieHelper kh = new KieHelper();
- kh.addContent( s1, ResourceType.DRL );
+ kh.addContent(s1, ResourceType.DRL);
- assertThat(kh.verify().getMessages(Message.Level.ERROR).size()).isEqualTo(0);
+ assertThat(kh.verify().getMessages(Message.Level.ERROR)).isEmpty();
}
}
diff --git a/drools-traits/src/test/java/org/drools/traits/compiler/factmodel/traits/LogicalTraitTest.java b/drools-traits/src/test/java/org/drools/traits/compiler/factmodel/traits/LogicalTraitTest.java
index f9217d22ac3..bedb76d286e 100644
--- a/drools-traits/src/test/java/org/drools/traits/compiler/factmodel/traits/LogicalTraitTest.java
+++ b/drools-traits/src/test/java/org/drools/traits/compiler/factmodel/traits/LogicalTraitTest.java
@@ -26,6 +26,7 @@
import org.drools.core.common.InternalFactHandle;
import org.drools.base.factmodel.traits.CoreWrapper;
+import org.drools.base.factmodel.traits.Thing;
import org.drools.base.factmodel.traits.TraitField;
import org.drools.base.factmodel.traits.Traitable;
import org.drools.base.factmodel.traits.TraitableBean;
@@ -66,12 +67,8 @@ public class LogicalTraitTest extends CommonTraitTest {
public VirtualPropertyMode mode;
@Parameterized.Parameters
- public static Collection modes() {
- return Arrays.asList( new VirtualPropertyMode[][]
- {
- { VirtualPropertyMode.MAP },
- { VirtualPropertyMode.TRIPLES }
- } );
+ public static Collection modes() {
+ return List.of(VirtualPropertyMode.MAP, VirtualPropertyMode.TRIPLES);
}
public LogicalTraitTest( VirtualPropertyMode m ) {
@@ -80,7 +77,7 @@ public LogicalTraitTest( VirtualPropertyMode m ) {
@Test
- public void testShadowAlias() {
+ public void testShadowAlias() throws Exception {
KnowledgeBuilder kbuilderImpl = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilderImpl.add( ResourceFactory.newClassPathResource( "org/drools/compiler/factmodel/traits/testTraitedAliasing.drl" ), ResourceType.DRL );
@@ -94,7 +91,7 @@ public void testShadowAlias() {
KieSession ks = kbase.newKieSession();
- ArrayList list = new ArrayList( );
+ List