@Test public void testFromOverflow() throws Exception { expectedEx.expect(TypeConverterException.class); expectedEx.expectMessage("Field to small for value"); byte[] bytes = typeConverter.from(TestIntEnum.MEDIUM, 1, -1, true); }
@Override public byte[] from(Object value, int length, int decimals, boolean addPadding) { if(value == null && this.defaultValue == null) { return null; } byte[] strBytes = fromEnumMap.get(value); if (strBytes.length > length) { throw new TypeConverterException("Field to small for value: " + length + " < " + strBytes.length); } if (addPadding) { strBytes = padBytes(strBytes, length); } return strBytes; }
IntegerToTypeConverterIntEnum extends IntegerToInteger { @Override public byte[] from(Object value, int length, int decimals, boolean addPadding) { if(value == null && this.defaultValue == null) { return null; } byte[] strBytes = fromEnumMap.get(value); if (strBytes.length > length) { throw new TypeConverterException("Field to small for value: " + length + " < " + strBytes.length); } if (addPadding) { strBytes = padBytes(strBytes, length); } return strBytes; } }
IntegerToTypeConverterIntEnum extends IntegerToInteger { @Override public byte[] from(Object value, int length, int decimals, boolean addPadding) { if(value == null && this.defaultValue == null) { return null; } byte[] strBytes = fromEnumMap.get(value); if (strBytes.length > length) { throw new TypeConverterException("Field to small for value: " + length + " < " + strBytes.length); } if (addPadding) { strBytes = padBytes(strBytes, length); } return strBytes; }  }
IntegerToTypeConverterIntEnum extends IntegerToInteger { @Override public byte[] from(Object value, int length, int decimals, boolean addPadding) { if(value == null && this.defaultValue == null) { return null; } byte[] strBytes = fromEnumMap.get(value); if (strBytes.length > length) { throw new TypeConverterException("Field to small for value: " + length + " < " + strBytes.length); } if (addPadding) { strBytes = padBytes(strBytes, length); } return strBytes; }  @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); }
IntegerToTypeConverterIntEnum extends IntegerToInteger { @Override public byte[] from(Object value, int length, int decimals, boolean addPadding) { if(value == null && this.defaultValue == null) { return null; } byte[] strBytes = fromEnumMap.get(value); if (strBytes.length > length) { throw new TypeConverterException("Field to small for value: " + length + " < " + strBytes.length); } if (addPadding) { strBytes = padBytes(strBytes, length); } return strBytes; }  @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);  }