aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/test/java/com/vaadin/tests/components/ui/UIAccessExceptionHandlingTest.java
blob: 6a973cdd51664053af1bd6a55e061f9b06a23b0c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.vaadin.tests.components.ui;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

import com.vaadin.testbench.elements.ButtonElement;
import com.vaadin.tests.tb3.SingleBrowserTest;

public class UIAccessExceptionHandlingTest extends SingleBrowserTest {

    @Test
    public void testExceptionHandlingOnUIAccess() throws Exception {
        openTestURL();
        $(ButtonElement.class).first().click();
        assertLogTexts(
                "1. Exception caught on get: java.util.concurrent.ExecutionException",
                "0. Exception caught on execution with ConnectorErrorEvent : java.lang.RuntimeException");

        $(ButtonElement.class).get(1).click();
        assertLogTexts(
                "1. Exception caught on get: java.util.concurrent.ExecutionException",
                "0. Exception caught on execution with ErrorEvent : java.lang.RuntimeException");

        $(ButtonElement.class).get(2).click();
        assertLogTexts(
                "1. Exception caught on get: java.util.concurrent.ExecutionException",
                "0. Exception caught on execution with ConnectorErrorEvent : java.lang.RuntimeException");

        $(ButtonElement.class).get(3).click();
        assertLogText(0,
                "0. Exception caught on execution with ConnectorErrorEvent : java.lang.NullPointerException");
    }

    private void assertLogTexts(String first, String second) {
        assertLogText(0, first);
        assertLogText(1, second);
    }

    private void assertLogText(int index, String expected) {
        assertEquals("Unexpected log contents,", expected, getLogRow(index));
    }
}