aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin/tests/components/SaneErrors.java
blob: b82c1dd18b15f326149480dde69de7f1b3ce1d1e (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package com.vaadin.tests.components;

import com.vaadin.event.ItemClickEvent;
import com.vaadin.event.ItemClickEvent.ItemClickListener;
import com.vaadin.server.VaadinRequest;
import com.vaadin.ui.AbstractComponent;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.Label;
import com.vaadin.ui.Table;
import com.vaadin.ui.Table.RowHeaderMode;
import com.vaadin.ui.VerticalLayout;

public class SaneErrors extends AbstractTestUI {

    @Override
    protected void setup(VaadinRequest request) {
        final Button b = new Button("Show me my NPE!");
        b.addClickListener(new ClickListener() {

            @Override
            public void buttonClick(ClickEvent event) {
                throwError();
            }

        });

        /*
         * Errors from "legacy variable changes"
         */
        final Table table = new Table();
        table.addItem("Show me my NPE!");
        table.setRowHeaderMode(RowHeaderMode.ID);
        table.addItemClickListener(new ItemClickListener() {
            @Override
            public void itemClick(ItemClickEvent event) {
                throwError();
            }
        });

        final VerticalLayout content = new VerticalLayout(b, table);

        /**
         * Button that shows reported exception for TB integration test
         */
        Button button = new Button("Collect exceptions", new ClickListener() {

            @Override
            public void buttonClick(ClickEvent event) {
                reportException(b, content);
                reportException(table, content);
            }

            private void reportException(final AbstractComponent b,
                    final VerticalLayout content) {
                String message = b.getErrorMessage().getFormattedHtmlMessage();
                message = message.replaceAll(".", ".");
                message = message.substring(message.indexOf("h2>") + 3,
                        message.indexOf("
"));
                Label label = new Label(message);
                content.addComponent(label);
            }
        });
        content.addComponent(button);

        setContent(content);

    }

    private void throwError() {
        Object o = null;
        o.getClass();
    }

    @Override
    protected String getTestDescription() {
        return "Vaadin should by default report exceptions relevant for the developer.";
    }

    @Override
    protected Integer getTicketNumber() {
        return 11599;
    }

}