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 List<Action> actions = new ArrayList<>();
public static RuleBuilder aNewRule() {
return new RuleBuilder();
}
public RuleBuilder named(String name) {
public RuleBuilder name(String name) {
this.name = name;
return this;
}
public RuleBuilder withDescription(String description) {
public RuleBuilder description(String description) {
this.description = description;
return this;
}
public RuleBuilder withPriority(int priority) {
public RuleBuilder priority(int priority) {
this.priority = priority;
return this;
}

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

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

@ -5,8 +5,8 @@ import org.jeasy.rules.api.Rule;
import org.jeasy.rules.api.Rules;
import org.jeasy.rules.api.RulesEngine;
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.HighTemperatureCondition.itIsHot;
@ -18,8 +18,8 @@ public class Launcher {
facts.put("temperature", 30);
// define rules
Rule airConditioningRule = aNewRule()
.named("air conditioning rule")
Rule airConditioningRule = new RuleBuilder()
.name("air conditioning rule")
.when(itIsHot())
.then(decreaseTemperature())
.build();

Loading…
Cancel
Save