SimpleBean data = new SimpleBean().setS("Main").setBeanMap(
ImmutableMap.<String, SimpleBean>of( "s1", new SimpleBean().setS("sub1").setList(list),
"s2", new SimpleBean().setS("sub2").setList(list).setBeanMap(
ImmutableMap.of("s2s1", new SimpleBean().setS("sub2-sub1"))
)));
SimpleBeanInterface dataBean = (SimpleBeanInterface) beanDelegator.createDelegator(data);
SimpleBeanInterface newData = (SimpleBeanInterface) beanFilter.createFilteredBean(dataBean,
ImmutableSet.<String>of("beanmap"));
assertEquals(2, newData.getBeanMap().size());
assertEquals(null, newData.getBeanMap().get("s1").getS());
newData = (SimpleBeanInterface) beanFilter.createFilteredBean(dataBean,
ImmutableSet.<String>of("beanmap", "beanmap.s"));
assertNotSame(dataBean.getBeanMap().getClass(), newData.getBeanMap().getClass());
assertEquals(2, newData.getBeanMap().size());
assertEquals("sub1", newData.getBeanMap().get("s1").getS());
assertNull("List is filtered out", newData.getBeanMap().get("s1").getList());
newData = (SimpleBeanInterface) beanFilter.createFilteredBean(dataBean,
ImmutableSet.<String>of("beanmap", "beanmap.*"));
// Verify filter is a simple pass through.
// can only check class since each time different delegator is created
assertSame(dataBean.getBeanMap().getClass(), newData.getBeanMap().getClass());
newData = (SimpleBeanInterface) beanFilter.createFilteredBean(dataBean,
ImmutableSet.<String>of("beanmap", "beanmap.beanmap", "beanmap.beanmap.s"));
assertEquals(2, newData.getBeanMap().size());
Map<String, SimpleBeanInterface> subSubMap = newData.getBeanMap().get("s2").getBeanMap();
assertEquals(1, subSubMap.size());
assertEquals("sub2-sub1", subSubMap.get("s2s1").getS());
assertNull("list is filtered", subSubMap.get("s2s1").getList());
newData = (SimpleBeanInterface) beanFilter.createFilteredBean(dataBean,
ImmutableSet.<String>of("beanmap", "beanmap.beanmap", "beanmap.beanmap.*"));
assertEquals(2, newData.getBeanMap().size());
assertNotSame(dataBean.getBeanMap().getClass(), newData.getBeanMap().getClass());
assertSame(data.getBeanMap().get("s2").getBeanMap().getClass(),
newData.getBeanMap().get("s2").getBeanMap().getClass());
}