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");
}
Aggregations