diff options
author | Leif Åstrand <legioth@gmail.com> | 2017-01-28 15:06:40 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-28 15:06:40 +0200 |
commit | e7b49b4893607904bac69ca79e5ef583abfbe679 (patch) | |
tree | 0eb2c6100232251208989b51718475b5d3ddf739 | |
parent | 9ef479303bb514622ef90d95b94d912780c1812d (diff) | |
download | vaadin-framework-e7b49b4893607904bac69ca79e5ef583abfbe679.tar.gz vaadin-framework-e7b49b4893607904bac69ca79e5ef583abfbe679.zip |
Add regression tests for HasValue.getOptionalValue (#8352)
-rw-r--r-- | server/src/test/java/com/vaadin/data/HasValueTest.java | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/server/src/test/java/com/vaadin/data/HasValueTest.java b/server/src/test/java/com/vaadin/data/HasValueTest.java index b40b7e64a1..5f255454c9 100644 --- a/server/src/test/java/com/vaadin/data/HasValueTest.java +++ b/server/src/test/java/com/vaadin/data/HasValueTest.java @@ -15,9 +15,15 @@ */ package com.vaadin.data; +import java.time.LocalDate; + +import org.junit.Assert; import org.junit.Test; import org.mockito.Mockito; +import com.vaadin.ui.DateField; +import com.vaadin.ui.TextField; + /** * @author Vaadin Ltd * @@ -42,4 +48,42 @@ public class HasValueTest { Mockito.verify(hasValue).setValue(value); } + + @Test + public void getOptionalValue_nullableHasValue() { + HasValue<LocalDate> nullable = new DateField(); + + // Not using Assert since we're only verifying that DateField is working + // in a way appropriate for this test + assert nullable.isEmpty(); + assert nullable.getValue() == null; + + Assert.assertFalse(nullable.getOptionalValue().isPresent()); + + nullable.setValue(LocalDate.now()); + + assert !nullable.isEmpty(); + + Assert.assertSame(nullable.getValue(), + nullable.getOptionalValue().get()); + } + + @Test + public void getOptionalValue_nonNullableHasValue() { + HasValue<String> nonNullable = new TextField(); + + // Not using Assert since we're only verifying that TextField is working + // in a way appropriate for this test + assert nonNullable.isEmpty(); + assert nonNullable.getValue() != null; + + Assert.assertFalse(nonNullable.getOptionalValue().isPresent()); + + nonNullable.setValue("foo"); + + assert !nonNullable.isEmpty(); + + Assert.assertSame(nonNullable.getValue(), + nonNullable.getOptionalValue().get()); + } } |