### Question:
TokenBlobStrategy { public byte[] perform(byte[] data) throws TokenStrategyFailedException { return apply(strategies, true, data); } @Inject  TokenBlobStrategy(TokenStrategyFactory factory, CoreTokenConfig config); byte[] perform(byte[] data); byte[] reverse(byte[] data);  }### Answer:
@Test public void shouldPerformAllStrategy() throws TokenStrategyFailedException { BlobStrategy first = mock(BlobStrategy.class); BlobStrategy second = mock(BlobStrategy.class); BlobStrategy third = mock(BlobStrategy.class); given(factory.getStrategies(nullable(CoreTokenConfig.class))) .willReturn(Arrays.asList(first, second, third)); byte[] data = new byte[0]; TokenBlobStrategy strategy = new TokenBlobStrategy(factory, config); strategy.perform(data); verify(first).perform(any(byte[].class)); verify(second).perform(nullable(byte[].class)); verify(third).perform(nullable(byte[].class)); }
@Test public void shouldPerformAllStrategy() throws TokenStrategyFailedException { BlobStrategy first = mock(BlobStrategy.class); BlobStrategy second = mock(BlobStrategy.class); BlobStrategy third = mock(BlobStrategy.class); given(factory.getStrategies(any(CoreTokenConfig.class))) .willReturn(Arrays.asList(first, second, third)); byte[] data = new byte[0]; TokenBlobStrategy strategy = new TokenBlobStrategy(factory, config); strategy.perform(data); verify(first).perform(any(byte[].class)); verify(second).perform(any(byte[].class)); verify(third).perform(any(byte[].class)); }
@Test public void shouldDoNothingWithNoStrategy() throws TokenStrategyFailedException { byte[] data = new byte[0]; TokenBlobStrategy strategy = new TokenBlobStrategy(factory, config); byte[] result = strategy.perform(data); assertThat(result).isEqualTo(data); }
@Test public void shouldNotModifyProvidedByteArray() throws TokenStrategyFailedException { byte[] data = "badger".getBytes(); BlobStrategy first = mock(BlobStrategy.class); ArgumentCaptor<byte[]> captor = ArgumentCaptor.forClass(byte[].class); given(first.perform(captor.capture())).willReturn(data); given(factory.getStrategies(any(CoreTokenConfig.class))).willReturn(Arrays.asList(first)); TokenBlobStrategy strategy = new TokenBlobStrategy(factory, config); strategy.perform(data); Object dataRef = data; Object captorRef = captor.getValue(); if (dataRef == captorRef) { fail(); } }
@Test public void shouldReturnNullForNullInputDuringPerform() throws Exception { byte[] data = null; BlobStrategy first = mock(BlobStrategy.class); given(factory.getStrategies(any(CoreTokenConfig.class))).willReturn(Arrays.asList(first)); TokenBlobStrategy strategy = new TokenBlobStrategy(factory, config); assertThat(strategy.perform(data)).isNull(); verify(first, times(0)).perform(any(byte[].class)); }