Lower complexity of individual tests for isEnabled
The isEnabled tests for events used a helper method to abstract the
test setting. While we strive for abstraction in general, we try to
avoid it unneeded abstraction for tests, if it is only saves a few
lines of code. For tests, we rather have them explicit, even if it
means a bit of duplication. This "being explicit" helps to quicker
understand what a test is doing, if a test is failing.
Change-Id: Icdf848998ebdce329ecf5ad6b1808b45eb249b73
diff --git a/src/test/java/com/googlesource/gerrit/plugins/its/base/its/ItsConfigTest.java b/src/test/java/com/googlesource/gerrit/plugins/its/base/its/ItsConfigTest.java
index 22bc4ee..55572b4 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/its/base/its/ItsConfigTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/its/base/its/ItsConfigTest.java
@@ -419,43 +419,83 @@
}
public void testIsEnabledCommentAddedEvent() {
- testIsEnabledEvent(CommentAddedEvent.class);
+ String[] branches = {};
+ setupIsEnabled("true", null, branches);
+
+ CommentAddedEvent event = new CommentAddedEvent();
+ event.change = new ChangeAttribute();
+ event.change.project = "testProject";
+ event.change.branch = "testBranch";
+
+ ItsConfig itsConfig = createItsConfig();
+
+ replayMocks();
+
+ assertTrue(itsConfig.isEnabled(event));
}
public void testIsEnabledChangeMergedEvent() {
- testIsEnabledEvent(ChangeMergedEvent.class);
+ String[] branches = {};
+ setupIsEnabled("true", null, branches);
+
+ ChangeMergedEvent event = new ChangeMergedEvent();
+ event.change = new ChangeAttribute();
+ event.change.project = "testProject";
+ event.change.branch = "testBranch";
+
+ ItsConfig itsConfig = createItsConfig();
+
+ replayMocks();
+
+ assertTrue(itsConfig.isEnabled(event));
}
public void testIsEnabledChangeAbandonedEvent() {
- testIsEnabledEvent(ChangeAbandonedEvent.class);
+ String[] branches = {};
+ setupIsEnabled("true", null, branches);
+
+ ChangeAbandonedEvent event = new ChangeAbandonedEvent();
+ event.change = new ChangeAttribute();
+ event.change.project = "testProject";
+ event.change.branch = "testBranch";
+
+ ItsConfig itsConfig = createItsConfig();
+
+ replayMocks();
+
+ assertTrue(itsConfig.isEnabled(event));
}
public void testIsEnabledChangeRestoredEvent() {
- testIsEnabledEvent(ChangeRestoredEvent.class);
+ String[] branches = {};
+ setupIsEnabled("true", null, branches);
+
+ ChangeRestoredEvent event = new ChangeRestoredEvent();
+ event.change = new ChangeAttribute();
+ event.change.project = "testProject";
+ event.change.branch = "testBranch";
+
+ ItsConfig itsConfig = createItsConfig();
+
+ replayMocks();
+
+ assertTrue(itsConfig.isEnabled(event));
}
public void testIsEnabledDraftPublishedEvent() {
- testIsEnabledEvent(DraftPublishedEvent.class);
- }
+ String[] branches = {};
+ setupIsEnabled("true", null, branches);
- private <T extends ChangeEvent> void testIsEnabledEvent(Class<T> clazz) {
- try {
- String[] branches = {};
- setupIsEnabled("true", null, branches);
+ DraftPublishedEvent event = new DraftPublishedEvent();
+ event.change = new ChangeAttribute();
+ event.change.project = "testProject";
+ event.change.branch = "testBranch";
- T event = clazz.newInstance();
- event.change = new ChangeAttribute();
- event.change.project = "testProject";
- event.change.branch = "testBranch";
+ ItsConfig itsConfig = createItsConfig();
- ItsConfig itsConfig = createItsConfig();
+ replayMocks();
- replayMocks();
-
- assertTrue(itsConfig.isEnabled(event));
- } catch (InstantiationException | IllegalAccessException e) {
- throw new RuntimeException("Unable to implement event class " + clazz.getCanonicalName(), e);
- }
+ assertTrue(itsConfig.isEnabled(event));
}
public void testIsEnabledRefUpdatedEvent() {