@Test public void testBindingWithSystemFieldError() { TestBean rod = new TestBean(); DataBinder binder = new DataBinder(rod, "person"); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.add("class.classLoader.URLs[0]", "http://myserver"); binder.setIgnoreUnknownFields(false); try { binder.bind(pvs); fail("Should have thrown NotWritablePropertyException"); } catch (NotWritablePropertyException ex) { assertTrue(ex.getMessage().contains("classLoader")); } }
@Test public void testStrict() throws Exception { BeanWrapperFieldSetMapper<TestObject> mapper = new BeanWrapperFieldSetMapper<>(); mapper.setStrict(true); mapper.setTargetType(TestObject.class); mapper.afterPropertiesSet(); FieldSet fieldSet = new DefaultFieldSet(new String[] { "This is some dummy string", "This won't be mapped", "true", "C" }, new String[] { "varString", "illegalPropertyName", "varBoolean", "varChar" }); try { mapper.mapFieldSet(fieldSet); fail("expected error"); } catch (NotWritablePropertyException e) { assertTrue(e.getMessage().contains("'illegalPropertyName'")); } }