Skip to content

Commit

Permalink
Add ErrorHandler to AbstractTestUI (#12256)
Browse files Browse the repository at this point in the history
* Add ErrorHandler to AbstractTestUI
  • Loading branch information
Ansku authored Mar 29, 2021
1 parent 8570d58 commit fe37cc4
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,7 @@ protected LinkedHashMap<String, Resource> createIconOptions(
return options;
}

@Override
protected void log(String msg) {
log.log(msg);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.io.File;

import com.vaadin.annotations.Widgetset;
import com.vaadin.server.DefaultErrorHandler;
import com.vaadin.server.ErrorHandler;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
import com.vaadin.server.WebBrowser;
Expand All @@ -19,12 +21,14 @@
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;

public abstract class AbstractTestUI extends UI {
public abstract class AbstractTestUI extends UI implements ErrorHandler {

@Override
public void init(VaadinRequest request) {
getPage().setTitle(getClass().getName());

setErrorHandler(this);

Label label = new Label(getTestDescription(), ContentMode.HTML);
label.setWidth("100%");

Expand Down Expand Up @@ -227,4 +231,18 @@ public void run() {
}
}.start();
}

@Override
public void error(com.vaadin.server.ErrorEvent event) {
final Throwable throwable = DefaultErrorHandler
.findRelevantThrowable(event.getThrowable());

log("Exception occurred, " + throwable.getClass().getName() + ": "
+ throwable.getMessage());
throwable.printStackTrace();
}

protected void log(String message) {
// NOP
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public void init(VaadinRequest request) {
((VerticalLayout) getContent()).addComponent(log, 0);
}

@Override
protected void log(String message) {
log.log(message);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.vaadin.tests.components.grid;

import java.util.ArrayList;
import java.util.List;

import com.vaadin.annotations.Widgetset;
import com.vaadin.data.provider.ListDataProvider;
import com.vaadin.server.VaadinRequest;
Expand All @@ -10,12 +13,8 @@
import com.vaadin.tests.data.bean.Sex;
import com.vaadin.ui.Button;
import com.vaadin.ui.Grid;
import com.vaadin.ui.TextField;
import com.vaadin.ui.renderers.TextRenderer;

import java.util.ArrayList;
import java.util.List;

@Widgetset("com.vaadin.DefaultWidgetSet")
public class GridNullSafeNestedPropertyColumn extends AbstractTestUI {

Expand All @@ -26,6 +25,8 @@ public class GridNullSafeNestedPropertyColumn extends AbstractTestUI {

@Override
protected void setup(VaadinRequest request) {
setErrorHandler(null);

Grid<Person> grid = new Grid<>(Person.class);
grid.setSizeFull();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
import java.util.Random;

import com.vaadin.annotations.Theme;
import com.vaadin.server.DefaultErrorHandler;
import com.vaadin.server.ErrorHandler;
import com.vaadin.shared.data.sort.SortDirection;
import com.vaadin.shared.ui.ContentMode;
import com.vaadin.tests.components.AbstractComponentTest;
Expand Down Expand Up @@ -78,8 +76,7 @@
* @author Vaadin Ltd
*/
@Theme("valo")
public class GridBasicFeatures extends AbstractComponentTest<Grid>
implements ErrorHandler {
public class GridBasicFeatures extends AbstractComponentTest<Grid> {

public static final String ROW_STYLE_GENERATOR_ROW_NUMBERS_FOR_3_OF_4 = "Row numbers for 3/4";
public static final String ROW_STYLE_GENERATOR_NONE = "None";
Expand Down Expand Up @@ -237,11 +234,6 @@ public Component getDetails(RowReference rowReference) {
}
};

public GridBasicFeatures() {
super();
setErrorHandler(this);
}

@Override
protected void createActions() {
super.createActions();
Expand Down Expand Up @@ -1711,14 +1703,4 @@ protected Class<Grid> getTestClass() {
return Grid.class;
}

@Override
public void error(com.vaadin.server.ErrorEvent event) {
final Throwable throwable = DefaultErrorHandler
.findRelevantThrowable(event.getThrowable());

log("Exception occurred, " + throwable.getClass().getName() + ": "
+ throwable.getMessage());
throwable.printStackTrace();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@ public void exceptionCanBeThrown() {
$(ButtonElement.class).get(2).click();

assertTrue(logContainsText("0. Throwing exception in access"));
assertTrue(logContainsText("1. firstFuture is done? true"));
assertTrue(logContainsText(
"2. Got exception from firstFuture: java.lang.RuntimeException: Catch me if you can"));
"1. Exception occurred, java.lang.RuntimeException: Catch me if you can"));
assertTrue(logContainsText("2. firstFuture is done? true"));
assertTrue(logContainsText(
"3. Got exception from firstFuture: java.lang.RuntimeException: Catch me if you can"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ public void changeListenerWorksAfterFirstUpload() throws IOException {

upload.click();

assertEquals("2. finished", getLogRow(0));
assertEquals("2. finished", getLogRow(1));
assertEquals(
"3. Exception occurred, com.vaadin.server.UploadException: Upload failed",
getLogRow(0));

tempFile = createTempFile();
fillPathToUploadInput(tempFile.getPath());

assertEquals("3. change", getLogRow(0));
assertEquals("4. change", getLogRow(0));
}

/**
Expand Down

0 comments on commit fe37cc4

Please sign in to comment.