My favorites
▼
|
Sign in
tumbler-glass
Behaviour-Driven Development tool for Java
Project Home
Downloads
Wiki
Issues
Source
READ-ONLY: This project has been
archived
. For more information see
this post
.
Search
Search within:
All issues
Open issues
New issues
Issues to verify
for
Advanced search
Search tips
Subscriptions
Issue
22
attachment: tumbler.patch
(7.1 KB)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# HG changeset patch
# User mbalbus
# Date 1358157320 -3600
# Node ID c99185120c47b7a627e6f7ee67184f3a61f14ebb
# Parent 1becb82093d0b9ccb6f5cd3dcf695dd6e56ed1a8
diff -r 1becb82093d0 -r c99185120c47 src/main/java/tumbler/TumblerRunner.java
--- a/src/main/java/tumbler/TumblerRunner.java Mon Jan 14 10:38:16 2013 +0100
+++ b/src/main/java/tumbler/TumblerRunner.java Mon Jan 14 10:55:20 2013 +0100
@@ -74,15 +74,13 @@
Statement methodBlock = methodBlock(method);
Description description = describeMethod(method);
- if (isPending(method))
- runScenario(true, description, notifier, methodBlock);
- else {
- TestMethod testMethod = parameterisedRunner.testMethodFor(method);
- if (parameterisedRunner.shouldRun(testMethod))
- parameterisedRunner.runParameterisedTest(testMethod, methodBlock, notifier);
- else
- runScenario(false, description, notifier, methodBlock);
- }
+ notifier = decorateWithNotificationStrategy(notifier, method);
+
+ TestMethod testMethod = parameterisedRunner.testMethodFor(method);
+ if (parameterisedRunner.shouldRun(testMethod)) {
+ parameterisedRunner.runParameterisedTest(testMethod, methodBlock, notifier);
+ } else
+ runScenario(isPending(method), description, notifier, methodBlock);
}
private boolean handleIgnored(FrameworkMethod method, RunNotifier notifier) {
@@ -93,6 +91,51 @@
return testMethod.isIgnored();
}
+ /**
+ * Wraps RunNotifier with RunNotifierWrapper and adds logic to deal with
+ * pending tests
+ *
+ * @param notifier
+ * @param method
+ * @return
+ */
+ private RunNotifier decorateWithNotificationStrategy(RunNotifier notifier, FrameworkMethod method) {
+ final boolean isPending = isPending(method);
+ return new RunNotifierWrapper(notifier) {
+
+ @Override
+ public void fireTestAssumptionFailed(Failure failure) {
+ if (!isPending)
+ wrappedNotifier.fireTestAssumptionFailed(failure);
+ }
+
+ @Override
+ public void fireTestFailure(Failure failure) {
+ if (!isPending)
+ wrappedNotifier.fireTestFailure(failure);
+ }
+
+ @Override
+ public void fireTestFinished(Description description) {
+ if (isPending) {
+ wrappedNotifier.fireTestIgnored(description);
+ scenarioListener.testFinished(description);
+ } else {
+ wrappedNotifier.fireTestFinished(description);
+ }
+ }
+
+ @Override
+ public void fireTestStarted(Description description) throws StoppedByUserException {
+ if (isPending)
+ scenarioListener.testStarted(description);
+ else
+ wrappedNotifier.fireTestStarted(description);
+ }
+
+ };
+ }
+
private boolean isPending(FrameworkMethod method) {
return method.getAnnotation(Scenario.class).pending();
}
@@ -100,10 +143,7 @@
private void runScenario(boolean pending, Description description, RunNotifier notifier, Statement methodInvoker) {
EachTestNotifier eachNotifier = new EachTestNotifier(notifier, description);
try {
- if (pending)
- scenarioListener.testStarted(description);
- else
- eachNotifier.fireTestStarted();
+ eachNotifier.fireTestStarted();
methodInvoker.evaluate();
} catch (Throwable e) {
@@ -113,9 +153,6 @@
eachNotifier.fireTestFinished();
}
- if (pending) {
- eachNotifier.fireTestIgnored();
- }
}
@Override
diff -r 1becb82093d0 -r c99185120c47 src/main/java/tumbler/internal/RunNotifierWrapper.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/tumbler/internal/RunNotifierWrapper.java Mon Jan 14 10:55:20 2013 +0100
@@ -0,0 +1,74 @@
+package tumbler.internal;
+
+import org.junit.runner.Description;
+import org.junit.runner.Result;
+import org.junit.runner.notification.Failure;
+import org.junit.runner.notification.RunListener;
+import org.junit.runner.notification.RunNotifier;
+import org.junit.runner.notification.StoppedByUserException;
+
+public class RunNotifierWrapper extends RunNotifier {
+
+ protected final RunNotifier wrappedNotifier;
+
+ public RunNotifierWrapper(RunNotifier runNotifier) {
+ super();
+ this.wrappedNotifier = runNotifier;
+ }
+
+ @Override
+ public void addFirstListener(RunListener listener) {
+ wrappedNotifier.addFirstListener(listener);
+ }
+
+ @Override
+ public void addListener(RunListener listener) {
+ wrappedNotifier.addListener(listener);
+ }
+
+ @Override
+ public void fireTestAssumptionFailed(Failure failure) {
+ wrappedNotifier.fireTestAssumptionFailed(failure);
+ }
+
+ @Override
+ public void fireTestFailure(Failure failure) {
+ wrappedNotifier.fireTestFailure(failure);
+ }
+
+ @Override
+ public void fireTestFinished(Description description) {
+ wrappedNotifier.fireTestFinished(description);
+ }
+
+ @Override
+ public void fireTestIgnored(Description description) {
+ wrappedNotifier.fireTestIgnored(description);
+ }
+
+ @Override
+ public void fireTestRunFinished(Result result) {
+ wrappedNotifier.fireTestRunFinished(result);
+ }
+
+ @Override
+ public void fireTestRunStarted(Description description) {
+ wrappedNotifier.fireTestRunStarted(description);
+ }
+
+ @Override
+ public void fireTestStarted(Description description) throws StoppedByUserException {
+ wrappedNotifier.fireTestStarted(description);
+ }
+
+ @Override
+ public void pleaseStop() {
+ wrappedNotifier.pleaseStop();
+ }
+
+ @Override
+ public void removeListener(RunListener listener) {
+ wrappedNotifier.removeListener(listener);
+ }
+
+}
diff -r 1becb82093d0 -r c99185120c47 src/main/java/tumbler/internal/ScenarioListener.java
--- a/src/main/java/tumbler/internal/ScenarioListener.java Mon Jan 14 10:38:16 2013 +0100
+++ b/src/main/java/tumbler/internal/ScenarioListener.java Mon Jan 14 10:55:20 2013 +0100
@@ -91,7 +91,7 @@
}
@Override
- public void testStarted(Description description) throws Exception {
+ public void testStarted(Description description) {
if (isItSingleScenario(description)) {
ScenarioManager.startScenario();
ScenarioManager.currentScenario().withStory(story);
@@ -107,7 +107,7 @@
}
@Override
- public void testFinished(Description description) throws Exception {
+ public void testFinished(Description description) {
if (isItSingleScenario(description)) {
ScenarioModel namedScenario = namedScenario(description);
story.addScenario(namedScenario);
@@ -183,4 +183,4 @@
public StoryFileWriter getWriter() {
return fileWriter;
}
-}
\ No newline at end of file
+}
Powered by
Google Project Hosting