@Test public void noSuccessfulPredicateExecutesDefault() throws ProcessingException { when(predicate1.apply(input)).thenReturn(false); when(predicate2.apply(input)).thenReturn(false); final Processor<In, Out> processor = selector.otherwise(byDefault) .getProcessor(); processor.process(report, input); verifyZeroInteractions(processor1, processor2); verify(byDefault, onlyOnce()).process(report, input); for (final Processor<In, Out> p: otherProcessors) verifyZeroInteractions(p); }
@Test public void firstSuccessfulPredicateIsExecuted() throws ProcessingException { when(predicate1.apply(input)).thenReturn(false); when(predicate2.apply(input)).thenReturn(true); final Processor<In, Out> processor = selector.otherwise(byDefault) .getProcessor(); processor.process(report, input); verify(processor2, onlyOnce()).process(same(report), same(input)); verifyZeroInteractions(processor1, byDefault); for (final Processor<In, Out> p: otherProcessors) verifyZeroInteractions(p); }
@Test public void firstComeFirstServed() throws ProcessingException { when(predicate1.apply(input)).thenReturn(true); when(predicate2.apply(input)).thenReturn(true); final Processor<In, Out> processor = selector.otherwise(byDefault) .getProcessor(); processor.process(report, input); verify(processor1, onlyOnce()).process(same(report), same(input)); verifyZeroInteractions(processor2, byDefault); for (final Processor<In, Out> p: otherProcessors) verifyZeroInteractions(p); }
@Test public void noSuccessfulPredicateAndNoDefaultThrowsException() { when(predicate1.apply(input)).thenReturn(false); when(predicate2.apply(input)).thenReturn(false); final Processor<In, Out> processor = selector.getProcessor(); try { processor.process(report, input); fail("No exception thrown!!"); } catch (ProcessingException e) { verifyZeroInteractions(processor1, processor2); for (final Processor<In, Out> p: otherProcessors) verifyZeroInteractions(p); assertMessage(e.getProcessingMessage()) .hasMessage(BUNDLE.getMessage("processing.noProcessor")); } }