Search in sources :

Example 1 with BooleanTestBean

use of cn.taketoday.beans.BooleanTestBean in project today-infrastructure by TAKETODAY.

the class CustomEditorTests method testDefaultBooleanEditorForPrimitiveType.

@Test
void testDefaultBooleanEditorForPrimitiveType() {
    BooleanTestBean tb = new BooleanTestBean();
    BeanWrapper bw = new BeanWrapperImpl(tb);
    bw.setPropertyValue("bool1", "true");
    assertThat(Boolean.TRUE.equals(bw.getPropertyValue("bool1"))).as("Correct bool1 value").isTrue();
    assertThat(tb.isBool1()).as("Correct bool1 value").isTrue();
    bw.setPropertyValue("bool1", "false");
    assertThat(Boolean.FALSE.equals(bw.getPropertyValue("bool1"))).as("Correct bool1 value").isTrue();
    boolean condition4 = !tb.isBool1();
    assertThat(condition4).as("Correct bool1 value").isTrue();
    bw.setPropertyValue("bool1", "  true  ");
    assertThat(tb.isBool1()).as("Correct bool1 value").isTrue();
    bw.setPropertyValue("bool1", "  false  ");
    boolean condition3 = !tb.isBool1();
    assertThat(condition3).as("Correct bool1 value").isTrue();
    bw.setPropertyValue("bool1", "on");
    assertThat(tb.isBool1()).as("Correct bool1 value").isTrue();
    bw.setPropertyValue("bool1", "off");
    boolean condition2 = !tb.isBool1();
    assertThat(condition2).as("Correct bool1 value").isTrue();
    bw.setPropertyValue("bool1", "yes");
    assertThat(tb.isBool1()).as("Correct bool1 value").isTrue();
    bw.setPropertyValue("bool1", "no");
    boolean condition1 = !tb.isBool1();
    assertThat(condition1).as("Correct bool1 value").isTrue();
    bw.setPropertyValue("bool1", "1");
    assertThat(tb.isBool1()).as("Correct bool1 value").isTrue();
    bw.setPropertyValue("bool1", "0");
    boolean condition = !tb.isBool1();
    assertThat(condition).as("Correct bool1 value").isTrue();
    assertThatExceptionOfType(BeansException.class).isThrownBy(() -> bw.setPropertyValue("bool1", "argh"));
}
Also used : BooleanTestBean(cn.taketoday.beans.BooleanTestBean) BeanWrapper(cn.taketoday.beans.BeanWrapper) BeanWrapperImpl(cn.taketoday.beans.BeanWrapperImpl) BeansException(cn.taketoday.beans.BeansException) Test(org.junit.jupiter.api.Test)

Example 2 with BooleanTestBean

use of cn.taketoday.beans.BooleanTestBean in project today-infrastructure by TAKETODAY.

the class CustomEditorTests method testDefaultBooleanEditorForWrapperType.

@Test
void testDefaultBooleanEditorForWrapperType() {
    BooleanTestBean tb = new BooleanTestBean();
    BeanWrapper bw = new BeanWrapperImpl(tb);
    bw.setPropertyValue("bool2", "true");
    assertThat(Boolean.TRUE.equals(bw.getPropertyValue("bool2"))).as("Correct bool2 value").isTrue();
    assertThat(tb.getBool2().booleanValue()).as("Correct bool2 value").isTrue();
    bw.setPropertyValue("bool2", "false");
    assertThat(Boolean.FALSE.equals(bw.getPropertyValue("bool2"))).as("Correct bool2 value").isTrue();
    boolean condition3 = !tb.getBool2();
    assertThat(condition3).as("Correct bool2 value").isTrue();
    bw.setPropertyValue("bool2", "on");
    assertThat(tb.getBool2().booleanValue()).as("Correct bool2 value").isTrue();
    bw.setPropertyValue("bool2", "off");
    boolean condition2 = !tb.getBool2();
    assertThat(condition2).as("Correct bool2 value").isTrue();
    bw.setPropertyValue("bool2", "yes");
    assertThat(tb.getBool2().booleanValue()).as("Correct bool2 value").isTrue();
    bw.setPropertyValue("bool2", "no");
    boolean condition1 = !tb.getBool2();
    assertThat(condition1).as("Correct bool2 value").isTrue();
    bw.setPropertyValue("bool2", "1");
    assertThat(tb.getBool2().booleanValue()).as("Correct bool2 value").isTrue();
    bw.setPropertyValue("bool2", "0");
    boolean condition = !tb.getBool2();
    assertThat(condition).as("Correct bool2 value").isTrue();
    bw.setPropertyValue("bool2", "");
    assertThat(tb.getBool2()).as("Correct bool2 value").isNull();
}
Also used : BooleanTestBean(cn.taketoday.beans.BooleanTestBean) BeanWrapper(cn.taketoday.beans.BeanWrapper) BeanWrapperImpl(cn.taketoday.beans.BeanWrapperImpl) Test(org.junit.jupiter.api.Test)

