Created
October 19, 2017 10:32
-
-
Save heruan/b252dee42f812450fbbcc8bcc0be44ac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/flow-html-components/src/test/java/com/vaadin/ui/html/ComponentProperty.java b/flow-html-components/src/test/java/com/vaadin/ui/html/ComponentProperty.java | |
index bd670982ff..c92bc10f41 100644 | |
--- a/flow-html-components/src/test/java/com/vaadin/ui/html/ComponentProperty.java | |
+++ b/flow-html-components/src/test/java/com/vaadin/ui/html/ComponentProperty.java | |
@@ -23,19 +23,20 @@ import com.vaadin.ui.Component; | |
public class ComponentProperty { | |
public String name; | |
- public Object defaultValue, otherValue; | |
+ public Object defaultValue, otherValue, clientDefault; | |
public boolean optional; | |
public boolean removeDefault; | |
public Class<?> type; | |
private Class<? extends Component> componentType; | |
- public <T> ComponentProperty(Class<? extends Component> componentType, | |
- String name, Class<T> type, T defaultValue, boolean optional, | |
- boolean removeDefault) { | |
+ public <S, T> ComponentProperty(Class<? extends Component> componentType, | |
+ String name, Class<T> type, T defaultValue, S clientDefault, | |
+ boolean optional, boolean removeDefault) { | |
this.componentType = componentType; | |
this.name = name; | |
this.type = type; | |
this.defaultValue = defaultValue; | |
+ this.clientDefault = clientDefault; | |
this.optional = optional; | |
this.removeDefault = removeDefault; | |
otherValue = name + name; | |
diff --git a/flow-html-components/src/test/java/com/vaadin/ui/html/ComponentTest.java b/flow-html-components/src/test/java/com/vaadin/ui/html/ComponentTest.java | |
index 7cd270f475..a4b38191e1 100644 | |
--- a/flow-html-components/src/test/java/com/vaadin/ui/html/ComponentTest.java | |
+++ b/flow-html-components/src/test/java/com/vaadin/ui/html/ComponentTest.java | |
@@ -76,7 +76,8 @@ public abstract class ComponentTest { | |
protected void addStringProperty(String propertyName, String defaultValue, | |
boolean removeDefault) { | |
- addProperty(propertyName, String.class, defaultValue, false, removeDefault); | |
+ addProperty(propertyName, String.class, defaultValue, false, | |
+ removeDefault); | |
} | |
protected void addOptionalStringProperty(String propertyName) { | |
@@ -90,9 +91,16 @@ public abstract class ComponentTest { | |
protected <U> void addProperty(String propertyName, Class<U> propertyType, | |
U defaultValue, boolean isOptional, boolean removeDefault) { | |
+ addProperty(propertyName, propertyType, defaultValue, defaultValue, | |
+ isOptional, removeDefault); | |
+ } | |
+ | |
+ protected <U, V> void addProperty(String propertyName, | |
+ Class<U> propertyType, U defaultValue, V clientDefault, | |
+ boolean isOptional, boolean removeDefault) { | |
properties.add(new ComponentProperty(getComponent().getClass(), | |
- propertyName, propertyType, defaultValue, isOptional, | |
- removeDefault)); | |
+ propertyName, propertyType, defaultValue, clientDefault, | |
+ isOptional, removeDefault)); | |
} | |
protected HtmlComponent createComponent() throws InstantiationException, | |
@@ -222,9 +230,8 @@ public abstract class ComponentTest { | |
private void testEmptyStringForOptionalStringProperty(ComponentProperty p) { | |
try { | |
p.setUsingSetter(component, ""); | |
- Assert.assertEquals( | |
- "The getter for '" + p.name | |
- + "' should return an empty optional after setting \"\"", | |
+ Assert.assertEquals("The getter for '" + p.name | |
+ + "' should return an empty optional after setting \"\"", | |
Optional.empty(), p.getUsingGetter(component)); | |
} catch (Exception e) { | |
throw new AssertionError(e); | |
@@ -234,9 +241,8 @@ public abstract class ComponentTest { | |
private void testNullForOptionalNonStringProperty(ComponentProperty p) { | |
try { | |
p.setUsingSetter(component, null); | |
- Assert.assertEquals( | |
- "Setting the property " + p.name | |
- + " to null should cause an empty optional to be returned by the getter", | |
+ Assert.assertEquals("Setting the property " + p.name | |
+ + " to null should cause an empty optional to be returned by the getter", | |
Optional.empty(), p.getUsingGetter(component)); | |
} catch (Exception e) { | |
throw new AssertionError( | |
@@ -244,7 +250,6 @@ public abstract class ComponentTest { | |
+ "' does not work when setting the value to null", | |
e); | |
} | |
- | |
} | |
private void testNullForOptionalStringProperty(ComponentProperty p) { | |
@@ -259,7 +264,6 @@ public abstract class ComponentTest { | |
| NoSuchMethodException | SecurityException e) { | |
throw new AssertionError(e); | |
} | |
- | |
} | |
private void setDefaultValues() throws Exception { | |
@@ -283,6 +287,8 @@ public abstract class ComponentTest { | |
assertNoPropertyOrAttribute(component, property.name); | |
} else { | |
assertPropertyOrAttribute(component, property.name); | |
+ assertPropertyOrAttributeValue(component, property.name, | |
+ property.clientDefault); | |
} | |
} | |
} | |
@@ -334,4 +340,13 @@ public abstract class ComponentTest { | |
Assert.assertNotEquals(element.hasAttribute(propertyOrAttribute), | |
element.hasProperty(propertyOrAttribute)); | |
} | |
+ | |
+ private static void assertPropertyOrAttributeValue(Component component, | |
+ String propertyOrAttribute, Object value) { | |
+ Element element = component.getElement(); | |
+ String actual = element.hasAttribute(propertyOrAttribute) | |
+ ? element.getAttribute(propertyOrAttribute) | |
+ : element.getProperty(propertyOrAttribute); | |
+ Assert.assertEquals(value, actual); | |
+ } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment