@@ -51,6 +51,11 @@ public class PassFailJFrame {
51
51
private static final int ROWS = 10 ;
52
52
private static final int COLUMNS = 40 ;
53
53
54
+ /**
55
+ * Prefix for the user-provided failure reason.
56
+ */
57
+ private static final String FAILURE_REASON = "Failure Reason:\n " ;
58
+
54
59
private static final List <Frame > frameList = new ArrayList <>();
55
60
private static final Timer timer = new Timer (0 , null );
56
61
private static final CountDownLatch latch = new CountDownLatch (1 );
@@ -130,8 +135,8 @@ private static void createUI(String title, String instructions,
130
135
long leftTime = tTimeout - (System .currentTimeMillis () - startTime );
131
136
if ((leftTime < 0 ) || failed ) {
132
137
timer .stop ();
133
- testFailedReason = "Failure Reason: \n "
134
- + "Timeout User did not perform testing." ;
138
+ testFailedReason = FAILURE_REASON
139
+ + "Timeout User did not perform testing." ;
135
140
timeout = true ;
136
141
latch .countDown ();
137
142
}
@@ -161,8 +166,8 @@ private static void createUI(String title, String instructions,
161
166
@ Override
162
167
public void windowClosing (WindowEvent e ) {
163
168
super .windowClosing (e );
164
- testFailedReason = "Failure Reason: \n "
165
- + "User closed the instruction Frame" ;
169
+ testFailedReason = FAILURE_REASON
170
+ + "User closed the instruction Frame" ;
166
171
failed = true ;
167
172
latch .countDown ();
168
173
}
@@ -236,7 +241,7 @@ private static void getFailureReason() {
236
241
237
242
JButton okButton = new JButton ("OK" );
238
243
okButton .addActionListener ((ae ) -> {
239
- testFailedReason = "Failure Reason: \n " + jTextArea .getText ();
244
+ testFailedReason = FAILURE_REASON + jTextArea .getText ();
240
245
dialog .setVisible (false );
241
246
});
242
247
@@ -314,7 +319,17 @@ public static void forcePass() {
314
319
* Forcibly fail the test.
315
320
*/
316
321
public static void forceFail () {
322
+ forceFail ("forceFail called" );
323
+ }
324
+
325
+ /**
326
+ * Forcibly fail the test and provide a reason.
327
+ *
328
+ * @param reason the reason why the test is failed
329
+ */
330
+ public static void forceFail (String reason ) {
317
331
failed = true ;
332
+ testFailedReason = FAILURE_REASON + reason ;
318
333
latch .countDown ();
319
334
}
320
335
}
0 commit comments