TemplateSanitizer extends AbstractFieldSanitizer<String> { @Override public Optional<Object> apply(Object entity) { return entity != null ? apply(entity, "") : Optional.empty(); } TemplateSanitizer(Function<String, Optional<Object>> templateResolver,
                             Function<Class<?>, Boolean> innerEntityPredicate); @Override Optional<Object> apply(Object entity);  }
@Test public void testPrimitiveValueTemplate() throws Exception { Root root = new Root( null, new Child(null, 1, 2), null ); Optional<Object> sanitizedOpt = new TemplateSanitizer( path -> path.equals("child.childName") ? Optional.of("ChildGuest") : Optional.empty(), type -> true ).apply(root); assertThat(sanitizedOpt).isPresent(); Root sanitized = (Root) sanitizedOpt.get(); assertThat(sanitized.getName()).isNull(); assertThat(sanitized.getChild().getChildName()).isEqualTo("ChildGuest"); assertThat(sanitized.getChild().getMin()).isEqualTo(1); assertThat(sanitized.getChild().getMax()).isEqualTo(2); assertThat(sanitized.getNullableChild()).isNull(); }
@Test public void testCollectionTemplate() throws Exception { CollectionHolder root = new CollectionHolder(Collections.emptyList()); Optional<Object> sanitizedOpt = new TemplateSanitizer( path -> path.equals("values") ? Optional.of(asList("a", "b")) : Optional.empty(), type -> true ).apply(root); assertThat(sanitizedOpt).isPresent(); }