### Question:
PerThreadCipherProvider implements CipherProvider { public Cipher getCipher() { return cipherCache.getInstanceForCurrentThread(); } PerThreadCipherProvider(final CipherProvider delegate, final int maxSize);  PerThreadCipherProvider(CipherProvider delegate); Cipher getCipher();  }### Answer:
@Test public void shouldReturnSameCipherForSameThread() { Cipher cipher1 = testProvider.getCipher(); Cipher cipher2 = testProvider.getCipher(); assertThat(cipher1).isSameAs(cipher2); }
@Test public void shouldReturnDifferentCiphersForDifferentThreads() throws Exception { ExecutorService otherThread = Executors.newSingleThreadExecutor(); Cipher cipher1 = testProvider.getCipher(); Cipher cipher2 = otherThread.submit(getCipherInOtherThread()).get(); assertThat(cipher1).isNotSameAs(cipher2); }
@Test public void shouldEvictLeastRecentlyAccessedElements() throws Exception { int maxSize = 1; ExecutorService otherThread = Executors.newSingleThreadExecutor(); testProvider = new PerThreadCipherProvider(new MockCipherProvider(), maxSize); Cipher cipher1 = testProvider.getCipher(); otherThread.submit(getCipherInOtherThread()).get(); Cipher cipher2 = testProvider.getCipher(); assertThat(cipher1).isNotSameAs(cipher2); }