Example 3 with BooleanTestBean

use of cn.taketoday.beans.BooleanTestBean in project today-framework by TAKETODAY.

the class CustomEditorTests method testDefaultBooleanEditorForPrimitiveType.

@Test
void testDefaultBooleanEditorForPrimitiveType() {
    BooleanTestBean tb = new BooleanTestBean();
    BeanWrapper bw = new BeanWrapperImpl(tb);
    bw.setPropertyValue("bool1", "true");
    assertThat(Boolean.TRUE.equals(bw.getPropertyValue("bool1"))).as("Correct bool1 value").isTrue();
    assertThat(tb.isBool1()).as("Correct bool1 value").isTrue();
    bw.setPropertyValue("bool1", "false");
    assertThat(Boolean.FALSE.equals(bw.getPropertyValue("bool1"))).as("Correct bool1 value").isTrue();
    boolean condition4 = !tb.isBool1();
    assertThat(condition4).as("Correct bool1 value").isTrue();
    bw.setPropertyValue("bool1", "  true  ");
    assertThat(tb.isBool1()).as("Correct bool1 value").isTrue();
    bw.setPropertyValue("bool1", "  false  ");
    boolean condition3 = !tb.isBool1();
    assertThat(condition3).as("Correct bool1 value").isTrue();
    bw.setPropertyValue("bool1", "on");
    assertThat(tb.isBool1()).as("Correct bool1 value").isTrue();
    bw.setPropertyValue("bool1", "off");
    boolean condition2 = !tb.isBool1();
    assertThat(condition2).as("Correct bool1 value").isTrue();
    bw.setPropertyValue("bool1", "yes");
    assertThat(tb.isBool1()).as("Correct bool1 value").isTrue();
    bw.setPropertyValue("bool1", "no");
    boolean condition1 = !tb.isBool1();
    assertThat(condition1).as("Correct bool1 value").isTrue();
    bw.setPropertyValue("bool1", "1");
    assertThat(tb.isBool1()).as("Correct bool1 value").isTrue();
    bw.setPropertyValue("bool1", "0");
    boolean condition = !tb.isBool1();
    assertThat(condition).as("Correct bool1 value").isTrue();
    assertThatExceptionOfType(BeansException.class).isThrownBy(() -> bw.setPropertyValue("bool1", "argh"));
}
Also used : BooleanTestBean(cn.taketoday.beans.BooleanTestBean) BeanWrapper(cn.taketoday.beans.BeanWrapper) BeanWrapperImpl(cn.taketoday.beans.BeanWrapperImpl) BeansException(cn.taketoday.beans.BeansException) Test(org.junit.jupiter.api.Test)

Example 4 with BooleanTestBean

use of cn.taketoday.beans.BooleanTestBean in project today-framework by TAKETODAY.

the class CustomEditorTests method testDefaultBooleanEditorForWrapperType.

