]> source.dussan.org Git - vaadin-framework.git/commitdiff
Test for Window listeners (#4222)
authorArtur Signell <artur.signell@itmill.com>
Tue, 23 Feb 2010 07:58:38 +0000 (07:58 +0000)
committerArtur Signell <artur.signell@itmill.com>
Tue, 23 Feb 2010 07:58:38 +0000 (07:58 +0000)
svn changeset:11473/svn branch:6.2

tests/src/com/vaadin/tests/server/components/TestWindow.java [new file with mode: 0644]

diff --git a/tests/src/com/vaadin/tests/server/components/TestWindow.java b/tests/src/com/vaadin/tests/server/components/TestWindow.java
new file mode 100644 (file)
index 0000000..05604ab
--- /dev/null
@@ -0,0 +1,90 @@
+package com.vaadin.tests.server.components;\r
+\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+\r
+import junit.framework.TestCase;\r
+\r
+import org.easymock.EasyMock;\r
+\r
+import com.vaadin.ui.Window;\r
+import com.vaadin.ui.Window.CloseEvent;\r
+import com.vaadin.ui.Window.CloseListener;\r
+import com.vaadin.ui.Window.ResizeEvent;\r
+import com.vaadin.ui.Window.ResizeListener;\r
+\r
+public class TestWindow extends TestCase {\r
+\r
+    private Window window;\r
+\r
+    @Override\r
+    protected void setUp() throws Exception {\r
+        window = new Window();\r
+    }\r
+\r
+    public void testCloseListener() {\r
+        CloseListener cl = EasyMock.createMock(Window.CloseListener.class);\r
+\r
+        // Expectations\r
+        cl.windowClose(EasyMock.isA(CloseEvent.class));\r
+\r
+        // Start actual test\r
+        EasyMock.replay(cl);\r
+\r
+        // Add listener and send a close event -> should end up in listener once\r
+        window.addListener(cl);\r
+        sendClose(window);\r
+\r
+        // Ensure listener was called once\r
+        EasyMock.verify(cl);\r
+\r
+        // Remove the listener and send close event -> should not end up in\r
+        // listener\r
+        window.removeListener(cl);\r
+        sendClose(window);\r
+\r
+        // Ensure listener still has been called only once\r
+        EasyMock.verify(cl);\r
+\r
+    }\r
+\r
+    public void testResizeListener() {\r
+        ResizeListener rl = EasyMock.createMock(Window.ResizeListener.class);\r
+\r
+        // Expectations\r
+        rl.windowResized(EasyMock.isA(ResizeEvent.class));\r
+\r
+        // Start actual test\r
+        EasyMock.replay(rl);\r
+\r
+        // Add listener and send a resize event -> should end up in listener\r
+        // once\r
+        window.addListener(rl);\r
+        sendResize(window);\r
+\r
+        // Ensure listener was called once\r
+        EasyMock.verify(rl);\r
+\r
+        // Remove the listener and send close event -> should not end up in\r
+        // listener\r
+        window.removeListener(rl);\r
+        sendResize(window);\r
+\r
+        // Ensure listener still has been called only once\r
+        EasyMock.verify(rl);\r
+\r
+    }\r
+\r
+    private void sendResize(Window window2) {\r
+        Map<String, Object> variables = new HashMap<String, Object>();\r
+        variables.put("height", 1234);\r
+        window.changeVariables(window, variables);\r
+\r
+    }\r
+\r
+    private static void sendClose(Window window) {\r
+        Map<String, Object> variables = new HashMap<String, Object>();\r
+        variables.put("close", true);\r
+        window.changeVariables(window, variables);\r
+    }\r
+}\r