CompositeAcceptor { public WaiterState accepts(Output response) { for (WaiterAcceptor<Output> acceptor : acceptors) { if (acceptor.matches(response)) { return acceptor.getState(); } } return WaiterState.RETRY; } CompositeAcceptor(List<WaiterAcceptor<Output>> acceptors); List<WaiterAcceptor<Output>> getAcceptors(); WaiterState accepts(Output response); WaiterState accepts(AmazonServiceException exception);  }
@Test public void responseMatchExpected() throws Exception { List<WaiterAcceptor> waiterAcceptorsList = new ArrayList<WaiterAcceptor>(); waiterAcceptorsList.add(new TestExceptionAcceptor()); waiterAcceptorsList.add(new TestResultAcceptor()); CompositeAcceptor compositeAcceptor = new CompositeAcceptor(waiterAcceptorsList); Assert.assertEquals("Response output doesn't match expected output.", WaiterState.SUCCESS, compositeAcceptor.accepts(new DescribeTableResult())); }
@Test public void responseNotMatchExpected() throws Exception { List<WaiterAcceptor> waiterAcceptorsList = new ArrayList<WaiterAcceptor>(); waiterAcceptorsList.add(new TestExceptionAcceptor()); CompositeAcceptor compositeAcceptor = new CompositeAcceptor(waiterAcceptorsList); Assert.assertEquals("Response output doesn't match expected output.", WaiterState.RETRY, compositeAcceptor.accepts(new DescribeTableResult())); }
@Test (expected = AmazonServiceException.class) public void exceptionNotMatchExpected() throws Exception { List<WaiterAcceptor> waiterAcceptorsList = new ArrayList<WaiterAcceptor>(); waiterAcceptorsList.add(new TestResultAcceptor()); CompositeAcceptor compositeAcceptor = new CompositeAcceptor(waiterAcceptorsList); Assert.assertEquals("Exception thrown doesn't match expected exception.", WaiterState.RETRY, compositeAcceptor.accepts(new AmazonServiceException(""))); }
@Test public void exceptionMatchExpected() throws Exception { List<WaiterAcceptor> waiterAcceptorsList = new ArrayList<WaiterAcceptor>(); waiterAcceptorsList.add(new TestResultAcceptor()); waiterAcceptorsList.add(new TestExceptionAcceptor()); CompositeAcceptor compositeAcceptor = new CompositeAcceptor(waiterAcceptorsList); Assert.assertEquals("Exception thrown doesn't match expected exception.", WaiterState.RETRY, compositeAcceptor.accepts(new ResourceNotFoundException(""))); }