Lines 7-12
Link Here
|
7 |
* |
7 |
* |
8 |
* Contributors: |
8 |
* Contributors: |
9 |
* IBM Corporation - initial API and implementation |
9 |
* IBM Corporation - initial API and implementation |
|
|
10 |
* Alex Blewitt - https://bugs.eclipse.org/bugs/show_bug.cgi?id=168954 |
10 |
*******************************************************************************/ |
11 |
*******************************************************************************/ |
11 |
package org.eclipse.jdt.ui.tests.quickfix; |
12 |
package org.eclipse.jdt.ui.tests.quickfix; |
12 |
|
13 |
|
Lines 165-186
Link Here
|
165 |
buf.append(" * Sardinia during XP2000.\n"); |
166 |
buf.append(" * Sardinia during XP2000.\n"); |
166 |
buf.append(" */\n"); |
167 |
buf.append(" */\n"); |
167 |
buf.append("public abstract class BaseTestRunner implements TestListener {\n"); |
168 |
buf.append("public abstract class BaseTestRunner implements TestListener {\n"); |
168 |
buf.append(" public static final String SUITE_METHODNAME = \"suite\"; //$NON-NLS-1$\n"); |
169 |
buf.append(" static boolean fgFilterStack = true;\n"); |
169 |
buf.append("\n"); |
170 |
buf.append("\n"); |
170 |
buf.append(" private static Properties fPreferences;\n"); |
|
|
171 |
buf.append(" static int fgMaxMessageLength = 500;\n"); |
171 |
buf.append(" static int fgMaxMessageLength = 500;\n"); |
172 |
buf.append(" static boolean fgFilterStack = true;\n"); |
172 |
buf.append(" private static Properties fPreferences;\n"); |
173 |
buf.append(" boolean fLoading = true;\n"); |
173 |
buf.append(" public static final String SUITE_METHODNAME = \"suite\"; //$NON-NLS-1$\n"); |
|
|
174 |
buf.append(" static {\n"); |
175 |
buf.append(" BaseTestRunner.fgMaxMessageLength = BaseTestRunner.getPreference(\n"); |
176 |
buf.append(" \"maxmessage\", BaseTestRunner.fgMaxMessageLength); //$NON-NLS-1$\n"); |
177 |
buf.append(" }\n"); |
174 |
buf.append("\n"); |
178 |
buf.append("\n"); |
175 |
buf.append(" /*\n"); |
179 |
buf.append(" static boolean filterLine(final String line) {\n"); |
176 |
buf.append(" * Implementation of TestListener\n"); |
180 |
buf.append(" final String[] patterns = new String[]{\"junit.framework.TestCase\", //$NON-NLS-1$\n"); |
|
|
181 |
buf.append(" \"junit.framework.TestResult\", //$NON-NLS-1$\n"); |
182 |
buf.append(" \"junit.framework.TestSuite\", //$NON-NLS-1$\n"); |
183 |
buf.append(" \"junit.framework.Assert.\", // don't filter AssertionFailure\n"); |
184 |
buf.append(" // //$NON-NLS-1$\n"); |
185 |
buf.append(" \"junit.swingui.TestRunner\", //$NON-NLS-1$\n"); |
186 |
buf.append(" \"junit.awtui.TestRunner\", //$NON-NLS-1$\n"); |
187 |
buf.append(" \"junit.textui.TestRunner\", //$NON-NLS-1$\n"); |
188 |
buf.append(" \"java.lang.reflect.Method.invoke(\" //$NON-NLS-1$\n"); |
189 |
buf.append(" };\n"); |
190 |
buf.append(" for (final String element : patterns) {\n"); |
191 |
buf.append(" if (line.indexOf(element) > 0) {\n"); |
192 |
buf.append(" return true;\n"); |
193 |
buf.append(" }\n"); |
194 |
buf.append(" }\n"); |
195 |
buf.append(" return false;\n"); |
196 |
buf.append(" }\n"); |
197 |
buf.append("\n"); |
198 |
buf.append(" /**\n"); |
199 |
buf.append(" * Filters stack frames from internal JUnit classes\n"); |
177 |
buf.append(" */\n"); |
200 |
buf.append(" */\n"); |
178 |
buf.append(" public synchronized void startTest(final Test test) {\n"); |
201 |
buf.append(" public static String getFilteredTrace(final String stack) {\n"); |
179 |
buf.append(" this.testStarted(test.toString());\n"); |
202 |
buf.append(" if (BaseTestRunner.showStackRaw()) {\n"); |
|
|
203 |
buf.append(" return stack;\n"); |
204 |
buf.append(" }\n"); |
205 |
buf.append("\n"); |
206 |
buf.append(" final StringWriter sw = new StringWriter();\n"); |
207 |
buf.append(" final PrintWriter pw = new PrintWriter(sw);\n"); |
208 |
buf.append(" final StringReader sr = new StringReader(stack);\n"); |
209 |
buf.append(" final BufferedReader br = new BufferedReader(sr);\n"); |
210 |
buf.append("\n"); |
211 |
buf.append(" String line;\n"); |
212 |
buf.append(" try {\n"); |
213 |
buf.append(" while ((line = br.readLine()) != null) {\n"); |
214 |
buf.append(" if (!BaseTestRunner.filterLine(line)) {\n"); |
215 |
buf.append(" pw.println(line);\n"); |
216 |
buf.append(" }\n"); |
217 |
buf.append(" }\n"); |
218 |
buf.append(" } catch (final Exception IOException) {\n"); |
219 |
buf.append(" return stack; // return the stack unfiltered\n"); |
220 |
buf.append(" }\n"); |
221 |
buf.append(" return sw.toString();\n"); |
180 |
buf.append(" }\n"); |
222 |
buf.append(" }\n"); |
181 |
buf.append("\n"); |
223 |
buf.append("\n"); |
182 |
buf.append(" protected static void setPreferences(final Properties preferences) {\n"); |
224 |
buf.append(" /**\n"); |
183 |
buf.append(" BaseTestRunner.fPreferences = preferences;\n"); |
225 |
buf.append(" * Returns a filtered stack trace\n"); |
|
|
226 |
buf.append(" */\n"); |
227 |
buf.append(" public static String getFilteredTrace(final Throwable t) {\n"); |
228 |
buf.append(" final StringWriter stringWriter = new StringWriter();\n"); |
229 |
buf.append(" final PrintWriter writer = new PrintWriter(stringWriter);\n"); |
230 |
buf.append(" t.printStackTrace(writer);\n"); |
231 |
buf.append(" final StringBuffer buffer = stringWriter.getBuffer();\n"); |
232 |
buf.append(" final String trace = buffer.toString();\n"); |
233 |
buf.append(" return BaseTestRunner.getFilteredTrace(trace);\n"); |
234 |
buf.append(" }\n"); |
235 |
buf.append("\n"); |
236 |
buf.append(" public static String getPreference(final String key) {\n"); |
237 |
buf.append(" return BaseTestRunner.getPreferences().getProperty(key);\n"); |
238 |
buf.append(" }\n"); |
239 |
buf.append("\n"); |
240 |
buf.append(" public static int getPreference(final String key, final int dflt) {\n"); |
241 |
buf.append(" final String value = BaseTestRunner.getPreference(key);\n"); |
242 |
buf.append(" int intValue = dflt;\n"); |
243 |
buf.append(" if (value == null) {\n"); |
244 |
buf.append(" return intValue;\n"); |
245 |
buf.append(" }\n"); |
246 |
buf.append(" try {\n"); |
247 |
buf.append(" intValue = Integer.parseInt(value);\n"); |
248 |
buf.append(" } catch (final NumberFormatException ne) {\n"); |
249 |
buf.append(" }\n"); |
250 |
buf.append(" return intValue;\n"); |
184 |
buf.append(" }\n"); |
251 |
buf.append(" }\n"); |
185 |
buf.append("\n"); |
252 |
buf.append("\n"); |
186 |
buf.append(" protected static Properties getPreferences() {\n"); |
253 |
buf.append(" protected static Properties getPreferences() {\n"); |
Lines 193-198
Link Here
|
193 |
buf.append(" return BaseTestRunner.fPreferences;\n"); |
260 |
buf.append(" return BaseTestRunner.fPreferences;\n"); |
194 |
buf.append(" }\n"); |
261 |
buf.append(" }\n"); |
195 |
buf.append("\n"); |
262 |
buf.append("\n"); |
|
|
263 |
buf.append(" private static File getPreferencesFile() {\n"); |
264 |
buf.append(" final String home = System.getProperty(\"user.home\"); //$NON-NLS-1$\n"); |
265 |
buf.append(" return new File(home, \"junit.properties\"); //$NON-NLS-1$\n"); |
266 |
buf.append(" }\n"); |
267 |
buf.append("\n"); |
268 |
buf.append(" public static boolean inVAJava() {\n"); |
269 |
buf.append(" try {\n"); |
270 |
buf.append(" Class.forName(\"com.ibm.uvm.tools.DebugSupport\"); //$NON-NLS-1$\n"); |
271 |
buf.append(" } catch (final Exception e) {\n"); |
272 |
buf.append(" return false;\n"); |
273 |
buf.append(" }\n"); |
274 |
buf.append(" return true;\n"); |
275 |
buf.append(" }\n"); |
276 |
buf.append("\n"); |
277 |
buf.append(" // TestRunListener implementation\n"); |
278 |
buf.append("\n"); |
279 |
buf.append(" private static void readPreferences() {\n"); |
280 |
buf.append(" InputStream is = null;\n"); |
281 |
buf.append(" try {\n"); |
282 |
buf.append(" is = new FileInputStream(BaseTestRunner.getPreferencesFile());\n"); |
283 |
buf.append(" BaseTestRunner.setPreferences(new Properties(BaseTestRunner\n"); |
284 |
buf.append(" .getPreferences()));\n"); |
285 |
buf.append(" BaseTestRunner.getPreferences().load(is);\n"); |
286 |
buf.append(" } catch (final IOException e) {\n"); |
287 |
buf.append(" try {\n"); |
288 |
buf.append(" if (is != null) {\n"); |
289 |
buf.append(" is.close();\n"); |
290 |
buf.append(" }\n"); |
291 |
buf.append(" } catch (final IOException e1) {\n"); |
292 |
buf.append(" }\n"); |
293 |
buf.append(" }\n"); |
294 |
buf.append(" }\n"); |
295 |
buf.append("\n"); |
196 |
buf.append(" public static void savePreferences() throws IOException {\n"); |
296 |
buf.append(" public static void savePreferences() throws IOException {\n"); |
197 |
buf.append(" final FileOutputStream fos = new FileOutputStream(BaseTestRunner\n"); |
297 |
buf.append(" final FileOutputStream fos = new FileOutputStream(BaseTestRunner\n"); |
198 |
buf.append(" .getPreferencesFile());\n"); |
298 |
buf.append(" .getPreferencesFile());\n"); |
Lines 203-232
Link Here
|
203 |
buf.append(" }\n"); |
303 |
buf.append(" }\n"); |
204 |
buf.append(" }\n"); |
304 |
buf.append(" }\n"); |
205 |
buf.append("\n"); |
305 |
buf.append("\n"); |
206 |
buf.append(" public void setPreference(final String key, final String value) {\n"); |
306 |
buf.append(" protected static void setPreferences(final Properties preferences) {\n"); |
207 |
buf.append(" BaseTestRunner.getPreferences().setProperty(key, value);\n"); |
307 |
buf.append(" BaseTestRunner.fPreferences = preferences;\n"); |
208 |
buf.append(" }\n"); |
308 |
buf.append(" }\n"); |
209 |
buf.append("\n"); |
309 |
buf.append("\n"); |
210 |
buf.append(" public synchronized void endTest(final Test test) {\n"); |
310 |
buf.append(" protected static boolean showStackRaw() {\n"); |
211 |
buf.append(" this.testEnded(test.toString());\n"); |
311 |
buf.append(" return !BaseTestRunner.getPreference(\"filterstack\").equals(\"true\") || (BaseTestRunner.fgFilterStack == false); //$NON-NLS-1$ //$NON-NLS-2$\n"); |
|
|
312 |
buf.append(" }\n"); |
313 |
buf.append("\n"); |
314 |
buf.append(" /**\n"); |
315 |
buf.append(" * Truncates a String to the maximum length.\n"); |
316 |
buf.append(" */\n"); |
317 |
buf.append(" public static String truncate(String s) {\n"); |
318 |
buf.append(" if ((BaseTestRunner.fgMaxMessageLength != -1)\n"); |
319 |
buf.append(" && (s.length() > BaseTestRunner.fgMaxMessageLength)) {\n"); |
320 |
buf.append(" s = s.substring(0, BaseTestRunner.fgMaxMessageLength) + \"...\"; //$NON-NLS-1$\n"); |
321 |
buf.append(" }\n"); |
322 |
buf.append(" return s;\n"); |
212 |
buf.append(" }\n"); |
323 |
buf.append(" }\n"); |
213 |
buf.append("\n"); |
324 |
buf.append("\n"); |
|
|
325 |
buf.append(" boolean fLoading = true;\n"); |
326 |
buf.append("\n"); |
214 |
buf.append(" public synchronized void addError(final Test test, final Throwable t) {\n"); |
327 |
buf.append(" public synchronized void addError(final Test test, final Throwable t) {\n"); |
215 |
buf.append(" this.testFailed(TestRunListener.STATUS_ERROR, test, t);\n"); |
328 |
buf.append(" this.testFailed(TestRunListener.STATUS_ERROR, test, t);\n"); |
216 |
buf.append(" }\n"); |
329 |
buf.append(" }\n"); |
217 |
buf.append("\n"); |
|
|
218 |
buf.append(" public synchronized void addFailure(final Test test,\n"); |
330 |
buf.append(" public synchronized void addFailure(final Test test,\n"); |
219 |
buf.append(" final AssertionFailedError t) {\n"); |
331 |
buf.append(" final AssertionFailedError t) {\n"); |
220 |
buf.append(" this.testFailed(TestRunListener.STATUS_FAILURE, test, t);\n"); |
332 |
buf.append(" this.testFailed(TestRunListener.STATUS_FAILURE, test, t);\n"); |
221 |
buf.append(" }\n"); |
333 |
buf.append(" }\n"); |
222 |
buf.append("\n"); |
334 |
buf.append("\n"); |
223 |
buf.append(" // TestRunListener implementation\n"); |
335 |
buf.append(" /**\n"); |
|
|
336 |
buf.append(" * Clears the status message.\n"); |
337 |
buf.append(" */\n"); |
338 |
buf.append(" protected void clearStatus() { // Belongs in the GUI TestRunner class\n"); |
339 |
buf.append(" }\n"); |
224 |
buf.append("\n"); |
340 |
buf.append("\n"); |
225 |
buf.append(" public abstract void testStarted(String testName);\n"); |
341 |
buf.append(" /**\n"); |
|
|
342 |
buf.append(" * Returns the formatted string of the elapsed time.\n"); |
343 |
buf.append(" */\n"); |
344 |
buf.append(" public String elapsedTimeAsString(final long runTime) {\n"); |
345 |
buf.append(" return NumberFormat.getInstance().format((double) runTime / 1000);\n"); |
346 |
buf.append(" }\n"); |
226 |
buf.append("\n"); |
347 |
buf.append("\n"); |
227 |
buf.append(" public abstract void testEnded(String testName);\n"); |
348 |
buf.append(" public synchronized void endTest(final Test test) {\n"); |
|
|
349 |
buf.append(" this.testEnded(test.toString());\n"); |
350 |
buf.append(" }\n"); |
228 |
buf.append("\n"); |
351 |
buf.append("\n"); |
229 |
buf.append(" public abstract void testFailed(int status, Test test, Throwable t);\n"); |
352 |
buf.append(" /**\n"); |
|
|
353 |
buf.append(" * Extract the class name from a String in VA/Java style\n"); |
354 |
buf.append(" */\n"); |
355 |
buf.append(" public String extractClassName(final String className) {\n"); |
356 |
buf.append(" if (className.startsWith(\"Default package for\")) {\n"); |
357 |
buf.append(" return className.substring(className.lastIndexOf(\".\") + 1); //$NON-NLS-1$\n"); |
358 |
buf.append(" }\n"); |
359 |
buf.append(" return className;\n"); |
360 |
buf.append(" }\n"); |
361 |
buf.append("\n"); |
362 |
buf.append(" /**\n"); |
363 |
buf.append(" * Returns the loader to be used.\n"); |
364 |
buf.append(" */\n"); |
365 |
buf.append(" public TestSuiteLoader getLoader() {\n"); |
366 |
buf.append(" if (this.useReloadingTestSuiteLoader()) {\n"); |
367 |
buf.append(" return new ReloadingTestSuiteLoader();\n"); |
368 |
buf.append(" }\n"); |
369 |
buf.append(" return new StandardTestSuiteLoader();\n"); |
370 |
buf.append(" }\n"); |
230 |
buf.append("\n"); |
371 |
buf.append("\n"); |
231 |
buf.append(" /**\n"); |
372 |
buf.append(" /**\n"); |
232 |
buf.append(" * Returns the Test corresponding to the given suite. This is a template\n"); |
373 |
buf.append(" * Returns the Test corresponding to the given suite. This is a template\n"); |
Lines 285-294
Link Here
|
285 |
buf.append(" }\n"); |
426 |
buf.append(" }\n"); |
286 |
buf.append("\n"); |
427 |
buf.append("\n"); |
287 |
buf.append(" /**\n"); |
428 |
buf.append(" /**\n"); |
288 |
buf.append(" * Returns the formatted string of the elapsed time.\n"); |
429 |
buf.append(" * Returns the loaded Class for a suite name.\n"); |
289 |
buf.append(" */\n"); |
430 |
buf.append(" */\n"); |
290 |
buf.append(" public String elapsedTimeAsString(final long runTime) {\n"); |
431 |
buf.append(" protected Class loadSuiteClass(final String suiteClassName)\n"); |
291 |
buf.append(" return NumberFormat.getInstance().format((double) runTime / 1000);\n"); |
432 |
buf.append(" throws ClassNotFoundException {\n"); |
|
|
433 |
buf.append(" return this.getLoader().load(suiteClassName);\n"); |
292 |
buf.append(" }\n"); |
434 |
buf.append(" }\n"); |
293 |
buf.append("\n"); |
435 |
buf.append("\n"); |
294 |
buf.append(" /**\n"); |
436 |
buf.append(" /**\n"); |
Lines 317-493
Link Here
|
317 |
buf.append(" }\n"); |
459 |
buf.append(" }\n"); |
318 |
buf.append("\n"); |
460 |
buf.append("\n"); |
319 |
buf.append(" /**\n"); |
461 |
buf.append(" /**\n"); |
320 |
buf.append(" * Sets the loading behaviour of the test runner\n"); |
|
|
321 |
buf.append(" */\n"); |
322 |
buf.append(" public void setLoading(final boolean enable) {\n"); |
323 |
buf.append(" this.fLoading = enable;\n"); |
324 |
buf.append(" }\n"); |
325 |
buf.append(" /**\n"); |
326 |
buf.append(" * Extract the class name from a String in VA/Java style\n"); |
327 |
buf.append(" */\n"); |
328 |
buf.append(" public String extractClassName(final String className) {\n"); |
329 |
buf.append(" if (className.startsWith(\"Default package for\")) {\n"); |
330 |
buf.append(" return className.substring(className.lastIndexOf(\".\") + 1); //$NON-NLS-1$\n"); |
331 |
buf.append(" }\n"); |
332 |
buf.append(" return className;\n"); |
333 |
buf.append(" }\n"); |
334 |
buf.append("\n"); |
335 |
buf.append(" /**\n"); |
336 |
buf.append(" * Truncates a String to the maximum length.\n"); |
337 |
buf.append(" */\n"); |
338 |
buf.append(" public static String truncate(String s) {\n"); |
339 |
buf.append(" if ((BaseTestRunner.fgMaxMessageLength != -1)\n"); |
340 |
buf.append(" && (s.length() > BaseTestRunner.fgMaxMessageLength)) {\n"); |
341 |
buf.append(" s = s.substring(0, BaseTestRunner.fgMaxMessageLength) + \"...\"; //$NON-NLS-1$\n"); |
342 |
buf.append(" }\n"); |
343 |
buf.append(" return s;\n"); |
344 |
buf.append(" }\n"); |
345 |
buf.append("\n"); |
346 |
buf.append(" /**\n"); |
347 |
buf.append(" * Override to define how to handle a failed loading of a test suite.\n"); |
462 |
buf.append(" * Override to define how to handle a failed loading of a test suite.\n"); |
348 |
buf.append(" */\n"); |
463 |
buf.append(" */\n"); |
349 |
buf.append(" protected abstract void runFailed(String message);\n"); |
464 |
buf.append(" protected abstract void runFailed(String message);\n"); |
350 |
buf.append("\n"); |
465 |
buf.append("\n"); |
351 |
buf.append(" /**\n"); |
466 |
buf.append(" /**\n"); |
352 |
buf.append(" * Returns the loaded Class for a suite name.\n"); |
467 |
buf.append(" * Sets the loading behaviour of the test runner\n"); |
353 |
buf.append(" */\n"); |
|
|
354 |
buf.append(" protected Class loadSuiteClass(final String suiteClassName)\n"); |
355 |
buf.append(" throws ClassNotFoundException {\n"); |
356 |
buf.append(" return this.getLoader().load(suiteClassName);\n"); |
357 |
buf.append(" }\n"); |
358 |
buf.append("\n"); |
359 |
buf.append(" /**\n"); |
360 |
buf.append(" * Clears the status message.\n"); |
361 |
buf.append(" */\n"); |
362 |
buf.append(" protected void clearStatus() { // Belongs in the GUI TestRunner class\n"); |
363 |
buf.append(" }\n"); |
364 |
buf.append("\n"); |
365 |
buf.append(" /**\n"); |
366 |
buf.append(" * Returns the loader to be used.\n"); |
367 |
buf.append(" */\n"); |
468 |
buf.append(" */\n"); |
368 |
buf.append(" public TestSuiteLoader getLoader() {\n"); |
469 |
buf.append(" public void setLoading(final boolean enable) {\n"); |
369 |
buf.append(" if (this.useReloadingTestSuiteLoader()) {\n"); |
470 |
buf.append(" this.fLoading = enable;\n"); |
370 |
buf.append(" return new ReloadingTestSuiteLoader();\n"); |
|
|
371 |
buf.append(" }\n"); |
372 |
buf.append(" return new StandardTestSuiteLoader();\n"); |
373 |
buf.append(" }\n"); |
374 |
buf.append("\n"); |
375 |
buf.append(" protected boolean useReloadingTestSuiteLoader() {\n"); |
376 |
buf.append(" return BaseTestRunner.getPreference(\"loading\").equals(\"true\") && !BaseTestRunner.inVAJava() && this.fLoading; //$NON-NLS-1$ //$NON-NLS-2$\n"); |
377 |
buf.append(" }\n"); |
378 |
buf.append("\n"); |
379 |
buf.append(" private static File getPreferencesFile() {\n"); |
380 |
buf.append(" final String home = System.getProperty(\"user.home\"); //$NON-NLS-1$\n"); |
381 |
buf.append(" return new File(home, \"junit.properties\"); //$NON-NLS-1$\n"); |
382 |
buf.append(" }\n"); |
383 |
buf.append("\n"); |
384 |
buf.append(" private static void readPreferences() {\n"); |
385 |
buf.append(" InputStream is = null;\n"); |
386 |
buf.append(" try {\n"); |
387 |
buf.append(" is = new FileInputStream(BaseTestRunner.getPreferencesFile());\n"); |
388 |
buf.append(" BaseTestRunner.setPreferences(new Properties(BaseTestRunner\n"); |
389 |
buf.append(" .getPreferences()));\n"); |
390 |
buf.append(" BaseTestRunner.getPreferences().load(is);\n"); |
391 |
buf.append(" } catch (final IOException e) {\n"); |
392 |
buf.append(" try {\n"); |
393 |
buf.append(" if (is != null) {\n"); |
394 |
buf.append(" is.close();\n"); |
395 |
buf.append(" }\n"); |
396 |
buf.append(" } catch (final IOException e1) {\n"); |
397 |
buf.append(" }\n"); |
398 |
buf.append(" }\n"); |
399 |
buf.append(" }\n"); |
400 |
buf.append("\n"); |
401 |
buf.append(" public static String getPreference(final String key) {\n"); |
402 |
buf.append(" return BaseTestRunner.getPreferences().getProperty(key);\n"); |
403 |
buf.append(" }\n"); |
404 |
buf.append("\n"); |
405 |
buf.append(" public static int getPreference(final String key, final int dflt) {\n"); |
406 |
buf.append(" final String value = BaseTestRunner.getPreference(key);\n"); |
407 |
buf.append(" int intValue = dflt;\n"); |
408 |
buf.append(" if (value == null) {\n"); |
409 |
buf.append(" return intValue;\n"); |
410 |
buf.append(" }\n"); |
411 |
buf.append(" try {\n"); |
412 |
buf.append(" intValue = Integer.parseInt(value);\n"); |
413 |
buf.append(" } catch (final NumberFormatException ne) {\n"); |
414 |
buf.append(" }\n"); |
415 |
buf.append(" return intValue;\n"); |
416 |
buf.append(" }\n"); |
471 |
buf.append(" }\n"); |
417 |
buf.append("\n"); |
472 |
buf.append("\n"); |
418 |
buf.append(" public static boolean inVAJava() {\n"); |
473 |
buf.append(" public void setPreference(final String key, final String value) {\n"); |
419 |
buf.append(" try {\n"); |
474 |
buf.append(" BaseTestRunner.getPreferences().setProperty(key, value);\n"); |
420 |
buf.append(" Class.forName(\"com.ibm.uvm.tools.DebugSupport\"); //$NON-NLS-1$\n"); |
|
|
421 |
buf.append(" } catch (final Exception e) {\n"); |
422 |
buf.append(" return false;\n"); |
423 |
buf.append(" }\n"); |
424 |
buf.append(" return true;\n"); |
425 |
buf.append(" }\n"); |
475 |
buf.append(" }\n"); |
426 |
buf.append("\n"); |
476 |
buf.append("\n"); |
427 |
buf.append(" /**\n"); |
477 |
buf.append(" /*\n"); |
428 |
buf.append(" * Returns a filtered stack trace\n"); |
478 |
buf.append(" * Implementation of TestListener\n"); |
429 |
buf.append(" */\n"); |
479 |
buf.append(" */\n"); |
430 |
buf.append(" public static String getFilteredTrace(final Throwable t) {\n"); |
480 |
buf.append(" public synchronized void startTest(final Test test) {\n"); |
431 |
buf.append(" final StringWriter stringWriter = new StringWriter();\n"); |
481 |
buf.append(" this.testStarted(test.toString());\n"); |
432 |
buf.append(" final PrintWriter writer = new PrintWriter(stringWriter);\n"); |
|
|
433 |
buf.append(" t.printStackTrace(writer);\n"); |
434 |
buf.append(" final StringBuffer buffer = stringWriter.getBuffer();\n"); |
435 |
buf.append(" final String trace = buffer.toString();\n"); |
436 |
buf.append(" return BaseTestRunner.getFilteredTrace(trace);\n"); |
437 |
buf.append(" }\n"); |
482 |
buf.append(" }\n"); |
438 |
buf.append("\n"); |
483 |
buf.append("\n"); |
439 |
buf.append(" /**\n"); |
484 |
buf.append(" public abstract void testEnded(String testName);\n"); |
440 |
buf.append(" * Filters stack frames from internal JUnit classes\n"); |
|
|
441 |
buf.append(" */\n"); |
442 |
buf.append(" public static String getFilteredTrace(final String stack) {\n"); |
443 |
buf.append(" if (BaseTestRunner.showStackRaw()) {\n"); |
444 |
buf.append(" return stack;\n"); |
445 |
buf.append(" }\n"); |
446 |
buf.append("\n"); |
447 |
buf.append(" final StringWriter sw = new StringWriter();\n"); |
448 |
buf.append(" final PrintWriter pw = new PrintWriter(sw);\n"); |
449 |
buf.append(" final StringReader sr = new StringReader(stack);\n"); |
450 |
buf.append(" final BufferedReader br = new BufferedReader(sr);\n"); |
451 |
buf.append("\n"); |
452 |
buf.append(" String line;\n"); |
453 |
buf.append(" try {\n"); |
454 |
buf.append(" while ((line = br.readLine()) != null) {\n"); |
455 |
buf.append(" if (!BaseTestRunner.filterLine(line)) {\n"); |
456 |
buf.append(" pw.println(line);\n"); |
457 |
buf.append(" }\n"); |
458 |
buf.append(" }\n"); |
459 |
buf.append(" } catch (final Exception IOException) {\n"); |
460 |
buf.append(" return stack; // return the stack unfiltered\n"); |
461 |
buf.append(" }\n"); |
462 |
buf.append(" return sw.toString();\n"); |
463 |
buf.append(" }\n"); |
464 |
buf.append("\n"); |
485 |
buf.append("\n"); |
465 |
buf.append(" protected static boolean showStackRaw() {\n"); |
486 |
buf.append(" public abstract void testFailed(int status, Test test, Throwable t);\n"); |
466 |
buf.append(" return !BaseTestRunner.getPreference(\"filterstack\").equals(\"true\") || (BaseTestRunner.fgFilterStack == false); //$NON-NLS-1$ //$NON-NLS-2$\n"); |
|
|
467 |
buf.append(" }\n"); |
468 |
buf.append("\n"); |
487 |
buf.append("\n"); |
469 |
buf.append(" static boolean filterLine(final String line) {\n"); |
488 |
buf.append(" public abstract void testStarted(String testName);\n"); |
470 |
buf.append(" final String[] patterns = new String[]{\"junit.framework.TestCase\", //$NON-NLS-1$\n"); |
|
|
471 |
buf.append(" \"junit.framework.TestResult\", //$NON-NLS-1$\n"); |
472 |
buf.append(" \"junit.framework.TestSuite\", //$NON-NLS-1$\n"); |
473 |
buf.append(" \"junit.framework.Assert.\", // don't filter AssertionFailure\n"); |
474 |
buf.append(" // //$NON-NLS-1$\n"); |
475 |
buf.append(" \"junit.swingui.TestRunner\", //$NON-NLS-1$\n"); |
476 |
buf.append(" \"junit.awtui.TestRunner\", //$NON-NLS-1$\n"); |
477 |
buf.append(" \"junit.textui.TestRunner\", //$NON-NLS-1$\n"); |
478 |
buf.append(" \"java.lang.reflect.Method.invoke(\" //$NON-NLS-1$\n"); |
479 |
buf.append(" };\n"); |
480 |
buf.append(" for (final String element : patterns) {\n"); |
481 |
buf.append(" if (line.indexOf(element) > 0) {\n"); |
482 |
buf.append(" return true;\n"); |
483 |
buf.append(" }\n"); |
484 |
buf.append(" }\n"); |
485 |
buf.append(" return false;\n"); |
486 |
buf.append(" }\n"); |
487 |
buf.append("\n"); |
489 |
buf.append("\n"); |
488 |
buf.append(" static {\n"); |
490 |
buf.append(" protected boolean useReloadingTestSuiteLoader() {\n"); |
489 |
buf.append(" BaseTestRunner.fgMaxMessageLength = BaseTestRunner.getPreference(\n"); |
491 |
buf.append(" return BaseTestRunner.getPreference(\"loading\").equals(\"true\") && !BaseTestRunner.inVAJava() && this.fLoading; //$NON-NLS-1$ //$NON-NLS-2$\n"); |
490 |
buf.append(" \"maxmessage\", BaseTestRunner.fgMaxMessageLength); //$NON-NLS-1$\n"); |
|
|
491 |
buf.append(" }\n"); |
492 |
buf.append(" }\n"); |
492 |
buf.append("\n"); |
493 |
buf.append("\n"); |
493 |
buf.append("}"); |
494 |
buf.append("}"); |
Lines 602-636
Link Here
|
602 |
buf.append(" Assert.fail();\n"); |
603 |
buf.append(" Assert.fail();\n"); |
603 |
buf.append(" }\n"); |
604 |
buf.append(" }\n"); |
604 |
buf.append("\n"); |
605 |
buf.append("\n"); |
605 |
buf.append(" public void testAssertPosInfinityNotEqualsNegInfinity() {\n"); |
606 |
buf.append(" public void testAssertNegInfinityEqualsInfinity() {\n"); |
|
|
607 |
buf.append(" Assert.assertEquals(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY,\n"); |
608 |
buf.append(" 0.0);\n"); |
609 |
buf.append(" }\n"); |
610 |
buf.append("\n"); |
611 |
buf.append(" public void testAssertPosInfinityEqualsInfinity() {\n"); |
612 |
buf.append(" Assert.assertEquals(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY,\n"); |
613 |
buf.append(" 0.0);\n"); |
614 |
buf.append(" }\n"); |
615 |
buf.append("\n"); |
616 |
buf.append(" public void testAssertPosInfinityNotEquals() {\n"); |
606 |
buf.append(" try {\n"); |
617 |
buf.append(" try {\n"); |
607 |
buf.append(" Assert.assertEquals(Double.POSITIVE_INFINITY,\n"); |
618 |
buf.append(" Assert.assertEquals(Double.POSITIVE_INFINITY, 1.23, 0.0);\n"); |
608 |
buf.append(" Double.NEGATIVE_INFINITY, 0.0);\n"); |
|
|
609 |
buf.append(" } catch (final AssertionFailedError e) {\n"); |
619 |
buf.append(" } catch (final AssertionFailedError e) {\n"); |
610 |
buf.append(" return;\n"); |
620 |
buf.append(" return;\n"); |
611 |
buf.append(" }\n"); |
621 |
buf.append(" }\n"); |
612 |
buf.append(" Assert.fail();\n"); |
622 |
buf.append(" Assert.fail();\n"); |
613 |
buf.append(" }\n"); |
623 |
buf.append(" }\n"); |
614 |
buf.append("\n"); |
624 |
buf.append("\n"); |
615 |
buf.append(" public void testAssertPosInfinityNotEquals() {\n"); |
625 |
buf.append(" public void testAssertPosInfinityNotEqualsNegInfinity() {\n"); |
616 |
buf.append(" try {\n"); |
626 |
buf.append(" try {\n"); |
617 |
buf.append(" Assert.assertEquals(Double.POSITIVE_INFINITY, 1.23, 0.0);\n"); |
627 |
buf.append(" Assert.assertEquals(Double.POSITIVE_INFINITY,\n"); |
|
|
628 |
buf.append(" Double.NEGATIVE_INFINITY, 0.0);\n"); |
618 |
buf.append(" } catch (final AssertionFailedError e) {\n"); |
629 |
buf.append(" } catch (final AssertionFailedError e) {\n"); |
619 |
buf.append(" return;\n"); |
630 |
buf.append(" return;\n"); |
620 |
buf.append(" }\n"); |
631 |
buf.append(" }\n"); |
621 |
buf.append(" Assert.fail();\n"); |
632 |
buf.append(" Assert.fail();\n"); |
622 |
buf.append(" }\n"); |
633 |
buf.append(" }\n"); |
623 |
buf.append("\n"); |
634 |
buf.append("\n"); |
624 |
buf.append(" public void testAssertPosInfinityEqualsInfinity() {\n"); |
|
|
625 |
buf.append(" Assert.assertEquals(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY,\n"); |
626 |
buf.append(" 0.0);\n"); |
627 |
buf.append(" }\n"); |
628 |
buf.append("\n"); |
629 |
buf.append(" public void testAssertNegInfinityEqualsInfinity() {\n"); |
630 |
buf.append(" Assert.assertEquals(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY,\n"); |
631 |
buf.append(" 0.0);\n"); |
632 |
buf.append(" }\n"); |
633 |
buf.append("\n"); |
634 |
buf.append("}\n"); |
635 |
buf.append("}\n"); |
635 |
buf.append(""); |
636 |
buf.append(""); |
636 |
fExpectedChangesAllTests.put("junit.tests.framework.DoublePrecisionAssertTest.java", buf.toString()); |
637 |
fExpectedChangesAllTests.put("junit.tests.framework.DoublePrecisionAssertTest.java", buf.toString()); |
Lines 644-665
Link Here
|
644 |
buf.append("\n"); |
645 |
buf.append("\n"); |
645 |
buf.append("public class AssertTest extends TestCase {\n"); |
646 |
buf.append("public class AssertTest extends TestCase {\n"); |
646 |
buf.append("\n"); |
647 |
buf.append("\n"); |
647 |
buf.append(" /*\n"); |
|
|
648 |
buf.append(" * In the tests that follow, we can't use standard formatting for exception\n"); |
649 |
buf.append(" * tests: try { somethingThatShouldThrow(); fail(); catch\n"); |
650 |
buf.append(" * (AssertionFailedError e) { } because fail() would never be reported.\n"); |
651 |
buf.append(" */\n"); |
652 |
buf.append(" public void testFail() {\n"); |
653 |
buf.append(" // Also, we are testing fail, so we can't rely on fail() working.\n"); |
654 |
buf.append(" // We have to throw the exception manually, .\n"); |
655 |
buf.append(" try {\n"); |
656 |
buf.append(" Assert.fail();\n"); |
657 |
buf.append(" } catch (final AssertionFailedError e) {\n"); |
658 |
buf.append(" return;\n"); |
659 |
buf.append(" }\n"); |
660 |
buf.append(" throw new AssertionFailedError();\n"); |
661 |
buf.append(" }\n"); |
662 |
buf.append("\n"); |
663 |
buf.append(" public void testAssertEquals() {\n"); |
648 |
buf.append(" public void testAssertEquals() {\n"); |
664 |
buf.append(" final Object o = new Object();\n"); |
649 |
buf.append(" final Object o = new Object();\n"); |
665 |
buf.append(" Assert.assertEquals(o, o);\n"); |
650 |
buf.append(" Assert.assertEquals(o, o);\n"); |
Lines 675-749
Link Here
|
675 |
buf.append(" Assert.assertEquals(null, null);\n"); |
660 |
buf.append(" Assert.assertEquals(null, null);\n"); |
676 |
buf.append(" }\n"); |
661 |
buf.append(" }\n"); |
677 |
buf.append("\n"); |
662 |
buf.append("\n"); |
678 |
buf.append(" public void testAssertStringEquals() {\n"); |
663 |
buf.append(" public void testAssertFalse() {\n"); |
679 |
buf.append(" Assert.assertEquals(\"a\", \"a\"); //$NON-NLS-1$ //$NON-NLS-2$\n"); |
664 |
buf.append(" Assert.assertFalse(false);\n"); |
680 |
buf.append(" }\n"); |
|
|
681 |
buf.append("\n"); |
682 |
buf.append(" public void testAssertNullNotEqualsString() {\n"); |
683 |
buf.append(" try {\n"); |
665 |
buf.append(" try {\n"); |
684 |
buf.append(" Assert.assertEquals(null, \"foo\"); //$NON-NLS-1$\n"); |
666 |
buf.append(" Assert.assertFalse(true);\n"); |
685 |
buf.append(" Assert.fail();\n"); |
667 |
buf.append(" } catch (final AssertionFailedError e) {\n"); |
686 |
buf.append(" } catch (final ComparisonFailure e) {\n"); |
668 |
buf.append(" return;\n"); |
687 |
buf.append(" }\n"); |
669 |
buf.append(" }\n"); |
|
|
670 |
buf.append(" Assert.fail();\n"); |
688 |
buf.append(" }\n"); |
671 |
buf.append(" }\n"); |
689 |
buf.append("\n"); |
672 |
buf.append("\n"); |
690 |
buf.append(" public void testAssertStringNotEqualsNull() {\n"); |
673 |
buf.append(" public void testAssertNotNull() {\n"); |
|
|
674 |
buf.append(" Assert.assertNotNull(new Object());\n"); |
691 |
buf.append(" try {\n"); |
675 |
buf.append(" try {\n"); |
692 |
buf.append(" Assert.assertEquals(\"foo\", null); //$NON-NLS-1$\n"); |
676 |
buf.append(" Assert.assertNotNull(null);\n"); |
693 |
buf.append(" Assert.fail();\n"); |
677 |
buf.append(" } catch (final AssertionFailedError e) {\n"); |
694 |
buf.append(" } catch (final ComparisonFailure e) {\n"); |
678 |
buf.append(" return;\n"); |
695 |
buf.append(" e.getMessage(); // why no assertion?\n"); |
|
|
696 |
buf.append(" }\n"); |
679 |
buf.append(" }\n"); |
|
|
680 |
buf.append(" Assert.fail();\n"); |
697 |
buf.append(" }\n"); |
681 |
buf.append(" }\n"); |
698 |
buf.append("\n"); |
682 |
buf.append("\n"); |
699 |
buf.append(" public void testAssertNullNotEqualsNull() {\n"); |
683 |
buf.append(" public void testAssertNotSame() {\n"); |
|
|
684 |
buf.append(" Assert.assertNotSame(new Integer(1), null);\n"); |
685 |
buf.append(" Assert.assertNotSame(null, new Integer(1));\n"); |
686 |
buf.append(" Assert.assertNotSame(new Integer(1), new Integer(1));\n"); |
700 |
buf.append(" try {\n"); |
687 |
buf.append(" try {\n"); |
701 |
buf.append(" Assert.assertEquals(null, new Object());\n"); |
688 |
buf.append(" final Integer obj = new Integer(1);\n"); |
|
|
689 |
buf.append(" Assert.assertNotSame(obj, obj);\n"); |
702 |
buf.append(" } catch (final AssertionFailedError e) {\n"); |
690 |
buf.append(" } catch (final AssertionFailedError e) {\n"); |
703 |
buf.append(" e.getMessage(); // why no assertion?\n"); |
|
|
704 |
buf.append(" return;\n"); |
691 |
buf.append(" return;\n"); |
705 |
buf.append(" }\n"); |
692 |
buf.append(" }\n"); |
706 |
buf.append(" Assert.fail();\n"); |
693 |
buf.append(" Assert.fail();\n"); |
707 |
buf.append(" }\n"); |
694 |
buf.append(" }\n"); |
708 |
buf.append("\n"); |
695 |
buf.append("\n"); |
709 |
buf.append(" public void testAssertNull() {\n"); |
696 |
buf.append(" public void testAssertNotSameFailsNull() {\n"); |
710 |
buf.append(" Assert.assertNull(null);\n"); |
|
|
711 |
buf.append(" try {\n"); |
697 |
buf.append(" try {\n"); |
712 |
buf.append(" Assert.assertNull(new Object());\n"); |
698 |
buf.append(" Assert.assertNotSame(null, null);\n"); |
713 |
buf.append(" } catch (final AssertionFailedError e) {\n"); |
699 |
buf.append(" } catch (final AssertionFailedError e) {\n"); |
714 |
buf.append(" return;\n"); |
700 |
buf.append(" return;\n"); |
715 |
buf.append(" }\n"); |
701 |
buf.append(" }\n"); |
716 |
buf.append(" Assert.fail();\n"); |
702 |
buf.append(" Assert.fail();\n"); |
717 |
buf.append(" }\n"); |
703 |
buf.append(" }\n"); |
718 |
buf.append("\n"); |
704 |
buf.append("\n"); |
719 |
buf.append(" public void testAssertNotNull() {\n"); |
705 |
buf.append(" public void testAssertNull() {\n"); |
720 |
buf.append(" Assert.assertNotNull(new Object());\n"); |
706 |
buf.append(" Assert.assertNull(null);\n"); |
721 |
buf.append(" try {\n"); |
707 |
buf.append(" try {\n"); |
722 |
buf.append(" Assert.assertNotNull(null);\n"); |
708 |
buf.append(" Assert.assertNull(new Object());\n"); |
723 |
buf.append(" } catch (final AssertionFailedError e) {\n"); |
709 |
buf.append(" } catch (final AssertionFailedError e) {\n"); |
724 |
buf.append(" return;\n"); |
710 |
buf.append(" return;\n"); |
725 |
buf.append(" }\n"); |
711 |
buf.append(" }\n"); |
726 |
buf.append(" Assert.fail();\n"); |
712 |
buf.append(" Assert.fail();\n"); |
727 |
buf.append(" }\n"); |
713 |
buf.append(" }\n"); |
728 |
buf.append("\n"); |
714 |
buf.append("\n"); |
729 |
buf.append(" public void testAssertTrue() {\n"); |
715 |
buf.append(" public void testAssertNullNotEqualsNull() {\n"); |
730 |
buf.append(" Assert.assertTrue(true);\n"); |
|
|
731 |
buf.append(" try {\n"); |
716 |
buf.append(" try {\n"); |
732 |
buf.append(" Assert.assertTrue(false);\n"); |
717 |
buf.append(" Assert.assertEquals(null, new Object());\n"); |
733 |
buf.append(" } catch (final AssertionFailedError e) {\n"); |
718 |
buf.append(" } catch (final AssertionFailedError e) {\n"); |
|
|
719 |
buf.append(" e.getMessage(); // why no assertion?\n"); |
734 |
buf.append(" return;\n"); |
720 |
buf.append(" return;\n"); |
735 |
buf.append(" }\n"); |
721 |
buf.append(" }\n"); |
736 |
buf.append(" Assert.fail();\n"); |
722 |
buf.append(" Assert.fail();\n"); |
737 |
buf.append(" }\n"); |
723 |
buf.append(" }\n"); |
738 |
buf.append("\n"); |
724 |
buf.append("\n"); |
739 |
buf.append(" public void testAssertFalse() {\n"); |
725 |
buf.append(" public void testAssertNullNotEqualsString() {\n"); |
740 |
buf.append(" Assert.assertFalse(false);\n"); |
|
|
741 |
buf.append(" try {\n"); |
726 |
buf.append(" try {\n"); |
742 |
buf.append(" Assert.assertFalse(true);\n"); |
727 |
buf.append(" Assert.assertEquals(null, \"foo\"); //$NON-NLS-1$\n"); |
743 |
buf.append(" } catch (final AssertionFailedError e) {\n"); |
728 |
buf.append(" Assert.fail();\n"); |
744 |
buf.append(" return;\n"); |
729 |
buf.append(" } catch (final ComparisonFailure e) {\n"); |
745 |
buf.append(" }\n"); |
730 |
buf.append(" }\n"); |
746 |
buf.append(" Assert.fail();\n"); |
|
|
747 |
buf.append(" }\n"); |
731 |
buf.append(" }\n"); |
748 |
buf.append("\n"); |
732 |
buf.append("\n"); |
749 |
buf.append(" public void testAssertSame() {\n"); |
733 |
buf.append(" public void testAssertSame() {\n"); |
Lines 757-782
Link Here
|
757 |
buf.append(" Assert.fail();\n"); |
741 |
buf.append(" Assert.fail();\n"); |
758 |
buf.append(" }\n"); |
742 |
buf.append(" }\n"); |
759 |
buf.append("\n"); |
743 |
buf.append("\n"); |
760 |
buf.append(" public void testAssertNotSame() {\n"); |
744 |
buf.append(" public void testAssertStringEquals() {\n"); |
761 |
buf.append(" Assert.assertNotSame(new Integer(1), null);\n"); |
745 |
buf.append(" Assert.assertEquals(\"a\", \"a\"); //$NON-NLS-1$ //$NON-NLS-2$\n"); |
762 |
buf.append(" Assert.assertNotSame(null, new Integer(1));\n"); |
746 |
buf.append(" }\n"); |
763 |
buf.append(" Assert.assertNotSame(new Integer(1), new Integer(1));\n"); |
747 |
buf.append("\n"); |
|
|
748 |
buf.append(" public void testAssertStringNotEqualsNull() {\n"); |
764 |
buf.append(" try {\n"); |
749 |
buf.append(" try {\n"); |
765 |
buf.append(" final Integer obj = new Integer(1);\n"); |
750 |
buf.append(" Assert.assertEquals(\"foo\", null); //$NON-NLS-1$\n"); |
766 |
buf.append(" Assert.assertNotSame(obj, obj);\n"); |
751 |
buf.append(" Assert.fail();\n"); |
|
|
752 |
buf.append(" } catch (final ComparisonFailure e) {\n"); |
753 |
buf.append(" e.getMessage(); // why no assertion?\n"); |
754 |
buf.append(" }\n"); |
755 |
buf.append(" }\n"); |
756 |
buf.append("\n"); |
757 |
buf.append(" public void testAssertTrue() {\n"); |
758 |
buf.append(" Assert.assertTrue(true);\n"); |
759 |
buf.append(" try {\n"); |
760 |
buf.append(" Assert.assertTrue(false);\n"); |
767 |
buf.append(" } catch (final AssertionFailedError e) {\n"); |
761 |
buf.append(" } catch (final AssertionFailedError e) {\n"); |
768 |
buf.append(" return;\n"); |
762 |
buf.append(" return;\n"); |
769 |
buf.append(" }\n"); |
763 |
buf.append(" }\n"); |
770 |
buf.append(" Assert.fail();\n"); |
764 |
buf.append(" Assert.fail();\n"); |
771 |
buf.append(" }\n"); |
765 |
buf.append(" }\n"); |
772 |
buf.append("\n"); |
766 |
buf.append("\n"); |
773 |
buf.append(" public void testAssertNotSameFailsNull() {\n"); |
767 |
buf.append(" /*\n"); |
|
|
768 |
buf.append(" * In the tests that follow, we can't use standard formatting for exception\n"); |
769 |
buf.append(" * tests: try { somethingThatShouldThrow(); fail(); catch\n"); |
770 |
buf.append(" * (AssertionFailedError e) { } because fail() would never be reported.\n"); |
771 |
buf.append(" */\n"); |
772 |
buf.append(" public void testFail() {\n"); |
773 |
buf.append(" // Also, we are testing fail, so we can't rely on fail() working.\n"); |
774 |
buf.append(" // We have to throw the exception manually, .\n"); |
774 |
buf.append(" try {\n"); |
775 |
buf.append(" try {\n"); |
775 |
buf.append(" Assert.assertNotSame(null, null);\n"); |
776 |
buf.append(" Assert.fail();\n"); |
776 |
buf.append(" } catch (final AssertionFailedError e) {\n"); |
777 |
buf.append(" } catch (final AssertionFailedError e) {\n"); |
777 |
buf.append(" return;\n"); |
778 |
buf.append(" return;\n"); |
778 |
buf.append(" }\n"); |
779 |
buf.append(" }\n"); |
779 |
buf.append(" Assert.fail();\n"); |
780 |
buf.append(" throw new AssertionFailedError();\n"); |
780 |
buf.append(" }\n"); |
781 |
buf.append(" }\n"); |
781 |
buf.append("}"); |
782 |
buf.append("}"); |
782 |
fExpectedChangesAllTests.put("junit.tests.framework.AssertTest.java", buf.toString()); |
783 |
fExpectedChangesAllTests.put("junit.tests.framework.AssertTest.java", buf.toString()); |
Lines 822-842
Link Here
|
822 |
buf.append(" }\n"); |
823 |
buf.append(" }\n"); |
823 |
buf.append(" }\n"); |
824 |
buf.append(" }\n"); |
824 |
buf.append("\n"); |
825 |
buf.append("\n"); |
825 |
buf.append(" static public class ThrowRuntimeExceptionTestCase extends ExceptionTestCase {\n"); |
826 |
buf.append(" static public class ThrowNoExceptionTestCase extends ExceptionTestCase {\n"); |
826 |
buf.append(" public ThrowRuntimeExceptionTestCase(final String name,\n"); |
827 |
buf.append(" public ThrowNoExceptionTestCase(final String name, final Class exception) {\n"); |
827 |
buf.append(" final Class exception) {\n"); |
|
|
828 |
buf.append(" super(name, exception);\n"); |
828 |
buf.append(" super(name, exception);\n"); |
829 |
buf.append(" }\n"); |
829 |
buf.append(" }\n"); |
830 |
buf.append(" public void test() {\n"); |
830 |
buf.append(" public void test() {\n"); |
831 |
buf.append(" throw new RuntimeException();\n"); |
|
|
832 |
buf.append(" }\n"); |
831 |
buf.append(" }\n"); |
833 |
buf.append(" }\n"); |
832 |
buf.append(" }\n"); |
834 |
buf.append("\n"); |
833 |
buf.append("\n"); |
835 |
buf.append(" static public class ThrowNoExceptionTestCase extends ExceptionTestCase {\n"); |
834 |
buf.append(" static public class ThrowRuntimeExceptionTestCase extends ExceptionTestCase {\n"); |
836 |
buf.append(" public ThrowNoExceptionTestCase(final String name, final Class exception) {\n"); |
835 |
buf.append(" public ThrowRuntimeExceptionTestCase(final String name,\n"); |
|
|
836 |
buf.append(" final Class exception) {\n"); |
837 |
buf.append(" super(name, exception);\n"); |
837 |
buf.append(" super(name, exception);\n"); |
838 |
buf.append(" }\n"); |
838 |
buf.append(" }\n"); |
839 |
buf.append(" public void test() {\n"); |
839 |
buf.append(" public void test() {\n"); |
|
|
840 |
buf.append(" throw new RuntimeException();\n"); |
840 |
buf.append(" }\n"); |
841 |
buf.append(" }\n"); |
841 |
buf.append(" }\n"); |
842 |
buf.append(" }\n"); |
842 |
buf.append("\n"); |
843 |
buf.append("\n"); |
Lines 891-901
Link Here
|
891 |
buf.append("import junit.framework.TestResult;\n"); |
892 |
buf.append("import junit.framework.TestResult;\n"); |
892 |
buf.append("\n"); |
893 |
buf.append("\n"); |
893 |
buf.append("public class TestListenerTest extends TestCase implements TestListener {\n"); |
894 |
buf.append("public class TestListenerTest extends TestCase implements TestListener {\n"); |
894 |
buf.append(" private TestResult fResult;\n"); |
|
|
895 |
buf.append(" private int fStartCount;\n"); |
896 |
buf.append(" private int fEndCount;\n"); |
895 |
buf.append(" private int fEndCount;\n"); |
897 |
buf.append(" private int fFailureCount;\n"); |
|
|
898 |
buf.append(" private int fErrorCount;\n"); |
896 |
buf.append(" private int fErrorCount;\n"); |
|
|
897 |
buf.append(" private int fFailureCount;\n"); |
898 |
buf.append(" private TestResult fResult;\n"); |
899 |
buf.append(" private int fStartCount;\n"); |
899 |
buf.append("\n"); |
900 |
buf.append("\n"); |
900 |
buf.append(" public void addError(final Test test, final Throwable t) {\n"); |
901 |
buf.append(" public void addError(final Test test, final Throwable t) {\n"); |
901 |
buf.append(" this.fErrorCount++;\n"); |
902 |
buf.append(" this.fErrorCount++;\n"); |
Lines 1086-1091
Link Here
|
1086 |
buf.append(" public int countTestCases() {\n"); |
1087 |
buf.append(" public int countTestCases() {\n"); |
1087 |
buf.append(" return this.fTest.countTestCases();\n"); |
1088 |
buf.append(" return this.fTest.countTestCases();\n"); |
1088 |
buf.append(" }\n"); |
1089 |
buf.append(" }\n"); |
|
|
1090 |
buf.append(" public Test getTest() {\n"); |
1091 |
buf.append(" return this.fTest;\n"); |
1092 |
buf.append(" }\n"); |
1093 |
buf.append("\n"); |
1089 |
buf.append(" public void run(final TestResult result) {\n"); |
1094 |
buf.append(" public void run(final TestResult result) {\n"); |
1090 |
buf.append(" this.basicRun(result);\n"); |
1095 |
buf.append(" this.basicRun(result);\n"); |
1091 |
buf.append(" }\n"); |
1096 |
buf.append(" }\n"); |
Lines 1094-1103
Link Here
|
1094 |
buf.append(" public String toString() {\n"); |
1099 |
buf.append(" public String toString() {\n"); |
1095 |
buf.append(" return this.fTest.toString();\n"); |
1100 |
buf.append(" return this.fTest.toString();\n"); |
1096 |
buf.append(" }\n"); |
1101 |
buf.append(" }\n"); |
1097 |
buf.append("\n"); |
|
|
1098 |
buf.append(" public Test getTest() {\n"); |
1099 |
buf.append(" return this.fTest;\n"); |
1100 |
buf.append(" }\n"); |
1101 |
buf.append("}"); |
1102 |
buf.append("}"); |
1102 |
fExpectedChangesAllTests.put("junit.extensions.TestDecorator.java", buf.toString()); |
1103 |
fExpectedChangesAllTests.put("junit.extensions.TestDecorator.java", buf.toString()); |
1103 |
buf= new StringBuffer(); |
1104 |
buf= new StringBuffer(); |
Lines 1128-1135
Link Here
|
1128 |
buf.append(" * @see Test\n"); |
1129 |
buf.append(" * @see Test\n"); |
1129 |
buf.append(" */\n"); |
1130 |
buf.append(" */\n"); |
1130 |
buf.append("public class TestResult extends Object {\n"); |
1131 |
buf.append("public class TestResult extends Object {\n"); |
1131 |
buf.append(" protected Vector fFailures;\n"); |
|
|
1132 |
buf.append(" protected Vector fErrors;\n"); |
1132 |
buf.append(" protected Vector fErrors;\n"); |
|
|
1133 |
buf.append(" protected Vector fFailures;\n"); |
1133 |
buf.append(" protected Vector fListeners;\n"); |
1134 |
buf.append(" protected Vector fListeners;\n"); |
1134 |
buf.append(" protected int fRunTests;\n"); |
1135 |
buf.append(" protected int fRunTests;\n"); |
1135 |
buf.append(" private boolean fStop;\n"); |
1136 |
buf.append(" private boolean fStop;\n"); |
Lines 1171-1182
Link Here
|
1171 |
buf.append(" this.fListeners.addElement(listener);\n"); |
1172 |
buf.append(" this.fListeners.addElement(listener);\n"); |
1172 |
buf.append(" }\n"); |
1173 |
buf.append(" }\n"); |
1173 |
buf.append(" /**\n"); |
1174 |
buf.append(" /**\n"); |
1174 |
buf.append(" * Unregisters a TestListener\n"); |
|
|
1175 |
buf.append(" */\n"); |
1176 |
buf.append(" public synchronized void removeListener(final TestListener listener) {\n"); |
1177 |
buf.append(" this.fListeners.removeElement(listener);\n"); |
1178 |
buf.append(" }\n"); |
1179 |
buf.append(" /**\n"); |
1180 |
buf.append(" * Returns a copy of the listeners.\n"); |
1175 |
buf.append(" * Returns a copy of the listeners.\n"); |
1181 |
buf.append(" */\n"); |
1176 |
buf.append(" */\n"); |
1182 |
buf.append(" private synchronized Vector cloneListeners() {\n"); |
1177 |
buf.append(" private synchronized Vector cloneListeners() {\n"); |
Lines 1216-1221
Link Here
|
1216 |
buf.append(" return this.fFailures.elements();\n"); |
1211 |
buf.append(" return this.fFailures.elements();\n"); |
1217 |
buf.append(" }\n"); |
1212 |
buf.append(" }\n"); |
1218 |
buf.append(" /**\n"); |
1213 |
buf.append(" /**\n"); |
|
|
1214 |
buf.append(" * Unregisters a TestListener\n"); |
1215 |
buf.append(" */\n"); |
1216 |
buf.append(" public synchronized void removeListener(final TestListener listener) {\n"); |
1217 |
buf.append(" this.fListeners.removeElement(listener);\n"); |
1218 |
buf.append(" }\n"); |
1219 |
buf.append(" /**\n"); |
1219 |
buf.append(" * Runs a TestCase.\n"); |
1220 |
buf.append(" * Runs a TestCase.\n"); |
1220 |
buf.append(" */\n"); |
1221 |
buf.append(" */\n"); |
1221 |
buf.append(" protected void run(final TestCase test) {\n"); |
1222 |
buf.append(" protected void run(final TestCase test) {\n"); |
Lines 1319-1332
Link Here
|
1319 |
buf.append(" super(theClass);\n"); |
1320 |
buf.append(" super(theClass);\n"); |
1320 |
buf.append(" }\n"); |
1321 |
buf.append(" }\n"); |
1321 |
buf.append("\n"); |
1322 |
buf.append("\n"); |
1322 |
buf.append(" public ActiveTestSuite(final String name) {\n"); |
|
|
1323 |
buf.append(" super(name);\n"); |
1324 |
buf.append(" }\n"); |
1325 |
buf.append("\n"); |
1326 |
buf.append(" public ActiveTestSuite(final Class theClass, final String name) {\n"); |
1323 |
buf.append(" public ActiveTestSuite(final Class theClass, final String name) {\n"); |
1327 |
buf.append(" super(theClass, name);\n"); |
1324 |
buf.append(" super(theClass, name);\n"); |
1328 |
buf.append(" }\n"); |
1325 |
buf.append(" }\n"); |
1329 |
buf.append("\n"); |
1326 |
buf.append("\n"); |
|
|
1327 |
buf.append(" public ActiveTestSuite(final String name) {\n"); |
1328 |
buf.append(" super(name);\n"); |
1329 |
buf.append(" }\n"); |
1330 |
buf.append("\n"); |
1330 |
buf.append(" @Override\n"); |
1331 |
buf.append(" @Override\n"); |
1331 |
buf.append(" public void run(final TestResult result) {\n"); |
1332 |
buf.append(" public void run(final TestResult result) {\n"); |
1332 |
buf.append(" this.fActiveTestDeathCount = 0;\n"); |
1333 |
buf.append(" this.fActiveTestDeathCount = 0;\n"); |
Lines 1334-1339
Link Here
|
1334 |
buf.append(" this.waitUntilFinished();\n"); |
1335 |
buf.append(" this.waitUntilFinished();\n"); |
1335 |
buf.append(" }\n"); |
1336 |
buf.append(" }\n"); |
1336 |
buf.append("\n"); |
1337 |
buf.append("\n"); |
|
|
1338 |
buf.append(" synchronized public void runFinished(final Test test) {\n"); |
1339 |
buf.append(" this.fActiveTestDeathCount++;\n"); |
1340 |
buf.append(" this.notifyAll();\n"); |
1341 |
buf.append(" }\n"); |
1342 |
buf.append("\n"); |
1337 |
buf.append(" @Override\n"); |
1343 |
buf.append(" @Override\n"); |
1338 |
buf.append(" public void runTest(final Test test, final TestResult result) {\n"); |
1344 |
buf.append(" public void runTest(final Test test, final TestResult result) {\n"); |
1339 |
buf.append(" final Thread t = new Thread() {\n"); |
1345 |
buf.append(" final Thread t = new Thread() {\n"); |
Lines 1360-1370
Link Here
|
1360 |
buf.append(" }\n"); |
1366 |
buf.append(" }\n"); |
1361 |
buf.append(" }\n"); |
1367 |
buf.append(" }\n"); |
1362 |
buf.append(" }\n"); |
1368 |
buf.append(" }\n"); |
1363 |
buf.append("\n"); |
|
|
1364 |
buf.append(" synchronized public void runFinished(final Test test) {\n"); |
1365 |
buf.append(" this.fActiveTestDeathCount++;\n"); |
1366 |
buf.append(" this.notifyAll();\n"); |
1367 |
buf.append(" }\n"); |
1368 |
buf.append("}"); |
1369 |
buf.append("}"); |
1369 |
fExpectedChangesAllTests.put("junit.extensions.ActiveTestSuite.java", buf.toString()); |
1370 |
fExpectedChangesAllTests.put("junit.extensions.ActiveTestSuite.java", buf.toString()); |
1370 |
buf= new StringBuffer(); |
1371 |
buf= new StringBuffer(); |
Lines 1381-1394
Link Here
|
1381 |
buf.append(" * \n"); |
1382 |
buf.append(" * \n"); |
1382 |
buf.append(" */\n"); |
1383 |
buf.append(" */\n"); |
1383 |
buf.append("public class SuiteTest extends TestCase {\n"); |
1384 |
buf.append("public class SuiteTest extends TestCase {\n"); |
1384 |
buf.append(" protected TestResult fResult;\n"); |
|
|
1385 |
buf.append(" public SuiteTest(final String name) {\n"); |
1386 |
buf.append(" super(name);\n"); |
1387 |
buf.append(" }\n"); |
1388 |
buf.append(" @Override\n"); |
1389 |
buf.append(" protected void setUp() {\n"); |
1390 |
buf.append(" this.fResult = new TestResult();\n"); |
1391 |
buf.append(" }\n"); |
1392 |
buf.append(" public static Test suite() {\n"); |
1385 |
buf.append(" public static Test suite() {\n"); |
1393 |
buf.append(" final TestSuite suite = new TestSuite(\"Suite Tests\"); //$NON-NLS-1$\n"); |
1386 |
buf.append(" final TestSuite suite = new TestSuite(\"Suite Tests\"); //$NON-NLS-1$\n"); |
1394 |
buf.append(" // build the suite manually, because some of the suites are testing\n"); |
1387 |
buf.append(" // build the suite manually, because some of the suites are testing\n"); |
Lines 1405-1410
Link Here
|
1405 |
buf.append("\n"); |
1398 |
buf.append("\n"); |
1406 |
buf.append(" return suite;\n"); |
1399 |
buf.append(" return suite;\n"); |
1407 |
buf.append(" }\n"); |
1400 |
buf.append(" }\n"); |
|
|
1401 |
buf.append(" protected TestResult fResult;\n"); |
1402 |
buf.append(" public SuiteTest(final String name) {\n"); |
1403 |
buf.append(" super(name);\n"); |
1404 |
buf.append(" }\n"); |
1405 |
buf.append(" @Override\n"); |
1406 |
buf.append(" protected void setUp() {\n"); |
1407 |
buf.append(" this.fResult = new TestResult();\n"); |
1408 |
buf.append(" }\n"); |
1409 |
buf.append(" public void testAddTestSuite() {\n"); |
1410 |
buf.append(" final TestSuite suite = new TestSuite();\n"); |
1411 |
buf.append(" suite.addTestSuite(OneTestCase.class);\n"); |
1412 |
buf.append(" suite.run(this.fResult);\n"); |
1413 |
buf.append(" Assert.assertEquals(1, this.fResult.runCount());\n"); |
1414 |
buf.append(" }\n"); |
1408 |
buf.append(" public void testInheritedTests() {\n"); |
1415 |
buf.append(" public void testInheritedTests() {\n"); |
1409 |
buf.append(" final TestSuite suite = new TestSuite(InheritedTestCase.class);\n"); |
1416 |
buf.append(" final TestSuite suite = new TestSuite(InheritedTestCase.class);\n"); |
1410 |
buf.append(" suite.run(this.fResult);\n"); |
1417 |
buf.append(" suite.run(this.fResult);\n"); |
Lines 1453-1464
Link Here
|
1453 |
buf.append(" suite.run(this.fResult);\n"); |
1460 |
buf.append(" suite.run(this.fResult);\n"); |
1454 |
buf.append(" Assert.assertEquals(1, this.fResult.runCount());\n"); |
1461 |
buf.append(" Assert.assertEquals(1, this.fResult.runCount());\n"); |
1455 |
buf.append(" }\n"); |
1462 |
buf.append(" }\n"); |
1456 |
buf.append(" public void testAddTestSuite() {\n"); |
|
|
1457 |
buf.append(" final TestSuite suite = new TestSuite();\n"); |
1458 |
buf.append(" suite.addTestSuite(OneTestCase.class);\n"); |
1459 |
buf.append(" suite.run(this.fResult);\n"); |
1460 |
buf.append(" Assert.assertEquals(1, this.fResult.runCount());\n"); |
1461 |
buf.append(" }\n"); |
1462 |
buf.append("}"); |
1463 |
buf.append("}"); |
1463 |
fExpectedChangesAllTests.put("junit.tests.framework.SuiteTest.java", buf.toString()); |
1464 |
fExpectedChangesAllTests.put("junit.tests.framework.SuiteTest.java", buf.toString()); |
1464 |
buf= new StringBuffer(); |
1465 |
buf= new StringBuffer(); |
Lines 1557-1575
Link Here
|
1557 |
buf.append(" this.fLoader = new TestCaseClassLoader();\n"); |
1558 |
buf.append(" this.fLoader = new TestCaseClassLoader();\n"); |
1558 |
buf.append(" }\n"); |
1559 |
buf.append(" }\n"); |
1559 |
buf.append("\n"); |
1560 |
buf.append("\n"); |
1560 |
buf.append(" @Override\n"); |
|
|
1561 |
buf.append(" protected boolean isTestClass(final String classFileName) {\n"); |
1562 |
buf.append(" try {\n"); |
1563 |
buf.append(" if (classFileName.endsWith(\".class\")) { //$NON-NLS-1$\n"); |
1564 |
buf.append(" final Class testClass = this.classFromFile(classFileName);\n"); |
1565 |
buf.append(" return (testClass != null) && this.isTestClass(testClass);\n"); |
1566 |
buf.append(" }\n"); |
1567 |
buf.append(" } catch (final ClassNotFoundException expected) {\n"); |
1568 |
buf.append(" } catch (final NoClassDefFoundError notFatal) {\n"); |
1569 |
buf.append(" }\n"); |
1570 |
buf.append(" return false;\n"); |
1571 |
buf.append(" }\n"); |
1572 |
buf.append("\n"); |
1573 |
buf.append(" Class classFromFile(final String classFileName)\n"); |
1561 |
buf.append(" Class classFromFile(final String classFileName)\n"); |
1574 |
buf.append(" throws ClassNotFoundException {\n"); |
1562 |
buf.append(" throws ClassNotFoundException {\n"); |
1575 |
buf.append(" final String className = this.classNameFromFile(classFileName);\n"); |
1563 |
buf.append(" final String className = this.classNameFromFile(classFileName);\n"); |
Lines 1579-1594
Link Here
|
1579 |
buf.append(" return null;\n"); |
1567 |
buf.append(" return null;\n"); |
1580 |
buf.append(" }\n"); |
1568 |
buf.append(" }\n"); |
1581 |
buf.append("\n"); |
1569 |
buf.append("\n"); |
1582 |
buf.append(" boolean isTestClass(final Class testClass) {\n"); |
1570 |
buf.append(" boolean hasPublicConstructor(final Class testClass) {\n"); |
1583 |
buf.append(" if (this.hasSuiteMethod(testClass)) {\n"); |
1571 |
buf.append(" try {\n"); |
1584 |
buf.append(" return true;\n"); |
1572 |
buf.append(" TestSuite.getTestConstructor(testClass);\n"); |
1585 |
buf.append(" }\n"); |
1573 |
buf.append(" } catch (final NoSuchMethodException e) {\n"); |
1586 |
buf.append(" if (Test.class.isAssignableFrom(testClass)\n"); |
1574 |
buf.append(" return false;\n"); |
1587 |
buf.append(" && Modifier.isPublic(testClass.getModifiers())\n"); |
|
|
1588 |
buf.append(" && this.hasPublicConstructor(testClass)) {\n"); |
1589 |
buf.append(" return true;\n"); |
1590 |
buf.append(" }\n"); |
1575 |
buf.append(" }\n"); |
1591 |
buf.append(" return false;\n"); |
1576 |
buf.append(" return true;\n"); |
1592 |
buf.append(" }\n"); |
1577 |
buf.append(" }\n"); |
1593 |
buf.append("\n"); |
1578 |
buf.append("\n"); |
1594 |
buf.append(" boolean hasSuiteMethod(final Class testClass) {\n"); |
1579 |
buf.append(" boolean hasSuiteMethod(final Class testClass) {\n"); |
Lines 1600-1612
Link Here
|
1600 |
buf.append(" return true;\n"); |
1585 |
buf.append(" return true;\n"); |
1601 |
buf.append(" }\n"); |
1586 |
buf.append(" }\n"); |
1602 |
buf.append("\n"); |
1587 |
buf.append("\n"); |
1603 |
buf.append(" boolean hasPublicConstructor(final Class testClass) {\n"); |
1588 |
buf.append(" boolean isTestClass(final Class testClass) {\n"); |
|
|
1589 |
buf.append(" if (this.hasSuiteMethod(testClass)) {\n"); |
1590 |
buf.append(" return true;\n"); |
1591 |
buf.append(" }\n"); |
1592 |
buf.append(" if (Test.class.isAssignableFrom(testClass)\n"); |
1593 |
buf.append(" && Modifier.isPublic(testClass.getModifiers())\n"); |
1594 |
buf.append(" && this.hasPublicConstructor(testClass)) {\n"); |
1595 |
buf.append(" return true;\n"); |
1596 |
buf.append(" }\n"); |
1597 |
buf.append(" return false;\n"); |
1598 |
buf.append(" }\n"); |
1599 |
buf.append("\n"); |
1600 |
buf.append(" @Override\n"); |
1601 |
buf.append(" protected boolean isTestClass(final String classFileName) {\n"); |
1604 |
buf.append(" try {\n"); |
1602 |
buf.append(" try {\n"); |
1605 |
buf.append(" TestSuite.getTestConstructor(testClass);\n"); |
1603 |
buf.append(" if (classFileName.endsWith(\".class\")) { //$NON-NLS-1$\n"); |
1606 |
buf.append(" } catch (final NoSuchMethodException e) {\n"); |
1604 |
buf.append(" final Class testClass = this.classFromFile(classFileName);\n"); |
1607 |
buf.append(" return false;\n"); |
1605 |
buf.append(" return (testClass != null) && this.isTestClass(testClass);\n"); |
|
|
1606 |
buf.append(" }\n"); |
1607 |
buf.append(" } catch (final ClassNotFoundException expected) {\n"); |
1608 |
buf.append(" } catch (final NoClassDefFoundError notFatal) {\n"); |
1608 |
buf.append(" }\n"); |
1609 |
buf.append(" }\n"); |
1609 |
buf.append(" return true;\n"); |
1610 |
buf.append(" return false;\n"); |
1610 |
buf.append(" }\n"); |
1611 |
buf.append(" }\n"); |
1611 |
buf.append("}\n"); |
1612 |
buf.append("}\n"); |
1612 |
buf.append(""); |
1613 |
buf.append(""); |
Lines 1642-1658
Link Here
|
1642 |
buf.append(" */\n"); |
1643 |
buf.append(" */\n"); |
1643 |
buf.append("\n"); |
1644 |
buf.append("\n"); |
1644 |
buf.append("public class TestCaseClassLoader extends ClassLoader {\n"); |
1645 |
buf.append("public class TestCaseClassLoader extends ClassLoader {\n"); |
1645 |
buf.append(" /** scanned class path */\n"); |
1646 |
buf.append(" /** name of excluded properties file */\n"); |
1646 |
buf.append(" private Vector fPathItems;\n"); |
1647 |
buf.append(" static final String EXCLUDED_FILE = \"excluded.properties\"; //$NON-NLS-1$\n"); |
1647 |
buf.append(" /** default excluded paths */\n"); |
1648 |
buf.append(" /** default excluded paths */\n"); |
1648 |
buf.append(" private final String[] defaultExclusions = {\"junit.framework.\", //$NON-NLS-1$\n"); |
1649 |
buf.append(" private final String[] defaultExclusions = {\"junit.framework.\", //$NON-NLS-1$\n"); |
1649 |
buf.append(" \"junit.extensions.\", //$NON-NLS-1$\n"); |
1650 |
buf.append(" \"junit.extensions.\", //$NON-NLS-1$\n"); |
1650 |
buf.append(" \"junit.runner.\" //$NON-NLS-1$\n"); |
1651 |
buf.append(" \"junit.runner.\" //$NON-NLS-1$\n"); |
1651 |
buf.append(" };\n"); |
1652 |
buf.append(" };\n"); |
1652 |
buf.append(" /** name of excluded properties file */\n"); |
|
|
1653 |
buf.append(" static final String EXCLUDED_FILE = \"excluded.properties\"; //$NON-NLS-1$\n"); |
1654 |
buf.append(" /** excluded paths */\n"); |
1653 |
buf.append(" /** excluded paths */\n"); |
1655 |
buf.append(" private Vector fExcluded;\n"); |
1654 |
buf.append(" private Vector fExcluded;\n"); |
|
|
1655 |
buf.append(" /** scanned class path */\n"); |
1656 |
buf.append(" private Vector fPathItems;\n"); |
1656 |
buf.append("\n"); |
1657 |
buf.append("\n"); |
1657 |
buf.append(" /**\n"); |
1658 |
buf.append(" /**\n"); |
1658 |
buf.append(" * Constructs a TestCaseLoader. It scans the class path and the excluded\n"); |
1659 |
buf.append(" * Constructs a TestCaseLoader. It scans the class path and the excluded\n"); |
Lines 1671-1683
Link Here
|
1671 |
buf.append(" this.readExcludedPackages();\n"); |
1672 |
buf.append(" this.readExcludedPackages();\n"); |
1672 |
buf.append(" }\n"); |
1673 |
buf.append(" }\n"); |
1673 |
buf.append("\n"); |
1674 |
buf.append("\n"); |
1674 |
buf.append(" private void scanPath(final String classPath) {\n"); |
1675 |
buf.append(" private byte[] getClassData(final File f) {\n"); |
1675 |
buf.append(" final String separator = System.getProperty(\"path.separator\"); //$NON-NLS-1$\n"); |
1676 |
buf.append(" try {\n"); |
1676 |
buf.append(" this.fPathItems = new Vector(10);\n"); |
1677 |
buf.append(" final FileInputStream stream = new FileInputStream(f);\n"); |
1677 |
buf.append(" final StringTokenizer st = new StringTokenizer(classPath, separator);\n"); |
1678 |
buf.append(" final ByteArrayOutputStream out = new ByteArrayOutputStream(1000);\n"); |
1678 |
buf.append(" while (st.hasMoreTokens()) {\n"); |
1679 |
buf.append(" final byte[] b = new byte[1000];\n"); |
1679 |
buf.append(" this.fPathItems.addElement(st.nextToken());\n"); |
1680 |
buf.append(" int n;\n"); |
|
|
1681 |
buf.append(" while ((n = stream.read(b)) != -1) {\n"); |
1682 |
buf.append(" out.write(b, 0, n);\n"); |
1683 |
buf.append(" }\n"); |
1684 |
buf.append(" stream.close();\n"); |
1685 |
buf.append(" out.close();\n"); |
1686 |
buf.append(" return out.toByteArray();\n"); |
1687 |
buf.append("\n"); |
1688 |
buf.append(" } catch (final IOException e) {\n"); |
1680 |
buf.append(" }\n"); |
1689 |
buf.append(" }\n"); |
|
|
1690 |
buf.append(" return null;\n"); |
1681 |
buf.append(" }\n"); |
1691 |
buf.append(" }\n"); |
1682 |
buf.append("\n"); |
1692 |
buf.append("\n"); |
1683 |
buf.append(" @Override\n"); |
1693 |
buf.append(" @Override\n"); |
Lines 1699-1704
Link Here
|
1699 |
buf.append(" return false;\n"); |
1709 |
buf.append(" return false;\n"); |
1700 |
buf.append(" }\n"); |
1710 |
buf.append(" }\n"); |
1701 |
buf.append("\n"); |
1711 |
buf.append("\n"); |
|
|
1712 |
buf.append(" boolean isJar(final String pathEntry) {\n"); |
1713 |
buf.append(" return pathEntry.endsWith(\".jar\") || pathEntry.endsWith(\".zip\"); //$NON-NLS-1$ //$NON-NLS-2$\n"); |
1714 |
buf.append(" }\n"); |
1715 |
buf.append("\n"); |
1702 |
buf.append(" @Override\n"); |
1716 |
buf.append(" @Override\n"); |
1703 |
buf.append(" public synchronized Class loadClass(final String name, final boolean resolve)\n"); |
1717 |
buf.append(" public synchronized Class loadClass(final String name, final boolean resolve)\n"); |
1704 |
buf.append(" throws ClassNotFoundException {\n"); |
1718 |
buf.append(" throws ClassNotFoundException {\n"); |
Lines 1732-1759
Link Here
|
1732 |
buf.append(" return c;\n"); |
1746 |
buf.append(" return c;\n"); |
1733 |
buf.append(" }\n"); |
1747 |
buf.append(" }\n"); |
1734 |
buf.append("\n"); |
1748 |
buf.append("\n"); |
1735 |
buf.append(" private byte[] lookupClassData(final String className)\n"); |
|
|
1736 |
buf.append(" throws ClassNotFoundException {\n"); |
1737 |
buf.append(" byte[] data = null;\n"); |
1738 |
buf.append(" for (int i = 0; i < this.fPathItems.size(); i++) {\n"); |
1739 |
buf.append(" final String path = (String) this.fPathItems.elementAt(i);\n"); |
1740 |
buf.append(" final String fileName = className.replace('.', '/') + \".class\"; //$NON-NLS-1$\n"); |
1741 |
buf.append(" if (this.isJar(path)) {\n"); |
1742 |
buf.append(" data = this.loadJarData(path, fileName);\n"); |
1743 |
buf.append(" } else {\n"); |
1744 |
buf.append(" data = this.loadFileData(path, fileName);\n"); |
1745 |
buf.append(" }\n"); |
1746 |
buf.append(" if (data != null) {\n"); |
1747 |
buf.append(" return data;\n"); |
1748 |
buf.append(" }\n"); |
1749 |
buf.append(" }\n"); |
1750 |
buf.append(" throw new ClassNotFoundException(className);\n"); |
1751 |
buf.append(" }\n"); |
1752 |
buf.append("\n"); |
1753 |
buf.append(" boolean isJar(final String pathEntry) {\n"); |
1754 |
buf.append(" return pathEntry.endsWith(\".jar\") || pathEntry.endsWith(\".zip\"); //$NON-NLS-1$ //$NON-NLS-2$\n"); |
1755 |
buf.append(" }\n"); |
1756 |
buf.append("\n"); |
1757 |
buf.append(" private byte[] loadFileData(final String path, final String fileName) {\n"); |
1749 |
buf.append(" private byte[] loadFileData(final String path, final String fileName) {\n"); |
1758 |
buf.append(" final File file = new File(path, fileName);\n"); |
1750 |
buf.append(" final File file = new File(path, fileName);\n"); |
1759 |
buf.append(" if (file.exists()) {\n"); |
1751 |
buf.append(" if (file.exists()) {\n"); |
Lines 1762-1785
Link Here
|
1762 |
buf.append(" return null;\n"); |
1754 |
buf.append(" return null;\n"); |
1763 |
buf.append(" }\n"); |
1755 |
buf.append(" }\n"); |
1764 |
buf.append("\n"); |
1756 |
buf.append("\n"); |
1765 |
buf.append(" private byte[] getClassData(final File f) {\n"); |
|
|
1766 |
buf.append(" try {\n"); |
1767 |
buf.append(" final FileInputStream stream = new FileInputStream(f);\n"); |
1768 |
buf.append(" final ByteArrayOutputStream out = new ByteArrayOutputStream(1000);\n"); |
1769 |
buf.append(" final byte[] b = new byte[1000];\n"); |
1770 |
buf.append(" int n;\n"); |
1771 |
buf.append(" while ((n = stream.read(b)) != -1) {\n"); |
1772 |
buf.append(" out.write(b, 0, n);\n"); |
1773 |
buf.append(" }\n"); |
1774 |
buf.append(" stream.close();\n"); |
1775 |
buf.append(" out.close();\n"); |
1776 |
buf.append(" return out.toByteArray();\n"); |
1777 |
buf.append("\n"); |
1778 |
buf.append(" } catch (final IOException e) {\n"); |
1779 |
buf.append(" }\n"); |
1780 |
buf.append(" return null;\n"); |
1781 |
buf.append(" }\n"); |
1782 |
buf.append("\n"); |
1783 |
buf.append(" private byte[] loadJarData(final String path, final String fileName) {\n"); |
1757 |
buf.append(" private byte[] loadJarData(final String path, final String fileName) {\n"); |
1784 |
buf.append(" ZipFile zipFile = null;\n"); |
1758 |
buf.append(" ZipFile zipFile = null;\n"); |
1785 |
buf.append(" InputStream stream = null;\n"); |
1759 |
buf.append(" InputStream stream = null;\n"); |
Lines 1819-1824
Link Here
|
1819 |
buf.append(" return null;\n"); |
1793 |
buf.append(" return null;\n"); |
1820 |
buf.append(" }\n"); |
1794 |
buf.append(" }\n"); |
1821 |
buf.append("\n"); |
1795 |
buf.append("\n"); |
|
|
1796 |
buf.append(" private byte[] lookupClassData(final String className)\n"); |
1797 |
buf.append(" throws ClassNotFoundException {\n"); |
1798 |
buf.append(" byte[] data = null;\n"); |
1799 |
buf.append(" for (int i = 0; i < this.fPathItems.size(); i++) {\n"); |
1800 |
buf.append(" final String path = (String) this.fPathItems.elementAt(i);\n"); |
1801 |
buf.append(" final String fileName = className.replace('.', '/') + \".class\"; //$NON-NLS-1$\n"); |
1802 |
buf.append(" if (this.isJar(path)) {\n"); |
1803 |
buf.append(" data = this.loadJarData(path, fileName);\n"); |
1804 |
buf.append(" } else {\n"); |
1805 |
buf.append(" data = this.loadFileData(path, fileName);\n"); |
1806 |
buf.append(" }\n"); |
1807 |
buf.append(" if (data != null) {\n"); |
1808 |
buf.append(" return data;\n"); |
1809 |
buf.append(" }\n"); |
1810 |
buf.append(" }\n"); |
1811 |
buf.append(" throw new ClassNotFoundException(className);\n"); |
1812 |
buf.append(" }\n"); |
1813 |
buf.append("\n"); |
1822 |
buf.append(" private void readExcludedPackages() {\n"); |
1814 |
buf.append(" private void readExcludedPackages() {\n"); |
1823 |
buf.append(" this.fExcluded = new Vector(10);\n"); |
1815 |
buf.append(" this.fExcluded = new Vector(10);\n"); |
1824 |
buf.append(" for (final String element : this.defaultExclusions) {\n"); |
1816 |
buf.append(" for (final String element : this.defaultExclusions) {\n"); |
Lines 1855-1860
Link Here
|
1855 |
buf.append(" }\n"); |
1847 |
buf.append(" }\n"); |
1856 |
buf.append(" }\n"); |
1848 |
buf.append(" }\n"); |
1857 |
buf.append(" }\n"); |
1849 |
buf.append(" }\n"); |
|
|
1850 |
buf.append("\n"); |
1851 |
buf.append(" private void scanPath(final String classPath) {\n"); |
1852 |
buf.append(" final String separator = System.getProperty(\"path.separator\"); //$NON-NLS-1$\n"); |
1853 |
buf.append(" this.fPathItems = new Vector(10);\n"); |
1854 |
buf.append(" final StringTokenizer st = new StringTokenizer(classPath, separator);\n"); |
1855 |
buf.append(" while (st.hasMoreTokens()) {\n"); |
1856 |
buf.append(" this.fPathItems.addElement(st.nextToken());\n"); |
1857 |
buf.append(" }\n"); |
1858 |
buf.append(" }\n"); |
1858 |
buf.append("}"); |
1859 |
buf.append("}"); |
1859 |
fExpectedChangesAllTests.put("junit.runner.TestCaseClassLoader.java", buf.toString()); |
1860 |
fExpectedChangesAllTests.put("junit.runner.TestCaseClassLoader.java", buf.toString()); |
1860 |
buf= new StringBuffer(); |
1861 |
buf= new StringBuffer(); |
Lines 1898-1910
Link Here
|
1898 |
buf.append(" * \n"); |
1899 |
buf.append(" * \n"); |
1899 |
buf.append(" */\n"); |
1900 |
buf.append(" */\n"); |
1900 |
buf.append("public class SimpleTest extends TestCase {\n"); |
1901 |
buf.append("public class SimpleTest extends TestCase {\n"); |
1901 |
buf.append(" protected int fValue1;\n"); |
1902 |
buf.append(" public static void main(final String[] args) {\n"); |
1902 |
buf.append(" protected int fValue2;\n"); |
1903 |
buf.append(" junit.textui.TestRunner.run(SimpleTest.suite());\n"); |
1903 |
buf.append("\n"); |
|
|
1904 |
buf.append(" @Override\n"); |
1905 |
buf.append(" protected void setUp() {\n"); |
1906 |
buf.append(" this.fValue1 = 2;\n"); |
1907 |
buf.append(" this.fValue2 = 3;\n"); |
1908 |
buf.append(" }\n"); |
1904 |
buf.append(" }\n"); |
1909 |
buf.append(" public static Test suite() {\n"); |
1905 |
buf.append(" public static Test suite() {\n"); |
1910 |
buf.append("\n"); |
1906 |
buf.append("\n"); |
Lines 1923-1928
Link Here
|
1923 |
buf.append(" */\n"); |
1919 |
buf.append(" */\n"); |
1924 |
buf.append(" return new TestSuite(SimpleTest.class);\n"); |
1920 |
buf.append(" return new TestSuite(SimpleTest.class);\n"); |
1925 |
buf.append(" }\n"); |
1921 |
buf.append(" }\n"); |
|
|
1922 |
buf.append("\n"); |
1923 |
buf.append(" protected int fValue1;\n"); |
1924 |
buf.append(" protected int fValue2;\n"); |
1925 |
buf.append(" @Override\n"); |
1926 |
buf.append(" protected void setUp() {\n"); |
1927 |
buf.append(" this.fValue1 = 2;\n"); |
1928 |
buf.append(" this.fValue2 = 3;\n"); |
1929 |
buf.append(" }\n"); |
1926 |
buf.append(" public void testAdd() {\n"); |
1930 |
buf.append(" public void testAdd() {\n"); |
1927 |
buf.append(" final double result = this.fValue1 + this.fValue2;\n"); |
1931 |
buf.append(" final double result = this.fValue1 + this.fValue2;\n"); |
1928 |
buf.append(" // forced failure result == 5\n"); |
1932 |
buf.append(" // forced failure result == 5\n"); |
Lines 1939-1947
Link Here
|
1939 |
buf.append(" Assert.assertEquals(\"Size\", 12, 13); //$NON-NLS-1$\n"); |
1943 |
buf.append(" Assert.assertEquals(\"Size\", 12, 13); //$NON-NLS-1$\n"); |
1940 |
buf.append(" Assert.assertEquals(\"Capacity\", 12.0, 11.99, 0.0); //$NON-NLS-1$\n"); |
1944 |
buf.append(" Assert.assertEquals(\"Capacity\", 12.0, 11.99, 0.0); //$NON-NLS-1$\n"); |
1941 |
buf.append(" }\n"); |
1945 |
buf.append(" }\n"); |
1942 |
buf.append(" public static void main(final String[] args) {\n"); |
|
|
1943 |
buf.append(" junit.textui.TestRunner.run(SimpleTest.suite());\n"); |
1944 |
buf.append(" }\n"); |
1945 |
buf.append("}"); |
1946 |
buf.append("}"); |
1946 |
fExpectedChangesAllTests.put("junit.samples.SimpleTest.java", buf.toString()); |
1947 |
fExpectedChangesAllTests.put("junit.samples.SimpleTest.java", buf.toString()); |
1947 |
buf= new StringBuffer(); |
1948 |
buf= new StringBuffer(); |
Lines 1951-1963
Link Here
|
1951 |
buf.append(" * This class defines the current version of JUnit\n"); |
1952 |
buf.append(" * This class defines the current version of JUnit\n"); |
1952 |
buf.append(" */\n"); |
1953 |
buf.append(" */\n"); |
1953 |
buf.append("public class Version {\n"); |
1954 |
buf.append("public class Version {\n"); |
1954 |
buf.append(" private Version() {\n"); |
|
|
1955 |
buf.append(" // don't instantiate\n"); |
1956 |
buf.append(" }\n"); |
1957 |
buf.append("\n"); |
1958 |
buf.append(" public static String id() {\n"); |
1955 |
buf.append(" public static String id() {\n"); |
1959 |
buf.append(" return \"3.8.1\"; //$NON-NLS-1$\n"); |
1956 |
buf.append(" return \"3.8.1\"; //$NON-NLS-1$\n"); |
1960 |
buf.append(" }\n"); |
1957 |
buf.append(" }\n"); |
|
|
1958 |
buf.append("\n"); |
1959 |
buf.append(" private Version() {\n"); |
1960 |
buf.append(" // don't instantiate\n"); |
1961 |
buf.append(" }\n"); |
1961 |
buf.append("}\n"); |
1962 |
buf.append("}\n"); |
1962 |
buf.append(""); |
1963 |
buf.append(""); |
1963 |
fExpectedChangesAllTests.put("junit.runner.Version.java", buf.toString()); |
1964 |
fExpectedChangesAllTests.put("junit.runner.Version.java", buf.toString()); |
Lines 2059-2081
Link Here
|
2059 |
buf.append(" */\n"); |
2060 |
buf.append(" */\n"); |
2060 |
buf.append("public class TestSuite implements Test {\n"); |
2061 |
buf.append("public class TestSuite implements Test {\n"); |
2061 |
buf.append("\n"); |
2062 |
buf.append("\n"); |
2062 |
buf.append(" private final Vector fTests = new Vector(10);\n"); |
2063 |
buf.append(" /**\n"); |
2063 |
buf.append(" private String fName;\n"); |
2064 |
buf.append(" * ...as the moon sets over the early morning Merlin, Oregon mountains, our\n"); |
|
|
2065 |
buf.append(" * intrepid adventurers type...\n"); |
2066 |
buf.append(" */\n"); |
2067 |
buf.append(" static public Test createTest(final Class theClass, final String name) {\n"); |
2068 |
buf.append(" Constructor constructor;\n"); |
2069 |
buf.append(" try {\n"); |
2070 |
buf.append(" constructor = TestSuite.getTestConstructor(theClass);\n"); |
2071 |
buf.append(" } catch (final NoSuchMethodException e) {\n"); |
2072 |
buf.append(" return TestSuite\n"); |
2073 |
buf.append(" .warning(\"Class \" + theClass.getName() + \" has no public constructor TestCase(String name) or TestCase()\"); //$NON-NLS-1$ //$NON-NLS-2$\n"); |
2074 |
buf.append(" }\n"); |
2075 |
buf.append(" Object test;\n"); |
2076 |
buf.append(" try {\n"); |
2077 |
buf.append(" if (constructor.getParameterTypes().length == 0) {\n"); |
2078 |
buf.append(" test = constructor.newInstance(new Object[0]);\n"); |
2079 |
buf.append(" if (test instanceof TestCase) {\n"); |
2080 |
buf.append(" ((TestCase) test).setName(name);\n"); |
2081 |
buf.append(" }\n"); |
2082 |
buf.append(" } else {\n"); |
2083 |
buf.append(" test = constructor.newInstance(new Object[]{name});\n"); |
2084 |
buf.append(" }\n"); |
2085 |
buf.append(" } catch (final InstantiationException e) {\n"); |
2086 |
buf.append(" return (TestSuite\n"); |
2087 |
buf.append(" .warning(\"Cannot instantiate test case: \" + name + \" (\" + TestSuite.exceptionToString(e) + \")\")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\n"); |
2088 |
buf.append(" } catch (final InvocationTargetException e) {\n"); |
2089 |
buf.append(" return (TestSuite\n"); |
2090 |
buf.append(" .warning(\"Exception in constructor: \" + name + \" (\" + TestSuite.exceptionToString(e.getTargetException()) + \")\")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\n"); |
2091 |
buf.append(" } catch (final IllegalAccessException e) {\n"); |
2092 |
buf.append(" return (TestSuite\n"); |
2093 |
buf.append(" .warning(\"Cannot access test case: \" + name + \" (\" + TestSuite.exceptionToString(e) + \")\")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\n"); |
2094 |
buf.append(" }\n"); |
2095 |
buf.append(" return (Test) test;\n"); |
2096 |
buf.append(" }\n"); |
2097 |
buf.append(" /**\n"); |
2098 |
buf.append(" * Converts the stack trace into a string\n"); |
2099 |
buf.append(" */\n"); |
2100 |
buf.append(" private static String exceptionToString(final Throwable t) {\n"); |
2101 |
buf.append(" final StringWriter stringWriter = new StringWriter();\n"); |
2102 |
buf.append(" final PrintWriter writer = new PrintWriter(stringWriter);\n"); |
2103 |
buf.append(" t.printStackTrace(writer);\n"); |
2104 |
buf.append(" return stringWriter.toString();\n"); |
2105 |
buf.append("\n"); |
2106 |
buf.append(" }\n"); |
2064 |
buf.append("\n"); |
2107 |
buf.append("\n"); |
2065 |
buf.append(" /**\n"); |
2108 |
buf.append(" /**\n"); |
2066 |
buf.append(" * Constructs an empty TestSuite.\n"); |
2109 |
buf.append(" * Gets a constructor which takes a single String as its argument or a no\n"); |
|
|
2110 |
buf.append(" * arg constructor.\n"); |
2067 |
buf.append(" */\n"); |
2111 |
buf.append(" */\n"); |
2068 |
buf.append(" public TestSuite() {\n"); |
2112 |
buf.append(" public static Constructor getTestConstructor(final Class theClass)\n"); |
|
|
2113 |
buf.append(" throws NoSuchMethodException {\n"); |
2114 |
buf.append(" final Class[] args = {String.class};\n"); |
2115 |
buf.append(" try {\n"); |
2116 |
buf.append(" return theClass.getConstructor(args);\n"); |
2117 |
buf.append(" } catch (final NoSuchMethodException e) {\n"); |
2118 |
buf.append(" // fall through\n"); |
2119 |
buf.append(" }\n"); |
2120 |
buf.append(" return theClass.getConstructor(new Class[0]);\n"); |
2069 |
buf.append(" }\n"); |
2121 |
buf.append(" }\n"); |
2070 |
buf.append("\n"); |
2122 |
buf.append("\n"); |
2071 |
buf.append(" /**\n"); |
2123 |
buf.append(" /**\n"); |
2072 |
buf.append(" * Constructs a TestSuite from the given class with the given name.\n"); |
2124 |
buf.append(" * Returns a test which will fail and log a warning message.\n"); |
2073 |
buf.append(" * \n"); |
|
|
2074 |
buf.append(" * @see TestSuite#TestSuite(Class)\n"); |
2075 |
buf.append(" */\n"); |
2125 |
buf.append(" */\n"); |
2076 |
buf.append(" public TestSuite(final Class theClass, final String name) {\n"); |
2126 |
buf.append(" private static Test warning(final String message) {\n"); |
2077 |
buf.append(" this(theClass);\n"); |
2127 |
buf.append(" return new TestCase(\"warning\") { //$NON-NLS-1$\n"); |
2078 |
buf.append(" this.setName(name);\n"); |
2128 |
buf.append(" @Override\n"); |
|
|
2129 |
buf.append(" protected void runTest() {\n"); |
2130 |
buf.append(" Assert.fail(message);\n"); |
2131 |
buf.append(" }\n"); |
2132 |
buf.append(" };\n"); |
2133 |
buf.append(" }\n"); |
2134 |
buf.append("\n"); |
2135 |
buf.append(" private String fName;\n"); |
2136 |
buf.append("\n"); |
2137 |
buf.append(" private final Vector fTests = new Vector(10);\n"); |
2138 |
buf.append("\n"); |
2139 |
buf.append(" /**\n"); |
2140 |
buf.append(" * Constructs an empty TestSuite.\n"); |
2141 |
buf.append(" */\n"); |
2142 |
buf.append(" public TestSuite() {\n"); |
2079 |
buf.append(" }\n"); |
2143 |
buf.append(" }\n"); |
2080 |
buf.append("\n"); |
2144 |
buf.append("\n"); |
2081 |
buf.append(" /**\n"); |
2145 |
buf.append(" /**\n"); |
Lines 2117-2122
Link Here
|
2117 |
buf.append(" }\n"); |
2181 |
buf.append(" }\n"); |
2118 |
buf.append("\n"); |
2182 |
buf.append("\n"); |
2119 |
buf.append(" /**\n"); |
2183 |
buf.append(" /**\n"); |
|
|
2184 |
buf.append(" * Constructs a TestSuite from the given class with the given name.\n"); |
2185 |
buf.append(" * \n"); |
2186 |
buf.append(" * @see TestSuite#TestSuite(Class)\n"); |
2187 |
buf.append(" */\n"); |
2188 |
buf.append(" public TestSuite(final Class theClass, final String name) {\n"); |
2189 |
buf.append(" this(theClass);\n"); |
2190 |
buf.append(" this.setName(name);\n"); |
2191 |
buf.append(" }\n"); |
2192 |
buf.append("\n"); |
2193 |
buf.append(" /**\n"); |
2120 |
buf.append(" * Constructs an empty TestSuite.\n"); |
2194 |
buf.append(" * Constructs an empty TestSuite.\n"); |
2121 |
buf.append(" */\n"); |
2195 |
buf.append(" */\n"); |
2122 |
buf.append(" public TestSuite(final String name) {\n"); |
2196 |
buf.append(" public TestSuite(final String name) {\n"); |
Lines 2130-2142
Link Here
|
2130 |
buf.append(" this.fTests.addElement(test);\n"); |
2204 |
buf.append(" this.fTests.addElement(test);\n"); |
2131 |
buf.append(" }\n"); |
2205 |
buf.append(" }\n"); |
2132 |
buf.append("\n"); |
2206 |
buf.append("\n"); |
2133 |
buf.append(" /**\n"); |
|
|
2134 |
buf.append(" * Adds the tests from the given class to the suite\n"); |
2135 |
buf.append(" */\n"); |
2136 |
buf.append(" public void addTestSuite(final Class testClass) {\n"); |
2137 |
buf.append(" this.addTest(new TestSuite(testClass));\n"); |
2138 |
buf.append(" }\n"); |
2139 |
buf.append("\n"); |
2140 |
buf.append(" private void addTestMethod(final Method m, final Vector names,\n"); |
2207 |
buf.append(" private void addTestMethod(final Method m, final Vector names,\n"); |
2141 |
buf.append(" final Class theClass) {\n"); |
2208 |
buf.append(" final Class theClass) {\n"); |
2142 |
buf.append(" final String name = m.getName();\n"); |
2209 |
buf.append(" final String name = m.getName();\n"); |
Lines 2155-2203
Link Here
|
2155 |
buf.append(" }\n"); |
2222 |
buf.append(" }\n"); |
2156 |
buf.append("\n"); |
2223 |
buf.append("\n"); |
2157 |
buf.append(" /**\n"); |
2224 |
buf.append(" /**\n"); |
2158 |
buf.append(" * ...as the moon sets over the early morning Merlin, Oregon mountains, our\n"); |
2225 |
buf.append(" * Adds the tests from the given class to the suite\n"); |
2159 |
buf.append(" * intrepid adventurers type...\n"); |
|
|
2160 |
buf.append(" */\n"); |
2161 |
buf.append(" static public Test createTest(final Class theClass, final String name) {\n"); |
2162 |
buf.append(" Constructor constructor;\n"); |
2163 |
buf.append(" try {\n"); |
2164 |
buf.append(" constructor = TestSuite.getTestConstructor(theClass);\n"); |
2165 |
buf.append(" } catch (final NoSuchMethodException e) {\n"); |
2166 |
buf.append(" return TestSuite\n"); |
2167 |
buf.append(" .warning(\"Class \" + theClass.getName() + \" has no public constructor TestCase(String name) or TestCase()\"); //$NON-NLS-1$ //$NON-NLS-2$\n"); |
2168 |
buf.append(" }\n"); |
2169 |
buf.append(" Object test;\n"); |
2170 |
buf.append(" try {\n"); |
2171 |
buf.append(" if (constructor.getParameterTypes().length == 0) {\n"); |
2172 |
buf.append(" test = constructor.newInstance(new Object[0]);\n"); |
2173 |
buf.append(" if (test instanceof TestCase) {\n"); |
2174 |
buf.append(" ((TestCase) test).setName(name);\n"); |
2175 |
buf.append(" }\n"); |
2176 |
buf.append(" } else {\n"); |
2177 |
buf.append(" test = constructor.newInstance(new Object[]{name});\n"); |
2178 |
buf.append(" }\n"); |
2179 |
buf.append(" } catch (final InstantiationException e) {\n"); |
2180 |
buf.append(" return (TestSuite\n"); |
2181 |
buf.append(" .warning(\"Cannot instantiate test case: \" + name + \" (\" + TestSuite.exceptionToString(e) + \")\")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\n"); |
2182 |
buf.append(" } catch (final InvocationTargetException e) {\n"); |
2183 |
buf.append(" return (TestSuite\n"); |
2184 |
buf.append(" .warning(\"Exception in constructor: \" + name + \" (\" + TestSuite.exceptionToString(e.getTargetException()) + \")\")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\n"); |
2185 |
buf.append(" } catch (final IllegalAccessException e) {\n"); |
2186 |
buf.append(" return (TestSuite\n"); |
2187 |
buf.append(" .warning(\"Cannot access test case: \" + name + \" (\" + TestSuite.exceptionToString(e) + \")\")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\n"); |
2188 |
buf.append(" }\n"); |
2189 |
buf.append(" return (Test) test;\n"); |
2190 |
buf.append(" }\n"); |
2191 |
buf.append("\n"); |
2192 |
buf.append(" /**\n"); |
2193 |
buf.append(" * Converts the stack trace into a string\n"); |
2194 |
buf.append(" */\n"); |
2226 |
buf.append(" */\n"); |
2195 |
buf.append(" private static String exceptionToString(final Throwable t) {\n"); |
2227 |
buf.append(" public void addTestSuite(final Class testClass) {\n"); |
2196 |
buf.append(" final StringWriter stringWriter = new StringWriter();\n"); |
2228 |
buf.append(" this.addTest(new TestSuite(testClass));\n"); |
2197 |
buf.append(" final PrintWriter writer = new PrintWriter(stringWriter);\n"); |
|
|
2198 |
buf.append(" t.printStackTrace(writer);\n"); |
2199 |
buf.append(" return stringWriter.toString();\n"); |
2200 |
buf.append("\n"); |
2201 |
buf.append(" }\n"); |
2229 |
buf.append(" }\n"); |
2202 |
buf.append("\n"); |
2230 |
buf.append("\n"); |
2203 |
buf.append(" /**\n"); |
2231 |
buf.append(" /**\n"); |
Lines 2213-2230
Link Here
|
2213 |
buf.append(" }\n"); |
2241 |
buf.append(" }\n"); |
2214 |
buf.append("\n"); |
2242 |
buf.append("\n"); |
2215 |
buf.append(" /**\n"); |
2243 |
buf.append(" /**\n"); |
2216 |
buf.append(" * Gets a constructor which takes a single String as its argument or a no\n"); |
2244 |
buf.append(" * Returns the name of the suite. Not all test suites have a name and this\n"); |
2217 |
buf.append(" * arg constructor.\n"); |
2245 |
buf.append(" * method can return null.\n"); |
2218 |
buf.append(" */\n"); |
2246 |
buf.append(" */\n"); |
2219 |
buf.append(" public static Constructor getTestConstructor(final Class theClass)\n"); |
2247 |
buf.append(" public String getName() {\n"); |
2220 |
buf.append(" throws NoSuchMethodException {\n"); |
2248 |
buf.append(" return this.fName;\n"); |
2221 |
buf.append(" final Class[] args = {String.class};\n"); |
|
|
2222 |
buf.append(" try {\n"); |
2223 |
buf.append(" return theClass.getConstructor(args);\n"); |
2224 |
buf.append(" } catch (final NoSuchMethodException e) {\n"); |
2225 |
buf.append(" // fall through\n"); |
2226 |
buf.append(" }\n"); |
2227 |
buf.append(" return theClass.getConstructor(new Class[0]);\n"); |
2228 |
buf.append(" }\n"); |
2249 |
buf.append(" }\n"); |
2229 |
buf.append("\n"); |
2250 |
buf.append("\n"); |
2230 |
buf.append(" private boolean isPublicTestMethod(final Method m) {\n"); |
2251 |
buf.append(" private boolean isPublicTestMethod(final Method m) {\n"); |
Lines 2257-2262
Link Here
|
2257 |
buf.append(" }\n"); |
2278 |
buf.append(" }\n"); |
2258 |
buf.append("\n"); |
2279 |
buf.append("\n"); |
2259 |
buf.append(" /**\n"); |
2280 |
buf.append(" /**\n"); |
|
|
2281 |
buf.append(" * Sets the name of the suite.\n"); |
2282 |
buf.append(" * \n"); |
2283 |
buf.append(" * @param name\n"); |
2284 |
buf.append(" * The name to set\n"); |
2285 |
buf.append(" */\n"); |
2286 |
buf.append(" public void setName(final String name) {\n"); |
2287 |
buf.append(" this.fName = name;\n"); |
2288 |
buf.append(" }\n"); |
2289 |
buf.append("\n"); |
2290 |
buf.append(" /**\n"); |
2260 |
buf.append(" * Returns the test at the given index\n"); |
2291 |
buf.append(" * Returns the test at the given index\n"); |
2261 |
buf.append(" */\n"); |
2292 |
buf.append(" */\n"); |
2262 |
buf.append(" public Test testAt(final int index) {\n"); |
2293 |
buf.append(" public Test testAt(final int index) {\n"); |
Lines 2286-2321
Link Here
|
2286 |
buf.append(" }\n"); |
2317 |
buf.append(" }\n"); |
2287 |
buf.append(" return super.toString();\n"); |
2318 |
buf.append(" return super.toString();\n"); |
2288 |
buf.append(" }\n"); |
2319 |
buf.append(" }\n"); |
2289 |
buf.append("\n"); |
|
|
2290 |
buf.append(" /**\n"); |
2291 |
buf.append(" * Sets the name of the suite.\n"); |
2292 |
buf.append(" * \n"); |
2293 |
buf.append(" * @param name\n"); |
2294 |
buf.append(" * The name to set\n"); |
2295 |
buf.append(" */\n"); |
2296 |
buf.append(" public void setName(final String name) {\n"); |
2297 |
buf.append(" this.fName = name;\n"); |
2298 |
buf.append(" }\n"); |
2299 |
buf.append("\n"); |
2300 |
buf.append(" /**\n"); |
2301 |
buf.append(" * Returns the name of the suite. Not all test suites have a name and this\n"); |
2302 |
buf.append(" * method can return null.\n"); |
2303 |
buf.append(" */\n"); |
2304 |
buf.append(" public String getName() {\n"); |
2305 |
buf.append(" return this.fName;\n"); |
2306 |
buf.append(" }\n"); |
2307 |
buf.append("\n"); |
2308 |
buf.append(" /**\n"); |
2309 |
buf.append(" * Returns a test which will fail and log a warning message.\n"); |
2310 |
buf.append(" */\n"); |
2311 |
buf.append(" private static Test warning(final String message) {\n"); |
2312 |
buf.append(" return new TestCase(\"warning\") { //$NON-NLS-1$\n"); |
2313 |
buf.append(" @Override\n"); |
2314 |
buf.append(" protected void runTest() {\n"); |
2315 |
buf.append(" Assert.fail(message);\n"); |
2316 |
buf.append(" }\n"); |
2317 |
buf.append(" };\n"); |
2318 |
buf.append(" }\n"); |
2319 |
buf.append("}"); |
2320 |
buf.append("}"); |
2320 |
fExpectedChangesAllTests.put("junit.framework.TestSuite.java", buf.toString()); |
2321 |
fExpectedChangesAllTests.put("junit.framework.TestSuite.java", buf.toString()); |
2321 |
buf= new StringBuffer(); |
2322 |
buf= new StringBuffer(); |
Lines 2378-2443
Link Here
|
2378 |
buf.append("\n"); |
2379 |
buf.append("\n"); |
2379 |
buf.append("public class Assert {\n"); |
2380 |
buf.append("public class Assert {\n"); |
2380 |
buf.append(" /**\n"); |
2381 |
buf.append(" /**\n"); |
2381 |
buf.append(" * Protect constructor since it is a static only class\n"); |
2382 |
buf.append(" * Asserts that two booleans are equal.\n"); |
2382 |
buf.append(" */\n"); |
2383 |
buf.append(" */\n"); |
2383 |
buf.append(" protected Assert() {\n"); |
2384 |
buf.append(" static public void assertEquals(final boolean expected, final boolean actual) {\n"); |
|
|
2385 |
buf.append(" Assert.assertEquals(null, expected, actual);\n"); |
2384 |
buf.append(" }\n"); |
2386 |
buf.append(" }\n"); |
2385 |
buf.append("\n"); |
2387 |
buf.append("\n"); |
2386 |
buf.append(" /**\n"); |
2388 |
buf.append(" /**\n"); |
2387 |
buf.append(" * Asserts that a condition is true. If it isn't it throws an\n"); |
2389 |
buf.append(" * Asserts that two bytes are equal.\n"); |
2388 |
buf.append(" * AssertionFailedError with the given message.\n"); |
|
|
2389 |
buf.append(" */\n"); |
2390 |
buf.append(" static public void assertTrue(final String message, boolean condition) {\n"); |
2391 |
buf.append(" if (!condition) {\n"); |
2392 |
buf.append(" Assert.fail(message);\n"); |
2393 |
buf.append(" }\n"); |
2394 |
buf.append(" }\n"); |
2395 |
buf.append(" /**\n"); |
2396 |
buf.append(" * Asserts that a condition is true. If it isn't it throws an\n"); |
2397 |
buf.append(" * AssertionFailedError.\n"); |
2398 |
buf.append(" */\n"); |
2390 |
buf.append(" */\n"); |
2399 |
buf.append(" static public void assertTrue(final boolean condition) {\n"); |
2391 |
buf.append(" static public void assertEquals(final byte expected, final byte actual) {\n"); |
2400 |
buf.append(" Assert.assertTrue(null, condition);\n"); |
2392 |
buf.append(" Assert.assertEquals(null, expected, actual);\n"); |
2401 |
buf.append(" }\n"); |
2393 |
buf.append(" }\n"); |
2402 |
buf.append(" /**\n"); |
2394 |
buf.append(" /**\n"); |
2403 |
buf.append(" * Asserts that a condition is false. If it isn't it throws an\n"); |
2395 |
buf.append(" * Asserts that two chars are equal.\n"); |
2404 |
buf.append(" * AssertionFailedError with the given message.\n"); |
|
|
2405 |
buf.append(" */\n"); |
2396 |
buf.append(" */\n"); |
2406 |
buf.append(" static public void assertFalse(final String message, boolean condition) {\n"); |
2397 |
buf.append(" static public void assertEquals(final char expected, final char actual) {\n"); |
2407 |
buf.append(" Assert.assertTrue(message, !condition);\n"); |
2398 |
buf.append(" Assert.assertEquals(null, expected, actual);\n"); |
2408 |
buf.append(" }\n"); |
2399 |
buf.append(" }\n"); |
2409 |
buf.append(" /**\n"); |
2400 |
buf.append(" /**\n"); |
2410 |
buf.append(" * Asserts that a condition is false. If it isn't it throws an\n"); |
2401 |
buf.append(" * Asserts that two doubles are equal concerning a delta. If the expected\n"); |
2411 |
buf.append(" * AssertionFailedError.\n"); |
2402 |
buf.append(" * value is infinity then the delta value is ignored.\n"); |
2412 |
buf.append(" */\n"); |
2403 |
buf.append(" */\n"); |
2413 |
buf.append(" static public void assertFalse(final boolean condition) {\n"); |
2404 |
buf.append(" static public void assertEquals(final double expected, final double actual,\n"); |
2414 |
buf.append(" Assert.assertFalse(null, condition);\n"); |
2405 |
buf.append(" final double delta) {\n"); |
|
|
2406 |
buf.append(" Assert.assertEquals(null, expected, actual, delta);\n"); |
2415 |
buf.append(" }\n"); |
2407 |
buf.append(" }\n"); |
2416 |
buf.append(" /**\n"); |
2408 |
buf.append(" /**\n"); |
2417 |
buf.append(" * Fails a test with the given message.\n"); |
2409 |
buf.append(" * Asserts that two floats are equal concerning a delta. If the expected\n"); |
|
|
2410 |
buf.append(" * value is infinity then the delta value is ignored.\n"); |
2418 |
buf.append(" */\n"); |
2411 |
buf.append(" */\n"); |
2419 |
buf.append(" static public void fail(final String message) {\n"); |
2412 |
buf.append(" static public void assertEquals(final float expected, final float actual,\n"); |
2420 |
buf.append(" throw new AssertionFailedError(message);\n"); |
2413 |
buf.append(" final float delta) {\n"); |
|
|
2414 |
buf.append(" Assert.assertEquals(null, expected, actual, delta);\n"); |
2421 |
buf.append(" }\n"); |
2415 |
buf.append(" }\n"); |
2422 |
buf.append(" /**\n"); |
2416 |
buf.append(" /**\n"); |
2423 |
buf.append(" * Fails a test with no message.\n"); |
2417 |
buf.append(" * Asserts that two ints are equal.\n"); |
2424 |
buf.append(" */\n"); |
2418 |
buf.append(" */\n"); |
2425 |
buf.append(" static public void fail() {\n"); |
2419 |
buf.append(" static public void assertEquals(final int expected, final int actual) {\n"); |
2426 |
buf.append(" Assert.fail(null);\n"); |
2420 |
buf.append(" Assert.assertEquals(null, expected, actual);\n"); |
2427 |
buf.append(" }\n"); |
2421 |
buf.append(" }\n"); |
2428 |
buf.append(" /**\n"); |
2422 |
buf.append(" /**\n"); |
2429 |
buf.append(" * Asserts that two objects are equal. If they are not an\n"); |
2423 |
buf.append(" * Asserts that two longs are equal.\n"); |
2430 |
buf.append(" * AssertionFailedError is thrown with the given message.\n"); |
|
|
2431 |
buf.append(" */\n"); |
2424 |
buf.append(" */\n"); |
2432 |
buf.append(" static public void assertEquals(final String message,\n"); |
2425 |
buf.append(" static public void assertEquals(final long expected, final long actual) {\n"); |
2433 |
buf.append(" final Object expected, final Object actual) {\n"); |
2426 |
buf.append(" Assert.assertEquals(null, expected, actual);\n"); |
2434 |
buf.append(" if ((expected == null) && (actual == null)) {\n"); |
|
|
2435 |
buf.append(" return;\n"); |
2436 |
buf.append(" }\n"); |
2437 |
buf.append(" if ((expected != null) && expected.equals(actual)) {\n"); |
2438 |
buf.append(" return;\n"); |
2439 |
buf.append(" }\n"); |
2440 |
buf.append(" Assert.failNotEquals(message, expected, actual);\n"); |
2441 |
buf.append(" }\n"); |
2427 |
buf.append(" }\n"); |
2442 |
buf.append(" /**\n"); |
2428 |
buf.append(" /**\n"); |
2443 |
buf.append(" * Asserts that two objects are equal. If they are not an\n"); |
2429 |
buf.append(" * Asserts that two objects are equal. If they are not an\n"); |
Lines 2447-2469
Link Here
|
2447 |
buf.append(" Assert.assertEquals(null, expected, actual);\n"); |
2433 |
buf.append(" Assert.assertEquals(null, expected, actual);\n"); |
2448 |
buf.append(" }\n"); |
2434 |
buf.append(" }\n"); |
2449 |
buf.append(" /**\n"); |
2435 |
buf.append(" /**\n"); |
2450 |
buf.append(" * Asserts that two Strings are equal.\n"); |
2436 |
buf.append(" * Asserts that two shorts are equal.\n"); |
|
|
2437 |
buf.append(" */\n"); |
2438 |
buf.append(" static public void assertEquals(final short expected, final short actual) {\n"); |
2439 |
buf.append(" Assert.assertEquals(null, expected, actual);\n"); |
2440 |
buf.append(" }\n"); |
2441 |
buf.append(" /**\n"); |
2442 |
buf.append(" * Asserts that two booleans are equal. If they are not an\n"); |
2443 |
buf.append(" * AssertionFailedError is thrown with the given message.\n"); |
2451 |
buf.append(" */\n"); |
2444 |
buf.append(" */\n"); |
2452 |
buf.append(" static public void assertEquals(final String message,\n"); |
2445 |
buf.append(" static public void assertEquals(final String message,\n"); |
2453 |
buf.append(" final String expected, final String actual) {\n"); |
2446 |
buf.append(" final boolean expected, final boolean actual) {\n"); |
2454 |
buf.append(" if ((expected == null) && (actual == null)) {\n"); |
2447 |
buf.append(" Assert\n"); |
2455 |
buf.append(" return;\n"); |
2448 |
buf.append(" .assertEquals(message, new Boolean(expected), new Boolean(\n"); |
2456 |
buf.append(" }\n"); |
2449 |
buf.append(" actual));\n"); |
2457 |
buf.append(" if ((expected != null) && expected.equals(actual)) {\n"); |
|
|
2458 |
buf.append(" return;\n"); |
2459 |
buf.append(" }\n"); |
2460 |
buf.append(" throw new ComparisonFailure(message, expected, actual);\n"); |
2461 |
buf.append(" }\n"); |
2450 |
buf.append(" }\n"); |
2462 |
buf.append(" /**\n"); |
2451 |
buf.append(" /**\n"); |
2463 |
buf.append(" * Asserts that two Strings are equal.\n"); |
2452 |
buf.append(" * Asserts that two bytes are equal. If they are not an AssertionFailedError\n"); |
|
|
2453 |
buf.append(" * is thrown with the given message.\n"); |
2464 |
buf.append(" */\n"); |
2454 |
buf.append(" */\n"); |
2465 |
buf.append(" static public void assertEquals(final String expected, final String actual) {\n"); |
2455 |
buf.append(" static public void assertEquals(final String message, final byte expected,\n"); |
2466 |
buf.append(" Assert.assertEquals(null, expected, actual);\n"); |
2456 |
buf.append(" final byte actual) {\n"); |
|
|
2457 |
buf.append(" Assert.assertEquals(message, new Byte(expected), new Byte(actual));\n"); |
2458 |
buf.append(" }\n"); |
2459 |
buf.append(" /**\n"); |
2460 |
buf.append(" * Asserts that two chars are equal. If they are not an AssertionFailedError\n"); |
2461 |
buf.append(" * is thrown with the given message.\n"); |
2462 |
buf.append(" */\n"); |
2463 |
buf.append(" static public void assertEquals(final String message, final char expected,\n"); |
2464 |
buf.append(" final char actual) {\n"); |
2465 |
buf.append(" Assert.assertEquals(message, new Character(expected), new Character(\n"); |
2466 |
buf.append(" actual));\n"); |
2467 |
buf.append(" }\n"); |
2467 |
buf.append(" }\n"); |
2468 |
buf.append(" /**\n"); |
2468 |
buf.append(" /**\n"); |
2469 |
buf.append(" * Asserts that two doubles are equal concerning a delta. If they are not an\n"); |
2469 |
buf.append(" * Asserts that two doubles are equal concerning a delta. If they are not an\n"); |
Lines 2486-2499
Link Here
|
2486 |
buf.append(" }\n"); |
2486 |
buf.append(" }\n"); |
2487 |
buf.append(" }\n"); |
2487 |
buf.append(" }\n"); |
2488 |
buf.append(" /**\n"); |
2488 |
buf.append(" /**\n"); |
2489 |
buf.append(" * Asserts that two doubles are equal concerning a delta. If the expected\n"); |
|
|
2490 |
buf.append(" * value is infinity then the delta value is ignored.\n"); |
2491 |
buf.append(" */\n"); |
2492 |
buf.append(" static public void assertEquals(final double expected, final double actual,\n"); |
2493 |
buf.append(" final double delta) {\n"); |
2494 |
buf.append(" Assert.assertEquals(null, expected, actual, delta);\n"); |
2495 |
buf.append(" }\n"); |
2496 |
buf.append(" /**\n"); |
2497 |
buf.append(" * Asserts that two floats are equal concerning a delta. If they are not an\n"); |
2489 |
buf.append(" * Asserts that two floats are equal concerning a delta. If they are not an\n"); |
2498 |
buf.append(" * AssertionFailedError is thrown with the given message. If the expected\n"); |
2490 |
buf.append(" * AssertionFailedError is thrown with the given message. If the expected\n"); |
2499 |
buf.append(" * value is infinity then the delta value is ignored.\n"); |
2491 |
buf.append(" * value is infinity then the delta value is ignored.\n"); |
Lines 2514-2525
Link Here
|
2514 |
buf.append(" }\n"); |
2506 |
buf.append(" }\n"); |
2515 |
buf.append(" }\n"); |
2507 |
buf.append(" }\n"); |
2516 |
buf.append(" /**\n"); |
2508 |
buf.append(" /**\n"); |
2517 |
buf.append(" * Asserts that two floats are equal concerning a delta. If the expected\n"); |
2509 |
buf.append(" * Asserts that two ints are equal. If they are not an AssertionFailedError\n"); |
2518 |
buf.append(" * value is infinity then the delta value is ignored.\n"); |
2510 |
buf.append(" * is thrown with the given message.\n"); |
2519 |
buf.append(" */\n"); |
2511 |
buf.append(" */\n"); |
2520 |
buf.append(" static public void assertEquals(final float expected, final float actual,\n"); |
2512 |
buf.append(" static public void assertEquals(final String message, final int expected,\n"); |
2521 |
buf.append(" final float delta) {\n"); |
2513 |
buf.append(" final int actual) {\n"); |
2522 |
buf.append(" Assert.assertEquals(null, expected, actual, delta);\n"); |
2514 |
buf.append(" Assert\n"); |
|
|
2515 |
buf.append(" .assertEquals(message, new Integer(expected), new Integer(\n"); |
2516 |
buf.append(" actual));\n"); |
2523 |
buf.append(" }\n"); |
2517 |
buf.append(" }\n"); |
2524 |
buf.append(" /**\n"); |
2518 |
buf.append(" /**\n"); |
2525 |
buf.append(" * Asserts that two longs are equal. If they are not an AssertionFailedError\n"); |
2519 |
buf.append(" * Asserts that two longs are equal. If they are not an AssertionFailedError\n"); |
Lines 2530-2584
Link Here
|
2530 |
buf.append(" Assert.assertEquals(message, new Long(expected), new Long(actual));\n"); |
2524 |
buf.append(" Assert.assertEquals(message, new Long(expected), new Long(actual));\n"); |
2531 |
buf.append(" }\n"); |
2525 |
buf.append(" }\n"); |
2532 |
buf.append(" /**\n"); |
2526 |
buf.append(" /**\n"); |
2533 |
buf.append(" * Asserts that two longs are equal.\n"); |
2527 |
buf.append(" * Asserts that two objects are equal. If they are not an\n"); |
2534 |
buf.append(" */\n"); |
|
|
2535 |
buf.append(" static public void assertEquals(final long expected, final long actual) {\n"); |
2536 |
buf.append(" Assert.assertEquals(null, expected, actual);\n"); |
2537 |
buf.append(" }\n"); |
2538 |
buf.append(" /**\n"); |
2539 |
buf.append(" * Asserts that two booleans are equal. If they are not an\n"); |
2540 |
buf.append(" * AssertionFailedError is thrown with the given message.\n"); |
2528 |
buf.append(" * AssertionFailedError is thrown with the given message.\n"); |
2541 |
buf.append(" */\n"); |
2529 |
buf.append(" */\n"); |
2542 |
buf.append(" static public void assertEquals(final String message,\n"); |
2530 |
buf.append(" static public void assertEquals(final String message,\n"); |
2543 |
buf.append(" final boolean expected, final boolean actual) {\n"); |
2531 |
buf.append(" final Object expected, final Object actual) {\n"); |
2544 |
buf.append(" Assert\n"); |
2532 |
buf.append(" if ((expected == null) && (actual == null)) {\n"); |
2545 |
buf.append(" .assertEquals(message, new Boolean(expected), new Boolean(\n"); |
2533 |
buf.append(" return;\n"); |
2546 |
buf.append(" actual));\n"); |
2534 |
buf.append(" }\n"); |
2547 |
buf.append(" }\n"); |
2535 |
buf.append(" if ((expected != null) && expected.equals(actual)) {\n"); |
2548 |
buf.append(" /**\n"); |
2536 |
buf.append(" return;\n"); |
2549 |
buf.append(" * Asserts that two booleans are equal.\n"); |
2537 |
buf.append(" }\n"); |
2550 |
buf.append(" */\n"); |
2538 |
buf.append(" Assert.failNotEquals(message, expected, actual);\n"); |
2551 |
buf.append(" static public void assertEquals(final boolean expected, final boolean actual) {\n"); |
|
|
2552 |
buf.append(" Assert.assertEquals(null, expected, actual);\n"); |
2553 |
buf.append(" }\n"); |
2554 |
buf.append(" /**\n"); |
2555 |
buf.append(" * Asserts that two bytes are equal. If they are not an AssertionFailedError\n"); |
2556 |
buf.append(" * is thrown with the given message.\n"); |
2557 |
buf.append(" */\n"); |
2558 |
buf.append(" static public void assertEquals(final String message, final byte expected,\n"); |
2559 |
buf.append(" final byte actual) {\n"); |
2560 |
buf.append(" Assert.assertEquals(message, new Byte(expected), new Byte(actual));\n"); |
2561 |
buf.append(" }\n"); |
2562 |
buf.append(" /**\n"); |
2563 |
buf.append(" * Asserts that two bytes are equal.\n"); |
2564 |
buf.append(" */\n"); |
2565 |
buf.append(" static public void assertEquals(final byte expected, final byte actual) {\n"); |
2566 |
buf.append(" Assert.assertEquals(null, expected, actual);\n"); |
2567 |
buf.append(" }\n"); |
2568 |
buf.append(" /**\n"); |
2569 |
buf.append(" * Asserts that two chars are equal. If they are not an AssertionFailedError\n"); |
2570 |
buf.append(" * is thrown with the given message.\n"); |
2571 |
buf.append(" */\n"); |
2572 |
buf.append(" static public void assertEquals(final String message, final char expected,\n"); |
2573 |
buf.append(" final char actual) {\n"); |
2574 |
buf.append(" Assert.assertEquals(message, new Character(expected), new Character(\n"); |
2575 |
buf.append(" actual));\n"); |
2576 |
buf.append(" }\n"); |
2577 |
buf.append(" /**\n"); |
2578 |
buf.append(" * Asserts that two chars are equal.\n"); |
2579 |
buf.append(" */\n"); |
2580 |
buf.append(" static public void assertEquals(final char expected, final char actual) {\n"); |
2581 |
buf.append(" Assert.assertEquals(null, expected, actual);\n"); |
2582 |
buf.append(" }\n"); |
2539 |
buf.append(" }\n"); |
2583 |
buf.append(" /**\n"); |
2540 |
buf.append(" /**\n"); |
2584 |
buf.append(" * Asserts that two shorts are equal. If they are not an\n"); |
2541 |
buf.append(" * Asserts that two shorts are equal. If they are not an\n"); |
Lines 2589-2614
Link Here
|
2589 |
buf.append(" Assert.assertEquals(message, new Short(expected), new Short(actual));\n"); |
2546 |
buf.append(" Assert.assertEquals(message, new Short(expected), new Short(actual));\n"); |
2590 |
buf.append(" }\n"); |
2547 |
buf.append(" }\n"); |
2591 |
buf.append(" /**\n"); |
2548 |
buf.append(" /**\n"); |
2592 |
buf.append(" * Asserts that two shorts are equal.\n"); |
2549 |
buf.append(" * Asserts that two Strings are equal.\n"); |
2593 |
buf.append(" */\n"); |
2550 |
buf.append(" */\n"); |
2594 |
buf.append(" static public void assertEquals(final short expected, final short actual) {\n"); |
2551 |
buf.append(" static public void assertEquals(final String expected, final String actual) {\n"); |
2595 |
buf.append(" Assert.assertEquals(null, expected, actual);\n"); |
2552 |
buf.append(" Assert.assertEquals(null, expected, actual);\n"); |
2596 |
buf.append(" }\n"); |
2553 |
buf.append(" }\n"); |
2597 |
buf.append(" /**\n"); |
2554 |
buf.append(" /**\n"); |
2598 |
buf.append(" * Asserts that two ints are equal. If they are not an AssertionFailedError\n"); |
2555 |
buf.append(" * Asserts that two Strings are equal.\n"); |
2599 |
buf.append(" * is thrown with the given message.\n"); |
|
|
2600 |
buf.append(" */\n"); |
2556 |
buf.append(" */\n"); |
2601 |
buf.append(" static public void assertEquals(final String message, final int expected,\n"); |
2557 |
buf.append(" static public void assertEquals(final String message,\n"); |
2602 |
buf.append(" final int actual) {\n"); |
2558 |
buf.append(" final String expected, final String actual) {\n"); |
2603 |
buf.append(" Assert\n"); |
2559 |
buf.append(" if ((expected == null) && (actual == null)) {\n"); |
2604 |
buf.append(" .assertEquals(message, new Integer(expected), new Integer(\n"); |
2560 |
buf.append(" return;\n"); |
2605 |
buf.append(" actual));\n"); |
2561 |
buf.append(" }\n"); |
|
|
2562 |
buf.append(" if ((expected != null) && expected.equals(actual)) {\n"); |
2563 |
buf.append(" return;\n"); |
2564 |
buf.append(" }\n"); |
2565 |
buf.append(" throw new ComparisonFailure(message, expected, actual);\n"); |
2606 |
buf.append(" }\n"); |
2566 |
buf.append(" }\n"); |
2607 |
buf.append(" /**\n"); |
2567 |
buf.append(" /**\n"); |
2608 |
buf.append(" * Asserts that two ints are equal.\n"); |
2568 |
buf.append(" * Asserts that a condition is false. If it isn't it throws an\n"); |
|
|
2569 |
buf.append(" * AssertionFailedError.\n"); |
2609 |
buf.append(" */\n"); |
2570 |
buf.append(" */\n"); |
2610 |
buf.append(" static public void assertEquals(final int expected, final int actual) {\n"); |
2571 |
buf.append(" static public void assertFalse(final boolean condition) {\n"); |
2611 |
buf.append(" Assert.assertEquals(null, expected, actual);\n"); |
2572 |
buf.append(" Assert.assertFalse(null, condition);\n"); |
|
|
2573 |
buf.append(" }\n"); |
2574 |
buf.append(" /**\n"); |
2575 |
buf.append(" * Asserts that a condition is false. If it isn't it throws an\n"); |
2576 |
buf.append(" * AssertionFailedError with the given message.\n"); |
2577 |
buf.append(" */\n"); |
2578 |
buf.append(" static public void assertFalse(final String message, boolean condition) {\n"); |
2579 |
buf.append(" Assert.assertTrue(message, !condition);\n"); |
2612 |
buf.append(" }\n"); |
2580 |
buf.append(" }\n"); |
2613 |
buf.append(" /**\n"); |
2581 |
buf.append(" /**\n"); |
2614 |
buf.append(" * Asserts that an object isn't null.\n"); |
2582 |
buf.append(" * Asserts that an object isn't null.\n"); |
Lines 2624-2629
Link Here
|
2624 |
buf.append(" Assert.assertTrue(message, object != null);\n"); |
2592 |
buf.append(" Assert.assertTrue(message, object != null);\n"); |
2625 |
buf.append(" }\n"); |
2593 |
buf.append(" }\n"); |
2626 |
buf.append(" /**\n"); |
2594 |
buf.append(" /**\n"); |
|
|
2595 |
buf.append(" * Asserts that two objects refer to the same object. If they are not the\n"); |
2596 |
buf.append(" * same an AssertionFailedError is thrown.\n"); |
2597 |
buf.append(" */\n"); |
2598 |
buf.append(" static public void assertNotSame(final Object expected, final Object actual) {\n"); |
2599 |
buf.append(" Assert.assertNotSame(null, expected, actual);\n"); |
2600 |
buf.append(" }\n"); |
2601 |
buf.append(" /**\n"); |
2602 |
buf.append(" * Asserts that two objects refer to the same object. If they are not an\n"); |
2603 |
buf.append(" * AssertionFailedError is thrown with the given message.\n"); |
2604 |
buf.append(" */\n"); |
2605 |
buf.append(" static public void assertNotSame(final String message,\n"); |
2606 |
buf.append(" final Object expected, final Object actual) {\n"); |
2607 |
buf.append(" if (expected == actual) {\n"); |
2608 |
buf.append(" Assert.failSame(message);\n"); |
2609 |
buf.append(" }\n"); |
2610 |
buf.append(" }\n"); |
2611 |
buf.append(" /**\n"); |
2627 |
buf.append(" * Asserts that an object is null.\n"); |
2612 |
buf.append(" * Asserts that an object is null.\n"); |
2628 |
buf.append(" */\n"); |
2613 |
buf.append(" */\n"); |
2629 |
buf.append(" static public void assertNull(final Object object) {\n"); |
2614 |
buf.append(" static public void assertNull(final Object object) {\n"); |
Lines 2637-2642
Link Here
|
2637 |
buf.append(" Assert.assertTrue(message, object == null);\n"); |
2622 |
buf.append(" Assert.assertTrue(message, object == null);\n"); |
2638 |
buf.append(" }\n"); |
2623 |
buf.append(" }\n"); |
2639 |
buf.append(" /**\n"); |
2624 |
buf.append(" /**\n"); |
|
|
2625 |
buf.append(" * Asserts that two objects refer to the same object. If they are not the\n"); |
2626 |
buf.append(" * same an AssertionFailedError is thrown.\n"); |
2627 |
buf.append(" */\n"); |
2628 |
buf.append(" static public void assertSame(final Object expected, final Object actual) {\n"); |
2629 |
buf.append(" Assert.assertSame(null, expected, actual);\n"); |
2630 |
buf.append(" }\n"); |
2631 |
buf.append(" /**\n"); |
2640 |
buf.append(" * Asserts that two objects refer to the same object. If they are not an\n"); |
2632 |
buf.append(" * Asserts that two objects refer to the same object. If they are not an\n"); |
2641 |
buf.append(" * AssertionFailedError is thrown with the given message.\n"); |
2633 |
buf.append(" * AssertionFailedError is thrown with the given message.\n"); |
2642 |
buf.append(" */\n"); |
2634 |
buf.append(" */\n"); |
Lines 2648-2683
Link Here
|
2648 |
buf.append(" Assert.failNotSame(message, expected, actual);\n"); |
2640 |
buf.append(" Assert.failNotSame(message, expected, actual);\n"); |
2649 |
buf.append(" }\n"); |
2641 |
buf.append(" }\n"); |
2650 |
buf.append(" /**\n"); |
2642 |
buf.append(" /**\n"); |
2651 |
buf.append(" * Asserts that two objects refer to the same object. If they are not the\n"); |
2643 |
buf.append(" * Asserts that a condition is true. If it isn't it throws an\n"); |
2652 |
buf.append(" * same an AssertionFailedError is thrown.\n"); |
2644 |
buf.append(" * AssertionFailedError.\n"); |
2653 |
buf.append(" */\n"); |
2645 |
buf.append(" */\n"); |
2654 |
buf.append(" static public void assertSame(final Object expected, final Object actual) {\n"); |
2646 |
buf.append(" static public void assertTrue(final boolean condition) {\n"); |
2655 |
buf.append(" Assert.assertSame(null, expected, actual);\n"); |
2647 |
buf.append(" Assert.assertTrue(null, condition);\n"); |
2656 |
buf.append(" }\n"); |
2648 |
buf.append(" }\n"); |
2657 |
buf.append(" /**\n"); |
2649 |
buf.append(" /**\n"); |
2658 |
buf.append(" * Asserts that two objects refer to the same object. If they are not an\n"); |
2650 |
buf.append(" * Asserts that a condition is true. If it isn't it throws an\n"); |
2659 |
buf.append(" * AssertionFailedError is thrown with the given message.\n"); |
2651 |
buf.append(" * AssertionFailedError with the given message.\n"); |
2660 |
buf.append(" */\n"); |
2652 |
buf.append(" */\n"); |
2661 |
buf.append(" static public void assertNotSame(final String message,\n"); |
2653 |
buf.append(" static public void assertTrue(final String message, boolean condition) {\n"); |
2662 |
buf.append(" final Object expected, final Object actual) {\n"); |
2654 |
buf.append(" if (!condition) {\n"); |
2663 |
buf.append(" if (expected == actual) {\n"); |
2655 |
buf.append(" Assert.fail(message);\n"); |
2664 |
buf.append(" Assert.failSame(message);\n"); |
|
|
2665 |
buf.append(" }\n"); |
2656 |
buf.append(" }\n"); |
2666 |
buf.append(" }\n"); |
2657 |
buf.append(" }\n"); |
2667 |
buf.append(" /**\n"); |
2658 |
buf.append(" /**\n"); |
2668 |
buf.append(" * Asserts that two objects refer to the same object. If they are not the\n"); |
2659 |
buf.append(" * Fails a test with no message.\n"); |
2669 |
buf.append(" * same an AssertionFailedError is thrown.\n"); |
|
|
2670 |
buf.append(" */\n"); |
2660 |
buf.append(" */\n"); |
2671 |
buf.append(" static public void assertNotSame(final Object expected, final Object actual) {\n"); |
2661 |
buf.append(" static public void fail() {\n"); |
2672 |
buf.append(" Assert.assertNotSame(null, expected, actual);\n"); |
2662 |
buf.append(" Assert.fail(null);\n"); |
2673 |
buf.append(" }\n"); |
2663 |
buf.append(" }\n"); |
2674 |
buf.append("\n"); |
2664 |
buf.append(" /**\n"); |
2675 |
buf.append(" static private void failSame(final String message) {\n"); |
2665 |
buf.append(" * Fails a test with the given message.\n"); |
2676 |
buf.append(" String formatted = \"\"; //$NON-NLS-1$\n"); |
2666 |
buf.append(" */\n"); |
2677 |
buf.append(" if (message != null) {\n"); |
2667 |
buf.append(" static public void fail(final String message) {\n"); |
2678 |
buf.append(" formatted = message + \" \"; //$NON-NLS-1$\n"); |
2668 |
buf.append(" throw new AssertionFailedError(message);\n"); |
2679 |
buf.append(" }\n"); |
2669 |
buf.append(" }\n"); |
2680 |
buf.append(" Assert.fail(formatted + \"expected not same\"); //$NON-NLS-1$\n"); |
2670 |
buf.append(" static private void failNotEquals(final String message,\n"); |
|
|
2671 |
buf.append(" final Object expected, final Object actual) {\n"); |
2672 |
buf.append(" Assert.fail(Assert.format(message, expected, actual));\n"); |
2681 |
buf.append(" }\n"); |
2673 |
buf.append(" }\n"); |
2682 |
buf.append("\n"); |
2674 |
buf.append("\n"); |
2683 |
buf.append(" static private void failNotSame(final String message,\n"); |
2675 |
buf.append(" static private void failNotSame(final String message,\n"); |
Lines 2690-2698
Link Here
|
2690 |
buf.append(" + \"expected same:<\" + expected + \"> was not:<\" + actual + \">\"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\n"); |
2682 |
buf.append(" + \"expected same:<\" + expected + \"> was not:<\" + actual + \">\"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\n"); |
2691 |
buf.append(" }\n"); |
2683 |
buf.append(" }\n"); |
2692 |
buf.append("\n"); |
2684 |
buf.append("\n"); |
2693 |
buf.append(" static private void failNotEquals(final String message,\n"); |
2685 |
buf.append(" static private void failSame(final String message) {\n"); |
2694 |
buf.append(" final Object expected, final Object actual) {\n"); |
2686 |
buf.append(" String formatted = \"\"; //$NON-NLS-1$\n"); |
2695 |
buf.append(" Assert.fail(Assert.format(message, expected, actual));\n"); |
2687 |
buf.append(" if (message != null) {\n"); |
|
|
2688 |
buf.append(" formatted = message + \" \"; //$NON-NLS-1$\n"); |
2689 |
buf.append(" }\n"); |
2690 |
buf.append(" Assert.fail(formatted + \"expected not same\"); //$NON-NLS-1$\n"); |
2696 |
buf.append(" }\n"); |
2691 |
buf.append(" }\n"); |
2697 |
buf.append("\n"); |
2692 |
buf.append("\n"); |
2698 |
buf.append(" static String format(final String message, final Object expected,\n"); |
2693 |
buf.append(" static String format(final String message, final Object expected,\n"); |
Lines 2704-2709
Link Here
|
2704 |
buf.append(" return formatted\n"); |
2699 |
buf.append(" return formatted\n"); |
2705 |
buf.append(" + \"expected:<\" + expected + \"> but was:<\" + actual + \">\"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\n"); |
2700 |
buf.append(" + \"expected:<\" + expected + \"> but was:<\" + actual + \">\"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\n"); |
2706 |
buf.append(" }\n"); |
2701 |
buf.append(" }\n"); |
|
|
2702 |
buf.append("\n"); |
2703 |
buf.append(" /**\n"); |
2704 |
buf.append(" * Protect constructor since it is a static only class\n"); |
2705 |
buf.append(" */\n"); |
2706 |
buf.append(" protected Assert() {\n"); |
2707 |
buf.append(" }\n"); |
2707 |
buf.append("}"); |
2708 |
buf.append("}"); |
2708 |
fExpectedChangesAllTests.put("junit.framework.Assert.java", buf.toString()); |
2709 |
fExpectedChangesAllTests.put("junit.framework.Assert.java", buf.toString()); |
2709 |
buf= new StringBuffer(); |
2710 |
buf= new StringBuffer(); |
Lines 2729-2738
Link Here
|
2729 |
buf.append(" public ClassPathTestCollector() {\n"); |
2730 |
buf.append(" public ClassPathTestCollector() {\n"); |
2730 |
buf.append(" }\n"); |
2731 |
buf.append(" }\n"); |
2731 |
buf.append("\n"); |
2732 |
buf.append("\n"); |
2732 |
buf.append(" public Enumeration collectTests() {\n"); |
2733 |
buf.append(" protected String classNameFromFile(final String classFileName) {\n"); |
2733 |
buf.append(" final String classPath = System.getProperty(\"java.class.path\"); //$NON-NLS-1$\n"); |
2734 |
buf.append(" // convert /a/b.class to a.b\n"); |
2734 |
buf.append(" final Hashtable result = this.collectFilesInPath(classPath);\n"); |
2735 |
buf.append(" final String s = classFileName.substring(0, classFileName.length()\n"); |
2735 |
buf.append(" return result.elements();\n"); |
2736 |
buf.append(" - ClassPathTestCollector.SUFFIX_LENGTH);\n"); |
|
|
2737 |
buf.append(" final String s2 = s.replace(File.separatorChar, '.');\n"); |
2738 |
buf.append(" if (s2.startsWith(\".\")) {\n"); |
2739 |
buf.append(" return s2.substring(1);\n"); |
2740 |
buf.append(" }\n"); |
2741 |
buf.append(" return s2;\n"); |
2736 |
buf.append(" }\n"); |
2742 |
buf.append(" }\n"); |
2737 |
buf.append("\n"); |
2743 |
buf.append("\n"); |
2738 |
buf.append(" public Hashtable collectFilesInPath(final String classPath) {\n"); |
2744 |
buf.append(" public Hashtable collectFilesInPath(final String classPath) {\n"); |
Lines 2750-2755
Link Here
|
2750 |
buf.append(" return result;\n"); |
2756 |
buf.append(" return result;\n"); |
2751 |
buf.append(" }\n"); |
2757 |
buf.append(" }\n"); |
2752 |
buf.append("\n"); |
2758 |
buf.append("\n"); |
|
|
2759 |
buf.append(" public Enumeration collectTests() {\n"); |
2760 |
buf.append(" final String classPath = System.getProperty(\"java.class.path\"); //$NON-NLS-1$\n"); |
2761 |
buf.append(" final Hashtable result = this.collectFilesInPath(classPath);\n"); |
2762 |
buf.append(" return result.elements();\n"); |
2763 |
buf.append(" }\n"); |
2764 |
buf.append("\n"); |
2753 |
buf.append(" void gatherFiles(final File classRoot, final String classFileName,\n"); |
2765 |
buf.append(" void gatherFiles(final File classRoot, final String classFileName,\n"); |
2754 |
buf.append(" final Hashtable result) {\n"); |
2766 |
buf.append(" final Hashtable result) {\n"); |
2755 |
buf.append(" final File thisRoot = new File(classRoot, classFileName);\n"); |
2767 |
buf.append(" final File thisRoot = new File(classRoot, classFileName);\n"); |
Lines 2769-2774
Link Here
|
2769 |
buf.append(" }\n"); |
2781 |
buf.append(" }\n"); |
2770 |
buf.append(" }\n"); |
2782 |
buf.append(" }\n"); |
2771 |
buf.append("\n"); |
2783 |
buf.append("\n"); |
|
|
2784 |
buf.append(" protected boolean isTestClass(final String classFileName) {\n"); |
2785 |
buf.append(" return classFileName.endsWith(\".class\") && //$NON-NLS-1$\n"); |
2786 |
buf.append(" (classFileName.indexOf('$') < 0)\n"); |
2787 |
buf.append(" && (classFileName.indexOf(\"Test\") > 0); //$NON-NLS-1$\n"); |
2788 |
buf.append(" }\n"); |
2789 |
buf.append("\n"); |
2772 |
buf.append(" Vector splitClassPath(final String classPath) {\n"); |
2790 |
buf.append(" Vector splitClassPath(final String classPath) {\n"); |
2773 |
buf.append(" final Vector result = new Vector();\n"); |
2791 |
buf.append(" final Vector result = new Vector();\n"); |
2774 |
buf.append(" final String separator = System.getProperty(\"path.separator\"); //$NON-NLS-1$\n"); |
2792 |
buf.append(" final String separator = System.getProperty(\"path.separator\"); //$NON-NLS-1$\n"); |
Lines 2779-2801
Link Here
|
2779 |
buf.append(" }\n"); |
2797 |
buf.append(" }\n"); |
2780 |
buf.append(" return result;\n"); |
2798 |
buf.append(" return result;\n"); |
2781 |
buf.append(" }\n"); |
2799 |
buf.append(" }\n"); |
2782 |
buf.append("\n"); |
|
|
2783 |
buf.append(" protected boolean isTestClass(final String classFileName) {\n"); |
2784 |
buf.append(" return classFileName.endsWith(\".class\") && //$NON-NLS-1$\n"); |
2785 |
buf.append(" (classFileName.indexOf('$') < 0)\n"); |
2786 |
buf.append(" && (classFileName.indexOf(\"Test\") > 0); //$NON-NLS-1$\n"); |
2787 |
buf.append(" }\n"); |
2788 |
buf.append("\n"); |
2789 |
buf.append(" protected String classNameFromFile(final String classFileName) {\n"); |
2790 |
buf.append(" // convert /a/b.class to a.b\n"); |
2791 |
buf.append(" final String s = classFileName.substring(0, classFileName.length()\n"); |
2792 |
buf.append(" - ClassPathTestCollector.SUFFIX_LENGTH);\n"); |
2793 |
buf.append(" final String s2 = s.replace(File.separatorChar, '.');\n"); |
2794 |
buf.append(" if (s2.startsWith(\".\")) {\n"); |
2795 |
buf.append(" return s2.substring(1);\n"); |
2796 |
buf.append(" }\n"); |
2797 |
buf.append(" return s2;\n"); |
2798 |
buf.append(" }\n"); |
2799 |
buf.append("}\n"); |
2800 |
buf.append("}\n"); |
2800 |
buf.append(""); |
2801 |
buf.append(""); |
2801 |
fExpectedChangesAllTests.put("junit.runner.ClassPathTestCollector.java", buf.toString()); |
2802 |
fExpectedChangesAllTests.put("junit.runner.ClassPathTestCollector.java", buf.toString()); |
Lines 2846-2858
Link Here
|
2846 |
buf.append(" }\n"); |
2847 |
buf.append(" }\n"); |
2847 |
buf.append(" }\n"); |
2848 |
buf.append(" }\n"); |
2848 |
buf.append("\n"); |
2849 |
buf.append("\n"); |
2849 |
buf.append(" public void testActiveTest() {\n"); |
2850 |
buf.append(" ActiveTestSuite createActiveTestSuite() {\n"); |
2850 |
buf.append(" final Test test = this.createActiveTestSuite();\n"); |
2851 |
buf.append(" final ActiveTestSuite suite = new ActiveTestSuite();\n"); |
2851 |
buf.append(" final TestResult result = new TestResult();\n"); |
2852 |
buf.append(" for (int i = 0; i < 100; i++) {\n"); |
2852 |
buf.append(" test.run(result);\n"); |
2853 |
buf.append(" suite.addTest(new SuccessTest());\n"); |
2853 |
buf.append(" Assert.assertEquals(100, result.runCount());\n"); |
2854 |
buf.append(" }\n"); |
2854 |
buf.append(" Assert.assertEquals(0, result.failureCount());\n"); |
2855 |
buf.append(" return suite;\n"); |
2855 |
buf.append(" Assert.assertEquals(0, result.errorCount());\n"); |
|
|
2856 |
buf.append(" }\n"); |
2856 |
buf.append(" }\n"); |
2857 |
buf.append("\n"); |
2857 |
buf.append("\n"); |
2858 |
buf.append(" public void testActiveRepeatedTest() {\n"); |
2858 |
buf.append(" public void testActiveRepeatedTest() {\n"); |
Lines 2882-2893
Link Here
|
2882 |
buf.append(" Assert.assertEquals(0, result.errorCount());\n"); |
2882 |
buf.append(" Assert.assertEquals(0, result.errorCount());\n"); |
2883 |
buf.append(" }\n"); |
2883 |
buf.append(" }\n"); |
2884 |
buf.append("\n"); |
2884 |
buf.append("\n"); |
2885 |
buf.append(" ActiveTestSuite createActiveTestSuite() {\n"); |
2885 |
buf.append(" public void testActiveTest() {\n"); |
2886 |
buf.append(" final ActiveTestSuite suite = new ActiveTestSuite();\n"); |
2886 |
buf.append(" final Test test = this.createActiveTestSuite();\n"); |
2887 |
buf.append(" for (int i = 0; i < 100; i++) {\n"); |
2887 |
buf.append(" final TestResult result = new TestResult();\n"); |
2888 |
buf.append(" suite.addTest(new SuccessTest());\n"); |
2888 |
buf.append(" test.run(result);\n"); |
2889 |
buf.append(" }\n"); |
2889 |
buf.append(" Assert.assertEquals(100, result.runCount());\n"); |
2890 |
buf.append(" return suite;\n"); |
2890 |
buf.append(" Assert.assertEquals(0, result.failureCount());\n"); |
|
|
2891 |
buf.append(" Assert.assertEquals(0, result.errorCount());\n"); |
2891 |
buf.append(" }\n"); |
2892 |
buf.append(" }\n"); |
2892 |
buf.append("\n"); |
2893 |
buf.append("\n"); |
2893 |
buf.append("}"); |
2894 |
buf.append("}"); |
Lines 2931-2936
Link Here
|
2931 |
buf.append(" */\n"); |
2932 |
buf.append(" */\n"); |
2932 |
buf.append(" public abstract IMoney addMoneyBag(MoneyBag s);\n"); |
2933 |
buf.append(" public abstract IMoney addMoneyBag(MoneyBag s);\n"); |
2933 |
buf.append(" /**\n"); |
2934 |
buf.append(" /**\n"); |
|
|
2935 |
buf.append(" * Append this to a MoneyBag m.\n"); |
2936 |
buf.append(" */\n"); |
2937 |
buf.append(" public abstract void appendTo(MoneyBag m);\n"); |
2938 |
buf.append(" /**\n"); |
2934 |
buf.append(" * Tests whether this money is zero\n"); |
2939 |
buf.append(" * Tests whether this money is zero\n"); |
2935 |
buf.append(" */\n"); |
2940 |
buf.append(" */\n"); |
2936 |
buf.append(" public abstract boolean isZero();\n"); |
2941 |
buf.append(" public abstract boolean isZero();\n"); |
Lines 2946-2955
Link Here
|
2946 |
buf.append(" * Subtracts a money from this money.\n"); |
2951 |
buf.append(" * Subtracts a money from this money.\n"); |
2947 |
buf.append(" */\n"); |
2952 |
buf.append(" */\n"); |
2948 |
buf.append(" public abstract IMoney subtract(IMoney m);\n"); |
2953 |
buf.append(" public abstract IMoney subtract(IMoney m);\n"); |
2949 |
buf.append(" /**\n"); |
|
|
2950 |
buf.append(" * Append this to a MoneyBag m.\n"); |
2951 |
buf.append(" */\n"); |
2952 |
buf.append(" public abstract void appendTo(MoneyBag m);\n"); |
2953 |
buf.append("}"); |
2954 |
buf.append("}"); |
2954 |
fExpectedChangesAllTests.put("junit.samples.money.IMoney.java", buf.toString()); |
2955 |
fExpectedChangesAllTests.put("junit.samples.money.IMoney.java", buf.toString()); |
2955 |
buf= new StringBuffer(); |
2956 |
buf= new StringBuffer(); |
Lines 2984-3014
Link Here
|
2984 |
buf.append(" * the end.\n"); |
2985 |
buf.append(" * the end.\n"); |
2985 |
buf.append(" */\n"); |
2986 |
buf.append(" */\n"); |
2986 |
buf.append("public class TestRunner extends BaseTestRunner {\n"); |
2987 |
buf.append("public class TestRunner extends BaseTestRunner {\n"); |
2987 |
buf.append(" private ResultPrinter fPrinter;\n"); |
|
|
2988 |
buf.append("\n"); |
2989 |
buf.append(" public static final int SUCCESS_EXIT = 0;\n"); |
2990 |
buf.append(" public static final int FAILURE_EXIT = 1;\n"); |
2991 |
buf.append(" public static final int EXCEPTION_EXIT = 2;\n"); |
2988 |
buf.append(" public static final int EXCEPTION_EXIT = 2;\n"); |
2992 |
buf.append("\n"); |
2989 |
buf.append("\n"); |
2993 |
buf.append(" /**\n"); |
2990 |
buf.append(" public static final int FAILURE_EXIT = 1;\n"); |
2994 |
buf.append(" * Constructs a TestRunner.\n"); |
2991 |
buf.append(" public static final int SUCCESS_EXIT = 0;\n"); |
2995 |
buf.append(" */\n"); |
2992 |
buf.append(" public static void main(final String args[]) {\n"); |
2996 |
buf.append(" public TestRunner() {\n"); |
2993 |
buf.append(" final TestRunner aTestRunner = new TestRunner();\n"); |
2997 |
buf.append(" this(System.out);\n"); |
2994 |
buf.append(" try {\n"); |
2998 |
buf.append(" }\n"); |
2995 |
buf.append(" final TestResult r = aTestRunner.start(args);\n"); |
2999 |
buf.append("\n"); |
2996 |
buf.append(" if (!r.wasSuccessful()) {\n"); |
3000 |
buf.append(" /**\n"); |
2997 |
buf.append(" System.exit(TestRunner.FAILURE_EXIT);\n"); |
3001 |
buf.append(" * Constructs a TestRunner using the given stream for all the output\n"); |
2998 |
buf.append(" }\n"); |
3002 |
buf.append(" */\n"); |
2999 |
buf.append(" System.exit(TestRunner.SUCCESS_EXIT);\n"); |
3003 |
buf.append(" public TestRunner(final PrintStream writer) {\n"); |
3000 |
buf.append(" } catch (final Exception e) {\n"); |
3004 |
buf.append(" this(new ResultPrinter(writer));\n"); |
3001 |
buf.append(" System.err.println(e.getMessage());\n"); |
3005 |
buf.append(" }\n"); |
3002 |
buf.append(" System.exit(TestRunner.EXCEPTION_EXIT);\n"); |
3006 |
buf.append("\n"); |
3003 |
buf.append(" }\n"); |
3007 |
buf.append(" /**\n"); |
|
|
3008 |
buf.append(" * Constructs a TestRunner using the given ResultPrinter all the output\n"); |
3009 |
buf.append(" */\n"); |
3010 |
buf.append(" public TestRunner(final ResultPrinter printer) {\n"); |
3011 |
buf.append(" this.fPrinter = printer;\n"); |
3012 |
buf.append(" }\n"); |
3004 |
buf.append(" }\n"); |
3013 |
buf.append("\n"); |
3005 |
buf.append("\n"); |
3014 |
buf.append(" /**\n"); |
3006 |
buf.append(" /**\n"); |
Lines 3041-3064
Link Here
|
3041 |
buf.append(" aTestRunner.doRun(suite, true);\n"); |
3033 |
buf.append(" aTestRunner.doRun(suite, true);\n"); |
3042 |
buf.append(" }\n"); |
3034 |
buf.append(" }\n"); |
3043 |
buf.append("\n"); |
3035 |
buf.append("\n"); |
|
|
3036 |
buf.append(" private ResultPrinter fPrinter;\n"); |
3037 |
buf.append("\n"); |
3044 |
buf.append(" /**\n"); |
3038 |
buf.append(" /**\n"); |
3045 |
buf.append(" * Always use the StandardTestSuiteLoader. Overridden from BaseTestRunner.\n"); |
3039 |
buf.append(" * Constructs a TestRunner.\n"); |
3046 |
buf.append(" */\n"); |
3040 |
buf.append(" */\n"); |
3047 |
buf.append(" @Override\n"); |
3041 |
buf.append(" public TestRunner() {\n"); |
3048 |
buf.append(" public TestSuiteLoader getLoader() {\n"); |
3042 |
buf.append(" this(System.out);\n"); |
3049 |
buf.append(" return new StandardTestSuiteLoader();\n"); |
|
|
3050 |
buf.append(" }\n"); |
3051 |
buf.append("\n"); |
3052 |
buf.append(" @Override\n"); |
3053 |
buf.append(" public void testFailed(final int status, final Test test, final Throwable t) {\n"); |
3054 |
buf.append(" }\n"); |
3043 |
buf.append(" }\n"); |
3055 |
buf.append("\n"); |
3044 |
buf.append("\n"); |
3056 |
buf.append(" @Override\n"); |
3045 |
buf.append(" /**\n"); |
3057 |
buf.append(" public void testStarted(final String testName) {\n"); |
3046 |
buf.append(" * Constructs a TestRunner using the given stream for all the output\n"); |
|
|
3047 |
buf.append(" */\n"); |
3048 |
buf.append(" public TestRunner(final PrintStream writer) {\n"); |
3049 |
buf.append(" this(new ResultPrinter(writer));\n"); |
3058 |
buf.append(" }\n"); |
3050 |
buf.append(" }\n"); |
3059 |
buf.append("\n"); |
3051 |
buf.append("\n"); |
3060 |
buf.append(" @Override\n"); |
3052 |
buf.append(" /**\n"); |
3061 |
buf.append(" public void testEnded(final String testName) {\n"); |
3053 |
buf.append(" * Constructs a TestRunner using the given ResultPrinter all the output\n"); |
|
|
3054 |
buf.append(" */\n"); |
3055 |
buf.append(" public TestRunner(final ResultPrinter printer) {\n"); |
3056 |
buf.append(" this.fPrinter = printer;\n"); |
3062 |
buf.append(" }\n"); |
3057 |
buf.append(" }\n"); |
3063 |
buf.append("\n"); |
3058 |
buf.append("\n"); |
3064 |
buf.append(" /**\n"); |
3059 |
buf.append(" /**\n"); |
Lines 3085-3090
Link Here
|
3085 |
buf.append(" return result;\n"); |
3080 |
buf.append(" return result;\n"); |
3086 |
buf.append(" }\n"); |
3081 |
buf.append(" }\n"); |
3087 |
buf.append("\n"); |
3082 |
buf.append("\n"); |
|
|
3083 |
buf.append(" /**\n"); |
3084 |
buf.append(" * Always use the StandardTestSuiteLoader. Overridden from BaseTestRunner.\n"); |
3085 |
buf.append(" */\n"); |
3086 |
buf.append(" @Override\n"); |
3087 |
buf.append(" public TestSuiteLoader getLoader() {\n"); |
3088 |
buf.append(" return new StandardTestSuiteLoader();\n"); |
3089 |
buf.append(" }\n"); |
3090 |
buf.append("\n"); |
3088 |
buf.append(" protected void pause(boolean wait) {\n"); |
3091 |
buf.append(" protected void pause(boolean wait) {\n"); |
3089 |
buf.append(" if (!wait) {\n"); |
3092 |
buf.append(" if (!wait) {\n"); |
3090 |
buf.append(" return;\n"); |
3093 |
buf.append(" return;\n"); |
Lines 3096-3113
Link Here
|
3096 |
buf.append(" }\n"); |
3099 |
buf.append(" }\n"); |
3097 |
buf.append(" }\n"); |
3100 |
buf.append(" }\n"); |
3098 |
buf.append("\n"); |
3101 |
buf.append("\n"); |
3099 |
buf.append(" public static void main(final String args[]) {\n"); |
3102 |
buf.append(" @Override\n"); |
3100 |
buf.append(" final TestRunner aTestRunner = new TestRunner();\n"); |
3103 |
buf.append(" protected void runFailed(final String message) {\n"); |
3101 |
buf.append(" try {\n"); |
3104 |
buf.append(" System.err.println(message);\n"); |
3102 |
buf.append(" final TestResult r = aTestRunner.start(args);\n"); |
3105 |
buf.append(" System.exit(TestRunner.FAILURE_EXIT);\n"); |
3103 |
buf.append(" if (!r.wasSuccessful()) {\n"); |
3106 |
buf.append(" }\n"); |
3104 |
buf.append(" System.exit(TestRunner.FAILURE_EXIT);\n"); |
3107 |
buf.append("\n"); |
3105 |
buf.append(" }\n"); |
3108 |
buf.append(" public void setPrinter(final ResultPrinter printer) {\n"); |
3106 |
buf.append(" System.exit(TestRunner.SUCCESS_EXIT);\n"); |
3109 |
buf.append(" this.fPrinter = printer;\n"); |
3107 |
buf.append(" } catch (final Exception e) {\n"); |
|
|
3108 |
buf.append(" System.err.println(e.getMessage());\n"); |
3109 |
buf.append(" System.exit(TestRunner.EXCEPTION_EXIT);\n"); |
3110 |
buf.append(" }\n"); |
3111 |
buf.append(" }\n"); |
3110 |
buf.append(" }\n"); |
3112 |
buf.append("\n"); |
3111 |
buf.append("\n"); |
3113 |
buf.append(" /**\n"); |
3112 |
buf.append(" /**\n"); |
Lines 3145-3157
Link Here
|
3145 |
buf.append(" }\n"); |
3144 |
buf.append(" }\n"); |
3146 |
buf.append("\n"); |
3145 |
buf.append("\n"); |
3147 |
buf.append(" @Override\n"); |
3146 |
buf.append(" @Override\n"); |
3148 |
buf.append(" protected void runFailed(final String message) {\n"); |
3147 |
buf.append(" public void testEnded(final String testName) {\n"); |
3149 |
buf.append(" System.err.println(message);\n"); |
|
|
3150 |
buf.append(" System.exit(TestRunner.FAILURE_EXIT);\n"); |
3151 |
buf.append(" }\n"); |
3148 |
buf.append(" }\n"); |
3152 |
buf.append("\n"); |
3149 |
buf.append("\n"); |
3153 |
buf.append(" public void setPrinter(final ResultPrinter printer) {\n"); |
3150 |
buf.append(" @Override\n"); |
3154 |
buf.append(" this.fPrinter = printer;\n"); |
3151 |
buf.append(" public void testFailed(final int status, final Test test, final Throwable t) {\n"); |
|
|
3152 |
buf.append(" }\n"); |
3153 |
buf.append("\n"); |
3154 |
buf.append(" @Override\n"); |
3155 |
buf.append(" public void testStarted(final String testName) {\n"); |
3155 |
buf.append(" }\n"); |
3156 |
buf.append(" }\n"); |
3156 |
buf.append("\n"); |
3157 |
buf.append("\n"); |
3157 |
buf.append("}"); |
3158 |
buf.append("}"); |
Lines 3168-3181
Link Here
|
3168 |
buf.append("public class ClassLoaderTest extends Assert {\n"); |
3169 |
buf.append("public class ClassLoaderTest extends Assert {\n"); |
3169 |
buf.append(" public ClassLoaderTest() {\n"); |
3170 |
buf.append(" public ClassLoaderTest() {\n"); |
3170 |
buf.append(" }\n"); |
3171 |
buf.append(" }\n"); |
3171 |
buf.append(" public void verify() {\n"); |
|
|
3172 |
buf.append(" this.verifyApplicationClassLoadedByTestLoader();\n"); |
3173 |
buf.append(" this.verifySystemClassNotLoadedByTestLoader();\n"); |
3174 |
buf.append(" }\n"); |
3175 |
buf.append(" private boolean isTestCaseClassLoader(final ClassLoader cl) {\n"); |
3172 |
buf.append(" private boolean isTestCaseClassLoader(final ClassLoader cl) {\n"); |
3176 |
buf.append(" return ((cl != null) && cl.getClass().getName().equals(\n"); |
3173 |
buf.append(" return ((cl != null) && cl.getClass().getName().equals(\n"); |
3177 |
buf.append(" junit.runner.TestCaseClassLoader.class.getName()));\n"); |
3174 |
buf.append(" junit.runner.TestCaseClassLoader.class.getName()));\n"); |
3178 |
buf.append(" }\n"); |
3175 |
buf.append(" }\n"); |
|
|
3176 |
buf.append(" public void verify() {\n"); |
3177 |
buf.append(" this.verifyApplicationClassLoadedByTestLoader();\n"); |
3178 |
buf.append(" this.verifySystemClassNotLoadedByTestLoader();\n"); |
3179 |
buf.append(" }\n"); |
3179 |
buf.append(" private void verifyApplicationClassLoadedByTestLoader() {\n"); |
3180 |
buf.append(" private void verifyApplicationClassLoadedByTestLoader() {\n"); |
3180 |
buf.append(" Assert.assertTrue(this.isTestCaseClassLoader(this.getClass()\n"); |
3181 |
buf.append(" Assert.assertTrue(this.isTestCaseClassLoader(this.getClass()\n"); |
3181 |
buf.append(" .getClassLoader()));\n"); |
3182 |
buf.append(" .getClassLoader()));\n"); |
Lines 3200-3211
Link Here
|
3200 |
buf.append(" public static final int STATUS_ERROR = 1;\n"); |
3201 |
buf.append(" public static final int STATUS_ERROR = 1;\n"); |
3201 |
buf.append(" public static final int STATUS_FAILURE = 2;\n"); |
3202 |
buf.append(" public static final int STATUS_FAILURE = 2;\n"); |
3202 |
buf.append("\n"); |
3203 |
buf.append("\n"); |
3203 |
buf.append(" public void testRunStarted(String testSuiteName, int testCount);\n"); |
3204 |
buf.append(" public void testEnded(String testName);\n"); |
|
|
3205 |
buf.append(" public void testFailed(int status, String testName, String trace);\n"); |
3204 |
buf.append(" public void testRunEnded(long elapsedTime);\n"); |
3206 |
buf.append(" public void testRunEnded(long elapsedTime);\n"); |
|
|
3207 |
buf.append(" public void testRunStarted(String testSuiteName, int testCount);\n"); |
3205 |
buf.append(" public void testRunStopped(long elapsedTime);\n"); |
3208 |
buf.append(" public void testRunStopped(long elapsedTime);\n"); |
3206 |
buf.append(" public void testStarted(String testName);\n"); |
3209 |
buf.append(" public void testStarted(String testName);\n"); |
3207 |
buf.append(" public void testEnded(String testName);\n"); |
|
|
3208 |
buf.append(" public void testFailed(int status, String testName, String trace);\n"); |
3209 |
buf.append("}\n"); |
3210 |
buf.append("}\n"); |
3210 |
buf.append(""); |
3211 |
buf.append(""); |
3211 |
fExpectedChangesAllTests.put("junit.runner.TestRunListener.java", buf.toString()); |
3212 |
fExpectedChangesAllTests.put("junit.runner.TestRunListener.java", buf.toString()); |
Lines 3225-3233
Link Here
|
3225 |
buf.append("import junit.textui.TestRunner;\n"); |
3226 |
buf.append("import junit.textui.TestRunner;\n"); |
3226 |
buf.append("\n"); |
3227 |
buf.append("\n"); |
3227 |
buf.append("public class TextFeedbackTest extends TestCase {\n"); |
3228 |
buf.append("public class TextFeedbackTest extends TestCase {\n"); |
3228 |
buf.append(" OutputStream output;\n"); |
|
|
3229 |
buf.append(" TestRunner runner;\n"); |
3230 |
buf.append("\n"); |
3231 |
buf.append(" class TestResultPrinter extends ResultPrinter {\n"); |
3229 |
buf.append(" class TestResultPrinter extends ResultPrinter {\n"); |
3232 |
buf.append(" TestResultPrinter(final PrintStream writer) {\n"); |
3230 |
buf.append(" TestResultPrinter(final PrintStream writer) {\n"); |
3233 |
buf.append(" super(writer);\n"); |
3231 |
buf.append(" super(writer);\n"); |
Lines 3241-3251
Link Here
|
3241 |
buf.append(" return \"0\"; //$NON-NLS-1$\n"); |
3239 |
buf.append(" return \"0\"; //$NON-NLS-1$\n"); |
3242 |
buf.append(" }\n"); |
3240 |
buf.append(" }\n"); |
3243 |
buf.append(" }\n"); |
3241 |
buf.append(" }\n"); |
3244 |
buf.append("\n"); |
|
|
3245 |
buf.append(" public static void main(final String[] args) {\n"); |
3242 |
buf.append(" public static void main(final String[] args) {\n"); |
3246 |
buf.append(" TestRunner.run(TextFeedbackTest.class);\n"); |
3243 |
buf.append(" TestRunner.run(TextFeedbackTest.class);\n"); |
3247 |
buf.append(" }\n"); |
3244 |
buf.append(" }\n"); |
3248 |
buf.append("\n"); |
3245 |
buf.append("\n"); |
|
|
3246 |
buf.append(" OutputStream output;\n"); |
3247 |
buf.append("\n"); |
3248 |
buf.append(" TestRunner runner;\n"); |
3249 |
buf.append("\n"); |
3250 |
buf.append(" private String expected(final String[] lines) {\n"); |
3251 |
buf.append(" final OutputStream expected = new ByteArrayOutputStream();\n"); |
3252 |
buf.append(" final PrintStream expectedWriter = new PrintStream(expected);\n"); |
3253 |
buf.append(" for (final String element : lines) {\n"); |
3254 |
buf.append(" expectedWriter.println(element);\n"); |
3255 |
buf.append(" }\n"); |
3256 |
buf.append(" return expected.toString();\n"); |
3257 |
buf.append(" }\n"); |
3258 |
buf.append("\n"); |
3249 |
buf.append(" @Override\n"); |
3259 |
buf.append(" @Override\n"); |
3250 |
buf.append(" public void setUp() {\n"); |
3260 |
buf.append(" public void setUp() {\n"); |
3251 |
buf.append(" this.output = new ByteArrayOutputStream();\n"); |
3261 |
buf.append(" this.output = new ByteArrayOutputStream();\n"); |
Lines 3260-3290
Link Here
|
3260 |
buf.append(" Assert.assertEquals(expected.toString(), this.output.toString());\n"); |
3270 |
buf.append(" Assert.assertEquals(expected.toString(), this.output.toString());\n"); |
3261 |
buf.append(" }\n"); |
3271 |
buf.append(" }\n"); |
3262 |
buf.append("\n"); |
3272 |
buf.append("\n"); |
3263 |
buf.append(" public void testOneTest() {\n"); |
3273 |
buf.append(" public void testError() {\n"); |
3264 |
buf.append(" final String expected = this.expected(new String[]{\n"); |
3274 |
buf.append(" final String expected = this\n"); |
3265 |
buf.append(" \".\", \"Time: 0\", \"\", \"OK (1 test)\", \"\"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$\n"); |
3275 |
buf.append(" .expected(new String[]{\n"); |
3266 |
buf.append(" final TestSuite suite = new TestSuite();\n"); |
3276 |
buf.append(" \".E\", \"Time: 0\", \"Errors here\", \"\", \"FAILURES!!!\", \"Tests run: 1, Failures: 0, Errors: 1\", \"\"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$\n"); |
3267 |
buf.append(" suite.addTest(new TestCase() {\n"); |
3277 |
buf.append(" final ResultPrinter printer = new TestResultPrinter(new PrintStream(\n"); |
|
|
3278 |
buf.append(" this.output)) {\n"); |
3268 |
buf.append(" @Override\n"); |
3279 |
buf.append(" @Override\n"); |
3269 |
buf.append(" public void runTest() {\n"); |
3280 |
buf.append(" public void printErrors(TestResult result) {\n"); |
|
|
3281 |
buf.append(" this.getWriter().println(\"Errors here\"); //$NON-NLS-1$\n"); |
3270 |
buf.append(" }\n"); |
3282 |
buf.append(" }\n"); |
3271 |
buf.append(" });\n"); |
3283 |
buf.append(" };\n"); |
3272 |
buf.append(" this.runner.doRun(suite);\n"); |
3284 |
buf.append(" this.runner.setPrinter(printer);\n"); |
3273 |
buf.append(" Assert.assertEquals(expected.toString(), this.output.toString());\n"); |
|
|
3274 |
buf.append(" }\n"); |
3275 |
buf.append("\n"); |
3276 |
buf.append(" public void testTwoTests() {\n"); |
3277 |
buf.append(" final String expected = this.expected(new String[]{\n"); |
3278 |
buf.append(" \"..\", \"Time: 0\", \"\", \"OK (2 tests)\", \"\"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$\n"); |
3279 |
buf.append(" final TestSuite suite = new TestSuite();\n"); |
3285 |
buf.append(" final TestSuite suite = new TestSuite();\n"); |
3280 |
buf.append(" suite.addTest(new TestCase() {\n"); |
3286 |
buf.append(" suite.addTest(new TestCase() {\n"); |
3281 |
buf.append(" @Override\n"); |
3287 |
buf.append(" @Override\n"); |
3282 |
buf.append(" public void runTest() {\n"); |
3288 |
buf.append(" public void runTest() throws Exception {\n"); |
3283 |
buf.append(" }\n"); |
3289 |
buf.append(" throw new Exception();\n"); |
3284 |
buf.append(" });\n"); |
|
|
3285 |
buf.append(" suite.addTest(new TestCase() {\n"); |
3286 |
buf.append(" @Override\n"); |
3287 |
buf.append(" public void runTest() {\n"); |
3288 |
buf.append(" }\n"); |
3290 |
buf.append(" }\n"); |
3289 |
buf.append(" });\n"); |
3291 |
buf.append(" });\n"); |
3290 |
buf.append(" this.runner.doRun(suite);\n"); |
3292 |
buf.append(" this.runner.doRun(suite);\n"); |
Lines 3314-3349
Link Here
|
3314 |
buf.append(" Assert.assertEquals(expected.toString(), this.output.toString());\n"); |
3316 |
buf.append(" Assert.assertEquals(expected.toString(), this.output.toString());\n"); |
3315 |
buf.append(" }\n"); |
3317 |
buf.append(" }\n"); |
3316 |
buf.append("\n"); |
3318 |
buf.append("\n"); |
3317 |
buf.append(" public void testError() {\n"); |
3319 |
buf.append(" public void testOneTest() {\n"); |
3318 |
buf.append(" final String expected = this\n"); |
3320 |
buf.append(" final String expected = this.expected(new String[]{\n"); |
3319 |
buf.append(" .expected(new String[]{\n"); |
3321 |
buf.append(" \".\", \"Time: 0\", \"\", \"OK (1 test)\", \"\"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$\n"); |
3320 |
buf.append(" \".E\", \"Time: 0\", \"Errors here\", \"\", \"FAILURES!!!\", \"Tests run: 1, Failures: 0, Errors: 1\", \"\"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$\n"); |
|
|
3321 |
buf.append(" final ResultPrinter printer = new TestResultPrinter(new PrintStream(\n"); |
3322 |
buf.append(" this.output)) {\n"); |
3323 |
buf.append(" @Override\n"); |
3324 |
buf.append(" public void printErrors(TestResult result) {\n"); |
3325 |
buf.append(" this.getWriter().println(\"Errors here\"); //$NON-NLS-1$\n"); |
3326 |
buf.append(" }\n"); |
3327 |
buf.append(" };\n"); |
3328 |
buf.append(" this.runner.setPrinter(printer);\n"); |
3329 |
buf.append(" final TestSuite suite = new TestSuite();\n"); |
3322 |
buf.append(" final TestSuite suite = new TestSuite();\n"); |
3330 |
buf.append(" suite.addTest(new TestCase() {\n"); |
3323 |
buf.append(" suite.addTest(new TestCase() {\n"); |
3331 |
buf.append(" @Override\n"); |
3324 |
buf.append(" @Override\n"); |
3332 |
buf.append(" public void runTest() throws Exception {\n"); |
3325 |
buf.append(" public void runTest() {\n"); |
3333 |
buf.append(" throw new Exception();\n"); |
|
|
3334 |
buf.append(" }\n"); |
3326 |
buf.append(" }\n"); |
3335 |
buf.append(" });\n"); |
3327 |
buf.append(" });\n"); |
3336 |
buf.append(" this.runner.doRun(suite);\n"); |
3328 |
buf.append(" this.runner.doRun(suite);\n"); |
3337 |
buf.append(" Assert.assertEquals(expected.toString(), this.output.toString());\n"); |
3329 |
buf.append(" Assert.assertEquals(expected.toString(), this.output.toString());\n"); |
3338 |
buf.append(" }\n"); |
3330 |
buf.append(" }\n"); |
3339 |
buf.append("\n"); |
3331 |
buf.append("\n"); |
3340 |
buf.append(" private String expected(final String[] lines) {\n"); |
3332 |
buf.append(" public void testTwoTests() {\n"); |
3341 |
buf.append(" final OutputStream expected = new ByteArrayOutputStream();\n"); |
3333 |
buf.append(" final String expected = this.expected(new String[]{\n"); |
3342 |
buf.append(" final PrintStream expectedWriter = new PrintStream(expected);\n"); |
3334 |
buf.append(" \"..\", \"Time: 0\", \"\", \"OK (2 tests)\", \"\"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$\n"); |
3343 |
buf.append(" for (final String element : lines) {\n"); |
3335 |
buf.append(" final TestSuite suite = new TestSuite();\n"); |
3344 |
buf.append(" expectedWriter.println(element);\n"); |
3336 |
buf.append(" suite.addTest(new TestCase() {\n"); |
3345 |
buf.append(" }\n"); |
3337 |
buf.append(" @Override\n"); |
3346 |
buf.append(" return expected.toString();\n"); |
3338 |
buf.append(" public void runTest() {\n"); |
|
|
3339 |
buf.append(" }\n"); |
3340 |
buf.append(" });\n"); |
3341 |
buf.append(" suite.addTest(new TestCase() {\n"); |
3342 |
buf.append(" @Override\n"); |
3343 |
buf.append(" public void runTest() {\n"); |
3344 |
buf.append(" }\n"); |
3345 |
buf.append(" });\n"); |
3346 |
buf.append(" this.runner.doRun(suite);\n"); |
3347 |
buf.append(" Assert.assertEquals(expected.toString(), this.output.toString());\n"); |
3347 |
buf.append(" }\n"); |
3348 |
buf.append(" }\n"); |
3348 |
buf.append("\n"); |
3349 |
buf.append("\n"); |
3349 |
buf.append("}\n"); |
3350 |
buf.append("}\n"); |
Lines 3484-3496
Link Here
|
3484 |
buf.append("import junit.framework.Assert;\n"); |
3485 |
buf.append("import junit.framework.Assert;\n"); |
3485 |
buf.append("\n"); |
3486 |
buf.append("\n"); |
3486 |
buf.append("public class LoadedFromJar extends Assert {\n"); |
3487 |
buf.append("public class LoadedFromJar extends Assert {\n"); |
3487 |
buf.append(" public void verify() {\n"); |
|
|
3488 |
buf.append(" this.verifyApplicationClassLoadedByTestLoader();\n"); |
3489 |
buf.append(" }\n"); |
3490 |
buf.append(" private boolean isTestCaseClassLoader(final ClassLoader cl) {\n"); |
3488 |
buf.append(" private boolean isTestCaseClassLoader(final ClassLoader cl) {\n"); |
3491 |
buf.append(" return ((cl != null) && cl.getClass().getName().equals(\n"); |
3489 |
buf.append(" return ((cl != null) && cl.getClass().getName().equals(\n"); |
3492 |
buf.append(" junit.runner.TestCaseClassLoader.class.getName()));\n"); |
3490 |
buf.append(" junit.runner.TestCaseClassLoader.class.getName()));\n"); |
3493 |
buf.append(" }\n"); |
3491 |
buf.append(" }\n"); |
|
|
3492 |
buf.append(" public void verify() {\n"); |
3493 |
buf.append(" this.verifyApplicationClassLoadedByTestLoader();\n"); |
3494 |
buf.append(" }\n"); |
3494 |
buf.append(" private void verifyApplicationClassLoadedByTestLoader() {\n"); |
3495 |
buf.append(" private void verifyApplicationClassLoadedByTestLoader() {\n"); |
3495 |
buf.append(" Assert.assertTrue(this.isTestCaseClassLoader(this.getClass()\n"); |
3496 |
buf.append(" Assert.assertTrue(this.isTestCaseClassLoader(this.getClass()\n"); |
3496 |
buf.append(" .getClassLoader()));\n"); |
3497 |
buf.append(" .getClassLoader()));\n"); |
Lines 3506-3528
Link Here
|
3506 |
buf.append("\n"); |
3507 |
buf.append("\n"); |
3507 |
buf.append("public class ComparisonFailureTest extends TestCase {\n"); |
3508 |
buf.append("public class ComparisonFailureTest extends TestCase {\n"); |
3508 |
buf.append("\n"); |
3509 |
buf.append("\n"); |
|
|
3510 |
buf.append(" public void testComparisonErrorEndSame() {\n"); |
3511 |
buf.append(" final ComparisonFailure failure = new ComparisonFailure(null,\n"); |
3512 |
buf.append(" \"ab\", \"cb\"); //$NON-NLS-1$ //$NON-NLS-2$\n"); |
3513 |
buf.append(" Assert.assertEquals(\n"); |
3514 |
buf.append(" \"expected:<a...> but was:<c...>\", failure.getMessage()); //$NON-NLS-1$\n"); |
3515 |
buf.append(" }\n"); |
3516 |
buf.append("\n"); |
3517 |
buf.append(" public void testComparisonErrorEndSameComplete() {\n"); |
3518 |
buf.append(" final ComparisonFailure failure = new ComparisonFailure(null,\n"); |
3519 |
buf.append(" \"bc\", \"abc\"); //$NON-NLS-1$ //$NON-NLS-2$\n"); |
3520 |
buf.append(" Assert.assertEquals(\n"); |
3521 |
buf.append(" \"expected:<...> but was:<a...>\", failure.getMessage()); //$NON-NLS-1$\n"); |
3522 |
buf.append(" }\n"); |
3523 |
buf.append("\n"); |
3509 |
buf.append(" public void testComparisonErrorMessage() {\n"); |
3524 |
buf.append(" public void testComparisonErrorMessage() {\n"); |
3510 |
buf.append(" final ComparisonFailure failure = new ComparisonFailure(\"a\", \"b\", \"c\"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\n"); |
3525 |
buf.append(" final ComparisonFailure failure = new ComparisonFailure(\"a\", \"b\", \"c\"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\n"); |
3511 |
buf.append(" Assert.assertEquals(\"a expected:<b> but was:<c>\", failure.getMessage()); //$NON-NLS-1$\n"); |
3526 |
buf.append(" Assert.assertEquals(\"a expected:<b> but was:<c>\", failure.getMessage()); //$NON-NLS-1$\n"); |
3512 |
buf.append(" }\n"); |
3527 |
buf.append(" }\n"); |
3513 |
buf.append("\n"); |
3528 |
buf.append("\n"); |
3514 |
buf.append(" public void testComparisonErrorStartSame() {\n"); |
3529 |
buf.append(" public void testComparisonErrorOverlapingMatches() {\n"); |
3515 |
buf.append(" final ComparisonFailure failure = new ComparisonFailure(null,\n"); |
3530 |
buf.append(" final ComparisonFailure failure = new ComparisonFailure(null,\n"); |
3516 |
buf.append(" \"ba\", \"bc\"); //$NON-NLS-1$ //$NON-NLS-2$\n"); |
3531 |
buf.append(" \"abc\", \"abbc\"); //$NON-NLS-1$ //$NON-NLS-2$\n"); |
3517 |
buf.append(" Assert.assertEquals(\n"); |
3532 |
buf.append(" Assert.assertEquals(\n"); |
3518 |
buf.append(" \"expected:<...a> but was:<...c>\", failure.getMessage()); //$NON-NLS-1$\n"); |
3533 |
buf.append(" \"expected:<......> but was:<...b...>\", failure.getMessage()); //$NON-NLS-1$\n"); |
3519 |
buf.append(" }\n"); |
3534 |
buf.append(" }\n"); |
3520 |
buf.append("\n"); |
3535 |
buf.append("\n"); |
3521 |
buf.append(" public void testComparisonErrorEndSame() {\n"); |
3536 |
buf.append(" public void testComparisonErrorOverlapingMatches2() {\n"); |
3522 |
buf.append(" final ComparisonFailure failure = new ComparisonFailure(null,\n"); |
3537 |
buf.append(" final ComparisonFailure failure = new ComparisonFailure(null,\n"); |
3523 |
buf.append(" \"ab\", \"cb\"); //$NON-NLS-1$ //$NON-NLS-2$\n"); |
3538 |
buf.append(" \"abcdde\", \"abcde\"); //$NON-NLS-1$ //$NON-NLS-2$\n"); |
3524 |
buf.append(" Assert.assertEquals(\n"); |
3539 |
buf.append(" Assert.assertEquals(\n"); |
3525 |
buf.append(" \"expected:<a...> but was:<c...>\", failure.getMessage()); //$NON-NLS-1$\n"); |
3540 |
buf.append(" \"expected:<...d...> but was:<......>\", failure.getMessage()); //$NON-NLS-1$\n"); |
3526 |
buf.append(" }\n"); |
3541 |
buf.append(" }\n"); |
3527 |
buf.append("\n"); |
3542 |
buf.append("\n"); |
3528 |
buf.append(" public void testComparisonErrorSame() {\n"); |
3543 |
buf.append(" public void testComparisonErrorSame() {\n"); |
Lines 3538-3569
Link Here
|
3538 |
buf.append(" \"expected:<...b...> but was:<...d...>\", failure.getMessage()); //$NON-NLS-1$\n"); |
3553 |
buf.append(" \"expected:<...b...> but was:<...d...>\", failure.getMessage()); //$NON-NLS-1$\n"); |
3539 |
buf.append(" }\n"); |
3554 |
buf.append(" }\n"); |
3540 |
buf.append("\n"); |
3555 |
buf.append("\n"); |
3541 |
buf.append(" public void testComparisonErrorStartSameComplete() {\n"); |
3556 |
buf.append(" public void testComparisonErrorStartSame() {\n"); |
3542 |
buf.append(" final ComparisonFailure failure = new ComparisonFailure(null,\n"); |
|
|
3543 |
buf.append(" \"ab\", \"abc\"); //$NON-NLS-1$ //$NON-NLS-2$\n"); |
3544 |
buf.append(" Assert.assertEquals(\n"); |
3545 |
buf.append(" \"expected:<...> but was:<...c>\", failure.getMessage()); //$NON-NLS-1$\n"); |
3546 |
buf.append(" }\n"); |
3547 |
buf.append("\n"); |
3548 |
buf.append(" public void testComparisonErrorEndSameComplete() {\n"); |
3549 |
buf.append(" final ComparisonFailure failure = new ComparisonFailure(null,\n"); |
3550 |
buf.append(" \"bc\", \"abc\"); //$NON-NLS-1$ //$NON-NLS-2$\n"); |
3551 |
buf.append(" Assert.assertEquals(\n"); |
3552 |
buf.append(" \"expected:<...> but was:<a...>\", failure.getMessage()); //$NON-NLS-1$\n"); |
3553 |
buf.append(" }\n"); |
3554 |
buf.append("\n"); |
3555 |
buf.append(" public void testComparisonErrorOverlapingMatches() {\n"); |
3556 |
buf.append(" final ComparisonFailure failure = new ComparisonFailure(null,\n"); |
3557 |
buf.append(" final ComparisonFailure failure = new ComparisonFailure(null,\n"); |
3557 |
buf.append(" \"abc\", \"abbc\"); //$NON-NLS-1$ //$NON-NLS-2$\n"); |
3558 |
buf.append(" \"ba\", \"bc\"); //$NON-NLS-1$ //$NON-NLS-2$\n"); |
3558 |
buf.append(" Assert.assertEquals(\n"); |
3559 |
buf.append(" Assert.assertEquals(\n"); |
3559 |
buf.append(" \"expected:<......> but was:<...b...>\", failure.getMessage()); //$NON-NLS-1$\n"); |
3560 |
buf.append(" \"expected:<...a> but was:<...c>\", failure.getMessage()); //$NON-NLS-1$\n"); |
3560 |
buf.append(" }\n"); |
3561 |
buf.append(" }\n"); |
3561 |
buf.append("\n"); |
3562 |
buf.append("\n"); |
3562 |
buf.append(" public void testComparisonErrorOverlapingMatches2() {\n"); |
3563 |
buf.append(" public void testComparisonErrorStartSameComplete() {\n"); |
3563 |
buf.append(" final ComparisonFailure failure = new ComparisonFailure(null,\n"); |
3564 |
buf.append(" final ComparisonFailure failure = new ComparisonFailure(null,\n"); |
3564 |
buf.append(" \"abcdde\", \"abcde\"); //$NON-NLS-1$ //$NON-NLS-2$\n"); |
3565 |
buf.append(" \"ab\", \"abc\"); //$NON-NLS-1$ //$NON-NLS-2$\n"); |
3565 |
buf.append(" Assert.assertEquals(\n"); |
3566 |
buf.append(" Assert.assertEquals(\n"); |
3566 |
buf.append(" \"expected:<...d...> but was:<......>\", failure.getMessage()); //$NON-NLS-1$\n"); |
3567 |
buf.append(" \"expected:<...> but was:<...c>\", failure.getMessage()); //$NON-NLS-1$\n"); |
3567 |
buf.append(" }\n"); |
3568 |
buf.append(" }\n"); |
3568 |
buf.append("\n"); |
3569 |
buf.append("\n"); |
3569 |
buf.append(" public void testComparisonErrorWithActualNull() {\n"); |
3570 |
buf.append(" public void testComparisonErrorWithActualNull() {\n"); |
Lines 3597-3604
Link Here
|
3597 |
buf.append("import junit.runner.BaseTestRunner;\n"); |
3598 |
buf.append("import junit.runner.BaseTestRunner;\n"); |
3598 |
buf.append("\n"); |
3599 |
buf.append("\n"); |
3599 |
buf.append("public class ResultPrinter implements TestListener {\n"); |
3600 |
buf.append("public class ResultPrinter implements TestListener {\n"); |
3600 |
buf.append(" PrintStream fWriter;\n"); |
|
|
3601 |
buf.append(" int fColumn = 0;\n"); |
3601 |
buf.append(" int fColumn = 0;\n"); |
|
|
3602 |
buf.append(" PrintStream fWriter;\n"); |
3602 |
buf.append("\n"); |
3603 |
buf.append("\n"); |
3603 |
buf.append(" public ResultPrinter(final PrintStream writer) {\n"); |
3604 |
buf.append(" public ResultPrinter(final PrintStream writer) {\n"); |
3604 |
buf.append(" this.fWriter = writer;\n"); |
3605 |
buf.append(" this.fWriter = writer;\n"); |
Lines 3608-3655
Link Here
|
3608 |
buf.append(" * API for use by textui.TestRunner\n"); |
3609 |
buf.append(" * API for use by textui.TestRunner\n"); |
3609 |
buf.append(" */\n"); |
3610 |
buf.append(" */\n"); |
3610 |
buf.append("\n"); |
3611 |
buf.append("\n"); |
3611 |
buf.append(" synchronized void print(final TestResult result, final long runTime) {\n"); |
3612 |
buf.append(" /**\n"); |
3612 |
buf.append(" this.printHeader(runTime);\n"); |
3613 |
buf.append(" * @see junit.framework.TestListener#addError(Test, Throwable)\n"); |
3613 |
buf.append(" this.printErrors(result);\n"); |
3614 |
buf.append(" */\n"); |
3614 |
buf.append(" this.printFailures(result);\n"); |
3615 |
buf.append(" public void addError(final Test test, final Throwable t) {\n"); |
3615 |
buf.append(" this.printFooter(result);\n"); |
3616 |
buf.append(" this.getWriter().print(\"E\"); //$NON-NLS-1$\n"); |
3616 |
buf.append(" }\n"); |
3617 |
buf.append(" }\n"); |
3617 |
buf.append("\n"); |
3618 |
buf.append("\n"); |
3618 |
buf.append(" void printWaitPrompt() {\n"); |
3619 |
buf.append(" /**\n"); |
3619 |
buf.append(" this.getWriter().println();\n"); |
3620 |
buf.append(" * @see junit.framework.TestListener#addFailure(Test, AssertionFailedError)\n"); |
3620 |
buf.append(" this.getWriter().println(\"<RETURN> to continue\"); //$NON-NLS-1$\n"); |
3621 |
buf.append(" */\n"); |
|
|
3622 |
buf.append(" public void addFailure(final Test test, final AssertionFailedError t) {\n"); |
3623 |
buf.append(" this.getWriter().print(\"F\"); //$NON-NLS-1$\n"); |
3621 |
buf.append(" }\n"); |
3624 |
buf.append(" }\n"); |
3622 |
buf.append("\n"); |
3625 |
buf.append("\n"); |
3623 |
buf.append(" /*\n"); |
3626 |
buf.append(" /*\n"); |
3624 |
buf.append(" * Internal methods\n"); |
3627 |
buf.append(" * Internal methods\n"); |
3625 |
buf.append(" */\n"); |
3628 |
buf.append(" */\n"); |
3626 |
buf.append("\n"); |
3629 |
buf.append("\n"); |
3627 |
buf.append(" protected void printHeader(final long runTime) {\n"); |
3630 |
buf.append(" /**\n"); |
3628 |
buf.append(" this.getWriter().println();\n"); |
3631 |
buf.append(" * Returns the formatted string of the elapsed time. Duplicated from\n"); |
3629 |
buf.append(" this.getWriter().println(\"Time: \" + this.elapsedTimeAsString(runTime)); //$NON-NLS-1$\n"); |
3632 |
buf.append(" * BaseTestRunner. Fix it.\n"); |
|
|
3633 |
buf.append(" */\n"); |
3634 |
buf.append(" protected String elapsedTimeAsString(final long runTime) {\n"); |
3635 |
buf.append(" return NumberFormat.getInstance().format((double) runTime / 1000);\n"); |
3630 |
buf.append(" }\n"); |
3636 |
buf.append(" }\n"); |
3631 |
buf.append("\n"); |
3637 |
buf.append("\n"); |
3632 |
buf.append(" protected void printErrors(final TestResult result) {\n"); |
3638 |
buf.append(" /**\n"); |
3633 |
buf.append(" this.printDefects(result.errors(), result.errorCount(), \"error\"); //$NON-NLS-1$\n"); |
3639 |
buf.append(" * @see junit.framework.TestListener#endTest(Test)\n"); |
|
|
3640 |
buf.append(" */\n"); |
3641 |
buf.append(" public void endTest(final Test test) {\n"); |
3634 |
buf.append(" }\n"); |
3642 |
buf.append(" }\n"); |
3635 |
buf.append("\n"); |
3643 |
buf.append("\n"); |
3636 |
buf.append(" protected void printFailures(final TestResult result) {\n"); |
3644 |
buf.append(" public PrintStream getWriter() {\n"); |
3637 |
buf.append(" this.printDefects(result.failures(), result.failureCount(), \"failure\"); //$NON-NLS-1$\n"); |
3645 |
buf.append(" return this.fWriter;\n"); |
3638 |
buf.append(" }\n"); |
3646 |
buf.append(" }\n"); |
3639 |
buf.append("\n"); |
3647 |
buf.append("\n"); |
3640 |
buf.append(" protected void printDefects(final Enumeration booBoos, final int count,\n"); |
3648 |
buf.append(" synchronized void print(final TestResult result, final long runTime) {\n"); |
3641 |
buf.append(" final String type) {\n"); |
3649 |
buf.append(" this.printHeader(runTime);\n"); |
3642 |
buf.append(" if (count == 0) {\n"); |
3650 |
buf.append(" this.printErrors(result);\n"); |
3643 |
buf.append(" return;\n"); |
3651 |
buf.append(" this.printFailures(result);\n"); |
3644 |
buf.append(" }\n"); |
3652 |
buf.append(" this.printFooter(result);\n"); |
3645 |
buf.append(" if (count == 1) {\n"); |
|
|
3646 |
buf.append(" this.getWriter().println(\"There was \" + count + \" \" + type + \":\"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\n"); |
3647 |
buf.append(" } else {\n"); |
3648 |
buf.append(" this.getWriter().println(\"There were \" + count + \" \" + type + \"s:\"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\n"); |
3649 |
buf.append(" }\n"); |
3650 |
buf.append(" for (int i = 1; booBoos.hasMoreElements(); i++) {\n"); |
3651 |
buf.append(" this.printDefect((TestFailure) booBoos.nextElement(), i);\n"); |
3652 |
buf.append(" }\n"); |
3653 |
buf.append(" }\n"); |
3653 |
buf.append(" }\n"); |
3654 |
buf.append("\n"); |
3654 |
buf.append("\n"); |
3655 |
buf.append(" public void printDefect(final TestFailure booBoo, final int count) { // only\n"); |
3655 |
buf.append(" public void printDefect(final TestFailure booBoo, final int count) { // only\n"); |
Lines 3668-3677
Link Here
|
3668 |
buf.append(" this.getWriter().print(count + \") \" + booBoo.failedTest()); //$NON-NLS-1$\n"); |
3668 |
buf.append(" this.getWriter().print(count + \") \" + booBoo.failedTest()); //$NON-NLS-1$\n"); |
3669 |
buf.append(" }\n"); |
3669 |
buf.append(" }\n"); |
3670 |
buf.append("\n"); |
3670 |
buf.append("\n"); |
|
|
3671 |
buf.append(" protected void printDefects(final Enumeration booBoos, final int count,\n"); |
3672 |
buf.append(" final String type) {\n"); |
3673 |
buf.append(" if (count == 0) {\n"); |
3674 |
buf.append(" return;\n"); |
3675 |
buf.append(" }\n"); |
3676 |
buf.append(" if (count == 1) {\n"); |
3677 |
buf.append(" this.getWriter().println(\"There was \" + count + \" \" + type + \":\"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\n"); |
3678 |
buf.append(" } else {\n"); |
3679 |
buf.append(" this.getWriter().println(\"There were \" + count + \" \" + type + \"s:\"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\n"); |
3680 |
buf.append(" }\n"); |
3681 |
buf.append(" for (int i = 1; booBoos.hasMoreElements(); i++) {\n"); |
3682 |
buf.append(" this.printDefect((TestFailure) booBoos.nextElement(), i);\n"); |
3683 |
buf.append(" }\n"); |
3684 |
buf.append(" }\n"); |
3685 |
buf.append("\n"); |
3671 |
buf.append(" protected void printDefectTrace(final TestFailure booBoo) {\n"); |
3686 |
buf.append(" protected void printDefectTrace(final TestFailure booBoo) {\n"); |
3672 |
buf.append(" this.getWriter().print(BaseTestRunner.getFilteredTrace(booBoo.trace()));\n"); |
3687 |
buf.append(" this.getWriter().print(BaseTestRunner.getFilteredTrace(booBoo.trace()));\n"); |
3673 |
buf.append(" }\n"); |
3688 |
buf.append(" }\n"); |
3674 |
buf.append("\n"); |
3689 |
buf.append("\n"); |
|
|
3690 |
buf.append(" protected void printErrors(final TestResult result) {\n"); |
3691 |
buf.append(" this.printDefects(result.errors(), result.errorCount(), \"error\"); //$NON-NLS-1$\n"); |
3692 |
buf.append(" }\n"); |
3693 |
buf.append("\n"); |
3694 |
buf.append(" protected void printFailures(final TestResult result) {\n"); |
3695 |
buf.append(" this.printDefects(result.failures(), result.failureCount(), \"failure\"); //$NON-NLS-1$\n"); |
3696 |
buf.append(" }\n"); |
3675 |
buf.append(" protected void printFooter(final TestResult result) {\n"); |
3697 |
buf.append(" protected void printFooter(final TestResult result) {\n"); |
3676 |
buf.append(" if (result.wasSuccessful()) {\n"); |
3698 |
buf.append(" if (result.wasSuccessful()) {\n"); |
3677 |
buf.append(" this.getWriter().println();\n"); |
3699 |
buf.append(" this.getWriter().println();\n"); |
Lines 3691-3725
Link Here
|
3691 |
buf.append(" this.getWriter().println();\n"); |
3713 |
buf.append(" this.getWriter().println();\n"); |
3692 |
buf.append(" }\n"); |
3714 |
buf.append(" }\n"); |
3693 |
buf.append("\n"); |
3715 |
buf.append("\n"); |
3694 |
buf.append(" /**\n"); |
3716 |
buf.append(" protected void printHeader(final long runTime) {\n"); |
3695 |
buf.append(" * Returns the formatted string of the elapsed time. Duplicated from\n"); |
3717 |
buf.append(" this.getWriter().println();\n"); |
3696 |
buf.append(" * BaseTestRunner. Fix it.\n"); |
3718 |
buf.append(" this.getWriter().println(\"Time: \" + this.elapsedTimeAsString(runTime)); //$NON-NLS-1$\n"); |
3697 |
buf.append(" */\n"); |
|
|
3698 |
buf.append(" protected String elapsedTimeAsString(final long runTime) {\n"); |
3699 |
buf.append(" return NumberFormat.getInstance().format((double) runTime / 1000);\n"); |
3700 |
buf.append(" }\n"); |
3701 |
buf.append("\n"); |
3702 |
buf.append(" public PrintStream getWriter() {\n"); |
3703 |
buf.append(" return this.fWriter;\n"); |
3704 |
buf.append(" }\n"); |
3705 |
buf.append(" /**\n"); |
3706 |
buf.append(" * @see junit.framework.TestListener#addError(Test, Throwable)\n"); |
3707 |
buf.append(" */\n"); |
3708 |
buf.append(" public void addError(final Test test, final Throwable t) {\n"); |
3709 |
buf.append(" this.getWriter().print(\"E\"); //$NON-NLS-1$\n"); |
3710 |
buf.append(" }\n"); |
3711 |
buf.append("\n"); |
3712 |
buf.append(" /**\n"); |
3713 |
buf.append(" * @see junit.framework.TestListener#addFailure(Test, AssertionFailedError)\n"); |
3714 |
buf.append(" */\n"); |
3715 |
buf.append(" public void addFailure(final Test test, final AssertionFailedError t) {\n"); |
3716 |
buf.append(" this.getWriter().print(\"F\"); //$NON-NLS-1$\n"); |
3717 |
buf.append(" }\n"); |
3719 |
buf.append(" }\n"); |
3718 |
buf.append("\n"); |
3720 |
buf.append("\n"); |
3719 |
buf.append(" /**\n"); |
3721 |
buf.append(" void printWaitPrompt() {\n"); |
3720 |
buf.append(" * @see junit.framework.TestListener#endTest(Test)\n"); |
3722 |
buf.append(" this.getWriter().println();\n"); |
3721 |
buf.append(" */\n"); |
3723 |
buf.append(" this.getWriter().println(\"<RETURN> to continue\"); //$NON-NLS-1$\n"); |
3722 |
buf.append(" public void endTest(final Test test) {\n"); |
|
|
3723 |
buf.append(" }\n"); |
3724 |
buf.append(" }\n"); |
3724 |
buf.append("\n"); |
3725 |
buf.append("\n"); |
3725 |
buf.append(" /**\n"); |
3726 |
buf.append(" /**\n"); |
Lines 3751-3762
Link Here
|
3751 |
buf.append(" * \n"); |
3752 |
buf.append(" * \n"); |
3752 |
buf.append(" */\n"); |
3753 |
buf.append(" */\n"); |
3753 |
buf.append("public class VectorTest extends TestCase {\n"); |
3754 |
buf.append("public class VectorTest extends TestCase {\n"); |
3754 |
buf.append(" protected Vector fEmpty;\n"); |
|
|
3755 |
buf.append(" protected Vector fFull;\n"); |
3756 |
buf.append("\n"); |
3757 |
buf.append(" public static void main(final String[] args) {\n"); |
3755 |
buf.append(" public static void main(final String[] args) {\n"); |
3758 |
buf.append(" junit.textui.TestRunner.run(VectorTest.suite());\n"); |
3756 |
buf.append(" junit.textui.TestRunner.run(VectorTest.suite());\n"); |
3759 |
buf.append(" }\n"); |
3757 |
buf.append(" }\n"); |
|
|
3758 |
buf.append(" public static Test suite() {\n"); |
3759 |
buf.append(" return new TestSuite(VectorTest.class);\n"); |
3760 |
buf.append(" }\n"); |
3761 |
buf.append("\n"); |
3762 |
buf.append(" protected Vector fEmpty;\n"); |
3763 |
buf.append(" protected Vector fFull;\n"); |
3760 |
buf.append(" @Override\n"); |
3764 |
buf.append(" @Override\n"); |
3761 |
buf.append(" protected void setUp() {\n"); |
3765 |
buf.append(" protected void setUp() {\n"); |
3762 |
buf.append(" this.fEmpty = new Vector();\n"); |
3766 |
buf.append(" this.fEmpty = new Vector();\n"); |
Lines 3765-3773
Link Here
|
3765 |
buf.append(" this.fFull.addElement(new Integer(2));\n"); |
3769 |
buf.append(" this.fFull.addElement(new Integer(2));\n"); |
3766 |
buf.append(" this.fFull.addElement(new Integer(3));\n"); |
3770 |
buf.append(" this.fFull.addElement(new Integer(3));\n"); |
3767 |
buf.append(" }\n"); |
3771 |
buf.append(" }\n"); |
3768 |
buf.append(" public static Test suite() {\n"); |
|
|
3769 |
buf.append(" return new TestSuite(VectorTest.class);\n"); |
3770 |
buf.append(" }\n"); |
3771 |
buf.append(" public void testCapacity() {\n"); |
3772 |
buf.append(" public void testCapacity() {\n"); |
3772 |
buf.append(" final int size = this.fFull.size();\n"); |
3773 |
buf.append(" final int size = this.fFull.size();\n"); |
3773 |
buf.append(" for (int i = 0; i < 100; i++) {\n"); |
3774 |
buf.append(" for (int i = 0; i < 100; i++) {\n"); |
Lines 3818-3825
Link Here
|
3818 |
buf.append("public class ComparisonFailure extends AssertionFailedError {\n"); |
3819 |
buf.append("public class ComparisonFailure extends AssertionFailedError {\n"); |
3819 |
buf.append(" /* Test */\n"); |
3820 |
buf.append(" /* Test */\n"); |
3820 |
buf.append(" private static final long serialVersionUID = 1L;\n"); |
3821 |
buf.append(" private static final long serialVersionUID = 1L;\n"); |
3821 |
buf.append(" private final String fExpected;\n"); |
|
|
3822 |
buf.append(" private final String fActual;\n"); |
3822 |
buf.append(" private final String fActual;\n"); |
|
|
3823 |
buf.append(" private final String fExpected;\n"); |
3823 |
buf.append("\n"); |
3824 |
buf.append("\n"); |
3824 |
buf.append(" /**\n"); |
3825 |
buf.append(" /**\n"); |
3825 |
buf.append(" * Constructs a comparison failure.\n"); |
3826 |
buf.append(" * Constructs a comparison failure.\n"); |
Lines 3914-3926
Link Here
|
3914 |
buf.append(" boolean fTornDown = false;\n"); |
3915 |
buf.append(" boolean fTornDown = false;\n"); |
3915 |
buf.append("\n"); |
3916 |
buf.append("\n"); |
3916 |
buf.append(" @Override\n"); |
3917 |
buf.append(" @Override\n"); |
3917 |
buf.append(" protected void tearDown() {\n"); |
|
|
3918 |
buf.append(" this.fTornDown = true;\n"); |
3919 |
buf.append(" }\n"); |
3920 |
buf.append(" @Override\n"); |
3921 |
buf.append(" protected void runTest() {\n"); |
3918 |
buf.append(" protected void runTest() {\n"); |
3922 |
buf.append(" throw new Error();\n"); |
3919 |
buf.append(" throw new Error();\n"); |
3923 |
buf.append(" }\n"); |
3920 |
buf.append(" }\n"); |
|
|
3921 |
buf.append(" @Override\n"); |
3922 |
buf.append(" protected void tearDown() {\n"); |
3923 |
buf.append(" this.fTornDown = true;\n"); |
3924 |
buf.append(" }\n"); |
3924 |
buf.append(" }\n"); |
3925 |
buf.append(" }\n"); |
3925 |
buf.append("\n"); |
3926 |
buf.append("\n"); |
3926 |
buf.append(" public void testCaseToString() {\n"); |
3927 |
buf.append(" public void testCaseToString() {\n"); |
Lines 3940-3968
Link Here
|
3940 |
buf.append(" };\n"); |
3941 |
buf.append(" };\n"); |
3941 |
buf.append(" this.verifyError(error);\n"); |
3942 |
buf.append(" this.verifyError(error);\n"); |
3942 |
buf.append(" }\n"); |
3943 |
buf.append(" }\n"); |
|
|
3944 |
buf.append(" public void testExceptionRunningAndTearDown() {\n"); |
3945 |
buf.append(" // This test documents the current behavior. With 1.4, we should\n"); |
3946 |
buf.append(" // wrap the exception thrown while running with the exception thrown\n"); |
3947 |
buf.append(" // while tearing down\n"); |
3948 |
buf.append(" final Test t = new TornDown() {\n"); |
3949 |
buf.append(" @Override\n"); |
3950 |
buf.append(" public void tearDown() {\n"); |
3951 |
buf.append(" throw new Error(\"tearDown\"); //$NON-NLS-1$\n"); |
3952 |
buf.append(" }\n"); |
3953 |
buf.append(" };\n"); |
3954 |
buf.append(" final TestResult result = new TestResult();\n"); |
3955 |
buf.append(" t.run(result);\n"); |
3956 |
buf.append(" final TestFailure failure = (TestFailure) result.errors().nextElement();\n"); |
3957 |
buf.append(" Assert.assertEquals(\"tearDown\", failure.thrownException().getMessage()); //$NON-NLS-1$\n"); |
3958 |
buf.append(" }\n"); |
3959 |
buf.append(" public void testFailure() {\n"); |
3960 |
buf.append(" final TestCase failure = new TestCase(\"failure\") { //$NON-NLS-1$\n"); |
3961 |
buf.append(" @Override\n"); |
3962 |
buf.append(" protected void runTest() {\n"); |
3963 |
buf.append(" Assert.fail();\n"); |
3964 |
buf.append(" }\n"); |
3965 |
buf.append(" };\n"); |
3966 |
buf.append(" this.verifyFailure(failure);\n"); |
3967 |
buf.append(" }\n"); |
3968 |
buf.append(" public void testNamelessTestCase() {\n"); |
3969 |
buf.append(" final TestCase t = new TestCase() {\n"); |
3970 |
buf.append(" };\n"); |
3971 |
buf.append(" try {\n"); |
3972 |
buf.append(" t.run();\n"); |
3973 |
buf.append(" Assert.fail();\n"); |
3974 |
buf.append(" } catch (final AssertionFailedError e) {\n"); |
3975 |
buf.append(" }\n"); |
3976 |
buf.append(" }\n"); |
3977 |
buf.append(" public void testNoArgTestCasePasses() {\n"); |
3978 |
buf.append(" final Test t = new TestSuite(NoArgTestCaseTest.class);\n"); |
3979 |
buf.append(" final TestResult result = new TestResult();\n"); |
3980 |
buf.append(" t.run(result);\n"); |
3981 |
buf.append(" Assert.assertTrue(result.runCount() == 1);\n"); |
3982 |
buf.append(" Assert.assertTrue(result.failureCount() == 0);\n"); |
3983 |
buf.append(" Assert.assertTrue(result.errorCount() == 0);\n"); |
3984 |
buf.append(" }\n"); |
3985 |
buf.append("\n"); |
3943 |
buf.append(" public void testRunAndTearDownFails() {\n"); |
3986 |
buf.append(" public void testRunAndTearDownFails() {\n"); |
3944 |
buf.append(" final TornDown fails = new TornDown() {\n"); |
3987 |
buf.append(" final TornDown fails = new TornDown() {\n"); |
3945 |
buf.append(" @Override\n"); |
3988 |
buf.append(" @Override\n"); |
3946 |
buf.append(" protected void tearDown() {\n"); |
3989 |
buf.append(" protected void runTest() {\n"); |
3947 |
buf.append(" super.tearDown();\n"); |
|
|
3948 |
buf.append(" throw new Error();\n"); |
3990 |
buf.append(" throw new Error();\n"); |
3949 |
buf.append(" }\n"); |
3991 |
buf.append(" }\n"); |
3950 |
buf.append(" @Override\n"); |
3992 |
buf.append(" @Override\n"); |
3951 |
buf.append(" protected void runTest() {\n"); |
3993 |
buf.append(" protected void tearDown() {\n"); |
|
|
3994 |
buf.append(" super.tearDown();\n"); |
3952 |
buf.append(" throw new Error();\n"); |
3995 |
buf.append(" throw new Error();\n"); |
3953 |
buf.append(" }\n"); |
3996 |
buf.append(" }\n"); |
3954 |
buf.append(" };\n"); |
3997 |
buf.append(" };\n"); |
3955 |
buf.append(" this.verifyError(fails);\n"); |
3998 |
buf.append(" this.verifyError(fails);\n"); |
3956 |
buf.append(" Assert.assertTrue(fails.fTornDown);\n"); |
3999 |
buf.append(" Assert.assertTrue(fails.fTornDown);\n"); |
3957 |
buf.append(" }\n"); |
4000 |
buf.append(" }\n"); |
|
|
4001 |
buf.append("\n"); |
3958 |
buf.append(" public void testSetupFails() {\n"); |
4002 |
buf.append(" public void testSetupFails() {\n"); |
3959 |
buf.append(" final TestCase fails = new TestCase(\"success\") { //$NON-NLS-1$\n"); |
4003 |
buf.append(" final TestCase fails = new TestCase(\"success\") { //$NON-NLS-1$\n"); |
3960 |
buf.append(" @Override\n"); |
4004 |
buf.append(" @Override\n"); |
3961 |
buf.append(" protected void setUp() {\n"); |
4005 |
buf.append(" protected void runTest() {\n"); |
3962 |
buf.append(" throw new Error();\n"); |
|
|
3963 |
buf.append(" }\n"); |
4006 |
buf.append(" }\n"); |
3964 |
buf.append(" @Override\n"); |
4007 |
buf.append(" @Override\n"); |
3965 |
buf.append(" protected void runTest() {\n"); |
4008 |
buf.append(" protected void setUp() {\n"); |
|
|
4009 |
buf.append(" throw new Error();\n"); |
3966 |
buf.append(" }\n"); |
4010 |
buf.append(" }\n"); |
3967 |
buf.append(" };\n"); |
4011 |
buf.append(" };\n"); |
3968 |
buf.append(" this.verifyError(fails);\n"); |
4012 |
buf.append(" this.verifyError(fails);\n"); |
Lines 3975-4008
Link Here
|
3975 |
buf.append(" };\n"); |
4019 |
buf.append(" };\n"); |
3976 |
buf.append(" this.verifySuccess(success);\n"); |
4020 |
buf.append(" this.verifySuccess(success);\n"); |
3977 |
buf.append(" }\n"); |
4021 |
buf.append(" }\n"); |
3978 |
buf.append(" public void testFailure() {\n"); |
|
|
3979 |
buf.append(" final TestCase failure = new TestCase(\"failure\") { //$NON-NLS-1$\n"); |
3980 |
buf.append(" @Override\n"); |
3981 |
buf.append(" protected void runTest() {\n"); |
3982 |
buf.append(" Assert.fail();\n"); |
3983 |
buf.append(" }\n"); |
3984 |
buf.append(" };\n"); |
3985 |
buf.append(" this.verifyFailure(failure);\n"); |
3986 |
buf.append(" }\n"); |
3987 |
buf.append("\n"); |
3988 |
buf.append(" public void testTearDownAfterError() {\n"); |
4022 |
buf.append(" public void testTearDownAfterError() {\n"); |
3989 |
buf.append(" final TornDown fails = new TornDown();\n"); |
4023 |
buf.append(" final TornDown fails = new TornDown();\n"); |
3990 |
buf.append(" this.verifyError(fails);\n"); |
4024 |
buf.append(" this.verifyError(fails);\n"); |
3991 |
buf.append(" Assert.assertTrue(fails.fTornDown);\n"); |
4025 |
buf.append(" Assert.assertTrue(fails.fTornDown);\n"); |
3992 |
buf.append(" }\n"); |
4026 |
buf.append(" }\n"); |
3993 |
buf.append("\n"); |
|
|
3994 |
buf.append(" public void testTearDownFails() {\n"); |
4027 |
buf.append(" public void testTearDownFails() {\n"); |
3995 |
buf.append(" final TestCase fails = new TestCase(\"success\") { //$NON-NLS-1$\n"); |
4028 |
buf.append(" final TestCase fails = new TestCase(\"success\") { //$NON-NLS-1$\n"); |
3996 |
buf.append(" @Override\n"); |
4029 |
buf.append(" @Override\n"); |
3997 |
buf.append(" protected void tearDown() {\n"); |
4030 |
buf.append(" protected void runTest() {\n"); |
3998 |
buf.append(" throw new Error();\n"); |
|
|
3999 |
buf.append(" }\n"); |
4031 |
buf.append(" }\n"); |
4000 |
buf.append(" @Override\n"); |
4032 |
buf.append(" @Override\n"); |
4001 |
buf.append(" protected void runTest() {\n"); |
4033 |
buf.append(" protected void tearDown() {\n"); |
|
|
4034 |
buf.append(" throw new Error();\n"); |
4002 |
buf.append(" }\n"); |
4035 |
buf.append(" }\n"); |
4003 |
buf.append(" };\n"); |
4036 |
buf.append(" };\n"); |
4004 |
buf.append(" this.verifyError(fails);\n"); |
4037 |
buf.append(" this.verifyError(fails);\n"); |
4005 |
buf.append(" }\n"); |
4038 |
buf.append(" }\n"); |
|
|
4039 |
buf.append("\n"); |
4006 |
buf.append(" public void testTearDownSetupFails() {\n"); |
4040 |
buf.append(" public void testTearDownSetupFails() {\n"); |
4007 |
buf.append(" final TornDown fails = new TornDown() {\n"); |
4041 |
buf.append(" final TornDown fails = new TornDown() {\n"); |
4008 |
buf.append(" @Override\n"); |
4042 |
buf.append(" @Override\n"); |
Lines 4013-4057
Link Here
|
4013 |
buf.append(" this.verifyError(fails);\n"); |
4047 |
buf.append(" this.verifyError(fails);\n"); |
4014 |
buf.append(" Assert.assertTrue(!fails.fTornDown);\n"); |
4048 |
buf.append(" Assert.assertTrue(!fails.fTornDown);\n"); |
4015 |
buf.append(" }\n"); |
4049 |
buf.append(" }\n"); |
|
|
4050 |
buf.append("\n"); |
4016 |
buf.append(" public void testWasRun() {\n"); |
4051 |
buf.append(" public void testWasRun() {\n"); |
4017 |
buf.append(" final WasRun test = new WasRun();\n"); |
4052 |
buf.append(" final WasRun test = new WasRun();\n"); |
4018 |
buf.append(" test.run();\n"); |
4053 |
buf.append(" test.run();\n"); |
4019 |
buf.append(" Assert.assertTrue(test.fWasRun);\n"); |
4054 |
buf.append(" Assert.assertTrue(test.fWasRun);\n"); |
4020 |
buf.append(" }\n"); |
4055 |
buf.append(" }\n"); |
4021 |
buf.append(" public void testExceptionRunningAndTearDown() {\n"); |
|
|
4022 |
buf.append(" // This test documents the current behavior. With 1.4, we should\n"); |
4023 |
buf.append(" // wrap the exception thrown while running with the exception thrown\n"); |
4024 |
buf.append(" // while tearing down\n"); |
4025 |
buf.append(" final Test t = new TornDown() {\n"); |
4026 |
buf.append(" @Override\n"); |
4027 |
buf.append(" public void tearDown() {\n"); |
4028 |
buf.append(" throw new Error(\"tearDown\"); //$NON-NLS-1$\n"); |
4029 |
buf.append(" }\n"); |
4030 |
buf.append(" };\n"); |
4031 |
buf.append(" final TestResult result = new TestResult();\n"); |
4032 |
buf.append(" t.run(result);\n"); |
4033 |
buf.append(" final TestFailure failure = (TestFailure) result.errors().nextElement();\n"); |
4034 |
buf.append(" Assert.assertEquals(\"tearDown\", failure.thrownException().getMessage()); //$NON-NLS-1$\n"); |
4035 |
buf.append(" }\n"); |
4036 |
buf.append("\n"); |
4037 |
buf.append(" public void testNoArgTestCasePasses() {\n"); |
4038 |
buf.append(" final Test t = new TestSuite(NoArgTestCaseTest.class);\n"); |
4039 |
buf.append(" final TestResult result = new TestResult();\n"); |
4040 |
buf.append(" t.run(result);\n"); |
4041 |
buf.append(" Assert.assertTrue(result.runCount() == 1);\n"); |
4042 |
buf.append(" Assert.assertTrue(result.failureCount() == 0);\n"); |
4043 |
buf.append(" Assert.assertTrue(result.errorCount() == 0);\n"); |
4044 |
buf.append(" }\n"); |
4045 |
buf.append("\n"); |
4046 |
buf.append(" public void testNamelessTestCase() {\n"); |
4047 |
buf.append(" final TestCase t = new TestCase() {\n"); |
4048 |
buf.append(" };\n"); |
4049 |
buf.append(" try {\n"); |
4050 |
buf.append(" t.run();\n"); |
4051 |
buf.append(" Assert.fail();\n"); |
4052 |
buf.append(" } catch (final AssertionFailedError e) {\n"); |
4053 |
buf.append(" }\n"); |
4054 |
buf.append(" }\n"); |
4055 |
buf.append("\n"); |
4056 |
buf.append("\n"); |
4056 |
buf.append(" void verifyError(final TestCase test) {\n"); |
4057 |
buf.append(" void verifyError(final TestCase test) {\n"); |
4057 |
buf.append(" final TestResult result = test.run();\n"); |
4058 |
buf.append(" final TestResult result = test.run();\n"); |
Lines 4096-4107
Link Here
|
4096 |
buf.append(" this.fFailedTest = failedTest;\n"); |
4097 |
buf.append(" this.fFailedTest = failedTest;\n"); |
4097 |
buf.append(" this.fThrownException = thrownException;\n"); |
4098 |
buf.append(" this.fThrownException = thrownException;\n"); |
4098 |
buf.append(" }\n"); |
4099 |
buf.append(" }\n"); |
|
|
4100 |
buf.append(" public String exceptionMessage() {\n"); |
4101 |
buf.append(" return this.thrownException().getMessage();\n"); |
4102 |
buf.append(" }\n"); |
4099 |
buf.append(" /**\n"); |
4103 |
buf.append(" /**\n"); |
4100 |
buf.append(" * Gets the failed test.\n"); |
4104 |
buf.append(" * Gets the failed test.\n"); |
4101 |
buf.append(" */\n"); |
4105 |
buf.append(" */\n"); |
4102 |
buf.append(" public Test failedTest() {\n"); |
4106 |
buf.append(" public Test failedTest() {\n"); |
4103 |
buf.append(" return this.fFailedTest;\n"); |
4107 |
buf.append(" return this.fFailedTest;\n"); |
4104 |
buf.append(" }\n"); |
4108 |
buf.append(" }\n"); |
|
|
4109 |
buf.append(" public boolean isFailure() {\n"); |
4110 |
buf.append(" return this.thrownException() instanceof AssertionFailedError;\n"); |
4111 |
buf.append(" }\n"); |
4105 |
buf.append(" /**\n"); |
4112 |
buf.append(" /**\n"); |
4106 |
buf.append(" * Gets the thrown exception.\n"); |
4113 |
buf.append(" * Gets the thrown exception.\n"); |
4107 |
buf.append(" */\n"); |
4114 |
buf.append(" */\n"); |
Lines 4125-4136
Link Here
|
4125 |
buf.append(" final StringBuffer buffer = stringWriter.getBuffer();\n"); |
4132 |
buf.append(" final StringBuffer buffer = stringWriter.getBuffer();\n"); |
4126 |
buf.append(" return buffer.toString();\n"); |
4133 |
buf.append(" return buffer.toString();\n"); |
4127 |
buf.append(" }\n"); |
4134 |
buf.append(" }\n"); |
4128 |
buf.append(" public String exceptionMessage() {\n"); |
|
|
4129 |
buf.append(" return this.thrownException().getMessage();\n"); |
4130 |
buf.append(" }\n"); |
4131 |
buf.append(" public boolean isFailure() {\n"); |
4132 |
buf.append(" return this.thrownException() instanceof AssertionFailedError;\n"); |
4133 |
buf.append(" }\n"); |
4134 |
buf.append("}"); |
4135 |
buf.append("}"); |
4135 |
fExpectedChangesAllTests.put("junit.framework.TestFailure.java", buf.toString()); |
4136 |
fExpectedChangesAllTests.put("junit.framework.TestFailure.java", buf.toString()); |
4136 |
buf= new StringBuffer(); |
4137 |
buf= new StringBuffer(); |
Lines 4141-4146
Link Here
|
4141 |
buf.append(" */\n"); |
4142 |
buf.append(" */\n"); |
4142 |
buf.append("public class ReloadingTestSuiteLoader implements TestSuiteLoader {\n"); |
4143 |
buf.append("public class ReloadingTestSuiteLoader implements TestSuiteLoader {\n"); |
4143 |
buf.append("\n"); |
4144 |
buf.append("\n"); |
|
|
4145 |
buf.append(" protected TestCaseClassLoader createLoader() {\n"); |
4146 |
buf.append(" return new TestCaseClassLoader();\n"); |
4147 |
buf.append(" }\n"); |
4148 |
buf.append("\n"); |
4144 |
buf.append(" public Class load(final String suiteClassName)\n"); |
4149 |
buf.append(" public Class load(final String suiteClassName)\n"); |
4145 |
buf.append(" throws ClassNotFoundException {\n"); |
4150 |
buf.append(" throws ClassNotFoundException {\n"); |
4146 |
buf.append(" return this.createLoader().loadClass(suiteClassName, true);\n"); |
4151 |
buf.append(" return this.createLoader().loadClass(suiteClassName, true);\n"); |
Lines 4149-4158
Link Here
|
4149 |
buf.append(" public Class reload(final Class aClass) throws ClassNotFoundException {\n"); |
4154 |
buf.append(" public Class reload(final Class aClass) throws ClassNotFoundException {\n"); |
4150 |
buf.append(" return this.createLoader().loadClass(aClass.getName(), true);\n"); |
4155 |
buf.append(" return this.createLoader().loadClass(aClass.getName(), true);\n"); |
4151 |
buf.append(" }\n"); |
4156 |
buf.append(" }\n"); |
4152 |
buf.append("\n"); |
|
|
4153 |
buf.append(" protected TestCaseClassLoader createLoader() {\n"); |
4154 |
buf.append(" return new TestCaseClassLoader();\n"); |
4155 |
buf.append(" }\n"); |
4156 |
buf.append("}"); |
4157 |
buf.append("}"); |
4157 |
fExpectedChangesAllTests.put("junit.runner.ReloadingTestSuiteLoader.java", buf.toString()); |
4158 |
fExpectedChangesAllTests.put("junit.runner.ReloadingTestSuiteLoader.java", buf.toString()); |
4158 |
buf= new StringBuffer(); |
4159 |
buf= new StringBuffer(); |
Lines 4234-4251
Link Here
|
4234 |
buf.append("\n"); |
4235 |
buf.append("\n"); |
4235 |
buf.append("public class TextRunnerTest extends TestCase {\n"); |
4236 |
buf.append("public class TextRunnerTest extends TestCase {\n"); |
4236 |
buf.append("\n"); |
4237 |
buf.append("\n"); |
4237 |
buf.append(" public void testFailure() throws Exception {\n"); |
|
|
4238 |
buf.append(" this.execTest(\"junit.tests.framework.Failure\", false); //$NON-NLS-1$\n"); |
4239 |
buf.append(" }\n"); |
4240 |
buf.append("\n"); |
4241 |
buf.append(" public void testSuccess() throws Exception {\n"); |
4242 |
buf.append(" this.execTest(\"junit.tests.framework.Success\", true); //$NON-NLS-1$\n"); |
4243 |
buf.append(" }\n"); |
4244 |
buf.append("\n"); |
4245 |
buf.append(" public void testError() throws Exception {\n"); |
4246 |
buf.append(" this.execTest(\"junit.tests.BogusDude\", false); //$NON-NLS-1$\n"); |
4247 |
buf.append(" }\n"); |
4248 |
buf.append("\n"); |
4249 |
buf.append(" void execTest(final String testClass, final boolean success)\n"); |
4238 |
buf.append(" void execTest(final String testClass, final boolean success)\n"); |
4250 |
buf.append(" throws Exception {\n"); |
4239 |
buf.append(" throws Exception {\n"); |
4251 |
buf.append(" final String java = System.getProperty(\"java.home\") + File.separator + \"bin\" + File.separator + \"java\"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\n"); |
4240 |
buf.append(" final String java = System.getProperty(\"java.home\") + File.separator + \"bin\" + File.separator + \"java\"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\n"); |
Lines 4269-4274
Link Here
|
4269 |
buf.append(" }\n"); |
4258 |
buf.append(" }\n"); |
4270 |
buf.append(" }\n"); |
4259 |
buf.append(" }\n"); |
4271 |
buf.append("\n"); |
4260 |
buf.append("\n"); |
|
|
4261 |
buf.append(" public void testError() throws Exception {\n"); |
4262 |
buf.append(" this.execTest(\"junit.tests.BogusDude\", false); //$NON-NLS-1$\n"); |
4263 |
buf.append(" }\n"); |
4264 |
buf.append("\n"); |
4265 |
buf.append(" public void testFailure() throws Exception {\n"); |
4266 |
buf.append(" this.execTest(\"junit.tests.framework.Failure\", false); //$NON-NLS-1$\n"); |
4267 |
buf.append(" }\n"); |
4268 |
buf.append("\n"); |
4272 |
buf.append(" public void testRunReturnsResult() {\n"); |
4269 |
buf.append(" public void testRunReturnsResult() {\n"); |
4273 |
buf.append(" final PrintStream oldOut = System.out;\n"); |
4270 |
buf.append(" final PrintStream oldOut = System.out;\n"); |
4274 |
buf.append(" System.setOut(new PrintStream(new OutputStream() {\n"); |
4271 |
buf.append(" System.setOut(new PrintStream(new OutputStream() {\n"); |
Lines 4285-4290
Link Here
|
4285 |
buf.append(" }\n"); |
4282 |
buf.append(" }\n"); |
4286 |
buf.append(" }\n"); |
4283 |
buf.append(" }\n"); |
4287 |
buf.append("\n"); |
4284 |
buf.append("\n"); |
|
|
4285 |
buf.append(" public void testSuccess() throws Exception {\n"); |
4286 |
buf.append(" this.execTest(\"junit.tests.framework.Success\", true); //$NON-NLS-1$\n"); |
4287 |
buf.append(" }\n"); |
4288 |
buf.append("\n"); |
4288 |
buf.append("}"); |
4289 |
buf.append("}"); |
4289 |
fExpectedChangesAllTests.put("junit.tests.runner.TextRunnerTest.java", buf.toString()); |
4290 |
fExpectedChangesAllTests.put("junit.tests.runner.TextRunnerTest.java", buf.toString()); |
4290 |
buf= new StringBuffer(); |
4291 |
buf= new StringBuffer(); |
Lines 4456-4463
Link Here
|
4456 |
buf.append(" */\n"); |
4457 |
buf.append(" */\n"); |
4457 |
buf.append("\n"); |
4458 |
buf.append("\n"); |
4458 |
buf.append("public class RepeatedTestTest extends TestCase {\n"); |
4459 |
buf.append("public class RepeatedTestTest extends TestCase {\n"); |
4459 |
buf.append(" private final TestSuite fSuite;\n"); |
|
|
4460 |
buf.append("\n"); |
4461 |
buf.append(" public static class SuccessTest extends TestCase {\n"); |
4460 |
buf.append(" public static class SuccessTest extends TestCase {\n"); |
4462 |
buf.append("\n"); |
4461 |
buf.append("\n"); |
4463 |
buf.append(" @Override\n"); |
4462 |
buf.append(" @Override\n"); |
Lines 4465-4470
Link Here
|
4465 |
buf.append(" }\n"); |
4464 |
buf.append(" }\n"); |
4466 |
buf.append(" }\n"); |
4465 |
buf.append(" }\n"); |
4467 |
buf.append("\n"); |
4466 |
buf.append("\n"); |
|
|
4467 |
buf.append(" private final TestSuite fSuite;\n"); |
4468 |
buf.append("\n"); |
4468 |
buf.append(" public RepeatedTestTest(final String name) {\n"); |
4469 |
buf.append(" public RepeatedTestTest(final String name) {\n"); |
4469 |
buf.append(" super(name);\n"); |
4470 |
buf.append(" super(name);\n"); |
4470 |
buf.append(" this.fSuite = new TestSuite();\n"); |
4471 |
buf.append(" this.fSuite = new TestSuite();\n"); |
Lines 4472-4485
Link Here
|
4472 |
buf.append(" this.fSuite.addTest(new SuccessTest());\n"); |
4473 |
buf.append(" this.fSuite.addTest(new SuccessTest());\n"); |
4473 |
buf.append(" }\n"); |
4474 |
buf.append(" }\n"); |
4474 |
buf.append("\n"); |
4475 |
buf.append("\n"); |
4475 |
buf.append(" public void testRepeatedOnce() {\n"); |
|
|
4476 |
buf.append(" final Test test = new RepeatedTest(this.fSuite, 1);\n"); |
4477 |
buf.append(" Assert.assertEquals(2, test.countTestCases());\n"); |
4478 |
buf.append(" final TestResult result = new TestResult();\n"); |
4479 |
buf.append(" test.run(result);\n"); |
4480 |
buf.append(" Assert.assertEquals(2, result.runCount());\n"); |
4481 |
buf.append(" }\n"); |
4482 |
buf.append("\n"); |
4483 |
buf.append(" public void testRepeatedMoreThanOnce() {\n"); |
4476 |
buf.append(" public void testRepeatedMoreThanOnce() {\n"); |
4484 |
buf.append(" final Test test = new RepeatedTest(this.fSuite, 3);\n"); |
4477 |
buf.append(" final Test test = new RepeatedTest(this.fSuite, 3);\n"); |
4485 |
buf.append(" Assert.assertEquals(6, test.countTestCases());\n"); |
4478 |
buf.append(" Assert.assertEquals(6, test.countTestCases());\n"); |
Lines 4488-4501
Link Here
|
4488 |
buf.append(" Assert.assertEquals(6, result.runCount());\n"); |
4481 |
buf.append(" Assert.assertEquals(6, result.runCount());\n"); |
4489 |
buf.append(" }\n"); |
4482 |
buf.append(" }\n"); |
4490 |
buf.append("\n"); |
4483 |
buf.append("\n"); |
4491 |
buf.append(" public void testRepeatedZero() {\n"); |
|
|
4492 |
buf.append(" final Test test = new RepeatedTest(this.fSuite, 0);\n"); |
4493 |
buf.append(" Assert.assertEquals(0, test.countTestCases());\n"); |
4494 |
buf.append(" final TestResult result = new TestResult();\n"); |
4495 |
buf.append(" test.run(result);\n"); |
4496 |
buf.append(" Assert.assertEquals(0, result.runCount());\n"); |
4497 |
buf.append(" }\n"); |
4498 |
buf.append("\n"); |
4499 |
buf.append(" public void testRepeatedNegative() {\n"); |
4484 |
buf.append(" public void testRepeatedNegative() {\n"); |
4500 |
buf.append(" try {\n"); |
4485 |
buf.append(" try {\n"); |
4501 |
buf.append(" new RepeatedTest(this.fSuite, -1);\n"); |
4486 |
buf.append(" new RepeatedTest(this.fSuite, -1);\n"); |
Lines 4504-4509
Link Here
|
4504 |
buf.append(" }\n"); |
4489 |
buf.append(" }\n"); |
4505 |
buf.append(" Assert.fail(\"Should throw an IllegalArgumentException\"); //$NON-NLS-1$\n"); |
4490 |
buf.append(" Assert.fail(\"Should throw an IllegalArgumentException\"); //$NON-NLS-1$\n"); |
4506 |
buf.append(" }\n"); |
4491 |
buf.append(" }\n"); |
|
|
4492 |
buf.append("\n"); |
4493 |
buf.append(" public void testRepeatedOnce() {\n"); |
4494 |
buf.append(" final Test test = new RepeatedTest(this.fSuite, 1);\n"); |
4495 |
buf.append(" Assert.assertEquals(2, test.countTestCases());\n"); |
4496 |
buf.append(" final TestResult result = new TestResult();\n"); |
4497 |
buf.append(" test.run(result);\n"); |
4498 |
buf.append(" Assert.assertEquals(2, result.runCount());\n"); |
4499 |
buf.append(" }\n"); |
4500 |
buf.append("\n"); |
4501 |
buf.append(" public void testRepeatedZero() {\n"); |
4502 |
buf.append(" final Test test = new RepeatedTest(this.fSuite, 0);\n"); |
4503 |
buf.append(" Assert.assertEquals(0, test.countTestCases());\n"); |
4504 |
buf.append(" final TestResult result = new TestResult();\n"); |
4505 |
buf.append(" test.run(result);\n"); |
4506 |
buf.append(" Assert.assertEquals(0, result.runCount());\n"); |
4507 |
buf.append(" }\n"); |
4507 |
buf.append("}"); |
4508 |
buf.append("}"); |
4508 |
fExpectedChangesAllTests.put("junit.tests.extensions.RepeatedTestTest.java", buf.toString()); |
4509 |
fExpectedChangesAllTests.put("junit.tests.extensions.RepeatedTestTest.java", buf.toString()); |
4509 |
buf= new StringBuffer(); |
4510 |
buf= new StringBuffer(); |
Lines 4519-4524
Link Here
|
4519 |
buf.append(" */\n"); |
4520 |
buf.append(" */\n"); |
4520 |
buf.append("public class AllTests {\n"); |
4521 |
buf.append("public class AllTests {\n"); |
4521 |
buf.append("\n"); |
4522 |
buf.append("\n"); |
|
|
4523 |
buf.append(" static boolean isJDK11() {\n"); |
4524 |
buf.append(" final String version = System.getProperty(\"java.version\"); //$NON-NLS-1$\n"); |
4525 |
buf.append(" return version.startsWith(\"1.1\"); //$NON-NLS-1$\n"); |
4526 |
buf.append(" }\n"); |
4527 |
buf.append("\n"); |
4522 |
buf.append(" public static void main(final String[] args) {\n"); |
4528 |
buf.append(" public static void main(final String[] args) {\n"); |
4523 |
buf.append(" junit.textui.TestRunner.run(AllTests.suite());\n"); |
4529 |
buf.append(" junit.textui.TestRunner.run(AllTests.suite());\n"); |
4524 |
buf.append(" }\n"); |
4530 |
buf.append(" }\n"); |
Lines 4539-4549
Link Here
|
4539 |
buf.append(" }\n"); |
4545 |
buf.append(" }\n"); |
4540 |
buf.append(" return suite;\n"); |
4546 |
buf.append(" return suite;\n"); |
4541 |
buf.append(" }\n"); |
4547 |
buf.append(" }\n"); |
4542 |
buf.append("\n"); |
|
|
4543 |
buf.append(" static boolean isJDK11() {\n"); |
4544 |
buf.append(" final String version = System.getProperty(\"java.version\"); //$NON-NLS-1$\n"); |
4545 |
buf.append(" return version.startsWith(\"1.1\"); //$NON-NLS-1$\n"); |
4546 |
buf.append(" }\n"); |
4547 |
buf.append("}"); |
4548 |
buf.append("}"); |
4548 |
fExpectedChangesAllTests.put("junit.tests.runner.AllTests.java", buf.toString()); |
4549 |
fExpectedChangesAllTests.put("junit.tests.runner.AllTests.java", buf.toString()); |
4549 |
buf= new StringBuffer(); |
4550 |
buf= new StringBuffer(); |
Lines 4581-4594
Link Here
|
4581 |
buf.append(" * constructors to create a MoneyBag.\n"); |
4582 |
buf.append(" * constructors to create a MoneyBag.\n"); |
4582 |
buf.append(" */\n"); |
4583 |
buf.append(" */\n"); |
4583 |
buf.append("class MoneyBag implements IMoney {\n"); |
4584 |
buf.append("class MoneyBag implements IMoney {\n"); |
4584 |
buf.append(" private final Vector fMonies = new Vector(5);\n"); |
|
|
4585 |
buf.append("\n"); |
4586 |
buf.append(" static IMoney create(final IMoney m1, final IMoney m2) {\n"); |
4585 |
buf.append(" static IMoney create(final IMoney m1, final IMoney m2) {\n"); |
4587 |
buf.append(" final MoneyBag result = new MoneyBag();\n"); |
4586 |
buf.append(" final MoneyBag result = new MoneyBag();\n"); |
4588 |
buf.append(" m1.appendTo(result);\n"); |
4587 |
buf.append(" m1.appendTo(result);\n"); |
4589 |
buf.append(" m2.appendTo(result);\n"); |
4588 |
buf.append(" m2.appendTo(result);\n"); |
4590 |
buf.append(" return result.simplify();\n"); |
4589 |
buf.append(" return result.simplify();\n"); |
4591 |
buf.append(" }\n"); |
4590 |
buf.append(" }\n"); |
|
|
4591 |
buf.append("\n"); |
4592 |
buf.append(" private final Vector fMonies = new Vector(5);\n"); |
4592 |
buf.append(" public IMoney add(final IMoney m) {\n"); |
4593 |
buf.append(" public IMoney add(final IMoney m) {\n"); |
4593 |
buf.append(" return m.addMoneyBag(this);\n"); |
4594 |
buf.append(" return m.addMoneyBag(this);\n"); |
4594 |
buf.append(" }\n"); |
4595 |
buf.append(" }\n"); |
Lines 4619-4624
Link Here
|
4619 |
buf.append(" }\n"); |
4620 |
buf.append(" }\n"); |
4620 |
buf.append(" this.fMonies.addElement(sum);\n"); |
4621 |
buf.append(" this.fMonies.addElement(sum);\n"); |
4621 |
buf.append(" }\n"); |
4622 |
buf.append(" }\n"); |
|
|
4623 |
buf.append(" public void appendTo(final MoneyBag m) {\n"); |
4624 |
buf.append(" m.appendBag(this);\n"); |
4625 |
buf.append(" }\n"); |
4626 |
buf.append(" private boolean contains(final Money m) {\n"); |
4627 |
buf.append(" final Money found = this.findMoney(m.currency());\n"); |
4628 |
buf.append(" if (found == null) {\n"); |
4629 |
buf.append(" return false;\n"); |
4630 |
buf.append(" }\n"); |
4631 |
buf.append(" return found.amount() == m.amount();\n"); |
4632 |
buf.append(" }\n"); |
4622 |
buf.append(" @Override\n"); |
4633 |
buf.append(" @Override\n"); |
4623 |
buf.append(" public boolean equals(final Object anObject) {\n"); |
4634 |
buf.append(" public boolean equals(final Object anObject) {\n"); |
4624 |
buf.append(" if (this.isZero()) {\n"); |
4635 |
buf.append(" if (this.isZero()) {\n"); |
Lines 4653-4665
Link Here
|
4653 |
buf.append(" }\n"); |
4664 |
buf.append(" }\n"); |
4654 |
buf.append(" return null;\n"); |
4665 |
buf.append(" return null;\n"); |
4655 |
buf.append(" }\n"); |
4666 |
buf.append(" }\n"); |
4656 |
buf.append(" private boolean contains(final Money m) {\n"); |
|
|
4657 |
buf.append(" final Money found = this.findMoney(m.currency());\n"); |
4658 |
buf.append(" if (found == null) {\n"); |
4659 |
buf.append(" return false;\n"); |
4660 |
buf.append(" }\n"); |
4661 |
buf.append(" return found.amount() == m.amount();\n"); |
4662 |
buf.append(" }\n"); |
4663 |
buf.append(" @Override\n"); |
4667 |
buf.append(" @Override\n"); |
4664 |
buf.append(" public int hashCode() {\n"); |
4668 |
buf.append(" public int hashCode() {\n"); |
4665 |
buf.append(" int hash = 0;\n"); |
4669 |
buf.append(" int hash = 0;\n"); |
Lines 4710-4718
Link Here
|
4710 |
buf.append(" buffer.append(\"}\"); //$NON-NLS-1$\n"); |
4714 |
buf.append(" buffer.append(\"}\"); //$NON-NLS-1$\n"); |
4711 |
buf.append(" return buffer.toString();\n"); |
4715 |
buf.append(" return buffer.toString();\n"); |
4712 |
buf.append(" }\n"); |
4716 |
buf.append(" }\n"); |
4713 |
buf.append(" public void appendTo(final MoneyBag m) {\n"); |
|
|
4714 |
buf.append(" m.appendBag(this);\n"); |
4715 |
buf.append(" }\n"); |
4716 |
buf.append("}"); |
4717 |
buf.append("}"); |
4717 |
fExpectedChangesAllTests.put("junit.samples.money.MoneyBag.java", buf.toString()); |
4718 |
fExpectedChangesAllTests.put("junit.samples.money.MoneyBag.java", buf.toString()); |
4718 |
buf= new StringBuffer(); |
4719 |
buf= new StringBuffer(); |
Lines 4847-4852
Link Here
|
4847 |
buf.append(" return new TestResult();\n"); |
4848 |
buf.append(" return new TestResult();\n"); |
4848 |
buf.append(" }\n"); |
4849 |
buf.append(" }\n"); |
4849 |
buf.append(" /**\n"); |
4850 |
buf.append(" /**\n"); |
|
|
4851 |
buf.append(" * Gets the name of a TestCase\n"); |
4852 |
buf.append(" * \n"); |
4853 |
buf.append(" * @return returns a String\n"); |
4854 |
buf.append(" */\n"); |
4855 |
buf.append(" public String getName() {\n"); |
4856 |
buf.append(" return this.fName;\n"); |
4857 |
buf.append(" }\n"); |
4858 |
buf.append(" /**\n"); |
4850 |
buf.append(" * A convenience method to run this test, collecting the results with a\n"); |
4859 |
buf.append(" * A convenience method to run this test, collecting the results with a\n"); |
4851 |
buf.append(" * default TestResult object.\n"); |
4860 |
buf.append(" * default TestResult object.\n"); |
4852 |
buf.append(" * \n"); |
4861 |
buf.append(" * \n"); |
Lines 4910-4915
Link Here
|
4910 |
buf.append(" }\n"); |
4919 |
buf.append(" }\n"); |
4911 |
buf.append(" }\n"); |
4920 |
buf.append(" }\n"); |
4912 |
buf.append(" /**\n"); |
4921 |
buf.append(" /**\n"); |
|
|
4922 |
buf.append(" * Sets the name of a TestCase\n"); |
4923 |
buf.append(" * \n"); |
4924 |
buf.append(" * @param name\n"); |
4925 |
buf.append(" * The name to set\n"); |
4926 |
buf.append(" */\n"); |
4927 |
buf.append(" public void setName(final String name) {\n"); |
4928 |
buf.append(" this.fName = name;\n"); |
4929 |
buf.append(" }\n"); |
4930 |
buf.append(" /**\n"); |
4913 |
buf.append(" * Sets up the fixture, for example, open a network connection. This method\n"); |
4931 |
buf.append(" * Sets up the fixture, for example, open a network connection. This method\n"); |
4914 |
buf.append(" * is called before a test is executed.\n"); |
4932 |
buf.append(" * is called before a test is executed.\n"); |
4915 |
buf.append(" */\n"); |
4933 |
buf.append(" */\n"); |
Lines 4928-4950
Link Here
|
4928 |
buf.append(" public String toString() {\n"); |
4946 |
buf.append(" public String toString() {\n"); |
4929 |
buf.append(" return this.getName() + \"(\" + this.getClass().getName() + \")\"; //$NON-NLS-1$ //$NON-NLS-2$\n"); |
4947 |
buf.append(" return this.getName() + \"(\" + this.getClass().getName() + \")\"; //$NON-NLS-1$ //$NON-NLS-2$\n"); |
4930 |
buf.append(" }\n"); |
4948 |
buf.append(" }\n"); |
4931 |
buf.append(" /**\n"); |
|
|
4932 |
buf.append(" * Gets the name of a TestCase\n"); |
4933 |
buf.append(" * \n"); |
4934 |
buf.append(" * @return returns a String\n"); |
4935 |
buf.append(" */\n"); |
4936 |
buf.append(" public String getName() {\n"); |
4937 |
buf.append(" return this.fName;\n"); |
4938 |
buf.append(" }\n"); |
4939 |
buf.append(" /**\n"); |
4940 |
buf.append(" * Sets the name of a TestCase\n"); |
4941 |
buf.append(" * \n"); |
4942 |
buf.append(" * @param name\n"); |
4943 |
buf.append(" * The name to set\n"); |
4944 |
buf.append(" */\n"); |
4945 |
buf.append(" public void setName(final String name) {\n"); |
4946 |
buf.append(" this.fName = name;\n"); |
4947 |
buf.append(" }\n"); |
4948 |
buf.append("}"); |
4949 |
buf.append("}"); |
4949 |
fExpectedChangesAllTests.put("junit.framework.TestCase.java", buf.toString()); |
4950 |
fExpectedChangesAllTests.put("junit.framework.TestCase.java", buf.toString()); |
4950 |
buf= new StringBuffer(); |
4951 |
buf= new StringBuffer(); |
Lines 4954-4970
Link Here
|
4954 |
buf.append("import junit.framework.TestCase;\n"); |
4955 |
buf.append("import junit.framework.TestCase;\n"); |
4955 |
buf.append("\n"); |
4956 |
buf.append("\n"); |
4956 |
buf.append("public class MoneyTest extends TestCase {\n"); |
4957 |
buf.append("public class MoneyTest extends TestCase {\n"); |
|
|
4958 |
buf.append(" public static void main(final String args[]) {\n"); |
4959 |
buf.append(" junit.textui.TestRunner.run(MoneyTest.class);\n"); |
4960 |
buf.append(" }\n"); |
4957 |
buf.append(" private Money f12CHF;\n"); |
4961 |
buf.append(" private Money f12CHF;\n"); |
4958 |
buf.append(" private Money f14CHF;\n"); |
4962 |
buf.append(" private Money f14CHF;\n"); |
4959 |
buf.append(" private Money f7USD;\n"); |
|
|
4960 |
buf.append(" private Money f21USD;\n"); |
4963 |
buf.append(" private Money f21USD;\n"); |
4961 |
buf.append("\n"); |
4964 |
buf.append("\n"); |
|
|
4965 |
buf.append(" private Money f7USD;\n"); |
4962 |
buf.append(" private IMoney fMB1;\n"); |
4966 |
buf.append(" private IMoney fMB1;\n"); |
4963 |
buf.append(" private IMoney fMB2;\n"); |
|
|
4964 |
buf.append("\n"); |
4967 |
buf.append("\n"); |
4965 |
buf.append(" public static void main(final String args[]) {\n"); |
4968 |
buf.append(" private IMoney fMB2;\n"); |
4966 |
buf.append(" junit.textui.TestRunner.run(MoneyTest.class);\n"); |
|
|
4967 |
buf.append(" }\n"); |
4968 |
buf.append(" @Override\n"); |
4969 |
buf.append(" @Override\n"); |
4969 |
buf.append(" protected void setUp() {\n"); |
4970 |
buf.append(" protected void setUp() {\n"); |
4970 |
buf.append(" this.f12CHF = new Money(12, \"CHF\"); //$NON-NLS-1$\n"); |
4971 |
buf.append(" this.f12CHF = new Money(12, \"CHF\"); //$NON-NLS-1$\n"); |
Lines 4989-4994
Link Here
|
4989 |
buf.append(" new Money(-12, \"CHF\"), new Money(-7, \"USD\")); //$NON-NLS-1$ //$NON-NLS-2$\n"); |
4990 |
buf.append(" new Money(-12, \"CHF\"), new Money(-7, \"USD\")); //$NON-NLS-1$ //$NON-NLS-2$\n"); |
4990 |
buf.append(" Assert.assertEquals(expected, this.fMB1.negate());\n"); |
4991 |
buf.append(" Assert.assertEquals(expected, this.fMB1.negate());\n"); |
4991 |
buf.append(" }\n"); |
4992 |
buf.append(" }\n"); |
|
|
4993 |
buf.append(" public void testBagNotEquals() {\n"); |
4994 |
buf.append(" final IMoney bag = MoneyBag.create(this.f12CHF, this.f7USD);\n"); |
4995 |
buf.append(" Assert.assertFalse(bag.equals(new Money(12, \"DEM\").add(this.f7USD))); //$NON-NLS-1$\n"); |
4996 |
buf.append(" }\n"); |
4992 |
buf.append(" public void testBagSimpleAdd() {\n"); |
4997 |
buf.append(" public void testBagSimpleAdd() {\n"); |
4993 |
buf.append(" // {[12 CHF][7 USD]} + [14 CHF] == {[26 CHF][7 USD]}\n"); |
4998 |
buf.append(" // {[12 CHF][7 USD]} + [14 CHF] == {[26 CHF][7 USD]}\n"); |
4994 |
buf.append(" final IMoney expected = MoneyBag.create(\n"); |
4999 |
buf.append(" final IMoney expected = MoneyBag.create(\n"); |
Lines 5017-5026
Link Here
|
5017 |
buf.append(" final IMoney expected = MoneyBag.create(this.f12CHF, this.f7USD);\n"); |
5022 |
buf.append(" final IMoney expected = MoneyBag.create(this.f12CHF, this.f7USD);\n"); |
5018 |
buf.append(" Assert.assertEquals(expected, this.f12CHF.add(this.f7USD));\n"); |
5023 |
buf.append(" Assert.assertEquals(expected, this.f12CHF.add(this.f7USD));\n"); |
5019 |
buf.append(" }\n"); |
5024 |
buf.append(" }\n"); |
5020 |
buf.append(" public void testBagNotEquals() {\n"); |
|
|
5021 |
buf.append(" final IMoney bag = MoneyBag.create(this.f12CHF, this.f7USD);\n"); |
5022 |
buf.append(" Assert.assertFalse(bag.equals(new Money(12, \"DEM\").add(this.f7USD))); //$NON-NLS-1$\n"); |
5023 |
buf.append(" }\n"); |
5024 |
buf.append(" public void testMoneyBagEquals() {\n"); |
5025 |
buf.append(" public void testMoneyBagEquals() {\n"); |
5025 |
buf.append(" Assert.assertTrue(!this.fMB1.equals(null));\n"); |
5026 |
buf.append(" Assert.assertTrue(!this.fMB1.equals(null));\n"); |
5026 |
buf.append("\n"); |
5027 |
buf.append("\n"); |
Lines 5050-5060
Link Here
|
5050 |
buf.append(" final Money equal = new Money(12, \"CHF\"); //$NON-NLS-1$\n"); |
5051 |
buf.append(" final Money equal = new Money(12, \"CHF\"); //$NON-NLS-1$\n"); |
5051 |
buf.append(" Assert.assertEquals(this.f12CHF.hashCode(), equal.hashCode());\n"); |
5052 |
buf.append(" Assert.assertEquals(this.f12CHF.hashCode(), equal.hashCode());\n"); |
5052 |
buf.append(" }\n"); |
5053 |
buf.append(" }\n"); |
5053 |
buf.append(" public void testSimplify() {\n"); |
|
|
5054 |
buf.append(" final IMoney money = MoneyBag.create(\n"); |
5055 |
buf.append(" new Money(26, \"CHF\"), new Money(28, \"CHF\")); //$NON-NLS-1$ //$NON-NLS-2$\n"); |
5056 |
buf.append(" Assert.assertEquals(new Money(54, \"CHF\"), money); //$NON-NLS-1$\n"); |
5057 |
buf.append(" }\n"); |
5058 |
buf.append(" public void testNormalize2() {\n"); |
5054 |
buf.append(" public void testNormalize2() {\n"); |
5059 |
buf.append(" // {[12 CHF][7 USD]} - [12 CHF] == [7 USD]\n"); |
5055 |
buf.append(" // {[12 CHF][7 USD]} - [12 CHF] == [7 USD]\n"); |
5060 |
buf.append(" final Money expected = new Money(7, \"USD\"); //$NON-NLS-1$\n"); |
5056 |
buf.append(" final Money expected = new Money(7, \"USD\"); //$NON-NLS-1$\n"); |
Lines 5103-5108
Link Here
|
5103 |
buf.append(" final Money expected = new Money(2, \"CHF\"); //$NON-NLS-1$\n"); |
5099 |
buf.append(" final Money expected = new Money(2, \"CHF\"); //$NON-NLS-1$\n"); |
5104 |
buf.append(" Assert.assertEquals(expected, this.f14CHF.subtract(this.f12CHF));\n"); |
5100 |
buf.append(" Assert.assertEquals(expected, this.f14CHF.subtract(this.f12CHF));\n"); |
5105 |
buf.append(" }\n"); |
5101 |
buf.append(" }\n"); |
|
|
5102 |
buf.append(" public void testSimplify() {\n"); |
5103 |
buf.append(" final IMoney money = MoneyBag.create(\n"); |
5104 |
buf.append(" new Money(26, \"CHF\"), new Money(28, \"CHF\")); //$NON-NLS-1$ //$NON-NLS-2$\n"); |
5105 |
buf.append(" Assert.assertEquals(new Money(54, \"CHF\"), money); //$NON-NLS-1$\n"); |
5106 |
buf.append(" }\n"); |
5106 |
buf.append("}"); |
5107 |
buf.append("}"); |
5107 |
fExpectedChangesAllTests.put("junit.samples.money.MoneyTest.java", buf.toString()); |
5108 |
fExpectedChangesAllTests.put("junit.samples.money.MoneyTest.java", buf.toString()); |
5108 |
buf= new StringBuffer(); |
5109 |
buf= new StringBuffer(); |
Lines 5234-5239
Link Here
|
5234 |
buf.append(" public int amount() {\n"); |
5235 |
buf.append(" public int amount() {\n"); |
5235 |
buf.append(" return this.fAmount;\n"); |
5236 |
buf.append(" return this.fAmount;\n"); |
5236 |
buf.append(" }\n"); |
5237 |
buf.append(" }\n"); |
|
|
5238 |
buf.append(" public/* this makes no sense */void appendTo(final MoneyBag m) {\n"); |
5239 |
buf.append(" m.appendMoney(this);\n"); |
5240 |
buf.append(" }\n"); |
5237 |
buf.append(" public String currency() {\n"); |
5241 |
buf.append(" public String currency() {\n"); |
5238 |
buf.append(" return this.fCurrency;\n"); |
5242 |
buf.append(" return this.fCurrency;\n"); |
5239 |
buf.append(" }\n"); |
5243 |
buf.append(" }\n"); |
Lines 5273-5281
Link Here
|
5273 |
buf.append(" buffer.append(\"[\" + this.amount() + \" \" + this.currency() + \"]\"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\n"); |
5277 |
buf.append(" buffer.append(\"[\" + this.amount() + \" \" + this.currency() + \"]\"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\n"); |
5274 |
buf.append(" return buffer.toString();\n"); |
5278 |
buf.append(" return buffer.toString();\n"); |
5275 |
buf.append(" }\n"); |
5279 |
buf.append(" }\n"); |
5276 |
buf.append(" public/* this makes no sense */void appendTo(final MoneyBag m) {\n"); |
|
|
5277 |
buf.append(" m.appendMoney(this);\n"); |
5278 |
buf.append(" }\n"); |
5279 |
buf.append("}"); |
5280 |
buf.append("}"); |
5280 |
fExpectedChangesAllTests.put("junit.samples.money.Money.java", buf.toString()); |
5281 |
fExpectedChangesAllTests.put("junit.samples.money.Money.java", buf.toString()); |
5281 |
} |
5282 |
} |
Lines 5341-5346
Link Here
|
5341 |
|
5342 |
|
5342 |
node.put(CleanUpConstants.ORGANIZE_IMPORTS, CleanUpConstants.TRUE); |
5343 |
node.put(CleanUpConstants.ORGANIZE_IMPORTS, CleanUpConstants.TRUE); |
5343 |
|
5344 |
|
|
|
5345 |
node.put(CleanUpConstants.SORT_MEMBERS, CleanUpConstants.TRUE); |
5346 |
node.put(CleanUpConstants.SORT_MEMBERS_ALL, CleanUpConstants.TRUE); |
5347 |
|
5344 |
ProfileManager.CustomProfile profile= new ProfileManager.CustomProfile("testProfile", node, CleanUpProfileVersioner.CURRENT_VERSION, CleanUpProfileVersioner.PROFILE_KIND); |
5348 |
ProfileManager.CustomProfile profile= new ProfileManager.CustomProfile("testProfile", node, CleanUpProfileVersioner.CURRENT_VERSION, CleanUpProfileVersioner.PROFILE_KIND); |
5345 |
new InstanceScope().getNode(JavaUI.ID_PLUGIN).put(CleanUpConstants.CLEANUP_PROFILE, profile.getID()); |
5349 |
new InstanceScope().getNode(JavaUI.ID_PLUGIN).put(CleanUpConstants.CLEANUP_PROFILE, profile.getID()); |
5346 |
|
5350 |
|