Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Adding rules count #284

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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