aboutsummaryrefslogtreecommitdiffstats
path: root/compatibility-server/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'compatibility-server/src/test')
-rw-r--r--compatibility-server/src/test/java/com/vaadin/tests/server/AbstractPropertyListenersTest.java30
-rw-r--r--compatibility-server/src/test/java/com/vaadin/tests/server/PropertyFormatterTest.java75
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
+ }
+
+ }
+}