--- /dev/null
+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