### Question:
JCECipherProvider implements CipherProvider { public Cipher getCipher() { try { return (preferredProvider != null) ? Cipher.getInstance(transformation, preferredProvider) : Cipher.getInstance(transformation); } catch (NoSuchAlgorithmException ex) { DEBUG.error("JCECipherProvider: Algorithm doesn't exist: " + transformation, ex); } catch (NoSuchPaddingException ex) { DEBUG.error("JCECipherProvider: Padding doesn't exist: " + transformation, ex); } return null; } JCECipherProvider(final String transformation, final String preferredProvider);  JCECipherProvider(final String transformation, final Provider preferredProvider); Cipher getCipher();  }### Answer:
@Test public void shouldUsePreferredProviderWhenAvailable() throws Exception { cipherProvider = new JCECipherProvider(CIPHER_ALGORITHM, preferredProvider); Cipher result = cipherProvider.getCipher(); assertThat(result.getProvider().getName()).isEqualTo(preferredProvider); }
@Test public void shouldFallbackOnAnyProviderWhenPreferredNotAvailable() throws Exception { String unknownProvider = "notARealProvider"; cipherProvider = new JCECipherProvider(CIPHER_ALGORITHM, unknownProvider); Cipher result = cipherProvider.getCipher(); assertThat(result).isNotNull(); assertThat(result.getProvider().getName()).isNotEqualTo(unknownProvider); }
@Test public void shouldReturnNullForUnknownAlgorithm() throws Exception { cipherProvider = new JCECipherProvider("UnknownAlgorithm", preferredProvider); Cipher result = cipherProvider.getCipher(); assertThat(result).isNull(); }
@Test public void shouldReturnNullForUnknownPadding() throws Exception { String transformation = CIPHER_ALGORITHM.replace("NoPadding", "UnknownWeirdPadding"); cipherProvider = new JCECipherProvider(transformation, preferredProvider); Cipher result = cipherProvider.getCipher(); assertThat(result).isNull(); }