1
2
3
4
5
6
7
8
9
10
11
12 package org.hyphenType.unittesting;
13
14 import java.util.ArrayList;
15
16 import org.hyphenType.input.UserInput;
17 import org.hyphenType.input.UserInputException;
18
19
20
21
22
23
24 public final class UnitTestingUserInput extends UserInput {
25
26
27
28
29
30
31
32
33 private ArrayList<Object> textUIInputs = new ArrayList<Object>();
34
35
36
37
38 private boolean textUIAvailable = true;
39
40
41
42
43 public void addTextUIInput(final Object input) {
44 textUIInputs.add(input);
45 }
46
47
48
49
50
51
52
53 public void setTextUIAvailable(final boolean available) {
54 this.textUIAvailable = available;
55 }
56
57 @Override
58 protected boolean isTextUIAvailable() {
59 return textUIAvailable;
60 }
61
62 @SuppressWarnings("unchecked")
63 @Override
64 protected <T> T readFromTextUI(final Class<T> type, final String message, final String regex) throws UserInputException {
65 if (textUIInputs.size() > 0) {
66 return (T) textUIInputs.remove(0);
67 } else {
68 throw new UserInputException("No input text available");
69 }
70 }
71
72
73
74
75
76
77
78
79 private ArrayList<Object> graphicalUIInputs = new ArrayList<Object>();
80
81
82
83
84 private boolean graphicalUIAvailable = true;
85
86
87
88
89 public void addGraphicalUIInput(final Object input) {
90 graphicalUIInputs.add(input);
91 }
92
93
94
95
96
97
98
99 public void setGraphicalUIAvailable(final boolean available) {
100 this.graphicalUIAvailable = available;
101 }
102
103 @Override
104 protected boolean isGraphicalUIAvailable() {
105 return graphicalUIAvailable;
106 }
107
108 @SuppressWarnings("unchecked")
109 @Override
110 protected <T> T readFromGraphicalUI(final Class<T> type, final String message, final String regex) throws UserInputException {
111 if (graphicalUIInputs.size() > 0) {
112 return (T) graphicalUIInputs.remove(0);
113 } else {
114 throw new UserInputException("No input text available");
115 }
116 }
117
118
119
120
121
122
123
124
125
126
127 public void addBothUIInput(final Object input) {
128 addTextUIInput(input);
129 addGraphicalUIInput(input);
130 }
131 }