Skip to content

Commit

Permalink
Remove unnecessary "throws Exception" from test methods
Browse files Browse the repository at this point in the history
  • Loading branch information
fmbenhassine committed Apr 5, 2020
1 parent 8189a5c commit 4600006
Show file tree
Hide file tree
Showing 20 changed files with 60 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class FactsTest {
private Facts facts = new Facts();

@Test
public void factsMustHaveUniqueName() throws Exception {
public void factsMustHaveUniqueName() {
facts.put("foo", 1);
facts.put("foo", 2);

Expand Down Expand Up @@ -92,17 +92,17 @@ public void testClear() {
}

@Test(expected = NullPointerException.class)
public void whenPutNullFact_thenShouldThrowNullPointerException() throws Exception {
public void whenPutNullFact_thenShouldThrowNullPointerException() {
facts.put(null, "foo");
}

@Test(expected = NullPointerException.class)
public void whenRemoveNullFact_thenShouldThrowNullPointerException() throws Exception {
public void whenRemoveNullFact_thenShouldThrowNullPointerException() {
facts.remove(null);
}

@Test(expected = NullPointerException.class)
public void whenGetNullFact_thenShouldThrowNullPointerException() throws Exception {
public void whenGetNullFact_thenShouldThrowNullPointerException() {
facts.get(null);
}
}
20 changes: 10 additions & 10 deletions easy-rules-core/src/test/java/org/jeasy/rules/api/RulesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ public class RulesTest {
private Rules rules = new Rules();

@Test
public void register() throws Exception {
public void register() {
rules.register(new DummyRule());

assertThat(rules).hasSize(1);
}

@Test
public void rulesMustHaveUniqueName() throws Exception {
public void rulesMustHaveUniqueName() {
Rule r1 = new BasicRule("rule");
Rule r2 = new BasicRule("rule");
Set<Rule> ruleSet = new HashSet<>();
Expand All @@ -58,7 +58,7 @@ public void rulesMustHaveUniqueName() throws Exception {
}

@Test
public void unregister() throws Exception {
public void unregister() {
DummyRule rule = new DummyRule();
rules.register(rule);
rules.unregister(rule);
Expand All @@ -67,7 +67,7 @@ public void unregister() throws Exception {
}

@Test
public void unregisterByName() throws Exception {
public void unregisterByName() {
Rule r1 = new BasicRule("rule1");
Rule r2 = new BasicRule("rule2");
Set<Rule> ruleSet = new HashSet<>();
Expand All @@ -81,7 +81,7 @@ public void unregisterByName() throws Exception {
}

@Test
public void unregisterByNameNonExistingRule() throws Exception {
public void unregisterByNameNonExistingRule() {
Rule r1 = new BasicRule("rule1");
Set<Rule> ruleSet = new HashSet<>();
ruleSet.add(r1);
Expand All @@ -93,20 +93,20 @@ public void unregisterByNameNonExistingRule() throws Exception {
}

@Test
public void isEmpty() throws Exception {
public void isEmpty() {
assertThat(rules.isEmpty()).isTrue();
}

@Test
public void clear() throws Exception {
public void clear() {
rules.register(new DummyRule());
rules.clear();

assertThat(rules).isEmpty();
}

@Test
public void sort() throws Exception {
public void sort() {
Rule r1 = new BasicRule("rule", "", 1);
Rule r2 = new BasicRule("rule", "", Integer.MAX_VALUE);
DummyRule r3 = new DummyRule();
Expand All @@ -119,12 +119,12 @@ public void sort() throws Exception {
}

@Test(expected = NullPointerException.class)
public void whenRegisterNullRule_thenShouldThrowNullPointerException() throws Exception {
public void whenRegisterNullRule_thenShouldThrowNullPointerException() {
rules.register(null);
}

@Test(expected = NullPointerException.class)
public void whenUnregisterNullRule_thenShouldThrowNullPointerException() throws Exception {
public void whenUnregisterNullRule_thenShouldThrowNullPointerException() {
rules.unregister(null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

import org.jeasy.rules.annotation.Action;
import org.jeasy.rules.annotation.Condition;
import org.jeasy.rules.api.Facts;
import org.jeasy.rules.api.Rules;
import org.jeasy.rules.api.RulesEngine;
import org.jeasy.rules.annotation.Rule;
import org.junit.Test;
Expand All @@ -36,7 +34,7 @@
public class AnnotationInheritanceTest extends AbstractTest {

@Test
public void annotationsShouldBeInherited() throws Exception {
public void annotationsShouldBeInherited() {
// Given
MyChildRule myChildRule = new MyChildRule();
rules.register(myChildRule);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
public class BasicRuleTest extends AbstractTest {

@Test
public void basicRuleEvaluateShouldReturnFalse() throws Exception {
public void basicRuleEvaluateShouldReturnFalse() {
BasicRule basicRule = new BasicRule();
assertThat(basicRule.evaluate(facts)).isFalse();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void rulesMustBeTriggeredInTheirNaturalOrder() throws Exception {
}

@Test
public void rulesMustBeCheckedInTheirNaturalOrder() throws Exception {
public void rulesMustBeCheckedInTheirNaturalOrder() {
// Given
when(rule1.evaluate(facts)).thenReturn(true);
when(rule2.evaluate(facts)).thenReturn(true);
Expand Down Expand Up @@ -157,19 +157,19 @@ public void annotatedRulesAndNonAnnotatedRulesShouldBeUsableTogether() throws Ex
}

@Test
public void whenRuleNameIsNotSpecified_thenItShouldBeEqualToClassNameByDefault() throws Exception {
public void whenRuleNameIsNotSpecified_thenItShouldBeEqualToClassNameByDefault() {
org.jeasy.rules.api.Rule rule = RuleProxy.asRule(new DummyRule());
assertThat(rule.getName()).isEqualTo("DummyRule");
}

@Test
public void whenRuleDescriptionIsNotSpecified_thenItShouldBeEqualToConditionNameFollowedByActionsNames() throws Exception {
public void whenRuleDescriptionIsNotSpecified_thenItShouldBeEqualToConditionNameFollowedByActionsNames() {
org.jeasy.rules.api.Rule rule = RuleProxy.asRule(new DummyRule());
assertThat(rule.getDescription()).isEqualTo("when condition then action1,action2");
}

@Test
public void testCheckRules() throws Exception {
public void testCheckRules() {
// Given
when(rule1.evaluate(facts)).thenReturn(true);
rules.register(rule1);
Expand All @@ -186,7 +186,7 @@ public void testCheckRules() throws Exception {
}

@Test
public void listenerShouldBeInvokedBeforeCheckingRules() throws Exception {
public void listenerShouldBeInvokedBeforeCheckingRules() {
// Given
when(rule1.evaluate(facts)).thenReturn(true);
when(ruleListener.beforeEvaluate(rule1, facts)).thenReturn(true);
Expand Down Expand Up @@ -236,7 +236,7 @@ public void getParametersShouldReturnACopyOfTheParameters() {
}

@Test
public void testGetRuleListeners() throws Exception {
public void testGetRuleListeners() {
// Given
DefaultRulesEngine rulesEngine = new DefaultRulesEngine();
rulesEngine.registerRuleListener(ruleListener);
Expand Down Expand Up @@ -264,7 +264,7 @@ public void getRuleListenersShouldReturnAnUnmodifiableList() {
}

@Test
public void testGetRulesEngineListeners() throws Exception {
public void testGetRulesEngineListeners() {
// Given
DefaultRulesEngine rulesEngine = new DefaultRulesEngine();
rulesEngine.registerRulesEngineListener(rulesEngineListener);
Expand Down Expand Up @@ -309,17 +309,17 @@ public boolean when() {
}

@Action
public void then0() throws Exception {
public void then0() {
actionSequence += "0";
}

@Action(order = 1)
public void then1() throws Exception {
public void then1() {
actionSequence += "1";
}

@Action(order = 2)
public void then2() throws Exception {
public void then2() {
actionSequence += "2";
executed = true;
}
Expand Down Expand Up @@ -348,12 +348,12 @@ public boolean condition() {
}

@Action(order = 1)
public void action1() throws Exception {
public void action1() {
// no op
}

@Action(order = 2)
public void action2() throws Exception {
public void action2() {
// no op
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
public class FactInjectionTest {

@Test
public void declaredFactsShouldBeCorrectlyInjectedByNameOrType() throws Exception {
public void declaredFactsShouldBeCorrectlyInjectedByNameOrType() {
// Given
Object fact1 = new Object();
Object fact2 = new Object();
Expand All @@ -62,7 +62,7 @@ public void declaredFactsShouldBeCorrectlyInjectedByNameOrType() throws Exceptio
}

@Test
public void rulesShouldBeExecutedWhenFactsAreCorrectlyInjected() throws Exception {
public void rulesShouldBeExecutedWhenFactsAreCorrectlyInjected() {
// Given
Facts facts = new Facts();
facts.put("rain", true);
Expand All @@ -82,7 +82,7 @@ public void rulesShouldBeExecutedWhenFactsAreCorrectlyInjected() throws Exceptio
}

@Test(expected = RuntimeException.class)
public void whenFactTypeDoesNotMatchParameterType_thenShouldThrowRuntimeException() throws Exception {
public void whenFactTypeDoesNotMatchParameterType_thenShouldThrowRuntimeException() {
// Given
Facts facts = new Facts();
facts.put("age", "foo");
Expand All @@ -97,7 +97,7 @@ public void whenFactTypeDoesNotMatchParameterType_thenShouldThrowRuntimeExceptio
}

@Test
public void whenADeclaredFactIsMissingInEvaluateMethod_thenTheRuleShouldNotBeExecuted() throws Exception {
public void whenADeclaredFactIsMissingInEvaluateMethod_thenTheRuleShouldNotBeExecuted() {
// Given
Facts facts = new Facts();
AgeRule ageRule = new AgeRule();
Expand All @@ -112,7 +112,7 @@ public void whenADeclaredFactIsMissingInEvaluateMethod_thenTheRuleShouldNotBeExe
}

@Test
public void whenADeclaredFactIsMissingInExecuteMethod_thenTheRuleShouldNotBeExecuted() throws Exception {
public void whenADeclaredFactIsMissingInExecuteMethod_thenTheRuleShouldNotBeExecuted() {
// Given
Facts facts = new Facts();
AnotherDummyRule rule = new AnotherDummyRule();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
public class InferenceRulesEngineTest {

@Test
public void testCandidateSelection() throws Exception {
public void testCandidateSelection() {
// Given
Facts facts = new Facts();
facts.put("foo", true);
Expand All @@ -53,7 +53,7 @@ public void testCandidateSelection() throws Exception {
}

@Test
public void testCandidateOrdering() throws Exception {
public void testCandidateOrdering() {
// Given
Facts facts = new Facts();
facts.put("foo", true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;

import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;

@RunWith(MockitoJUnitRunner.class)
Expand All @@ -43,7 +42,7 @@ public class RuleBuilderTest {
private Action action1, action2;

@Test
public void testDefaultRuleCreationWithDefaultValues() throws Exception {
public void testDefaultRuleCreationWithDefaultValues() {
// when
Rule rule = new RuleBuilder().build();

Expand All @@ -55,7 +54,7 @@ public void testDefaultRuleCreationWithDefaultValues() throws Exception {
}

@Test
public void testDefaultRuleCreationWithCustomValues() throws Exception {
public void testDefaultRuleCreationWithCustomValues() {
// when
Rule rule = new RuleBuilder()
.name("myRule")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void notAnnotatedRuleMustNotBeAccepted() {
}

@Test
public void withCustomAnnotationThatIsItselfAnnotatedWithTheRuleAnnotation() throws Throwable {
public void withCustomAnnotationThatIsItselfAnnotatedWithTheRuleAnnotation() {
ruleDefinitionValidator.validateRuleDefinition(new AnnotatedRuleWithMetaRuleAnnotation());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void setup() throws Exception {
}

@Test
public void whenTheRuleExecutesSuccessfully_thenOnSuccessShouldBeExecuted() throws Exception {
public void whenTheRuleExecutesSuccessfully_thenOnSuccessShouldBeExecuted() {
// Given
when(rule1.evaluate(facts)).thenReturn(true);
rules.register(rule1);
Expand Down Expand Up @@ -82,7 +82,7 @@ public void whenTheRuleFails_thenOnFailureShouldBeExecuted() throws Exception {
}

@Test
public void whenListenerBeforeEvaluateReturnsFalse_thenTheRuleShouldBeSkippedBeforeBeingEvaluated() throws Exception {
public void whenListenerBeforeEvaluateReturnsFalse_thenTheRuleShouldBeSkippedBeforeBeingEvaluated() {
// Given
when(ruleListener1.beforeEvaluate(rule1, facts)).thenReturn(false);
rules.register(rule1);
Expand All @@ -95,7 +95,7 @@ public void whenListenerBeforeEvaluateReturnsFalse_thenTheRuleShouldBeSkippedBef
}

@Test
public void whenListenerBeforeEvaluateReturnsTrue_thenTheRuleShouldBeEvaluated() throws Exception {
public void whenListenerBeforeEvaluateReturnsTrue_thenTheRuleShouldBeEvaluated() {
// Given
when(ruleListener1.beforeEvaluate(rule1, facts)).thenReturn(true);
rules.register(rule1);
Expand All @@ -108,7 +108,7 @@ public void whenListenerBeforeEvaluateReturnsTrue_thenTheRuleShouldBeEvaluated()
}

@Test
public void whenTheRuleEvaluatesToTrue_thenTheListenerShouldBeInvoked() throws Exception {
public void whenTheRuleEvaluatesToTrue_thenTheListenerShouldBeInvoked() {
// Given
when(rule1.evaluate(facts)).thenReturn(true);
rules.register(rule1);
Expand All @@ -121,7 +121,7 @@ public void whenTheRuleEvaluatesToTrue_thenTheListenerShouldBeInvoked() throws E
}

@Test
public void whenTheRuleEvaluatesToFalse_thenTheListenerShouldBeInvoked() throws Exception {
public void whenTheRuleEvaluatesToFalse_thenTheListenerShouldBeInvoked() {
// Given
when(rule1.evaluate(facts)).thenReturn(false);
rules.register(rule1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void rulesEngineListenersShouldBeCalledInOrderWhenFiringRules() throws Ex
}

@Test
public void rulesEngineListenersShouldBeCalledInOrderWhenCheckingRules() throws Exception {
public void rulesEngineListenersShouldBeCalledInOrderWhenCheckingRules() {
// Given
when(rule1.evaluate(facts)).thenReturn(true);
rules.register(rule1);
Expand Down
Loading

0 comments on commit 4600006

Please sign in to comment.