use of org.springframework.tests.sample.beans.BooleanTestBean in project spring-framework by spring-projects.
the class CustomEditorTests method testCustomBooleanEditorWithAllowEmpty.
@Test
public void testCustomBooleanEditorWithAllowEmpty() {
BooleanTestBean tb = new BooleanTestBean();
BeanWrapper bw = new BeanWrapperImpl(tb);
bw.registerCustomEditor(Boolean.class, new CustomBooleanEditor(true));
bw.setPropertyValue("bool2", "true");
assertTrue("Correct bool2 value", Boolean.TRUE.equals(bw.getPropertyValue("bool2")));
assertTrue("Correct bool2 value", tb.getBool2().booleanValue());
bw.setPropertyValue("bool2", "false");
assertTrue("Correct bool2 value", Boolean.FALSE.equals(bw.getPropertyValue("bool2")));
assertTrue("Correct bool2 value", !tb.getBool2().booleanValue());
bw.setPropertyValue("bool2", "on");
assertTrue("Correct bool2 value", tb.getBool2().booleanValue());
bw.setPropertyValue("bool2", "off");
assertTrue("Correct bool2 value", !tb.getBool2().booleanValue());
bw.setPropertyValue("bool2", "yes");
assertTrue("Correct bool2 value", tb.getBool2().booleanValue());
bw.setPropertyValue("bool2", "no");
assertTrue("Correct bool2 value", !tb.getBool2().booleanValue());
bw.setPropertyValue("bool2", "1");
assertTrue("Correct bool2 value", tb.getBool2().booleanValue());
bw.setPropertyValue("bool2", "0");
assertTrue("Correct bool2 value", !tb.getBool2().booleanValue());
bw.setPropertyValue("bool2", "");
assertTrue("Correct bool2 value", bw.getPropertyValue("bool2") == null);
assertTrue("Correct bool2 value", tb.getBool2() == null);
}
use of org.springframework.tests.sample.beans.BooleanTestBean in project spring-framework by spring-projects.
the class AbstractPropertyAccessorTests method setBooleanProperty.
@Test
public void setBooleanProperty() {
BooleanTestBean target = new BooleanTestBean();
AbstractPropertyAccessor accessor = createAccessor(target);
accessor.setPropertyValue("bool2", "true");
assertTrue("Correct bool2 value", Boolean.TRUE.equals(accessor.getPropertyValue("bool2")));
assertTrue("Correct bool2 value", target.getBool2());
accessor.setPropertyValue("bool2", "false");
assertTrue("Correct bool2 value", Boolean.FALSE.equals(accessor.getPropertyValue("bool2")));
assertTrue("Correct bool2 value", !target.getBool2());
}
use of org.springframework.tests.sample.beans.BooleanTestBean in project spring-framework by spring-projects.
the class CustomEditorTests method testDefaultBooleanEditorForWrapperType.
@Test
public void testDefaultBooleanEditorForWrapperType() {
BooleanTestBean tb = new BooleanTestBean();
BeanWrapper bw = new BeanWrapperImpl(tb);
bw.setPropertyValue("bool2", "true");
assertTrue("Correct bool2 value", Boolean.TRUE.equals(bw.getPropertyValue("bool2")));
assertTrue("Correct bool2 value", tb.getBool2().booleanValue());
bw.setPropertyValue("bool2", "false");
assertTrue("Correct bool2 value", Boolean.FALSE.equals(bw.getPropertyValue("bool2")));
assertTrue("Correct bool2 value", !tb.getBool2().booleanValue());
bw.setPropertyValue("bool2", "on");
assertTrue("Correct bool2 value", tb.getBool2().booleanValue());
bw.setPropertyValue("bool2", "off");
assertTrue("Correct bool2 value", !tb.getBool2().booleanValue());
bw.setPropertyValue("bool2", "yes");
assertTrue("Correct bool2 value", tb.getBool2().booleanValue());
bw.setPropertyValue("bool2", "no");
assertTrue("Correct bool2 value", !tb.getBool2().booleanValue());
bw.setPropertyValue("bool2", "1");
assertTrue("Correct bool2 value", tb.getBool2().booleanValue());
bw.setPropertyValue("bool2", "0");
assertTrue("Correct bool2 value", !tb.getBool2().booleanValue());
bw.setPropertyValue("bool2", "");
assertNull("Correct bool2 value", tb.getBool2());
}
use of org.springframework.tests.sample.beans.BooleanTestBean in project spring-framework by spring-projects.
the class CustomEditorTests method testDefaultBooleanEditorForPrimitiveType.
@Test
public void testDefaultBooleanEditorForPrimitiveType() {
BooleanTestBean tb = new BooleanTestBean();
BeanWrapper bw = new BeanWrapperImpl(tb);
bw.setPropertyValue("bool1", "true");
assertTrue("Correct bool1 value", Boolean.TRUE.equals(bw.getPropertyValue("bool1")));
assertTrue("Correct bool1 value", tb.isBool1());
bw.setPropertyValue("bool1", "false");
assertTrue("Correct bool1 value", Boolean.FALSE.equals(bw.getPropertyValue("bool1")));
assertTrue("Correct bool1 value", !tb.isBool1());
bw.setPropertyValue("bool1", " true ");
assertTrue("Correct bool1 value", tb.isBool1());
bw.setPropertyValue("bool1", " false ");
assertTrue("Correct bool1 value", !tb.isBool1());
bw.setPropertyValue("bool1", "on");
assertTrue("Correct bool1 value", tb.isBool1());
bw.setPropertyValue("bool1", "off");
assertTrue("Correct bool1 value", !tb.isBool1());
bw.setPropertyValue("bool1", "yes");
assertTrue("Correct bool1 value", tb.isBool1());
bw.setPropertyValue("bool1", "no");
assertTrue("Correct bool1 value", !tb.isBool1());
bw.setPropertyValue("bool1", "1");
assertTrue("Correct bool1 value", tb.isBool1());
bw.setPropertyValue("bool1", "0");
assertTrue("Correct bool1 value", !tb.isBool1());
try {
bw.setPropertyValue("bool1", "argh");
fail("Should have thrown BeansException");
} catch (BeansException ex) {
// expected
}
}
Aggregations