diff --git a/easy-rules-core/src/test/java/org/jeasy/rules/core/DefaultRulesEngineTest.java b/easy-rules-core/src/test/java/org/jeasy/rules/core/DefaultRulesEngineTest.java index 72f25d5..ec5151f 100644 --- a/easy-rules-core/src/test/java/org/jeasy/rules/core/DefaultRulesEngineTest.java +++ b/easy-rules-core/src/test/java/org/jeasy/rules/core/DefaultRulesEngineTest.java @@ -24,6 +24,7 @@ package org.jeasy.rules.core; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.never; @@ -36,22 +37,16 @@ import org.assertj.core.api.Assertions; import org.jeasy.rules.annotation.Action; import org.jeasy.rules.annotation.Condition; import org.jeasy.rules.annotation.Priority; -import org.jeasy.rules.api.Fact; import org.jeasy.rules.api.RuleListener; import org.jeasy.rules.api.RulesEngineListener; import org.junit.After; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.mockito.InOrder; import org.mockito.Mock; public class DefaultRulesEngineTest extends AbstractTest { - @Rule - public ExpectedException expectedException = ExpectedException.none(); - @Mock private RuleListener ruleListener; @@ -236,16 +231,14 @@ public class DefaultRulesEngineTest extends AbstractTest { @Test public void getRuleListenersShouldReturnAnUnmodifiableList() { // Given - expectedException.expect(UnsupportedOperationException.class); DefaultRulesEngine rulesEngine = new DefaultRulesEngine(); rulesEngine.registerRuleListener(ruleListener); // When List ruleListeners = rulesEngine.getRuleListeners(); - ruleListeners.clear(); // Then - // expected exception + assertThatThrownBy(ruleListeners::clear).isInstanceOf(UnsupportedOperationException.class); } @Test @@ -264,16 +257,14 @@ public class DefaultRulesEngineTest extends AbstractTest { @Test public void getRulesEngineListenersShouldReturnAnUnmodifiableList() { // Given - expectedException.expect(UnsupportedOperationException.class); DefaultRulesEngine rulesEngine = new DefaultRulesEngine(); rulesEngine.registerRulesEngineListener(rulesEngineListener); // When List rulesEngineListeners = rulesEngine.getRulesEngineListeners(); - rulesEngineListeners.clear(); // Then - // excepted exception + assertThatThrownBy(rulesEngineListeners::clear).isInstanceOf(UnsupportedOperationException.class); } @After diff --git a/easy-rules-mvel/src/test/java/org/jeasy/rules/mvel/MVELActionTest.java b/easy-rules-mvel/src/test/java/org/jeasy/rules/mvel/MVELActionTest.java index 4cdbc8d..455f819 100644 --- a/easy-rules-mvel/src/test/java/org/jeasy/rules/mvel/MVELActionTest.java +++ b/easy-rules-mvel/src/test/java/org/jeasy/rules/mvel/MVELActionTest.java @@ -28,19 +28,16 @@ import org.jeasy.rules.api.Facts; import org.junit.Rule; import org.junit.Test; import org.junit.contrib.java.lang.system.SystemOutRule; -import org.junit.rules.ExpectedException; import org.mvel2.ParserContext; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; public class MVELActionTest { @Rule public final SystemOutRule systemOutRule = new SystemOutRule().enableLog(); - @Rule - public final ExpectedException expectedException = ExpectedException.none(); - @Test public void testMVELActionExecution() throws Exception { // given @@ -70,20 +67,18 @@ public class MVELActionTest { } @Test - public void testMVELActionExecutionWithFailure() throws Exception { + public void testMVELActionExecutionWithFailure() { // given - expectedException.expect(Exception.class); - expectedException.expectMessage("Error: unable to resolve method: org.jeasy.rules.mvel.Person.setBlah(java.lang.Boolean)"); Action action = new MVELAction("person.setBlah(true);"); Facts facts = new Facts(); Person foo = new Person("foo", 20); facts.put("person", foo); // when - action.execute(facts); - - // then - // excepted exception + assertThatThrownBy(() -> action.execute(facts)) + // then + .isInstanceOf(Exception.class) + .hasMessageContaining("Error: unable to resolve method: org.jeasy.rules.mvel.Person.setBlah(java.lang.Boolean)"); } @Test diff --git a/easy-rules-mvel/src/test/java/org/jeasy/rules/mvel/MVELRuleFactoryTest.java b/easy-rules-mvel/src/test/java/org/jeasy/rules/mvel/MVELRuleFactoryTest.java index 23a942b..056f31f 100644 --- a/easy-rules-mvel/src/test/java/org/jeasy/rules/mvel/MVELRuleFactoryTest.java +++ b/easy-rules-mvel/src/test/java/org/jeasy/rules/mvel/MVELRuleFactoryTest.java @@ -34,13 +34,13 @@ import java.util.Arrays; import java.util.Collection; import java.util.Iterator; +import org.assertj.core.api.Assertions; import org.jeasy.rules.api.Rule; import org.jeasy.rules.api.Rules; import org.jeasy.rules.support.composite.UnitRuleGroup; import org.jeasy.rules.support.reader.JsonRuleDefinitionReader; import org.jeasy.rules.support.reader.YamlRuleDefinitionReader; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -57,9 +57,6 @@ public class MVELRuleFactoryTest { }); } - @org.junit.Rule - public ExpectedException expectedException = ExpectedException.none(); - @Parameterized.Parameter(0) public MVELRuleFactory factory; @@ -147,44 +144,38 @@ public class MVELRuleFactoryTest { } @Test - public void testRuleCreationFromFileReader_withInvalidCompositeRuleType() throws Exception { + public void testRuleCreationFromFileReader_withInvalidCompositeRuleType() { // given - expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage("Invalid composite rule type, must be one of [UnitRuleGroup, ConditionalRuleGroup, ActivationRuleGroup]"); File rulesDescriptor = new File("src/test/resources/composite-rule-invalid-composite-rule-type." + fileExtension); // when - Rule rule = factory.createRule(new FileReader(rulesDescriptor)); - - // then - // expected exception + Assertions.assertThatThrownBy(() -> factory.createRule(new FileReader(rulesDescriptor))) + // then + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("Invalid composite rule type, must be one of [UnitRuleGroup, ConditionalRuleGroup, ActivationRuleGroup]"); } @Test - public void testRuleCreationFromFileReader_withEmptyComposingRules() throws Exception { + public void testRuleCreationFromFileReader_withEmptyComposingRules() { // given - expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage("Composite rules must have composing rules specified"); File rulesDescriptor = new File("src/test/resources/composite-rule-invalid-empty-composing-rules." + fileExtension); // when - Rule rule = factory.createRule(new FileReader(rulesDescriptor)); - - // then - // expected exception + Assertions.assertThatThrownBy(() -> factory.createRule(new FileReader(rulesDescriptor))) + // then + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("Composite rules must have composing rules specified"); } @Test - public void testRuleCreationFromFileReader_withNonCompositeRuleDeclaresComposingRules() throws Exception { + public void testRuleCreationFromFileReader_withNonCompositeRuleDeclaresComposingRules() { // given - expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage("Non-composite rules cannot have composing rules"); File rulesDescriptor = new File("src/test/resources/non-composite-rule-with-composing-rules." + fileExtension); // when - Rule rule = factory.createRule(new FileReader(rulesDescriptor)); - - // then - // expected exception + Assertions.assertThatThrownBy(() -> factory.createRule(new FileReader(rulesDescriptor))) + // then + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("Non-composite rules cannot have composing rules"); } } diff --git a/easy-rules-spel/src/test/java/org/jeasy/rules/spel/SpELActionTest.java b/easy-rules-spel/src/test/java/org/jeasy/rules/spel/SpELActionTest.java index 81cb7d7..eb1ad0b 100644 --- a/easy-rules-spel/src/test/java/org/jeasy/rules/spel/SpELActionTest.java +++ b/easy-rules-spel/src/test/java/org/jeasy/rules/spel/SpELActionTest.java @@ -28,20 +28,17 @@ import org.jeasy.rules.api.Facts; import org.junit.Rule; import org.junit.Test; import org.junit.contrib.java.lang.system.SystemOutRule; -import org.junit.rules.ExpectedException; import org.springframework.expression.ParserContext; import org.springframework.expression.common.TemplateParserContext; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; public class SpELActionTest { @Rule public final SystemOutRule systemOutRule = new SystemOutRule().enableLog(); - @Rule - public final ExpectedException expectedException = ExpectedException.none(); - @Test public void testSpELActionExecution() throws Exception { // given @@ -71,20 +68,18 @@ public class SpELActionTest { } @Test - public void testSpELActionExecutionWithFailure() throws Exception { + public void testSpELActionExecutionWithFailure() { // given - expectedException.expect(Exception.class); - expectedException.expectMessage("EL1004E: Method call: Method sayHi() cannot be found on type org.jeasy.rules.spel.Person"); Action action = new SpELAction("#{ T(org.jeasy.rules.spel.Person).sayHi() }"); Facts facts = new Facts(); Person foo = new Person("foo", 20); facts.put("person", foo); // when - action.execute(facts); - - // then - // excepted exception + assertThatThrownBy(() -> action.execute(facts)) + // then + .isInstanceOf(Exception.class) + .hasMessage("EL1004E: Method call: Method sayHi() cannot be found on type org.jeasy.rules.spel.Person"); } @Test diff --git a/easy-rules-spel/src/test/java/org/jeasy/rules/spel/SpELRuleFactoryTest.java b/easy-rules-spel/src/test/java/org/jeasy/rules/spel/SpELRuleFactoryTest.java index dbdd64d..3449397 100644 --- a/easy-rules-spel/src/test/java/org/jeasy/rules/spel/SpELRuleFactoryTest.java +++ b/easy-rules-spel/src/test/java/org/jeasy/rules/spel/SpELRuleFactoryTest.java @@ -34,13 +34,13 @@ import java.util.Arrays; import java.util.Collection; import java.util.Iterator; +import org.assertj.core.api.Assertions; import org.jeasy.rules.api.Rule; import org.jeasy.rules.api.Rules; import org.jeasy.rules.support.composite.UnitRuleGroup; import org.jeasy.rules.support.reader.JsonRuleDefinitionReader; import org.jeasy.rules.support.reader.YamlRuleDefinitionReader; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -57,9 +57,6 @@ public class SpELRuleFactoryTest { }); } - @org.junit.Rule - public ExpectedException expectedException = ExpectedException.none(); - @Parameterized.Parameter(0) public SpELRuleFactory factory; @@ -147,44 +144,38 @@ public class SpELRuleFactoryTest { } @Test - public void testRuleCreationFromFileReader_withInvalidCompositeRuleType() throws Exception { + public void testRuleCreationFromFileReader_withInvalidCompositeRuleType() { // given - expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage("Invalid composite rule type, must be one of [UnitRuleGroup, ConditionalRuleGroup, ActivationRuleGroup]"); File rulesDescriptor = new File("src/test/resources/composite-rule-invalid-composite-rule-type." + fileExtension); // when - Rule rule = factory.createRule(new FileReader(rulesDescriptor)); - - // then - // expected exception + Assertions.assertThatThrownBy(() -> factory.createRule(new FileReader(rulesDescriptor))) + // then + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("Invalid composite rule type, must be one of [UnitRuleGroup, ConditionalRuleGroup, ActivationRuleGroup]"); } @Test - public void testRuleCreationFromFileReader_withEmptyComposingRules() throws Exception { + public void testRuleCreationFromFileReader_withEmptyComposingRules() { // given - expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage("Composite rules must have composing rules specified"); File rulesDescriptor = new File("src/test/resources/composite-rule-invalid-empty-composing-rules." + fileExtension); // when - Rule rule = factory.createRule(new FileReader(rulesDescriptor)); - - // then - // expected exception + Assertions.assertThatThrownBy(() -> factory.createRule(new FileReader(rulesDescriptor))) + // then + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("Composite rules must have composing rules specified"); } @Test - public void testRuleCreationFromFileReader_withNonCompositeRuleDeclaresComposingRules() throws Exception { + public void testRuleCreationFromFileReader_withNonCompositeRuleDeclaresComposingRules() { // given - expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage("Non-composite rules cannot have composing rules"); File rulesDescriptor = new File("src/test/resources/non-composite-rule-with-composing-rules." + fileExtension); // when - Rule rule = factory.createRule(new FileReader(rulesDescriptor)); - - // then - // expected exception + Assertions.assertThatThrownBy(() -> factory.createRule(new FileReader(rulesDescriptor))) + // then + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("Non-composite rules cannot have composing rules"); } }