Skip to content

Commit

Permalink
Add rulesCount method in Rules API
Browse files Browse the repository at this point in the history
Issue #283
  • Loading branch information
Desislav-Petrov authored and fmbenhassine committed May 31, 2020
1 parent 68a509e commit 8748d60
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
9 changes: 9 additions & 0 deletions easy-rules-core/src/main/java/org/jeasy/rules/api/Rules.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ public void clear() {
rules.clear();
}

/**
* Check how many rules are currently registered
*
* @return the number of rules currently registered
*/
public int rulesCount() {
return rules.size();
}

/**
* Return an iterator on the rules set. It is not intended to remove rules
* using this iterator.
Expand Down
11 changes: 11 additions & 0 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 @@ -118,6 +118,17 @@ public void sort() {
assertThat(rules).startsWith(r1).endsWith(r2);
}

@Test
public void rulesCount() {
assertThat(rules.rulesCount()).isEqualTo(0);

rules.register(new DummyRule());
assertThat(rules.rulesCount()).isEqualTo(1);

rules.unregister(new DummyRule());
assertThat(rules.rulesCount()).isEqualTo(0);
}

@Test(expected = NullPointerException.class)
public void whenRegisterNullRule_thenShouldThrowNullPointerException() {
rules.register(null);
Expand Down

0 comments on commit 8748d60

Please sign in to comment.