diff options
author | Artur Signell <artur@vaadin.com> | 2016-08-26 11:36:24 +0300 |
---|---|---|
committer | Artur Signell <artur@vaadin.com> | 2016-08-26 18:08:07 +0000 |
commit | 13b99cfa265913ab8cb2d948f2ab2bf152a959e4 (patch) | |
tree | b4268a68c0703839f10b559972f7e9a7be8fb9b7 /compatibility-server/src/test | |
parent | 44cb252e45650c1a4686d7d695af99b04a284084 (diff) | |
download | vaadin-framework-13b99cfa265913ab8cb2d948f2ab2bf152a959e4.tar.gz vaadin-framework-13b99cfa265913ab8cb2d948f2ab2bf152a959e4.zip |
Move remaining Vaadin 7 classes to the compatibility package
Change-Id: I3be37350a638028d89fb527a3dfb09e74fdebeed
Diffstat (limited to 'compatibility-server/src/test')
2 files changed, 105 insertions, 0 deletions
diff --git a/compatibility-server/src/test/java/com/vaadin/tests/server/AbstractPropertyListenersTest.java b/compatibility-server/src/test/java/com/vaadin/tests/server/AbstractPropertyListenersTest.java new file mode 100644 index 0000000000..854f3666ac --- /dev/null +++ b/compatibility-server/src/test/java/com/vaadin/tests/server/AbstractPropertyListenersTest.java @@ -0,0 +1,30 @@ +package com.vaadin.tests.server; + +import org.junit.Test; + +import com.vaadin.tests.server.component.AbstractListenerMethodsTestBase; +import com.vaadin.v7.data.Property.ReadOnlyStatusChangeEvent; +import com.vaadin.v7.data.Property.ReadOnlyStatusChangeListener; +import com.vaadin.v7.data.Property.ValueChangeEvent; +import com.vaadin.v7.data.Property.ValueChangeListener; +import com.vaadin.v7.data.util.AbstractProperty; +import com.vaadin.v7.data.util.ObjectProperty; + +public class AbstractPropertyListenersTest + extends AbstractListenerMethodsTestBase { + + @Test + public void testValueChangeListenerAddGetRemove() throws Exception { + testListenerAddGetRemove(AbstractProperty.class, ValueChangeEvent.class, + ValueChangeListener.class, new ObjectProperty<String>("")); + } + + @Test + public void testReadOnlyStatusChangeListenerAddGetRemove() + throws Exception { + testListenerAddGetRemove(AbstractProperty.class, + ReadOnlyStatusChangeEvent.class, + ReadOnlyStatusChangeListener.class, + new ObjectProperty<String>("")); + } +} diff --git a/compatibility-server/src/test/java/com/vaadin/tests/server/PropertyFormatterTest.java b/compatibility-server/src/test/java/com/vaadin/tests/server/PropertyFormatterTest.java new file mode 100644 index 0000000000..775018642a --- /dev/null +++ b/compatibility-server/src/test/java/com/vaadin/tests/server/PropertyFormatterTest.java @@ -0,0 +1,75 @@ +package com.vaadin.tests.server; + +import static org.junit.Assert.assertTrue; + +import java.util.Date; + +import org.junit.Test; + +import com.vaadin.v7.data.util.ObjectProperty; +import com.vaadin.v7.data.util.PropertyFormatter; + +@SuppressWarnings("unchecked") +public class PropertyFormatterTest { + + class TestFormatter extends PropertyFormatter { + + @Override + public String format(Object value) { + boolean isCorrectType = getExpectedClass() + .isAssignableFrom(value.getClass()); + assertTrue(isCorrectType); + return "FOO"; + } + + @Override + public Object parse(String formattedValue) throws Exception { + return getExpectedClass().newInstance(); + } + } + + @SuppressWarnings("rawtypes") + private Class expectedClass; + + @SuppressWarnings("rawtypes") + private Class getExpectedClass() { + return expectedClass; + } + + /** + * The object passed to format should be same as property's type. + * + * @throws IllegalAccessException + * @throws InstantiationException + */ + @Test + @SuppressWarnings({ "rawtypes" }) + public void testCorrectTypeForFormat() + throws InstantiationException, IllegalAccessException { + Class[] testedTypes = new Class[] { Integer.class, Boolean.class, + Double.class, String.class, Date.class }; + Object[] testValues = new Object[] { new Integer(3), Boolean.FALSE, + new Double(3.3), "bar", new Date() }; + + int i = 0; + for (Class class1 : testedTypes) { + expectedClass = class1; + + TestFormatter formatter = new TestFormatter(); + + // Should just return null, without formatting + Object value = formatter.getValue(); + + // test with property which value is null + formatter.setPropertyDataSource( + new ObjectProperty(null, expectedClass)); + formatter.getValue(); // calls format + + // test with a value + formatter.setPropertyDataSource( + new ObjectProperty(testValues[i++], expectedClass)); + formatter.getValue(); // calls format + } + + } +} |