### Question:
JCEHandler { protected Key formDESKey(short keyLength, byte[] clearKeyBytes) throws JCEHandlerException { Key key = null; switch (keyLength) { case SMAdapter.LENGTH_DES: { key = new SecretKeySpec(clearKeyBytes, ALG_DES); } break; case SMAdapter.LENGTH_DES3_2KEY: { clearKeyBytes = ISOUtil.concat(clearKeyBytes, 0, getBytesLength(SMAdapter.LENGTH_DES3_2KEY), clearKeyBytes, 0, getBytesLength(SMAdapter.LENGTH_DES)); } case SMAdapter.LENGTH_DES3_3KEY: { key = new SecretKeySpec(clearKeyBytes, ALG_TRIPLE_DES); } } if (key == null) throw new JCEHandlerException("Unsupported DES key length: " + keyLength + " bits"); return key; } JCEHandler(String jceProviderClassName);  JCEHandler(Provider provider); Key generateDESKey(short keyLength); byte[] encryptDESKey(short keyLength, Key clearDESKey, Key encryptingKey); Key decryptDESKey(short keyLength, byte[] encryptedDESKey, Key encryptingKey, boolean checkParity); byte[] encryptData(byte[] data, Key key); byte[] decryptData(byte[] encryptedData, Key key); byte[] encryptDataCBC(byte[] data, Key key, byte[] iv); byte[] decryptDataCBC(byte[] encryptedData, Key key, byte[] iv); byte[] generateMAC(byte[] data, Key kd, String macAlgorithm);  }### Answer:
@Test public void testFormDESKey() throws Throwable { byte[] clearKeyBytes = new byte[4]; SecretKeySpec result = (SecretKeySpec) jCEHandler.formDESKey((short) 64, clearKeyBytes); assertEquals("DES", result.getAlgorithm(), "result.getAlgorithm()"); }
@Test public void testFormDESKey1() throws Throwable { byte[] clearKeyBytes = new byte[1]; SecretKeySpec result = (SecretKeySpec) jCEHandler.formDESKey((short) 192, clearKeyBytes); assertEquals("DESede", result.getAlgorithm(), "result.getAlgorithm()"); }
@Test public void testFormDESKeyThrowsArrayIndexOutOfBoundsException() throws Throwable { byte[] clearKeyBytes = new byte[1]; try { jCEHandler.formDESKey((short) 128, clearKeyBytes); fail("Expected ArrayIndexOutOfBoundsException to be thrown"); } catch (ArrayIndexOutOfBoundsException ex) { if (isJavaVersionAtMost(JAVA_10)) { assertNull(ex.getMessage(), "ex.getMessage()"); } else { assertEquals("arraycopy: last source index 16 out of bounds for byte[1]", ex.getMessage(), "ex.getMessage()"); } } }
@Test public void testFormDESKeyThrowsIllegalArgumentException() throws Throwable { byte[] clearKeyBytes = new byte[0]; try { jCEHandler.formDESKey((short) 192, clearKeyBytes); fail("Expected IllegalArgumentException to be thrown"); } catch (IllegalArgumentException ex) { assertEquals("Empty key", ex.getMessage(), "ex.getMessage()"); } }
@Test public void testFormDESKeyThrowsIllegalArgumentException1() throws Throwable { byte[] clearKeyBytes = new byte[0]; try { jCEHandler.formDESKey((short) 64, clearKeyBytes); fail("Expected IllegalArgumentException to be thrown"); } catch (IllegalArgumentException ex) { assertEquals("Empty key", ex.getMessage(), "ex.getMessage()"); } }
@Test public void testFormDESKeyThrowsJCEHandlerException() throws Throwable { byte[] clearKeyBytes = new byte[1]; try { jCEHandler.formDESKey((short) 100, clearKeyBytes); fail("Expected JCEHandlerException to be thrown"); } catch (JCEHandlerException ex) { assertEquals("Unsupported DES key length: 100 bits", ex.getMessage(), "ex.getMessage()"); assertNull(ex.getNested(), "ex.getNested()"); } }