aboutsummaryrefslogtreecommitdiffstats
path: root/compatibility-server/src/test/java/com/vaadin/data/fieldgroup/FieldGroupTest.java
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2016-08-18 18:04:59 +0300
committerArtur Signell <artur@vaadin.com>2016-08-20 00:08:44 +0300
commit6e0f2efe996cfd3b38c960e04cbced0a91215cf0 (patch)
tree9eafac7107b3d34d8d1e9bc7631a1debad4fd720 /compatibility-server/src/test/java/com/vaadin/data/fieldgroup/FieldGroupTest.java
parent016a2ceb86f771a3902ace98d9fe56351c0efdf2 (diff)
downloadvaadin-framework-6e0f2efe996cfd3b38c960e04cbced0a91215cf0.tar.gz
vaadin-framework-6e0f2efe996cfd3b38c960e04cbced0a91215cf0.zip
Move FieldGroup and Vaadin 7 Grid to compatibility package
Change-Id: I9aaef478e0b67462641239802b924b8461cb9225
Diffstat (limited to 'compatibility-server/src/test/java/com/vaadin/data/fieldgroup/FieldGroupTest.java')
-rw-r--r--compatibility-server/src/test/java/com/vaadin/data/fieldgroup/FieldGroupTest.java96
1 files changed, 96 insertions, 0 deletions
diff --git a/compatibility-server/src/test/java/com/vaadin/data/fieldgroup/FieldGroupTest.java b/compatibility-server/src/test/java/com/vaadin/data/fieldgroup/FieldGroupTest.java
new file mode 100644
index 0000000000..c0039fc4fb
--- /dev/null
+++ b/compatibility-server/src/test/java/com/vaadin/data/fieldgroup/FieldGroupTest.java
@@ -0,0 +1,96 @@
+package com.vaadin.data.fieldgroup;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.nullValue;
+import static org.mockito.Mockito.mock;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.vaadin.data.Property;
+import com.vaadin.data.Property.Transactional;
+import com.vaadin.data.util.BeanItem;
+import com.vaadin.data.util.TransactionalPropertyWrapper;
+import com.vaadin.v7.ui.LegacyField;
+import com.vaadin.v7.ui.LegacyTextField;
+
+public class FieldGroupTest {
+
+ private FieldGroup sut;
+ private LegacyField field;
+
+ @Before
+ public void setup() {
+ sut = new FieldGroup();
+ field = mock(LegacyField.class);
+ }
+
+ @Test
+ public void fieldIsBound() {
+ sut.bind(field, "foobar");
+
+ assertThat(sut.getField("foobar"), is(field));
+ }
+
+ @Test(expected = FieldGroup.BindException.class)
+ public void cannotBindToAlreadyBoundProperty() {
+ sut.bind(field, "foobar");
+ sut.bind(mock(LegacyField.class), "foobar");
+ }
+
+ @Test(expected = FieldGroup.BindException.class)
+ public void cannotBindNullField() {
+ sut.bind(null, "foobar");
+ }
+
+ public void canUnbindWithoutItem() {
+ sut.bind(field, "foobar");
+
+ sut.unbind(field);
+ assertThat(sut.getField("foobar"), is(nullValue()));
+ }
+
+ @Test
+ public void wrapInTransactionalProperty_provideCustomImpl_customTransactionalWrapperIsUsed() {
+ Bean bean = new Bean();
+ FieldGroup group = new FieldGroup() {
+ @Override
+ protected <T> Transactional<T> wrapInTransactionalProperty(
+ Property<T> itemProperty) {
+ return new TransactionalPropertyImpl(itemProperty);
+ }
+ };
+ group.setItemDataSource(new BeanItem<Bean>(bean));
+ LegacyTextField field = new LegacyTextField();
+ group.bind(field, "name");
+
+ Property propertyDataSource = field.getPropertyDataSource();
+ Assert.assertTrue(
+ "Custom implementation of transactional property "
+ + "has not been used",
+ propertyDataSource instanceof TransactionalPropertyImpl);
+ }
+
+ public static class TransactionalPropertyImpl<T>
+ extends TransactionalPropertyWrapper<T> {
+
+ public TransactionalPropertyImpl(Property<T> wrappedProperty) {
+ super(wrappedProperty);
+ }
+
+ }
+
+ public static class Bean {
+ private String name;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+ }
+}