use of com.vaadin.flow.component.HtmlComponent in project flow by vaadin.
the class HtmlComponentSmokeTest method smokeTestComponent.
private static void smokeTestComponent(Class<? extends HtmlComponent> clazz) {
try {
// Test that an instance can be created
HtmlComponent instance = createInstance(clazz);
// Tests that a String constructor sets the text and not the tag
// name for a component with @Tag
testStringConstructor(clazz);
// Component must be attached for some checks to work
UI ui = new UI();
ui.add(instance);
// Test that all setters produce a result
testSetters(instance);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
throw new RuntimeException(e);
}
}
use of com.vaadin.flow.component.HtmlComponent in project flow by vaadin.
the class HtmlComponentSmokeTest method testStringConstructor.
private static void testStringConstructor(Class<? extends HtmlComponent> clazz) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
try {
String parameterValue = "Lorem";
Constructor<? extends HtmlComponent> constructor = clazz.getConstructor(String.class);
HtmlComponent instance = constructor.newInstance(parameterValue);
if (clazz.getAnnotation(Tag.class) == null) {
Assert.assertEquals(constructor + " should set the tag for a class without @Tag", parameterValue, instance.getElement().getTag());
} else {
Assert.assertEquals(constructor + " should set the text content for a class with @Tag", parameterValue, instance.getElement().getText());
}
} catch (NoSuchMethodException e) {
// No constructor to test
return;
}
}
Aggregations