DecisionMakerFailedItems { public List<Decision> execute(Collection<CommitItem> items) { List<Decision> ret = new ArrayList<>(); Collection<CommitItem> failedItems = getFailedAndRefresh(items); Iterator<CommitItem> iterate = failedItems.iterator(); CommitItem currItem; while (iterate.hasNext()) { currItem = iterate.next(); if (!isPending(currItem.getParent())) { ret.addAll(handleItem(currItem)); } failedItems = getFailedAndRefresh(items); iterate = failedItems.iterator(); } return ret; }  List<Decision> execute(Collection<CommitItem> items);  }
@Test public void testExecute1Failed() { Collection<CommitItem> items = new ArrayList<>(); CommitItem commit = CommitItemFactory.create(VerificationStatus.FAILED); items.add(commit); List<Decision> decisions = new DecisionMakerFailedItems().execute(items); Assert.assertEquals(1, decisions.size()); Assert.assertEquals(OnFailureHandler.class, decisions.get(0).getHandler().getClass()); CommitItemContainer commitItemContainer = CollectorApi.getCommitItemContainer(); commit = commitItemContainer.get(commit.getKey()); Assert.assertTrue(commit.isDone()); }
@Test public void testExecute1Failed1Running() { Collection<CommitItem> items = new ArrayList<>(); CommitItem commit1 = CommitItemFactory.create(VerificationStatus.RUNNING); items.add(commit1); CommitItem commit2 = CommitItemFactory.create(VerificationStatus.FAILED); commit2.setParent(commit1); items.add(commit2); List<Decision> decisions = new DecisionMakerFailedItems().execute(items); Assert.assertEquals(0, decisions.size()); Assert.assertFalse(commit2.isDone()); }
@Test public void testExecute1Failed2Passed() { Collection<CommitItem> items = new ArrayList<>(); CommitItem commit1 = CommitItemFactory.create(VerificationStatus.PASSED); items.add(commit1); CommitItem commit2 = CommitItemFactory.create(VerificationStatus.PASSED); commit2.setParent(commit1); items.add(commit2); CommitItem commit3 = CommitItemFactory.create(VerificationStatus.FAILED); commit3.setParent(commit2); items.add(commit3); List<Decision> decisions = new DecisionMakerFailedItems().execute(items); Assert.assertEquals(1, decisions.size()); Assert.assertEquals(OnFailureHandler.class, decisions.get(0).getHandler().getClass()); CommitItemContainer commitItemContainer = CollectorApi.getCommitItemContainer(); commit3 = commitItemContainer.get(commit3.getKey()); Assert.assertTrue(commit3.isDone()); }
@Test public void testExecute2Failed1Passed() { Collection<CommitItem> items = new ArrayList<>(); CommitItem commit1 = CommitItemFactory.create(VerificationStatus.PASSED); items.add(commit1); CommitItem commit2 = CommitItemFactory.create(VerificationStatus.FAILED); commit2.setParent(commit1); items.add(commit2); CommitItem commit3 = CommitItemFactory.create(VerificationStatus.FAILED); commit3.setParent(commit2); items.add(commit3); List<Decision> decisions = new DecisionMakerFailedItems().execute(items); Assert.assertEquals(1, decisions.size()); Decision decision = decisions.get(0); CommitItemContainer commitItemContainer = CollectorApi.getCommitItemContainer(); commit1 = commitItemContainer.get(commit1.getKey()); commit2 = commitItemContainer.get(commit2.getKey()); commit3 = commitItemContainer.get(commit3.getKey()); assertDecision(commit1, commit2, decision, OnFailureHandler.class); Assert.assertTrue(commit2.isDone()); assertNotStarted(commit3); }
@Test public void testExecute3Failed1Passed() { Collection<CommitItem> items = new ArrayList<>(); CommitItem commit1 = CommitItemFactory.create(VerificationStatus.PASSED); items.add(commit1); CommitItem commit2 = CommitItemFactory.create(VerificationStatus.FAILED); commit2.setParent(commit1); items.add(commit2); CommitItem commit3 = CommitItemFactory.create(VerificationStatus.FAILED); commit3.setParent(commit2); items.add(commit3); CommitItem commit4 = CommitItemFactory.create(VerificationStatus.FAILED); commit4.setParent(commit3); items.add(commit4); List<Decision> decisions = new DecisionMakerFailedItems().execute(items); Assert.assertEquals(1, decisions.size()); Decision decision = decisions.get(0); CommitItemContainer commitItemContainer = CollectorApi.getCommitItemContainer(); commit1 = commitItemContainer.get(commit1.getKey()); commit2 = commitItemContainer.get(commit2.getKey()); commit3 = commitItemContainer.get(commit3.getKey()); commit4 = commitItemContainer.get(commit4.getKey()); assertDecision(commit1, commit2, decision, OnFailureHandler.class); assertNotStarted(commit3); assertNotStarted(commit4); }
@Test public void test1Failed2Running() { CommitItem commitItem1 = CommitItemFactory.create(VerificationStatus.FAILED); CommitItem commitItem2 = CommitItemFactory.create(VerificationStatus.RUNNING, commitItem1); CommitItem commitItem3 = CommitItemFactory.create(VerificationStatus.RUNNING, commitItem2); List<Decision> decisions = new DecisionMakerFailedItems().execute(Arrays.asList( commitItem1, commitItem2, commitItem3)); Assert.assertEquals(3, decisions.size()); CommitItemContainer commitItemContainer = CollectorApi.getCommitItemContainer(); commitItem1 = commitItemContainer.get(commitItem1.getKey()); commitItem2 = commitItemContainer.get(commitItem2.getKey()); commitItem3 = commitItemContainer.get(commitItem3.getKey()); assertDecision(null, commitItem1, decisions.get(0), OnFailureHandler.class); assertDecision(null, commitItem2, decisions.get(1), OnFailedByParentHandler.class); assertDecision(null, commitItem3, decisions.get(2), OnFailedByParentHandler.class); commitItem2 = CollectorApi.getCommitItemContainer().get(commitItem2.getKey()); Assert.assertEquals(VerificationStatus.NOT_STARTED, commitItem2.getStatus()); Assert.assertEquals(null, commitItem2.getParent()); commitItem3 = CollectorApi.getCommitItemContainer().get(commitItem2.getKey()); Assert.assertEquals(VerificationStatus.NOT_STARTED, commitItem3.getStatus()); Assert.assertEquals(null, commitItem3.getParent()); }