StringToString extends TypeConverterBase { @Override public Object to(byte[] bytes, int offset, int length, int decimals, boolean removePadding) { if(ByteUtils.allEquals(bytes, this.nullFillerByte, offset, bytes.length)) { if(this.defaultValue != null) { return this.defaultValue; } else { return null; } } else { return getString(bytes, offset, length, removePadding, 0); } }  @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("k", typeConverter.to("k".getBytes(StandardCharsets.UTF_8), 0, 1, -1, true)); assertEquals("ok", typeConverter.to("ok".getBytes(StandardCharsets.UTF_8), 0, 2, -1, true)); assertEquals("ab12", typeConverter.to("ab12".getBytes(StandardCharsets.UTF_8), 0, 4, -1, true)); assertEquals("12", typeConverter.to(" 12".getBytes(StandardCharsets.UTF_8), 0, 4, -1, true)); }
@Test public void testToZeroValue() throws Exception { assertEquals("", typeConverter.to(" ".getBytes(StandardCharsets.UTF_8), 0, 4, -1, true)); }
@Test public void testToNullValue() throws Exception { assertNull(typeConverter.to(new byte[] { (byte)0, (byte)0 }, 0, 2, -1, true)); }
@Test public void testToNullDefaultValue() throws Exception { config.setNullFillerChar((char)0); config.setDefaultValue("42"); typeConverter.initialize(config); assertEquals("42", typeConverter.to(new byte[4], 0, 2, 2, true)); }