IntegerToInteger extends TypeConverterBase { @Override public Object to(byte[] bytes, int offset, int length, int decimals, boolean removePadding) { if(this.defaultValue != null && ByteUtils.allEquals(bytes, this.nullFillerByte, offset, bytes.length)) { return Integer.parseInt(this.defaultValue); } else { return Integer.parseInt(getIntegerString(bytes, offset, length, removePadding)); } }  @Override void validate(Class<?> type, int size, int decimal); @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(0, (int)typeConverter.to("0".getBytes(StandardCharsets.UTF_8), 0, 1, -1, true)); assertEquals(9, (int)typeConverter.to("9".getBytes(StandardCharsets.UTF_8), 0, 1, -1, true)); assertEquals(10, (int)typeConverter.to("10".getBytes(StandardCharsets.UTF_8), 0, 2, -1, true)); assertEquals(12, (int)typeConverter.to("0012".getBytes(StandardCharsets.UTF_8), 0, 4, -1, true)); }
@Test public void testToZeroValue() throws Exception { assertEquals(0, (int)typeConverter.to("00000000".getBytes(StandardCharsets.UTF_8), 0, 8, -1, true)); }
@Test public void testToNullDefaultValue() throws Exception { config.setNullFillerChar((char)0); config.setDefaultValue("42"); typeConverter.initialize(config); assertEquals(42, (int)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)); }