org.springframework.tests.sample.beans.BooleanTestBean Java Examples

The following examples show how to use org.springframework.tests.sample.beans.BooleanTestBean. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CustomEditorTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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());
}
 
Example #2
Source File: CustomEditorTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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);
}
 
Example #3
Source File: AbstractPropertyAccessorTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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());
}
 
Example #4
Source File: CustomEditorTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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());
}
 
Example #5
Source File: CustomEditorTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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);
}
 
Example #6
Source File: AbstractPropertyAccessorTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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());
}
 
Example #7
Source File: CustomEditorTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #8
Source File: CustomEditorTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #9
Source File: AbstractPropertyAccessorTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #10
Source File: CustomEditorTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@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
	}
}
 
Example #11
Source File: CustomEditorTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@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
	}
}
 
Example #12
Source File: CustomEditorTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@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
	}
}