remove static method RuleBuilder.aNewRule

This method is confusing, it returns a rule builder (not a rule).
pull/130/merge
Mahmoud Ben Hassine 7 years ago
parent f18389ee9b
commit 001dd0c7e8

@ -39,21 +39,17 @@ public class RuleBuilder {
private Condition condition = Condition.FALSE; private Condition condition = Condition.FALSE;
private List<Action> actions = new ArrayList<>(); private List<Action> actions = new ArrayList<>();
public static RuleBuilder aNewRule() { public RuleBuilder name(String name) {
return new RuleBuilder();
}
public RuleBuilder named(String name) {
this.name = name; this.name = name;
return this; return this;
} }
public RuleBuilder withDescription(String description) { public RuleBuilder description(String description) {
this.description = description; this.description = description;
return this; return this;
} }
public RuleBuilder withPriority(int priority) { public RuleBuilder priority(int priority) {
this.priority = priority; this.priority = priority;
return this; return this;
} }

@ -44,7 +44,7 @@ public class DefaultRuleTest extends AbstractTest {
public void WhenConditionIsTrue_ThenActionsShouldBeExecutedInOrder() throws Exception { public void WhenConditionIsTrue_ThenActionsShouldBeExecutedInOrder() throws Exception {
// given // given
when(condition.evaluate(facts)).thenReturn(true); when(condition.evaluate(facts)).thenReturn(true);
Rule rule = RuleBuilder.aNewRule() Rule rule = new RuleBuilder()
.when(condition) .when(condition)
.then(action1) .then(action1)
.then(action2) .then(action2)
@ -64,7 +64,7 @@ public class DefaultRuleTest extends AbstractTest {
public void WhenConditionIsFalse_ThenActionsShouldNotBeExecuted() throws Exception { public void WhenConditionIsFalse_ThenActionsShouldNotBeExecuted() throws Exception {
// given // given
when(condition.evaluate(facts)).thenReturn(false); when(condition.evaluate(facts)).thenReturn(false);
Rule rule = RuleBuilder.aNewRule() Rule rule = new RuleBuilder()
.when(condition) .when(condition)
.then(action1) .then(action1)
.then(action2) .then(action2)

@ -45,7 +45,7 @@ public class RuleBuilderTest {
@Test @Test
public void testDefaultRuleCreationWithDefaultValues() throws Exception { public void testDefaultRuleCreationWithDefaultValues() throws Exception {
// when // when
Rule rule = RuleBuilder.aNewRule().build(); Rule rule = new RuleBuilder().build();
// then // then
assertThat(rule.getName()).isEqualTo(Rule.DEFAULT_NAME); assertThat(rule.getName()).isEqualTo(Rule.DEFAULT_NAME);
@ -57,10 +57,10 @@ public class RuleBuilderTest {
@Test @Test
public void testDefaultRuleCreationWithCustomValues() throws Exception { public void testDefaultRuleCreationWithCustomValues() throws Exception {
// when // when
Rule rule = RuleBuilder.aNewRule() Rule rule = new RuleBuilder()
.named("myRule") .name("myRule")
.withDescription("myRuleDescription") .description("myRuleDescription")
.withPriority(3) .priority(3)
.when(condition) .when(condition)
.then(action1) .then(action1)
.then(action2) .then(action2)

@ -5,8 +5,8 @@ import org.jeasy.rules.api.Rule;
import org.jeasy.rules.api.Rules; import org.jeasy.rules.api.Rules;
import org.jeasy.rules.api.RulesEngine; import org.jeasy.rules.api.RulesEngine;
import org.jeasy.rules.core.InferenceRulesEngine; import org.jeasy.rules.core.InferenceRulesEngine;
import org.jeasy.rules.core.RuleBuilder;
import static org.jeasy.rules.core.RuleBuilder.aNewRule;
import static org.jeasy.rules.tutorials.airco.DecreaseTemperatureAction.decreaseTemperature; import static org.jeasy.rules.tutorials.airco.DecreaseTemperatureAction.decreaseTemperature;
import static org.jeasy.rules.tutorials.airco.HighTemperatureCondition.itIsHot; import static org.jeasy.rules.tutorials.airco.HighTemperatureCondition.itIsHot;
@ -18,8 +18,8 @@ public class Launcher {
facts.put("temperature", 30); facts.put("temperature", 30);
// define rules // define rules
Rule airConditioningRule = aNewRule() Rule airConditioningRule = new RuleBuilder()
.named("air conditioning rule") .name("air conditioning rule")
.when(itIsHot()) .when(itIsHot())
.then(decreaseTemperature()) .then(decreaseTemperature())
.build(); .build();

Loading…
Cancel
Save