TransformerPipeline implements Transformer { @Override public Data transform(Data data) { if (usePipeline()) { return pipeline(data); } return data; } TransformerPipeline();  TransformerPipeline(List<Transformer> pipeline); @Override Data transform(Data data);  }
@Test public void shouldCallTransformerInOrder() { Transformer transformer1 = mock(Transformer.class); Transformer transformer2 = mock(Transformer.class); Data sourceData = mock(Data.class); Data output1 = mock(Data.class); Data output2 = mock(Data.class); when(transformer1.transform(sourceData)).thenReturn(output1); when(transformer2.transform(output1)).thenReturn(output2); TransformerPipeline sut = new TransformerPipeline(asList(transformer1, transformer2)); Data result = sut.transform(sourceData); assertThat(result, is(output2)); verify(transformer1).transform(sourceData); verify(transformer2).transform(output1); }
@Test public void shouldNotThrowErrorIfPipelineIsNull() { TransformerPipeline sut = new TransformerPipeline(null); Data sourceData = mock(Data.class); Data result = sut.transform(sourceData); assertThat(result, is(sourceData)); }
@Test public void shouldNotTransformDataIfEmpty() { TransformerPipeline sut = new TransformerPipeline(new ArrayList<>()); Data sourceData = mock(Data.class); Data result = sut.transform(sourceData); assertThat(result, is(sourceData)); }