IntegerToTypeConverterIntEnum extends IntegerToInteger { @Override public void validate(Class<?> type, int size, int decimals) { if(!(TypeConverterIntEnum.class.isAssignableFrom(type))) { throw new TypeConverterException("Only supports converting to and from TypeConverterIntEnum"); } if(this.type != null && this.type != type) { throw new TypeConverterException("Type converter can only be used on " + type.getSimpleName() + " fields"); } this.type = type; enumConstants = type.getEnumConstants(); if(enumConstants == null || enumConstants.length == 0) { throw new TypeConverterException("Could not find any enum constants on type"); } for (Object enumConstant : enumConstants) { int value = ((TypeConverterIntEnum) enumConstant).getValue(); toEnumMap.put(value, enumConstant); fromEnumMap.put(enumConstant, Integer.toString(value).getBytes(this.charset)); } }  @Override void validate(Class<?> type, int size, int decimals); @Override Object to(byte[] bytes, int offset, int length, int decimals, boolean removePadding); @Override byte[] from(Object value, int length, int decimals, boolean addPadding);  }
@Test public void testValidateSuccess() throws Exception { typeConverter.validate(TestIntEnum.class, 2, -1); }
@Test(expected = TypeConverterException.class) public void testValidateFail() throws Exception { typeConverter.validate(Long.TYPE, 2, -1); }