Change RulesEngine#getParameters to return a copy of the parameters

Resolves #158
pull/210/head
Mahmoud Ben Hassine 6 years ago
parent f6a8b9a6fa
commit b3ba58c7ec

@ -56,7 +56,12 @@ abstract class AbstractRuleEngine implements RulesEngine {
@Override @Override
public RulesEngineParameters getParameters() { public RulesEngineParameters getParameters() {
return parameters; return new RulesEngineParameters(
parameters.isSkipOnFirstAppliedRule(),
parameters.isSkipOnFirstFailedRule(),
parameters.isSkipOnFirstNonTriggeredRule(),
parameters.getPriorityThreshold()
);
} }
@Override @Override

@ -217,6 +217,24 @@ public class DefaultRulesEngineTest extends AbstractTest {
// Should not throw exception // Should not throw exception
} }
@Test
public void getParametersShouldReturnACopyOfTheParameters() {
// Given
RulesEngineParameters parameters = new RulesEngineParameters()
.skipOnFirstAppliedRule(true)
.skipOnFirstFailedRule(true)
.skipOnFirstNonTriggeredRule(true)
.priorityThreshold(42);
DefaultRulesEngine rulesEngine = new DefaultRulesEngine(parameters);
// When
RulesEngineParameters engineParameters = rulesEngine.getParameters();
// Then
Assertions.assertThat(engineParameters).isNotSameAs(parameters);
Assertions.assertThat(engineParameters).isEqualToComparingFieldByField(parameters);
}
@Test @Test
public void testGetRuleListeners() throws Exception { public void testGetRuleListeners() throws Exception {
// Given // Given

Loading…
Cancel
Save