@Test
void testDefaultBooleanEditorForWrapperType() {
    BooleanTestBean tb = new BooleanTestBean();
    BeanWrapper bw = new BeanWrapperImpl(tb);
    bw.setPropertyValue("bool2", "true");
    assertThat(Boolean.TRUE.equals(bw.getPropertyValue("bool2"))).as("Correct bool2 value").isTrue();
    assertThat(tb.getBool2().booleanValue()).as("Correct bool2 value").isTrue();
    bw.setPropertyValue("bool2", "false");
    assertThat(Boolean.FALSE.equals(bw.getPropertyValue("bool2"))).as("Correct bool2 value").isTrue();
    boolean condition3 = !tb.getBool2();
    assertThat(condition3).as("Correct bool2 value").isTrue();
    bw.setPropertyValue("bool2", "on");
    assertThat(tb.getBool2().booleanValue()).as("Correct bool2 value").isTrue();
    bw.setPropertyValue("bool2", "off");
    boolean condition2 = !tb.getBool2();
    assertThat(condition2).as("Correct bool2 value").isTrue();
    bw.setPropertyValue("bool2", "yes");
    assertThat(tb.getBool2().booleanValue()).as("Correct bool2 value").isTrue();
    bw.setPropertyValue("bool2", "no");
    boolean condition1 = !tb.getBool2();
    assertThat(condition1).as("Correct bool2 value").isTrue();
    bw.setPropertyValue("bool2", "1");
    assertThat(tb.getBool2().booleanValue()).as("Correct bool2 value").isTrue();
    bw.setPropertyValue("bool2", "0");
    boolean condition = !tb.getBool2();
    assertThat(condition).as("Correct bool2 value").isTrue();
    bw.setPropertyValue("bool2", "");
    assertThat(tb.getBool2()).as("Correct bool2 value").isNull();
}
Also used : BooleanTestBean(cn.taketoday.beans.BooleanTestBean) BeanWrapper(cn.taketoday.beans.BeanWrapper) BeanWrapperImpl(cn.taketoday.beans.BeanWrapperImpl) Test(org.junit.jupiter.api.Test)

Example 5 with BooleanTestBean

use of cn.taketoday.beans.BooleanTestBean in project today-framework by TAKETODAY.

the class CustomEditorTests method testCustomBooleanEditorWithAllowEmpty.

@Test
void testCustomBooleanEditorWithAllowEmpty() {
    BooleanTestBean tb = new BooleanTestBean();
    BeanWrapper bw = new BeanWrapperImpl(tb);
    bw.registerCustomEditor(Boolean.class, new CustomBooleanEditor(true));
    bw.setPropertyValue("bool2", "true");
    assertThat(Boolean.TRUE.equals(bw.getPropertyValue("bool2"))).as("Correct bool2 value").isTrue();
    assertThat(tb.getBool2().booleanValue()).as("Correct bool2 value").isTrue();
    bw.setPropertyValue("bool2", "false");
    assertThat(Boolean.FALSE.equals(bw.getPropertyValue("bool2"))).as("Correct bool2 value").isTrue();
    boolean condition3 = !tb.getBool2();
    assertThat(condition3).as("Correct bool2 value").isTrue();
    bw.setPropertyValue("bool2", "on");
    assertThat(tb.getBool2().booleanValue()).as("Correct bool2 value").isTrue();
    bw.setPropertyValue("bool2", "off");
    boolean condition2 = !tb.getBool2();
    assertThat(condition2).as("Correct bool2 value").isTrue();
    bw.setPropertyValue("bool2", "yes");
    assertThat(tb.getBool2().booleanValue()).as("Correct bool2 value").isTrue();
    bw.setPropertyValue("bool2", "no");
    boolean condition1 = !tb.getBool2();
    assertThat(condition1).as("Correct bool2 value").isTrue();
    bw.setPropertyValue("bool2", "1");
    assertThat(tb.getBool2().booleanValue()).as("Correct bool2 value").isTrue();
    bw.setPropertyValue("bool2", "0");
    boolean condition = !tb.getBool2();
    assertThat(condition).as("Correct bool2 value").isTrue();
    bw.setPropertyValue("bool2", "");
    assertThat(bw.getPropertyValue("bool2")).as("Correct bool2 value").isNull();
    assertThat(tb.getBool2()).as("Correct bool2 value").isNull();
}
Also used : BooleanTestBean(cn.taketoday.beans.BooleanTestBean) BeanWrapper(cn.taketoday.beans.BeanWrapper) BeanWrapperImpl(cn.taketoday.beans.BeanWrapperImpl) Test(org.junit.jupiter.api.Test)

Aggregations

BeanWrapper (cn.taketoday.beans.BeanWrapper)6 BeanWrapperImpl (cn.taketoday.beans.BeanWrapperImpl)6 BooleanTestBean (cn.taketoday.beans.BooleanTestBean)6 Test (org.junit.jupiter.api.Test)6 BeansException (cn.taketoday.beans.BeansException)2