Search in sources :

Example 56 with PropertyEditorSupport

use of java.beans.PropertyEditorSupport in project jdk8u_jdk by JetBrains.

the class Test4274639 method main.

public static void main(String[] args) {
    TestBean bean = new TestBean(STRING_VALUE);
    if (!STRING_VALUE.equals(bean.getString()))
        throw new Error("unexpected string property: " + bean.getString());
    boolean string = false;
    boolean integer = false;
    for (PropertyDescriptor pd : BeanUtils.getPropertyDescriptors(bean.getClass())) {
        String name = pd.getName();
        System.out.println(" - " + name);
        if (name.equals(STRING_PROPERTY)) {
            // This tests createPropertyEditor such that the PropertyEditor
            // returned will have the bean as the source object.
            Class type = pd.getPropertyEditorClass();
            if (!StringEditor.class.equals(type))
                throw new Error("unexpected property editor type: " + type);
            PropertyEditor editor = pd.createPropertyEditor(bean);
            if (editor == null)
                throw new Error("property editor cannot be created");
            if (STRING_VALUE != editor.getValue())
                throw new Error("unexpected value: " + editor.getValue());
            Object source = ((PropertyEditorSupport) editor).getSource();
            if (source != bean)
                throw new Error("unexpected source: " + source);
            string = true;
        }
        if (name.equals(INTEGER_PROPERTY)) {
            // This tests createPropertyEditor such that the PropertyEditor
            // returned will be just a new instance
            Class type = pd.getPropertyEditorClass();
            if (!IntegerEditor.class.equals(type))
                throw new Error("unexpected property editor type: " + type);
            PropertyEditor editor = pd.createPropertyEditor(bean);
            if (editor == null)
                throw new Error("property editor cannot be created");
            if (INTEGER_VALUE != editor.getValue())
                throw new Error("unexpected value: " + editor.getValue());
            Object source = ((PropertyEditorSupport) editor).getSource();
            if (source != editor)
                throw new Error("unexpected source: " + source);
            integer = true;
        }
    }
    if (!string)
        throw new Error("string property is not tested");
    if (!integer)
        throw new Error("integer property is not tested");
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) PropertyEditor(java.beans.PropertyEditor) PropertyEditorSupport(java.beans.PropertyEditorSupport)

Aggregations

PropertyEditorSupport (java.beans.PropertyEditorSupport)56 Test (org.junit.Test)55 IndexedTestBean (org.springframework.tests.sample.beans.IndexedTestBean)37 TestBean (org.springframework.tests.sample.beans.TestBean)31 ITestBean (org.springframework.tests.sample.beans.ITestBean)30 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)23 BooleanTestBean (org.springframework.tests.sample.beans.BooleanTestBean)19 NumberTestBean (org.springframework.tests.sample.beans.NumberTestBean)19 BeanWrapper (org.springframework.beans.BeanWrapper)14 BeanWrapperImpl (org.springframework.beans.BeanWrapperImpl)14 DerivedTestBean (org.springframework.tests.sample.beans.DerivedTestBean)12 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)10 StringReader (java.io.StringReader)5 BigInteger (java.math.BigInteger)5 ArrayList (java.util.ArrayList)5 Document (org.dom4j.Document)5 Element (org.dom4j.Element)5 SAXReader (org.dom4j.io.SAXReader)5 HashMap (java.util.HashMap)4 List (java.util.List)4