### Question:
UUIDTypeConversion implements TypeConverter.Conversion<UUID> { @Override public UUID convert(Object value) { if (value == null) { return null; } else if (value instanceof UUID) { return (UUID)value; } else if (value instanceof String) { return UUID.fromString((String)value); } else if (value.getClass().isArray()) { if (value.getClass().getComponentType() == Byte.TYPE) { return UUID.nameUUIDFromBytes((byte[])value); } else if (value.getClass().getComponentType() == Character.TYPE) { return UUID.fromString(String.valueOf((char[])value)); } else { throw new IllegalArgumentException("Cannot convert to UUID "+ "from array of \""+ value.getClass().getComponentType()+"\""); } } else { return UUID.fromString(value.toString()); } }  @Override Object[] getTypeKeys(); @Override UUID convert(Object value);  }### Answer:
@Test public void testUUIDTypeConversionWithNullInput(){ UUIDTypeConversion uuidTypeConverison = new UUIDTypeConversion(); assertNull(uuidTypeConverison.convert(null)); }
@Test public void testUUIDTypeConversionWithUUIDInput(){ UUIDTypeConversion uuidTypeConverison = new UUIDTypeConversion(); UUID uuid = UUID.randomUUID(); assertTrue(uuidTypeConverison.convert(uuid) instanceof UUID); }
@Test public void testUUIDTypeConversionWithStringInput(){ UUIDTypeConversion uuidTypeConverison = new UUIDTypeConversion(); String uuid = UUID.randomUUID().toString(); UUID uuidRetval = uuidTypeConverison.convert(uuid); assertTrue(uuidRetval instanceof UUID); assertEquals(uuid, uuidRetval.toString()); }
@Test public void testUUIDTypeConversionWithByteArrayInput(){ UUIDTypeConversion uuidTypeConverison = new UUIDTypeConversion(); byte[] uuid = UUID.randomUUID().toString().getBytes(); UUID uuidRetval = uuidTypeConverison.convert(uuid); assertTrue(uuidRetval instanceof UUID); byte[] returnedUUID = uuidRetval.toString().getBytes(); assertEquals(uuid.length, returnedUUID.length); }
@Test public void testUUIDTypeConversionWithCharArrayInput(){ UUIDTypeConversion uuidTypeConverison = new UUIDTypeConversion(); char[] uuidChars = UUID.randomUUID().toString().toCharArray(); UUID uuidRetval = uuidTypeConverison.convert(uuidChars); assertTrue(uuidRetval instanceof UUID); char[] returnedUUID = uuidRetval.toString().toCharArray(); assertEquals(uuidChars.length, returnedUUID.length); }
@Test public void testUUIDTypeConversionWithNumberArrayInput(){ UUIDTypeConversion uuidTypeConverison = new UUIDTypeConversion(); int[] uuidChars = new int[]{1,2,3,4}; try{ uuidTypeConverison.convert(uuidChars); }catch(Exception e){ assertTrue(e instanceof IllegalArgumentException); assertEquals(e.getMessage(), "Cannot convert to UUID from array of \"int\""); } }
@Test public void testUUIDTypeConversionWithAnyClass(){ UUIDTypeConversion uuidTypeConverison = new UUIDTypeConversion(); class UUIDInput { public String uuidinput = UUID.randomUUID().toString(); @Override public String toString(){ return this.uuidinput; } }; UUID uuidOutput = uuidTypeConverison.convert(new UUIDInput()); assertTrue(uuidOutput instanceof UUID); }