01: // Copyright © 2006-2007 ASERT. Released under the Canoo Webtest license.
02: package com.canoo.webtest.extension.dialogs;
03:
04: import com.canoo.webtest.engine.Context;
05:
06: import java.util.List;
07: import java.util.ArrayList;
08:
09: /**
10: * Used by Dialog steps
11: *
12: * @author Paul King
13: */
14: public class DialogHelper {
15: private static final String EXPECTED_DIALOGS_KEY = "ExpectedDialogs";
16:
17: static int getExpectedDialogsCount(final Context context) {
18: return getExpectedDialogs(context).size();
19: }
20:
21: static void clearExpectedDialogs(final Context context) {
22: getExpectedDialogs(context).clear();
23: }
24:
25: static void addExpectedDialog(final Context context,
26: final AbstractDialogStep abstractDialogStep) {
27: getExpectedDialogs(context).add(abstractDialogStep);
28: }
29:
30: static AbstractDialogStep getNextExpectedDialog(
31: final Context context) {
32: final List expectedDialogs = getExpectedDialogs(context);
33: if (expectedDialogs.isEmpty()) {
34: return null;
35: }
36: final AbstractDialogStep this Dialog = (AbstractDialogStep) expectedDialogs
37: .get(0);
38: expectedDialogs.remove(0);
39: return this Dialog;
40: }
41:
42: private static List getExpectedDialogs(final Context context) {
43: initIfNeeded(context);
44: return (List) context.get(EXPECTED_DIALOGS_KEY);
45: }
46:
47: private static void initIfNeeded(final Context context) {
48: if (!context.containsKey(EXPECTED_DIALOGS_KEY)) {
49: context.put(EXPECTED_DIALOGS_KEY, new ArrayList());
50: }
51: }
52: }
|