]> source.dussan.org Git - vaadin-framework.git/commitdiff
Enable assertions for TestingWidgetset, add test to verify this
authorTeemu Suo-Anttila <teemusa@vaadin.com>
Wed, 31 Aug 2016 12:09:50 +0000 (15:09 +0300)
committerVaadin Code Review <review@vaadin.com>
Wed, 31 Aug 2016 13:03:35 +0000 (13:03 +0000)
Change-Id: I0c5fc24e490edc6e0d3fb7a9b1d2a71d564bb13c

uitest/pom.xml
uitest/src/main/java/com/vaadin/tests/widgetset/client/AssertionFailureWidget.java [new file with mode: 0644]
uitest/src/main/java/com/vaadin/tests/widgetset/server/AssertionsEnabled.java [new file with mode: 0644]
uitest/src/test/java/com/vaadin/tests/widgetset/server/AssertionsEnabledTest.java [new file with mode: 0644]

index 63e1f92a429d8e6602b9fc16e0bc79e6ed91a88f..6a6c94a627626f956214fb0e3e24752a7d587bf2 100644 (file)
@@ -50,7 +50,8 @@
                </dependency>
 
                <!-- jetty-servlets needed by ProxyTest, but not by jetty-runner -->
-               <!-- Jetty before vaadin-* on the classpath to make Eclipse use the right version -->
+               <!-- Jetty before vaadin-* on the classpath to make Eclipse use the right 
+                       version -->
                <dependency>
                        <groupId>org.eclipse.jetty</groupId>
                        <artifactId>jetty-server</artifactId>
 
                <!-- Servlet API -->
                <dependency>
-                       <!--  Jetty requires 3.1.0 -->
+                       <!-- Jetty requires 3.1.0 -->
                        <groupId>javax.servlet</groupId>
                        <artifactId>javax.servlet-api</artifactId>
                        <version>3.1.0</version>
                                        <warSourceDirectory>src/main/themes</warSourceDirectory>
                                        <webappDirectory>${project.build.outputDirectory}/VAADIN/widgetsets</webappDirectory>
                                        <persistentunitcachedir>${project.build.directory}/gwt-unitCache</persistentunitcachedir>
+                                       <checkAssertions>true</checkAssertions>
                                </configuration>
                                <executions>
                                        <execution>
diff --git a/uitest/src/main/java/com/vaadin/tests/widgetset/client/AssertionFailureWidget.java b/uitest/src/main/java/com/vaadin/tests/widgetset/client/AssertionFailureWidget.java
new file mode 100644 (file)
index 0000000..91e50fd
--- /dev/null
@@ -0,0 +1,18 @@
+package com.vaadin.tests.widgetset.client;
+
+import com.google.gwt.core.client.Scheduler;
+import com.google.gwt.user.client.ui.SimplePanel;
+import com.vaadin.client.ui.VLabel;
+
+public class AssertionFailureWidget extends SimplePanel {
+
+    public AssertionFailureWidget() {
+        Scheduler.get().scheduleDeferred(() -> {
+            assert 1 == 2 : "This should fail.";
+            VLabel w = new VLabel();
+            add(w);
+            w.setText("This should not be here.");
+            w.addStyleName("non-existent-widget");
+        });
+    }
+}
diff --git a/uitest/src/main/java/com/vaadin/tests/widgetset/server/AssertionsEnabled.java b/uitest/src/main/java/com/vaadin/tests/widgetset/server/AssertionsEnabled.java
new file mode 100644 (file)
index 0000000..a844a68
--- /dev/null
@@ -0,0 +1,16 @@
+package com.vaadin.tests.widgetset.server;
+
+import com.vaadin.annotations.Widgetset;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.tests.widgetset.TestingWidgetSet;
+import com.vaadin.tests.widgetset.client.AssertionFailureWidget;
+
+@Widgetset(TestingWidgetSet.NAME)
+public class AssertionsEnabled extends AbstractTestUI {
+
+    @Override
+    protected void setup(VaadinRequest request) {
+        addComponent(new TestWidgetComponent(AssertionFailureWidget.class));
+    }
+}
diff --git a/uitest/src/test/java/com/vaadin/tests/widgetset/server/AssertionsEnabledTest.java b/uitest/src/test/java/com/vaadin/tests/widgetset/server/AssertionsEnabledTest.java
new file mode 100644 (file)
index 0000000..f6bbe2d
--- /dev/null
@@ -0,0 +1,30 @@
+package com.vaadin.tests.widgetset.server;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.vaadin.testbench.By;
+import com.vaadin.testbench.elements.NotificationElement;
+import com.vaadin.tests.tb3.SingleBrowserTest;
+
+public class AssertionsEnabledTest extends SingleBrowserTest {
+
+    private static final String FAILING_CLASSNAME = "non-existent-widget";
+
+    @Test
+    public void testAssertionsAreEnabled() {
+        setDebug(true);
+        openTestURL();
+
+        // If assertions are disabled, the AssertionFailureWidget will add a
+        // label to the UI.
+        Assert.assertFalse(
+                "Label with classname " + FAILING_CLASSNAME
+                        + " should not exist",
+                isElementPresent(By.className(FAILING_CLASSNAME)));
+
+        Assert.assertTrue("Assertion error Notification is not present",
+                isElementPresent(NotificationElement.class));
+    }
+
+}