StringToTypeConverterStringEnum extends StringToString { @Override public Object to(byte[] bytes, int offset, int length, int decimals, boolean removePadding) { String value = (String)super.to(bytes, offset, length, decimals, removePadding); if (toEnumMap.containsKey(value)) { return toEnumMap.get(value); } else { throw new TypeConverterException("Unknown value for enum: " + value); } }  @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(TestStringEnum.HIGH, typeConverter.to("HH".getBytes(StandardCharsets.UTF_8), 0, 2, -1, true)); assertEquals(TestStringEnum.MEDIUM, typeConverter.to("MM".getBytes(StandardCharsets.UTF_8), 0, 2, -1, true)); assertEquals(TestStringEnum.LOW, typeConverter.to("LL".getBytes(StandardCharsets.UTF_8), 0, 2, -1, true)); }
@Test public void testToNullDefaultValue() throws Exception { config.setNullFillerChar((char)0); config.setDefaultValue("MM"); typeConverter.initialize(config); assertEquals(TestStringEnum.MEDIUM, typeConverter.to(new byte[4], 0, 2, 2, true)); }
@Test public void testToNullValue() throws Exception { expectedEx.expect(TypeConverterException.class); expectedEx.expectMessage("Unknown value for enum: null"); config.setNullFillerChar((char)0); typeConverter.initialize(config); assertEquals(null, typeConverter.to(new byte[4], 0, 2, 2, true)); }