Add unit test for custom converter chaining.
@@ -403,6 +403,24 @@ public class ConverterTest {
assertArrayEquals(ia, adapted.convert("1,2").to(int[].class));
}
+ @Test
+ public void testCustomConverterChaining() {
+ ConverterBuilder cb = converter.newConverterBuilder();
+ cb.rule(Date.class,
+ (f,t) -> f instanceof String ? new Date(0) : ConverterFunction.CANNOT_HANDLE);
+ Converter c1 = cb.build();
+ assertEquals(new Date(0), c1.convert("something").to(Date.class));
+ assertEquals(new Date(0), c1.convert("foo").to(Date.class));
+
+ ConverterBuilder cb2 = c1.newConverterBuilder();
+ cb2.rule(Date.class,
+ (f,t) -> f.equals("foo") ? new Date(100000) : ConverterFunction.CANNOT_HANDLE);
+ Converter c2 = cb2.build();
+ assertEquals(new Date(0), c2.convert("something").to(Date.class));
+ assertEquals(new Date(100000), c2.convert("foo").to(Date.class));
+ }
+
+
@Test
public void testCustomErrorHandling() {
ConverterFunction func = new ConverterFunction() {
