ComplexContentApprover implements ContentApprover { @Override public boolean approve(byte[] content) { for (ContentApprover currentApprover : approvers) { if (!currentApprover.approve(content)) { return false; } } return true; } ComplexContentApprover(List<ContentApprover> approvers);  ComplexContentApprover(ContentApprover... approvers); @Override boolean approve(byte[] content);  }
@Test public void testApproveEmpty() throws Exception { ComplexContentApprover complexApprover = new ComplexContentApprover(); assertTrue(complexApprover.approve(content)); }
@Test public void testApprove() throws Exception { ComplexContentApprover complexApprover = new ComplexContentApprover(approver1, approver2); doReturn(true).when(approver1).approve(content); doReturn(true).when(approver2).approve(content); boolean result = complexApprover.approve(content); assertTrue(result); verify(approver1).approve(approver1Captor.capture()); verify(approver2).approve(approver2Captor.capture()); assertTrue(content == approver1Captor.getValue()); assertTrue(content == approver2Captor.getValue()); }
@Test public void testDisapproveFirst() throws Exception { ComplexContentApprover complexApprover = new ComplexContentApprover(approver1, approver2); doReturn(false).when(approver1).approve(content); boolean result = complexApprover.approve(content); assertFalse(result); verify(approver1, times(1)).approve(approver1Captor.capture()); verify(approver2, never()).approve(approver2Captor.capture()); assertTrue(content == approver1Captor.getValue()); }
@Test public void testDisapproveLast() throws Exception { ComplexContentApprover complexApprover = new ComplexContentApprover(approver1, approver2); doReturn(true).when(approver1).approve(content); doReturn(false).when(approver2).approve(content); boolean result = complexApprover.approve(content); assertFalse(result); verify(approver1).approve(approver1Captor.capture()); verify(approver2).approve(approver2Captor.capture()); assertTrue(content == approver1Captor.getValue()); assertTrue(content == approver2Captor.getValue()); }