Search in sources :

Example 1 with HtmlComponent

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);
    }
}
Also used : UI(com.vaadin.flow.component.UI) HtmlComponent(com.vaadin.flow.component.HtmlComponent) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with HtmlComponent

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;
    }
}
Also used : HtmlComponent(com.vaadin.flow.component.HtmlComponent) Tag(com.vaadin.flow.component.Tag)

Aggregations

HtmlComponent (com.vaadin.flow.component.HtmlComponent)2 Tag (com.vaadin.flow.component.Tag)1 UI (com.vaadin.flow.component.UI)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1