Skip to content

Commit

Permalink
[incubator-kie-drools-6136] Migrate drools test coverage to JUnit5 (a…
Browse files Browse the repository at this point in the history
…pache#6142)

* Migrated first group of tests in mvel

* More tests migrated

* More tests migrated to Junit5

* Migrated more tests to Junit5

* More tests migrated to Junit5
  • Loading branch information
pibizza authored and rgdoliveira committed Nov 7, 2024
1 parent af01c00 commit 1a8b576
Show file tree
Hide file tree
Showing 121 changed files with 2,214 additions and 2,043 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
*/
package org.drools.mvel;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.stream.Stream;

import org.drools.core.base.ClassFieldAccessorCache;

Expand All @@ -40,38 +40,27 @@
import org.drools.kiesession.session.StatefulKnowledgeSessionImpl;
import org.drools.mvel.model.Cheese;
import org.drools.mvel.model.MockObjectSource;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

@RunWith(Parameterized.class)
public class AlphaNodeTest {

ClassFieldAccessorStore store = new ClassFieldAccessorStore();

private final boolean useLambdaConstraint;

public AlphaNodeTest(boolean useLambdaConstraint) {
this.useLambdaConstraint = useLambdaConstraint;
}

@Parameterized.Parameters(name = "useLambdaConstraint={0}")
public static Collection<Object[]> getParameters() {
Collection<Object[]> parameters = new ArrayList<>();
parameters.add(new Object[]{false});
parameters.add(new Object[]{true});
return parameters;
public static Stream<Boolean> parameters() {
return Stream.of(false, true);
}

@Before
@BeforeEach
public void setUp() throws Exception {
store.setClassFieldAccessorCache( new ClassFieldAccessorCache( Thread.currentThread().getContextClassLoader() ) );
store.setEagerWire( true );
}

@Test
public void testLiteralConstraintAssertObjectWithoutMemory() throws Exception {
@ParameterizedTest(name = "useLambdaConstraint={0}")
@MethodSource("parameters")
public void testLiteralConstraintAssertObjectWithoutMemory(boolean useLambdaConstraint) throws Exception {
InternalKnowledgeBase kBase = KnowledgeBaseFactory.newKnowledgeBase();
BuildContext buildContext = new BuildContext( kBase, Collections.emptyList() );
buildContext.setRule(new RuleImpl("test"));
Expand Down Expand Up @@ -131,8 +120,9 @@ public void testLiteralConstraintAssertObjectWithoutMemory() throws Exception {
/*
* This just test AlphaNode With a different Constraint type.
*/
@Test
public void testReturnValueConstraintAssertObject() throws Exception {
@ParameterizedTest(name = "useLambdaConstraint={0}")
@MethodSource("parameters")
public void testReturnValueConstraintAssertObject(boolean useLambdaConstraint) throws Exception {
InternalKnowledgeBase kBase = KnowledgeBaseFactory.newKnowledgeBase();
BuildContext buildContext = new BuildContext( kBase, Collections.emptyList() );
buildContext.setRule(new RuleImpl("test"));
Expand Down Expand Up @@ -184,8 +174,9 @@ public void testReturnValueConstraintAssertObject() throws Exception {
assertThat((Collection) sink.getAsserted()).hasSize(0);
}

@Test
public void testUpdateSinkWithoutMemory() {
@ParameterizedTest(name = "useLambdaConstraint={0}")
@MethodSource("parameters")
public void testUpdateSinkWithoutMemory(boolean useLambdaConstraint) {
// An AlphaNode should try and repropagate from its source
InternalKnowledgeBase kBase = KnowledgeBaseFactory.newKnowledgeBase();
BuildContext buildContext = new BuildContext( kBase, Collections.emptyList() );
Expand Down
Loading

0 comments on commit 1a8b576

Please sign in to comment.