Remove usage of deprecated APIs

pull/284/head
Mahmoud Ben Hassine 5 years ago
parent c8b541b32c
commit 90ecf58e68
No known key found for this signature in database
GPG Key ID: 79FCFB0A184E0036

@ -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<RuleListener> 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<RulesEngineListener> rulesEngineListeners = rulesEngine.getRulesEngineListeners();
rulesEngineListeners.clear();
// Then
// excepted exception
assertThatThrownBy(rulesEngineListeners::clear).isInstanceOf(UnsupportedOperationException.class);
}
@After

@ -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

@ -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");
}
}

@ -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

@ -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");
}
}

Loading…
Cancel
Save