@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 cannotInputNullDefaultProcessor() { try { new ProcessorSelector<In, Out>().when(predicate1).then(processor1) .otherwise(null); fail("No exception thrown!!"); } catch (NullPointerException e) { assertEquals(e.getMessage(), BUNDLE.getMessage("processing.nullProcessor")); } }
@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); }