summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorDenis <denis@vaadin.com>2016-12-06 21:34:59 +0200
committerPekka Hyvönen <pekka@vaadin.com>2016-12-06 21:34:59 +0200
commit77fd42425b59805b5c30dcafc3512eecaa78e24c (patch)
tree7fad3e2140311771b5f6e41ac18421cb31deeda6 /server
parent29f296d2d5a4a42035e543d7a139da8e8724bdda (diff)
downloadvaadin-framework-77fd42425b59805b5c30dcafc3512eecaa78e24c.tar.gz
vaadin-framework-77fd42425b59805b5c30dcafc3512eecaa78e24c.zip
Provide a shorthand for the HasValue::clear() method. (#94)
* Provide a shorthand for the HasValue::clear() method. Fixes vaadin/framework8-issues#496
Diffstat (limited to 'server')
-rw-r--r--server/src/main/java/com/vaadin/data/HasValue.java13
-rw-r--r--server/src/test/java/com/vaadin/server/data/HasValueTest.java47
2 files changed, 60 insertions, 0 deletions
diff --git a/server/src/main/java/com/vaadin/data/HasValue.java b/server/src/main/java/com/vaadin/data/HasValue.java
index 1a612dbb80..a7fe8901db 100644
--- a/server/src/main/java/com/vaadin/data/HasValue.java
+++ b/server/src/main/java/com/vaadin/data/HasValue.java
@@ -257,4 +257,17 @@ public interface HasValue<V> extends Serializable {
* not.
*/
public boolean isReadOnly();
+
+ /**
+ * Resets the value to the empty one.
+ * <p>
+ * This is just a shorthand for resetting the value, see the methods
+ * {@link #setValue(Object)} and {@link #getEmptyValue()}.
+ *
+ * @see #setValue(Object)
+ * @see #getEmptyValue()
+ */
+ public default void clear() {
+ setValue(getEmptyValue());
+ }
}
diff --git a/server/src/test/java/com/vaadin/server/data/HasValueTest.java b/server/src/test/java/com/vaadin/server/data/HasValueTest.java
new file mode 100644
index 0000000000..cc3815d0e5
--- /dev/null
+++ b/server/src/test/java/com/vaadin/server/data/HasValueTest.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.server.data;
+
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import com.vaadin.data.HasValue;
+
+/**
+ * @author Vaadin Ltd
+ *
+ */
+public class HasValueTest {
+
+ public abstract static class TestHasValue implements HasValue<String> {
+ @Override
+ public void clear() {
+ HasValue.super.clear();
+ }
+ }
+
+ @Test
+ public void clear() {
+ TestHasValue hasValue = Mockito.mock(TestHasValue.class);
+ Mockito.doCallRealMethod().when(hasValue).clear();
+ String value = "foo";
+ Mockito.when(hasValue.getEmptyValue()).thenReturn(value);
+
+ hasValue.clear();
+
+ Mockito.verify(hasValue).setValue(value);
+ }
+}