IntegerToTypeConverterIntEnum extends IntegerToInteger { @Override public Object to(byte[] bytes, int offset, int length, int decimals, boolean removePadding) { int i = (int)super.to(bytes, offset, length, decimals, removePadding); if(toEnumMap.size() > 0) { if (toEnumMap.containsKey(i)) { return toEnumMap.get(i); } else { throw new TypeConverterException("Unknown value for enum: " + i); } } else if(i < enumConstants.length) { return enumConstants[i]; } else { throw new TypeConverterException("Unknown ordinal value for enum: " + i); } }  @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 testTo() throws Exception { assertEquals(TestIntEnum.HIGH, typeConverter.to("30".getBytes(StandardCharsets.UTF_8), 0, 2, -1, true)); assertEquals(TestIntEnum.MEDIUM, typeConverter.to("20".getBytes(StandardCharsets.UTF_8), 0, 2, -1, true)); assertEquals(TestIntEnum.LOW, typeConverter.to("10".getBytes(StandardCharsets.UTF_8), 0, 2, -1, true)); }
@Test public void testToNullDefaultValue() throws Exception { config.setNullFillerChar((char)0); config.setDefaultValue("10"); typeConverter.initialize(config); assertEquals(TestIntEnum.LOW, typeConverter.to(new byte[4], 0, 2, 2, true)); }
@Test public void testToNullValue() throws Exception { expectedEx.expect(NumberFormatException.class); expectedEx.expectMessage("For input string"); config.setNullFillerChar((char)0); typeConverter.initialize(config); assertEquals(null, typeConverter.to(new byte[4], 0, 2, 2, true)); }