summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2016-11-28 12:44:58 +0200
committerVaadin Code Review <review@vaadin.com>2016-11-29 07:44:02 +0000
commitf586bc155f7aa18cefd7b09f68ed2bf975e24174 (patch)
tree90bad1ec7da637def5c02b597242937c1c205d8f /server
parent3fd7537c14e63e7558acfa553f9996c6cfc323d6 (diff)
downloadvaadin-framework-f586bc155f7aa18cefd7b09f68ed2bf975e24174.tar.gz
vaadin-framework-f586bc155f7aa18cefd7b09f68ed2bf975e24174.zip
Ensure all BeanBinding chaining methods return BeanBinding
Change-Id: Ifbd5f278c83fcadbe6cf21d6c1f40914b35c4aba
Diffstat (limited to 'server')
-rw-r--r--server/src/main/java/com/vaadin/data/BeanBinder.java51
-rw-r--r--server/src/test/java/com/vaadin/data/BeanBinderTest.java24
2 files changed, 75 insertions, 0 deletions
diff --git a/server/src/main/java/com/vaadin/data/BeanBinder.java b/server/src/main/java/com/vaadin/data/BeanBinder.java
index 8bc207ae56..068b681d9c 100644
--- a/server/src/main/java/com/vaadin/data/BeanBinder.java
+++ b/server/src/main/java/com/vaadin/data/BeanBinder.java
@@ -40,6 +40,7 @@ import com.vaadin.data.validator.BeanValidator;
import com.vaadin.server.SerializableBiConsumer;
import com.vaadin.server.SerializableFunction;
import com.vaadin.server.SerializablePredicate;
+import com.vaadin.ui.Label;
import com.vaadin.util.ReflectTools;
/**
@@ -80,6 +81,32 @@ public class BeanBinder<BEAN> extends Binder<BEAN> {
}
@Override
+ default BeanBinding<BEAN, TARGET> withValidator(
+ SerializablePredicate<? super TARGET> predicate,
+ ErrorMessageProvider errorMessageProvider) {
+ return (BeanBinding<BEAN, TARGET>) Binding.super.withValidator(
+ predicate, errorMessageProvider);
+ }
+
+ @Override
+ default BeanBinding<BEAN, TARGET> withNullRepresentation(
+ TARGET nullRepresentation) {
+ return (BeanBinding<BEAN, TARGET>) Binding.super.withNullRepresentation(
+ nullRepresentation);
+ }
+
+ @Override
+ public BeanBinding<BEAN, TARGET> setRequired(
+ ErrorMessageProvider errorMessageProvider);
+
+ @Override
+ public default BeanBinding<BEAN, TARGET> setRequired(
+ String errorMessage) {
+ return (BeanBinding<BEAN, TARGET>) Binding.super.setRequired(
+ errorMessage);
+ }
+
+ @Override
public <NEWTARGET> BeanBinding<BEAN, NEWTARGET> withConverter(
Converter<TARGET, NEWTARGET> converter);
@@ -100,6 +127,16 @@ public class BeanBinder<BEAN> extends Binder<BEAN> {
toModel, toPresentation, errorMessage);
}
+ @Override
+ public BeanBinding<BEAN, TARGET> withValidationStatusHandler(
+ ValidationStatusHandler handler);
+
+ @Override
+ public default BeanBinding<BEAN, TARGET> withStatusLabel(Label label) {
+ return (BeanBinding<BEAN, TARGET>) Binding.super.withStatusLabel(
+ label);
+ }
+
/**
* Completes this binding by connecting the field to the property with
* the given name. The getter and setter methods of the property are
@@ -176,6 +213,20 @@ public class BeanBinder<BEAN> extends Binder<BEAN> {
}
@Override
+ public BeanBinding<BEAN, TARGET> withValidationStatusHandler(
+ ValidationStatusHandler handler) {
+ return (BeanBinding<BEAN, TARGET>) super.withValidationStatusHandler(
+ handler);
+ }
+
+ @Override
+ public BeanBinding<BEAN, TARGET> setRequired(
+ ErrorMessageProvider errorMessageProvider) {
+ return (BeanBinding<BEAN, TARGET>) super.setRequired(
+ errorMessageProvider);
+ }
+
+ @Override
public void bind(String propertyName) {
checkUnbound();
diff --git a/server/src/test/java/com/vaadin/data/BeanBinderTest.java b/server/src/test/java/com/vaadin/data/BeanBinderTest.java
index 117b4e81eb..08cdf38426 100644
--- a/server/src/test/java/com/vaadin/data/BeanBinderTest.java
+++ b/server/src/test/java/com/vaadin/data/BeanBinderTest.java
@@ -3,11 +3,15 @@ package com.vaadin.data;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
+import java.lang.reflect.Method;
import java.util.List;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
+import com.vaadin.data.BeanBinder.BeanBinding;
+import com.vaadin.data.Binder.Binding;
import com.vaadin.tests.data.bean.BeanToValidate;
public class BeanBinderTest
@@ -171,4 +175,24 @@ public class BeanBinderTest
assertSame(field, errors.get(0).getField());
assertEquals(message, errors.get(0).getMessage().get());
}
+
+ @Test
+ public void beanBindingChainingMethods() {
+ Method[] methods = BeanBinding.class.getMethods();
+ for (int i = 0; i < methods.length; i++) {
+ Method method = methods[i];
+ try {
+ Method actualMethod = BeanBinding.class.getMethod(
+ method.getName(), method.getParameterTypes());
+
+ Assert.assertNotSame(
+ actualMethod + " should be overridden in "
+ + BeanBinding.class
+ + " with more specific return type ",
+ Binding.class, actualMethod.getReturnType());
+ } catch (NoSuchMethodException | SecurityException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
}