]> source.dussan.org Git - vaadin-framework.git/commitdiff
Add ErrorHandler to AbstractTestUI (#12256)
authorAnna Koskinen <Ansku@users.noreply.github.com>
Mon, 29 Mar 2021 12:52:45 +0000 (15:52 +0300)
committerGitHub <noreply@github.com>
Mon, 29 Mar 2021 12:52:45 +0000 (15:52 +0300)
* Add ErrorHandler to AbstractTestUI

uitest/src/main/java/com/vaadin/tests/components/AbstractComponentTest.java
uitest/src/main/java/com/vaadin/tests/components/AbstractTestUI.java
uitest/src/main/java/com/vaadin/tests/components/AbstractTestUIWithLog.java
uitest/src/main/java/com/vaadin/tests/components/grid/GridNullSafeNestedPropertyColumn.java
uitest/src/main/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridBasicFeatures.java
uitest/src/test/java/com/vaadin/tests/components/ui/UIAccessTest.java
uitest/src/test/java/com/vaadin/tests/components/upload/UploadChangeListenerTest.java

index 7089a2e810557188a92e3392e26da5d26fb8145e..8a4499b10102377714fc1b4c32a2fa55aab671ae 100644 (file)
@@ -754,6 +754,7 @@ public abstract class AbstractComponentTest<T extends AbstractComponent> extends
         return options;
     }
 
+    @Override
     protected void log(String msg) {
         log.log(msg);
     }
index b030382ca6ba917a42c671aedb85679e0150f530..8255a21546a936387ed9b4dc1110a75f75e4d7c3 100644 (file)
@@ -3,6 +3,8 @@ package com.vaadin.tests.components;
 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;
@@ -19,12 +21,14 @@ import com.vaadin.ui.PushConfiguration;
 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%");
 
@@ -227,4 +231,18 @@ public abstract class AbstractTestUI extends UI {
             }
         }.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
+    }
 }
index 3905ea0ed5a76ba8a11ba73628b3c4b5b0daea29..2e2be536f9b6d0f8361000f7ba2e65ef57f83962 100644 (file)
@@ -14,6 +14,7 @@ public abstract class AbstractTestUIWithLog extends AbstractTestUI {
         ((VerticalLayout) getContent()).addComponent(log, 0);
     }
 
+    @Override
     protected void log(String message) {
         log.log(message);
     }
index 888296d5f8b6f128d49d3d5b07cd33c0c84ff04e..845a23ea48196acd10e7be70ad3e98def1d368f7 100644 (file)
@@ -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;
@@ -10,12 +13,8 @@ import com.vaadin.tests.data.bean.Person;
 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 {
 
@@ -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();
 
index cb9d4a25bdbdc364c7cb0e610aba246938136fd4..41a2d7b57ef2f1286a856627ee89585245a10417 100644 (file)
@@ -14,8 +14,6 @@ import java.util.Map;
 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;
@@ -78,8 +76,7 @@ import com.vaadin.v7.ui.renderers.NumberRenderer;
  * @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";
@@ -237,11 +234,6 @@ public class GridBasicFeatures extends AbstractComponentTest<Grid>
         }
     };
 
-    public GridBasicFeatures() {
-        super();
-        setErrorHandler(this);
-    }
-
     @Override
     protected void createActions() {
         super.createActions();
@@ -1711,14 +1703,4 @@ public class GridBasicFeatures extends AbstractComponentTest<Grid>
         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();
-    }
-
 }
index f1ac5a58414867900736bfac73f8f28eeb039bfb..3202d95e646d91fdea65dc18a0cf0f7d8769dba8 100644 (file)
@@ -60,9 +60,11 @@ public class UIAccessTest extends MultiBrowserTest {
         $(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
index a7e8a4e3cea099b1328585067d990b94528eee4c..a55029c249c887661d965e0c88f990c342ff0946 100644 (file)
@@ -30,12 +30,15 @@ public class UploadChangeListenerTest extends MultiBrowserTest {
 
         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));
     }
 
     /**