01: package org.uispec4j.interception.handlers;
02:
03: import junit.framework.Assert;
04: import org.uispec4j.Window;
05: import org.uispec4j.utils.Utils;
06:
07: public class ShownInterceptionDetectionHandler extends
08: AbstractInterceptionHandlerDecorator {
09: public static final String NO_WINDOW_WAS_SHOWN_ERROR_MESSAGE = "No window was shown (timeout expired)";
10:
11: private boolean windowWasShown = false;
12: private long waitTimeLimit;
13:
14: public ShownInterceptionDetectionHandler(
15: InterceptionHandler handler, long waitTimeLimit) {
16: super (handler);
17: this .waitTimeLimit = waitTimeLimit;
18: }
19:
20: public void process(Window window) {
21: windowWasShown = true;
22: super .process(window);
23: }
24:
25: public void waitWindow() {
26: long step = waitTimeLimit / 100;
27: for (int i = 0; i < 100; i++) {
28: if (windowWasShown) {
29: return;
30: }
31: Utils.sleep(step);
32: }
33: Assert.fail(NO_WINDOW_WAS_SHOWN_ERROR_MESSAGE);
34: }
35: }
|