0001: /*******************************************************************************
0002: * Copyright (c) 2000, 2007 IBM Corporation and others.
0003: * All rights reserved. This program and the accompanying materials
0004: * are made available under the terms of the Eclipse Public License v1.0
0005: * which accompanies this distribution, and is available at
0006: * http://www.eclipse.org/legal/epl-v10.html
0007: *
0008: * Contributors:
0009: * IBM Corporation - initial API and implementation
0010: * Alex Blewitt - https://bugs.eclipse.org/bugs/show_bug.cgi?id=168954
0011: *******************************************************************************/package org.eclipse.jdt.ui.tests.quickfix;
0012:
0013: import java.io.File;
0014: import java.util.ArrayList;
0015: import java.util.Hashtable;
0016: import java.util.List;
0017:
0018: import junit.framework.Test;
0019: import junit.framework.TestSuite;
0020:
0021: import org.eclipse.jface.text.BadLocationException;
0022: import org.eclipse.jface.text.Document;
0023: import org.eclipse.jface.text.IDocument;
0024: import org.eclipse.jface.text.IRegion;
0025:
0026: import org.eclipse.jdt.core.ICompilationUnit;
0027: import org.eclipse.jdt.core.IJavaElement;
0028: import org.eclipse.jdt.core.IPackageFragment;
0029: import org.eclipse.jdt.core.IPackageFragmentRoot;
0030: import org.eclipse.jdt.core.JavaModelException;
0031:
0032: import org.eclipse.jdt.internal.corext.fix.CleanUpConstants;
0033:
0034: import org.eclipse.jdt.ui.JavaElementLabels;
0035:
0036: import org.eclipse.jdt.testplugin.JavaProjectHelper;
0037: import org.eclipse.jdt.testplugin.JavaTestPlugin;
0038:
0039: import org.eclipse.jdt.ui.tests.core.ProjectTestSetup;
0040:
0041: public class CleanUpStressTest extends CleanUpTestCase {
0042:
0043: private static final String SRC_CONTAINER = "src";
0044:
0045: protected static IPackageFragmentRoot fJunitSrcRoot;
0046:
0047: protected void setUp() throws Exception {
0048: super .setUp();
0049:
0050: File junitSrcArchive = JavaTestPlugin.getDefault()
0051: .getFileInPlugin(JavaProjectHelper.JUNIT_SRC_381);
0052: fJunitSrcRoot = JavaProjectHelper.addSourceContainerWithImport(
0053: fJProject1, SRC_CONTAINER, junitSrcArchive,
0054: JavaProjectHelper.JUNIT_SRC_ENCODING);
0055: }
0056:
0057: public CleanUpStressTest(String name) {
0058: super (name);
0059: }
0060:
0061: public static Test suite() {
0062: return new ProjectTestSetup(new TestSuite(
0063: CleanUpStressTest.class));
0064: }
0065:
0066: private void addAllCUs(IJavaElement[] children, List result)
0067: throws JavaModelException {
0068: for (int i = 0; i < children.length; i++) {
0069: IJavaElement element = children[i];
0070: if (element instanceof ICompilationUnit) {
0071: result.add(element);
0072: } else if (element instanceof IPackageFragmentRoot) {
0073: IPackageFragmentRoot root = (IPackageFragmentRoot) element;
0074: addAllCUs(root.getChildren(), result);
0075: } else if (element instanceof IPackageFragment) {
0076: IPackageFragment pack = (IPackageFragment) element;
0077: addAllCUs(pack.getChildren(), result);
0078: }
0079: }
0080: }
0081:
0082: private static Hashtable fExpectedChangesAllTests;
0083: static {
0084: fExpectedChangesAllTests = new Hashtable();
0085: StringBuffer buf = null;
0086: buf = new StringBuffer();
0087: buf.append("package junit.runner;\n");
0088: buf.append("\n");
0089: buf.append("import java.io.BufferedReader;\n");
0090: buf.append("import java.io.File;\n");
0091: buf.append("import java.io.FileInputStream;\n");
0092: buf.append("import java.io.FileOutputStream;\n");
0093: buf.append("import java.io.IOException;\n");
0094: buf.append("import java.io.InputStream;\n");
0095: buf.append("import java.io.PrintWriter;\n");
0096: buf.append("import java.io.StringReader;\n");
0097: buf.append("import java.io.StringWriter;\n");
0098: buf
0099: .append("import java.lang.reflect.InvocationTargetException;\n");
0100: buf.append("import java.lang.reflect.Method;\n");
0101: buf.append("import java.lang.reflect.Modifier;\n");
0102: buf.append("import java.text.NumberFormat;\n");
0103: buf.append("import java.util.Properties;\n");
0104: buf.append("\n");
0105: buf.append("import junit.framework.AssertionFailedError;\n");
0106: buf.append("import junit.framework.Test;\n");
0107: buf.append("import junit.framework.TestListener;\n");
0108: buf.append("import junit.framework.TestSuite;\n");
0109: buf.append("\n");
0110: buf.append("/**\n");
0111: buf
0112: .append(" * Base class for all test runners. This class was born live on stage in\n");
0113: buf.append(" * Sardinia during XP2000.\n");
0114: buf.append(" */\n");
0115: buf
0116: .append("public abstract class BaseTestRunner implements TestListener {\n");
0117: buf.append(" static boolean fgFilterStack = true;\n");
0118: buf.append("\n");
0119: buf.append(" static int fgMaxMessageLength = 500;\n");
0120: buf.append(" private static Properties fPreferences;\n");
0121: buf
0122: .append(" public static final String SUITE_METHODNAME = \"suite\"; //$NON-NLS-1$\n");
0123: buf.append(" static {\n");
0124: buf
0125: .append(" BaseTestRunner.fgMaxMessageLength = BaseTestRunner.getPreference(\n");
0126: buf
0127: .append(" \"maxmessage\", BaseTestRunner.fgMaxMessageLength); //$NON-NLS-1$\n");
0128: buf.append(" }\n");
0129: buf.append("\n");
0130: buf
0131: .append(" static boolean filterLine(final String line) {\n");
0132: buf
0133: .append(" final String[] patterns = new String[]{\"junit.framework.TestCase\", //$NON-NLS-1$\n");
0134: buf
0135: .append(" \"junit.framework.TestResult\", //$NON-NLS-1$\n");
0136: buf
0137: .append(" \"junit.framework.TestSuite\", //$NON-NLS-1$\n");
0138: buf
0139: .append(" \"junit.framework.Assert.\", // don't filter AssertionFailure\n");
0140: buf.append(" // //$NON-NLS-1$\n");
0141: buf
0142: .append(" \"junit.swingui.TestRunner\", //$NON-NLS-1$\n");
0143: buf
0144: .append(" \"junit.awtui.TestRunner\", //$NON-NLS-1$\n");
0145: buf
0146: .append(" \"junit.textui.TestRunner\", //$NON-NLS-1$\n");
0147: buf
0148: .append(" \"java.lang.reflect.Method.invoke(\" //$NON-NLS-1$\n");
0149: buf.append(" };\n");
0150: buf.append(" for (final String element : patterns) {\n");
0151: buf.append(" if (line.indexOf(element) > 0) {\n");
0152: buf.append(" return true;\n");
0153: buf.append(" }\n");
0154: buf.append(" }\n");
0155: buf.append(" return false;\n");
0156: buf.append(" }\n");
0157: buf.append("\n");
0158: buf.append(" /**\n");
0159: buf
0160: .append(" * Filters stack frames from internal JUnit classes\n");
0161: buf.append(" */\n");
0162: buf
0163: .append(" public static String getFilteredTrace(final String stack) {\n");
0164: buf.append(" if (BaseTestRunner.showStackRaw()) {\n");
0165: buf.append(" return stack;\n");
0166: buf.append(" }\n");
0167: buf.append("\n");
0168: buf
0169: .append(" final StringWriter sw = new StringWriter();\n");
0170: buf
0171: .append(" final PrintWriter pw = new PrintWriter(sw);\n");
0172: buf
0173: .append(" final StringReader sr = new StringReader(stack);\n");
0174: buf
0175: .append(" final BufferedReader br = new BufferedReader(sr);\n");
0176: buf.append("\n");
0177: buf.append(" String line;\n");
0178: buf.append(" try {\n");
0179: buf
0180: .append(" while ((line = br.readLine()) != null) {\n");
0181: buf
0182: .append(" if (!BaseTestRunner.filterLine(line)) {\n");
0183: buf.append(" pw.println(line);\n");
0184: buf.append(" }\n");
0185: buf.append(" }\n");
0186: buf.append(" } catch (final Exception IOException) {\n");
0187: buf
0188: .append(" return stack; // return the stack unfiltered\n");
0189: buf.append(" }\n");
0190: buf.append(" return sw.toString();\n");
0191: buf.append(" }\n");
0192: buf.append("\n");
0193: buf.append(" /**\n");
0194: buf.append(" * Returns a filtered stack trace\n");
0195: buf.append(" */\n");
0196: buf
0197: .append(" public static String getFilteredTrace(final Throwable t) {\n");
0198: buf
0199: .append(" final StringWriter stringWriter = new StringWriter();\n");
0200: buf
0201: .append(" final PrintWriter writer = new PrintWriter(stringWriter);\n");
0202: buf.append(" t.printStackTrace(writer);\n");
0203: buf
0204: .append(" final StringBuffer buffer = stringWriter.getBuffer();\n");
0205: buf.append(" final String trace = buffer.toString();\n");
0206: buf
0207: .append(" return BaseTestRunner.getFilteredTrace(trace);\n");
0208: buf.append(" }\n");
0209: buf.append("\n");
0210: buf
0211: .append(" public static String getPreference(final String key) {\n");
0212: buf
0213: .append(" return BaseTestRunner.getPreferences().getProperty(key);\n");
0214: buf.append(" }\n");
0215: buf.append("\n");
0216: buf
0217: .append(" public static int getPreference(final String key, final int dflt) {\n");
0218: buf
0219: .append(" final String value = BaseTestRunner.getPreference(key);\n");
0220: buf.append(" int intValue = dflt;\n");
0221: buf.append(" if (value == null) {\n");
0222: buf.append(" return intValue;\n");
0223: buf.append(" }\n");
0224: buf.append(" try {\n");
0225: buf.append(" intValue = Integer.parseInt(value);\n");
0226: buf
0227: .append(" } catch (final NumberFormatException ne) {\n");
0228: buf.append(" }\n");
0229: buf.append(" return intValue;\n");
0230: buf.append(" }\n");
0231: buf.append("\n");
0232: buf
0233: .append(" protected static Properties getPreferences() {\n");
0234: buf
0235: .append(" if (BaseTestRunner.fPreferences == null) {\n");
0236: buf
0237: .append(" BaseTestRunner.fPreferences = new Properties();\n");
0238: buf
0239: .append(" BaseTestRunner.fPreferences.put(\"loading\", \"true\"); //$NON-NLS-1$ //$NON-NLS-2$\n");
0240: buf
0241: .append(" BaseTestRunner.fPreferences.put(\"filterstack\", \"true\"); //$NON-NLS-1$ //$NON-NLS-2$\n");
0242: buf.append(" BaseTestRunner.readPreferences();\n");
0243: buf.append(" }\n");
0244: buf.append(" return BaseTestRunner.fPreferences;\n");
0245: buf.append(" }\n");
0246: buf.append("\n");
0247: buf.append(" private static File getPreferencesFile() {\n");
0248: buf
0249: .append(" final String home = System.getProperty(\"user.home\"); //$NON-NLS-1$\n");
0250: buf
0251: .append(" return new File(home, \"junit.properties\"); //$NON-NLS-1$\n");
0252: buf.append(" }\n");
0253: buf.append("\n");
0254: buf.append(" public static boolean inVAJava() {\n");
0255: buf.append(" try {\n");
0256: buf
0257: .append(" Class.forName(\"com.ibm.uvm.tools.DebugSupport\"); //$NON-NLS-1$\n");
0258: buf.append(" } catch (final Exception e) {\n");
0259: buf.append(" return false;\n");
0260: buf.append(" }\n");
0261: buf.append(" return true;\n");
0262: buf.append(" }\n");
0263: buf.append("\n");
0264: buf.append(" // TestRunListener implementation\n");
0265: buf.append("\n");
0266: buf.append(" private static void readPreferences() {\n");
0267: buf.append(" InputStream is = null;\n");
0268: buf.append(" try {\n");
0269: buf
0270: .append(" is = new FileInputStream(BaseTestRunner.getPreferencesFile());\n");
0271: buf
0272: .append(" BaseTestRunner.setPreferences(new Properties(BaseTestRunner\n");
0273: buf.append(" .getPreferences()));\n");
0274: buf
0275: .append(" BaseTestRunner.getPreferences().load(is);\n");
0276: buf.append(" } catch (final IOException e) {\n");
0277: buf.append(" try {\n");
0278: buf.append(" if (is != null) {\n");
0279: buf.append(" is.close();\n");
0280: buf.append(" }\n");
0281: buf.append(" } catch (final IOException e1) {\n");
0282: buf.append(" }\n");
0283: buf.append(" }\n");
0284: buf.append(" }\n");
0285: buf.append("\n");
0286: buf
0287: .append(" public static void savePreferences() throws IOException {\n");
0288: buf
0289: .append(" final FileOutputStream fos = new FileOutputStream(BaseTestRunner\n");
0290: buf.append(" .getPreferencesFile());\n");
0291: buf.append(" try {\n");
0292: buf
0293: .append(" BaseTestRunner.getPreferences().store(fos, \"\"); //$NON-NLS-1$\n");
0294: buf.append(" } finally {\n");
0295: buf.append(" fos.close();\n");
0296: buf.append(" }\n");
0297: buf.append(" }\n");
0298: buf.append("\n");
0299: buf
0300: .append(" protected static void setPreferences(final Properties preferences) {\n");
0301: buf
0302: .append(" BaseTestRunner.fPreferences = preferences;\n");
0303: buf.append(" }\n");
0304: buf.append("\n");
0305: buf.append(" protected static boolean showStackRaw() {\n");
0306: buf
0307: .append(" return !BaseTestRunner.getPreference(\"filterstack\").equals(\"true\") || (BaseTestRunner.fgFilterStack == false); //$NON-NLS-1$ //$NON-NLS-2$\n");
0308: buf.append(" }\n");
0309: buf.append("\n");
0310: buf.append(" /**\n");
0311: buf
0312: .append(" * Truncates a String to the maximum length.\n");
0313: buf.append(" */\n");
0314: buf.append(" public static String truncate(String s) {\n");
0315: buf
0316: .append(" if ((BaseTestRunner.fgMaxMessageLength != -1)\n");
0317: buf
0318: .append(" && (s.length() > BaseTestRunner.fgMaxMessageLength)) {\n");
0319: buf
0320: .append(" s = s.substring(0, BaseTestRunner.fgMaxMessageLength) + \"...\"; //$NON-NLS-1$\n");
0321: buf.append(" }\n");
0322: buf.append(" return s;\n");
0323: buf.append(" }\n");
0324: buf.append("\n");
0325: buf.append(" boolean fLoading = true;\n");
0326: buf.append("\n");
0327: buf
0328: .append(" public synchronized void addError(final Test test, final Throwable t) {\n");
0329: buf
0330: .append(" this.testFailed(TestRunListener.STATUS_ERROR, test, t);\n");
0331: buf.append(" }\n");
0332: buf
0333: .append(" public synchronized void addFailure(final Test test,\n");
0334: buf.append(" final AssertionFailedError t) {\n");
0335: buf
0336: .append(" this.testFailed(TestRunListener.STATUS_FAILURE, test, t);\n");
0337: buf.append(" }\n");
0338: buf.append("\n");
0339: buf.append(" /**\n");
0340: buf.append(" * Clears the status message.\n");
0341: buf.append(" */\n");
0342: buf
0343: .append(" protected void clearStatus() { // Belongs in the GUI TestRunner class\n");
0344: buf.append(" }\n");
0345: buf.append("\n");
0346: buf.append(" /**\n");
0347: buf
0348: .append(" * Returns the formatted string of the elapsed time.\n");
0349: buf.append(" */\n");
0350: buf
0351: .append(" public String elapsedTimeAsString(final long runTime) {\n");
0352: buf
0353: .append(" return NumberFormat.getInstance().format((double) runTime / 1000);\n");
0354: buf.append(" }\n");
0355: buf.append("\n");
0356: buf
0357: .append(" public synchronized void endTest(final Test test) {\n");
0358: buf.append(" this.testEnded(test.toString());\n");
0359: buf.append(" }\n");
0360: buf.append("\n");
0361: buf.append(" /**\n");
0362: buf
0363: .append(" * Extract the class name from a String in VA/Java style\n");
0364: buf.append(" */\n");
0365: buf
0366: .append(" public String extractClassName(final String className) {\n");
0367: buf
0368: .append(" if (className.startsWith(\"Default package for\")) {\n");
0369: buf
0370: .append(" return className.substring(className.lastIndexOf(\".\") + 1); //$NON-NLS-1$\n");
0371: buf.append(" }\n");
0372: buf.append(" return className;\n");
0373: buf.append(" }\n");
0374: buf.append("\n");
0375: buf.append(" /**\n");
0376: buf.append(" * Returns the loader to be used.\n");
0377: buf.append(" */\n");
0378: buf.append(" public TestSuiteLoader getLoader() {\n");
0379: buf
0380: .append(" if (this.useReloadingTestSuiteLoader()) {\n");
0381: buf
0382: .append(" return new ReloadingTestSuiteLoader();\n");
0383: buf.append(" }\n");
0384: buf.append(" return new StandardTestSuiteLoader();\n");
0385: buf.append(" }\n");
0386: buf.append("\n");
0387: buf.append(" /**\n");
0388: buf
0389: .append(" * Returns the Test corresponding to the given suite. This is a template\n");
0390: buf
0391: .append(" * method, subclasses override runFailed(), clearStatus().\n");
0392: buf.append(" */\n");
0393: buf
0394: .append(" public Test getTest(final String suiteClassName) {\n");
0395: buf.append(" if (suiteClassName.length() <= 0) {\n");
0396: buf.append(" this.clearStatus();\n");
0397: buf.append(" return null;\n");
0398: buf.append(" }\n");
0399: buf.append(" Class testClass = null;\n");
0400: buf.append(" try {\n");
0401: buf
0402: .append(" testClass = this.loadSuiteClass(suiteClassName);\n");
0403: buf
0404: .append(" } catch (final ClassNotFoundException e) {\n");
0405: buf.append(" String clazz = e.getMessage();\n");
0406: buf.append(" if (clazz == null) {\n");
0407: buf.append(" clazz = suiteClassName;\n");
0408: buf.append(" }\n");
0409: buf
0410: .append(" this.runFailed(\"Class not found \\\"\" + clazz + \"\\\"\"); //$NON-NLS-1$ //$NON-NLS-2$\n");
0411: buf.append(" return null;\n");
0412: buf.append(" } catch (final Exception e) {\n");
0413: buf
0414: .append(" this.runFailed(\"Error: \" + e.toString()); //$NON-NLS-1$\n");
0415: buf.append(" return null;\n");
0416: buf.append(" }\n");
0417: buf.append(" Method suiteMethod = null;\n");
0418: buf.append(" try {\n");
0419: buf
0420: .append(" suiteMethod = testClass.getMethod(BaseTestRunner.SUITE_METHODNAME,\n");
0421: buf.append(" new Class[0]);\n");
0422: buf.append(" } catch (final Exception e) {\n");
0423: buf
0424: .append(" // try to extract a test suite automatically\n");
0425: buf.append(" this.clearStatus();\n");
0426: buf.append(" return new TestSuite(testClass);\n");
0427: buf.append(" }\n");
0428: buf
0429: .append(" if (!Modifier.isStatic(suiteMethod.getModifiers())) {\n");
0430: buf
0431: .append(" this.runFailed(\"Suite() method must be static\"); //$NON-NLS-1$\n");
0432: buf.append(" return null;\n");
0433: buf.append(" }\n");
0434: buf.append(" Test test = null;\n");
0435: buf.append(" try {\n");
0436: buf
0437: .append(" test = (Test) suiteMethod.invoke(null, new Class[0]); // static method\n");
0438: buf.append(" if (test == null) {\n");
0439: buf.append(" return test;\n");
0440: buf.append(" }\n");
0441: buf
0442: .append(" } catch (final InvocationTargetException e) {\n");
0443: buf.append(" this\n");
0444: buf
0445: .append(" .runFailed(\"Failed to invoke suite():\" + e.getTargetException().toString()); //$NON-NLS-1$\n");
0446: buf.append(" return null;\n");
0447: buf
0448: .append(" } catch (final IllegalAccessException e) {\n");
0449: buf
0450: .append(" this.runFailed(\"Failed to invoke suite():\" + e.toString()); //$NON-NLS-1$\n");
0451: buf.append(" return null;\n");
0452: buf.append(" }\n");
0453: buf.append("\n");
0454: buf.append(" this.clearStatus();\n");
0455: buf.append(" return test;\n");
0456: buf.append(" }\n");
0457: buf.append("\n");
0458: buf.append(" /**\n");
0459: buf
0460: .append(" * Returns the loaded Class for a suite name.\n");
0461: buf.append(" */\n");
0462: buf
0463: .append(" protected Class loadSuiteClass(final String suiteClassName)\n");
0464: buf.append(" throws ClassNotFoundException {\n");
0465: buf
0466: .append(" return this.getLoader().load(suiteClassName);\n");
0467: buf.append(" }\n");
0468: buf.append("\n");
0469: buf.append(" /**\n");
0470: buf
0471: .append(" * Processes the command line arguments and returns the name of the suite\n");
0472: buf.append(" * class to run or null\n");
0473: buf.append(" */\n");
0474: buf
0475: .append(" protected String processArguments(final String[] args) {\n");
0476: buf.append(" String suiteName = null;\n");
0477: buf.append(" for (int i = 0; i < args.length; i++) {\n");
0478: buf
0479: .append(" if (args[i].equals(\"-noloading\")) { //$NON-NLS-1$\n");
0480: buf.append(" this.setLoading(false);\n");
0481: buf
0482: .append(" } else if (args[i].equals(\"-nofilterstack\")) { //$NON-NLS-1$\n");
0483: buf
0484: .append(" BaseTestRunner.fgFilterStack = false;\n");
0485: buf
0486: .append(" } else if (args[i].equals(\"-c\")) { //$NON-NLS-1$\n");
0487: buf.append(" if (args.length > i + 1) {\n");
0488: buf
0489: .append(" suiteName = this.extractClassName(args[i + 1]);\n");
0490: buf.append(" } else {\n");
0491: buf
0492: .append(" System.out.println(\"Missing Test class name\"); //$NON-NLS-1$\n");
0493: buf.append(" }\n");
0494: buf.append(" i++;\n");
0495: buf.append(" } else {\n");
0496: buf.append(" suiteName = args[i];\n");
0497: buf.append(" }\n");
0498: buf.append(" }\n");
0499: buf.append(" return suiteName;\n");
0500: buf.append(" }\n");
0501: buf.append("\n");
0502: buf.append(" /**\n");
0503: buf
0504: .append(" * Override to define how to handle a failed loading of a test suite.\n");
0505: buf.append(" */\n");
0506: buf
0507: .append(" protected abstract void runFailed(String message);\n");
0508: buf.append("\n");
0509: buf.append(" /**\n");
0510: buf
0511: .append(" * Sets the loading behaviour of the test runner\n");
0512: buf.append(" */\n");
0513: buf
0514: .append(" public void setLoading(final boolean enable) {\n");
0515: buf.append(" this.fLoading = enable;\n");
0516: buf.append(" }\n");
0517: buf.append("\n");
0518: buf
0519: .append(" public void setPreference(final String key, final String value) {\n");
0520: buf
0521: .append(" BaseTestRunner.getPreferences().setProperty(key, value);\n");
0522: buf.append(" }\n");
0523: buf.append("\n");
0524: buf.append(" /*\n");
0525: buf.append(" * Implementation of TestListener\n");
0526: buf.append(" */\n");
0527: buf
0528: .append(" public synchronized void startTest(final Test test) {\n");
0529: buf.append(" this.testStarted(test.toString());\n");
0530: buf.append(" }\n");
0531: buf.append("\n");
0532: buf
0533: .append(" public abstract void testEnded(String testName);\n");
0534: buf.append("\n");
0535: buf
0536: .append(" public abstract void testFailed(int status, Test test, Throwable t);\n");
0537: buf.append("\n");
0538: buf
0539: .append(" public abstract void testStarted(String testName);\n");
0540: buf.append("\n");
0541: buf
0542: .append(" protected boolean useReloadingTestSuiteLoader() {\n");
0543: buf
0544: .append(" return BaseTestRunner.getPreference(\"loading\").equals(\"true\") && !BaseTestRunner.inVAJava() && this.fLoading; //$NON-NLS-1$ //$NON-NLS-2$\n");
0545: buf.append(" }\n");
0546: buf.append("\n");
0547: buf.append("}");
0548: fExpectedChangesAllTests.put(
0549: "junit.runner.BaseTestRunner.java", buf.toString());
0550: buf = new StringBuffer();
0551: buf.append("package junit.tests.framework;\n");
0552: buf.append("\n");
0553: buf.append("/**\n");
0554: buf.append(" * Test class used in SuiteTest\n");
0555: buf.append(" */\n");
0556: buf.append("import junit.framework.TestCase;\n");
0557: buf.append("\n");
0558: buf.append("public class NotVoidTestCase extends TestCase {\n");
0559: buf.append(" public int testNotVoid() {\n");
0560: buf.append(" return 1;\n");
0561: buf.append(" }\n");
0562: buf.append(" public void testVoid() {\n");
0563: buf.append(" }\n");
0564: buf.append("}");
0565: fExpectedChangesAllTests.put(
0566: "junit.tests.framework.NotVoidTestCase.java", buf
0567: .toString());
0568: buf = new StringBuffer();
0569: buf.append("package junit.tests.runner;\n");
0570: buf.append("\n");
0571: buf.append("import java.io.PrintWriter;\n");
0572: buf.append("import java.io.StringWriter;\n");
0573: buf.append("\n");
0574: buf.append("import junit.framework.Assert;\n");
0575: buf.append("import junit.framework.TestCase;\n");
0576: buf.append("import junit.runner.BaseTestRunner;\n");
0577: buf.append("\n");
0578: buf.append("public class StackFilterTest extends TestCase {\n");
0579: buf.append(" String fFiltered;\n");
0580: buf.append(" String fUnfiltered;\n");
0581: buf.append("\n");
0582: buf.append(" @Override\n");
0583: buf.append(" protected void setUp() {\n");
0584: buf
0585: .append(" final StringWriter swin = new StringWriter();\n");
0586: buf
0587: .append(" final PrintWriter pwin = new PrintWriter(swin);\n");
0588: buf
0589: .append(" pwin.println(\"junit.framework.AssertionFailedError\"); //$NON-NLS-1$\n");
0590: buf
0591: .append(" pwin.println(\" at junit.framework.Assert.fail(Assert.java:144)\"); //$NON-NLS-1$\n");
0592: buf
0593: .append(" pwin.println(\" at junit.framework.Assert.assert(Assert.java:19)\"); //$NON-NLS-1$\n");
0594: buf
0595: .append(" pwin.println(\" at junit.framework.Assert.assert(Assert.java:26)\"); //$NON-NLS-1$\n");
0596: buf
0597: .append(" pwin.println(\" at MyTest.f(MyTest.java:13)\"); //$NON-NLS-1$\n");
0598: buf
0599: .append(" pwin.println(\" at MyTest.testStackTrace(MyTest.java:8)\"); //$NON-NLS-1$\n");
0600: buf
0601: .append(" pwin.println(\" at java.lang.reflect.Method.invoke(Native Method)\"); //$NON-NLS-1$\n");
0602: buf
0603: .append(" pwin.println(\" at junit.framework.TestCase.runTest(TestCase.java:156)\"); //$NON-NLS-1$\n");
0604: buf
0605: .append(" pwin.println(\" at junit.framework.TestCase.runBare(TestCase.java:130)\"); //$NON-NLS-1$\n");
0606: buf.append(" pwin\n");
0607: buf
0608: .append(" .println(\" at junit.framework.TestResult$1.protect(TestResult.java:100)\"); //$NON-NLS-1$\n");
0609: buf.append(" pwin\n");
0610: buf
0611: .append(" .println(\" at junit.framework.TestResult.runProtected(TestResult.java:118)\"); //$NON-NLS-1$\n");
0612: buf
0613: .append(" pwin.println(\" at junit.framework.TestResult.run(TestResult.java:103)\"); //$NON-NLS-1$\n");
0614: buf
0615: .append(" pwin.println(\" at junit.framework.TestCase.run(TestCase.java:121)\"); //$NON-NLS-1$\n");
0616: buf.append(" pwin\n");
0617: buf
0618: .append(" .println(\" at junit.framework.TestSuite.runTest(TestSuite.java:157)\"); //$NON-NLS-1$\n");
0619: buf.append(" pwin\n");
0620: buf
0621: .append(" .println(\" at junit.framework.TestSuite.run(TestSuite.java, Compiled Code)\"); //$NON-NLS-1$\n");
0622: buf.append(" pwin\n");
0623: buf
0624: .append(" .println(\" at junit.swingui.TestRunner$17.run(TestRunner.java:669)\"); //$NON-NLS-1$\n");
0625: buf.append(" this.fUnfiltered = swin.toString();\n");
0626: buf.append("\n");
0627: buf
0628: .append(" final StringWriter swout = new StringWriter();\n");
0629: buf
0630: .append(" final PrintWriter pwout = new PrintWriter(swout);\n");
0631: buf
0632: .append(" pwout.println(\"junit.framework.AssertionFailedError\"); //$NON-NLS-1$\n");
0633: buf
0634: .append(" pwout.println(\" at MyTest.f(MyTest.java:13)\"); //$NON-NLS-1$\n");
0635: buf
0636: .append(" pwout.println(\" at MyTest.testStackTrace(MyTest.java:8)\"); //$NON-NLS-1$\n");
0637: buf.append(" this.fFiltered = swout.toString();\n");
0638: buf.append(" }\n");
0639: buf.append("\n");
0640: buf.append(" public void testFilter() {\n");
0641: buf
0642: .append(" Assert.assertEquals(this.fFiltered, BaseTestRunner\n");
0643: buf
0644: .append(" .getFilteredTrace(this.fUnfiltered));\n");
0645: buf.append(" }\n");
0646: buf.append("}");
0647: fExpectedChangesAllTests.put(
0648: "junit.tests.runner.StackFilterTest.java", buf
0649: .toString());
0650: buf = new StringBuffer();
0651: buf.append("package junit.tests.framework;\n");
0652: buf.append("\n");
0653: buf.append("import junit.framework.Assert;\n");
0654: buf.append("import junit.framework.AssertionFailedError;\n");
0655: buf.append("import junit.framework.TestCase;\n");
0656: buf.append("\n");
0657: buf
0658: .append("public class DoublePrecisionAssertTest extends TestCase {\n");
0659: buf.append("\n");
0660: buf.append(" /**\n");
0661: buf.append(" * Test for the special Double.NaN value.\n");
0662: buf.append(" */\n");
0663: buf.append(" public void testAssertEqualsNaNFails() {\n");
0664: buf.append(" try {\n");
0665: buf
0666: .append(" Assert.assertEquals(1.234, Double.NaN, 0.0);\n");
0667: buf
0668: .append(" } catch (final AssertionFailedError e) {\n");
0669: buf.append(" return;\n");
0670: buf.append(" }\n");
0671: buf.append(" Assert.fail();\n");
0672: buf.append(" }\n");
0673: buf.append("\n");
0674: buf.append(" public void testAssertNaNEqualsFails() {\n");
0675: buf.append(" try {\n");
0676: buf
0677: .append(" Assert.assertEquals(Double.NaN, 1.234, 0.0);\n");
0678: buf
0679: .append(" } catch (final AssertionFailedError e) {\n");
0680: buf.append(" return;\n");
0681: buf.append(" }\n");
0682: buf.append(" Assert.fail();\n");
0683: buf.append(" }\n");
0684: buf.append("\n");
0685: buf.append(" public void testAssertNaNEqualsNaNFails() {\n");
0686: buf.append(" try {\n");
0687: buf
0688: .append(" Assert.assertEquals(Double.NaN, Double.NaN, 0.0);\n");
0689: buf
0690: .append(" } catch (final AssertionFailedError e) {\n");
0691: buf.append(" return;\n");
0692: buf.append(" }\n");
0693: buf.append(" Assert.fail();\n");
0694: buf.append(" }\n");
0695: buf.append("\n");
0696: buf
0697: .append(" public void testAssertNegInfinityEqualsInfinity() {\n");
0698: buf
0699: .append(" Assert.assertEquals(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY,\n");
0700: buf.append(" 0.0);\n");
0701: buf.append(" }\n");
0702: buf.append("\n");
0703: buf
0704: .append(" public void testAssertPosInfinityEqualsInfinity() {\n");
0705: buf
0706: .append(" Assert.assertEquals(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY,\n");
0707: buf.append(" 0.0);\n");
0708: buf.append(" }\n");
0709: buf.append("\n");
0710: buf
0711: .append(" public void testAssertPosInfinityNotEquals() {\n");
0712: buf.append(" try {\n");
0713: buf
0714: .append(" Assert.assertEquals(Double.POSITIVE_INFINITY, 1.23, 0.0);\n");
0715: buf
0716: .append(" } catch (final AssertionFailedError e) {\n");
0717: buf.append(" return;\n");
0718: buf.append(" }\n");
0719: buf.append(" Assert.fail();\n");
0720: buf.append(" }\n");
0721: buf.append("\n");
0722: buf
0723: .append(" public void testAssertPosInfinityNotEqualsNegInfinity() {\n");
0724: buf.append(" try {\n");
0725: buf
0726: .append(" Assert.assertEquals(Double.POSITIVE_INFINITY,\n");
0727: buf
0728: .append(" Double.NEGATIVE_INFINITY, 0.0);\n");
0729: buf
0730: .append(" } catch (final AssertionFailedError e) {\n");
0731: buf.append(" return;\n");
0732: buf.append(" }\n");
0733: buf.append(" Assert.fail();\n");
0734: buf.append(" }\n");
0735: buf.append("\n");
0736: buf.append("}\n");
0737: buf.append("");
0738: fExpectedChangesAllTests.put(
0739: "junit.tests.framework.DoublePrecisionAssertTest.java",
0740: buf.toString());
0741: buf = new StringBuffer();
0742: buf.append("package junit.tests.framework;\n");
0743: buf.append("\n");
0744: buf.append("import junit.framework.Assert;\n");
0745: buf.append("import junit.framework.AssertionFailedError;\n");
0746: buf.append("import junit.framework.ComparisonFailure;\n");
0747: buf.append("import junit.framework.TestCase;\n");
0748: buf.append("\n");
0749: buf.append("public class AssertTest extends TestCase {\n");
0750: buf.append("\n");
0751: buf.append(" public void testAssertEquals() {\n");
0752: buf.append(" final Object o = new Object();\n");
0753: buf.append(" Assert.assertEquals(o, o);\n");
0754: buf.append(" try {\n");
0755: buf
0756: .append(" Assert.assertEquals(new Object(), new Object());\n");
0757: buf
0758: .append(" } catch (final AssertionFailedError e) {\n");
0759: buf.append(" return;\n");
0760: buf.append(" }\n");
0761: buf.append(" Assert.fail();\n");
0762: buf.append(" }\n");
0763: buf.append("\n");
0764: buf.append(" public void testAssertEqualsNull() {\n");
0765: buf.append(" Assert.assertEquals(null, null);\n");
0766: buf.append(" }\n");
0767: buf.append("\n");
0768: buf.append(" public void testAssertFalse() {\n");
0769: buf.append(" Assert.assertFalse(false);\n");
0770: buf.append(" try {\n");
0771: buf.append(" Assert.assertFalse(true);\n");
0772: buf
0773: .append(" } catch (final AssertionFailedError e) {\n");
0774: buf.append(" return;\n");
0775: buf.append(" }\n");
0776: buf.append(" Assert.fail();\n");
0777: buf.append(" }\n");
0778: buf.append("\n");
0779: buf.append(" public void testAssertNotNull() {\n");
0780: buf.append(" Assert.assertNotNull(new Object());\n");
0781: buf.append(" try {\n");
0782: buf.append(" Assert.assertNotNull(null);\n");
0783: buf
0784: .append(" } catch (final AssertionFailedError e) {\n");
0785: buf.append(" return;\n");
0786: buf.append(" }\n");
0787: buf.append(" Assert.fail();\n");
0788: buf.append(" }\n");
0789: buf.append("\n");
0790: buf.append(" public void testAssertNotSame() {\n");
0791: buf
0792: .append(" Assert.assertNotSame(new Integer(1), null);\n");
0793: buf
0794: .append(" Assert.assertNotSame(null, new Integer(1));\n");
0795: buf
0796: .append(" Assert.assertNotSame(new Integer(1), new Integer(1));\n");
0797: buf.append(" try {\n");
0798: buf.append(" final Integer obj = new Integer(1);\n");
0799: buf.append(" Assert.assertNotSame(obj, obj);\n");
0800: buf
0801: .append(" } catch (final AssertionFailedError e) {\n");
0802: buf.append(" return;\n");
0803: buf.append(" }\n");
0804: buf.append(" Assert.fail();\n");
0805: buf.append(" }\n");
0806: buf.append("\n");
0807: buf.append(" public void testAssertNotSameFailsNull() {\n");
0808: buf.append(" try {\n");
0809: buf.append(" Assert.assertNotSame(null, null);\n");
0810: buf
0811: .append(" } catch (final AssertionFailedError e) {\n");
0812: buf.append(" return;\n");
0813: buf.append(" }\n");
0814: buf.append(" Assert.fail();\n");
0815: buf.append(" }\n");
0816: buf.append("\n");
0817: buf.append(" public void testAssertNull() {\n");
0818: buf.append(" Assert.assertNull(null);\n");
0819: buf.append(" try {\n");
0820: buf.append(" Assert.assertNull(new Object());\n");
0821: buf
0822: .append(" } catch (final AssertionFailedError e) {\n");
0823: buf.append(" return;\n");
0824: buf.append(" }\n");
0825: buf.append(" Assert.fail();\n");
0826: buf.append(" }\n");
0827: buf.append("\n");
0828: buf.append(" public void testAssertNullNotEqualsNull() {\n");
0829: buf.append(" try {\n");
0830: buf
0831: .append(" Assert.assertEquals(null, new Object());\n");
0832: buf
0833: .append(" } catch (final AssertionFailedError e) {\n");
0834: buf
0835: .append(" e.getMessage(); // why no assertion?\n");
0836: buf.append(" return;\n");
0837: buf.append(" }\n");
0838: buf.append(" Assert.fail();\n");
0839: buf.append(" }\n");
0840: buf.append("\n");
0841: buf
0842: .append(" public void testAssertNullNotEqualsString() {\n");
0843: buf.append(" try {\n");
0844: buf
0845: .append(" Assert.assertEquals(null, \"foo\"); //$NON-NLS-1$\n");
0846: buf.append(" Assert.fail();\n");
0847: buf.append(" } catch (final ComparisonFailure e) {\n");
0848: buf.append(" }\n");
0849: buf.append(" }\n");
0850: buf.append("\n");
0851: buf.append(" public void testAssertSame() {\n");
0852: buf.append(" final Object o = new Object();\n");
0853: buf.append(" Assert.assertSame(o, o);\n");
0854: buf.append(" try {\n");
0855: buf
0856: .append(" Assert.assertSame(new Integer(1), new Integer(1));\n");
0857: buf
0858: .append(" } catch (final AssertionFailedError e) {\n");
0859: buf.append(" return;\n");
0860: buf.append(" }\n");
0861: buf.append(" Assert.fail();\n");
0862: buf.append(" }\n");
0863: buf.append("\n");
0864: buf.append(" public void testAssertStringEquals() {\n");
0865: buf
0866: .append(" Assert.assertEquals(\"a\", \"a\"); //$NON-NLS-1$ //$NON-NLS-2$\n");
0867: buf.append(" }\n");
0868: buf.append("\n");
0869: buf
0870: .append(" public void testAssertStringNotEqualsNull() {\n");
0871: buf.append(" try {\n");
0872: buf
0873: .append(" Assert.assertEquals(\"foo\", null); //$NON-NLS-1$\n");
0874: buf.append(" Assert.fail();\n");
0875: buf.append(" } catch (final ComparisonFailure e) {\n");
0876: buf
0877: .append(" e.getMessage(); // why no assertion?\n");
0878: buf.append(" }\n");
0879: buf.append(" }\n");
0880: buf.append("\n");
0881: buf.append(" public void testAssertTrue() {\n");
0882: buf.append(" Assert.assertTrue(true);\n");
0883: buf.append(" try {\n");
0884: buf.append(" Assert.assertTrue(false);\n");
0885: buf
0886: .append(" } catch (final AssertionFailedError e) {\n");
0887: buf.append(" return;\n");
0888: buf.append(" }\n");
0889: buf.append(" Assert.fail();\n");
0890: buf.append(" }\n");
0891: buf.append("\n");
0892: buf.append(" /*\n");
0893: buf
0894: .append(" * In the tests that follow, we can't use standard formatting for exception\n");
0895: buf
0896: .append(" * tests: try { somethingThatShouldThrow(); fail(); catch\n");
0897: buf
0898: .append(" * (AssertionFailedError e) { } because fail() would never be reported.\n");
0899: buf.append(" */\n");
0900: buf.append(" public void testFail() {\n");
0901: buf
0902: .append(" // Also, we are testing fail, so we can't rely on fail() working.\n");
0903: buf
0904: .append(" // We have to throw the exception manually, .\n");
0905: buf.append(" try {\n");
0906: buf.append(" Assert.fail();\n");
0907: buf
0908: .append(" } catch (final AssertionFailedError e) {\n");
0909: buf.append(" return;\n");
0910: buf.append(" }\n");
0911: buf.append(" throw new AssertionFailedError();\n");
0912: buf.append(" }\n");
0913: buf.append("}");
0914: fExpectedChangesAllTests
0915: .put("junit.tests.framework.AssertTest.java", buf
0916: .toString());
0917: buf = new StringBuffer();
0918: buf.append("package junit.samples;\n");
0919: buf.append("\n");
0920: buf.append("import junit.framework.Test;\n");
0921: buf.append("import junit.framework.TestSuite;\n");
0922: buf.append("\n");
0923: buf.append("/**\n");
0924: buf.append(" * TestSuite that runs all the sample tests\n");
0925: buf.append(" * \n");
0926: buf.append(" */\n");
0927: buf.append("public class AllTests {\n");
0928: buf.append("\n");
0929: buf
0930: .append(" public static void main(final String[] args) {\n");
0931: buf
0932: .append(" junit.textui.TestRunner.run(AllTests.suite());\n");
0933: buf.append(" }\n");
0934: buf.append(" public static Test suite() {\n");
0935: buf
0936: .append(" final TestSuite suite = new TestSuite(\"All JUnit Tests\"); //$NON-NLS-1$\n");
0937: buf.append(" suite.addTest(VectorTest.suite());\n");
0938: buf
0939: .append(" suite.addTest(new TestSuite(junit.samples.money.MoneyTest.class));\n");
0940: buf
0941: .append(" suite.addTest(junit.tests.AllTests.suite());\n");
0942: buf.append(" return suite;\n");
0943: buf.append(" }\n");
0944: buf.append("}");
0945: fExpectedChangesAllTests.put("junit.samples.AllTests.java", buf
0946: .toString());
0947: buf = new StringBuffer();
0948: buf.append("package junit.tests.extensions;\n");
0949: buf.append("\n");
0950: buf.append("import junit.extensions.ExceptionTestCase;\n");
0951: buf.append("import junit.framework.Assert;\n");
0952: buf.append("import junit.framework.TestResult;\n");
0953: buf.append("\n");
0954: buf
0955: .append("public class ExceptionTestCaseTest extends junit.framework.TestCase {\n");
0956: buf.append("\n");
0957: buf
0958: .append(" static public class ThrowExceptionTestCase extends ExceptionTestCase {\n");
0959: buf
0960: .append(" public ThrowExceptionTestCase(final String name, final Class exception) {\n");
0961: buf.append(" super(name, exception);\n");
0962: buf.append(" }\n");
0963: buf.append(" public void test() {\n");
0964: buf
0965: .append(" throw new IndexOutOfBoundsException();\n");
0966: buf.append(" }\n");
0967: buf.append(" }\n");
0968: buf.append("\n");
0969: buf
0970: .append(" static public class ThrowNoExceptionTestCase extends ExceptionTestCase {\n");
0971: buf
0972: .append(" public ThrowNoExceptionTestCase(final String name, final Class exception) {\n");
0973: buf.append(" super(name, exception);\n");
0974: buf.append(" }\n");
0975: buf.append(" public void test() {\n");
0976: buf.append(" }\n");
0977: buf.append(" }\n");
0978: buf.append("\n");
0979: buf
0980: .append(" static public class ThrowRuntimeExceptionTestCase extends ExceptionTestCase {\n");
0981: buf
0982: .append(" public ThrowRuntimeExceptionTestCase(final String name,\n");
0983: buf.append(" final Class exception) {\n");
0984: buf.append(" super(name, exception);\n");
0985: buf.append(" }\n");
0986: buf.append(" public void test() {\n");
0987: buf.append(" throw new RuntimeException();\n");
0988: buf.append(" }\n");
0989: buf.append(" }\n");
0990: buf.append("\n");
0991: buf.append(" public void testExceptionSubclass() {\n");
0992: buf
0993: .append(" final ExceptionTestCase test = new ThrowExceptionTestCase(\n");
0994: buf
0995: .append(" \"test\", IndexOutOfBoundsException.class); //$NON-NLS-1$\n");
0996: buf.append(" final TestResult result = test.run();\n");
0997: buf
0998: .append(" Assert.assertEquals(1, result.runCount());\n");
0999: buf
1000: .append(" Assert.assertTrue(result.wasSuccessful());\n");
1001: buf.append(" }\n");
1002: buf.append(" public void testExceptionTest() {\n");
1003: buf
1004: .append(" final ExceptionTestCase test = new ThrowExceptionTestCase(\n");
1005: buf
1006: .append(" \"test\", IndexOutOfBoundsException.class); //$NON-NLS-1$\n");
1007: buf.append(" final TestResult result = test.run();\n");
1008: buf
1009: .append(" Assert.assertEquals(1, result.runCount());\n");
1010: buf
1011: .append(" Assert.assertTrue(result.wasSuccessful());\n");
1012: buf.append(" }\n");
1013: buf.append(" public void testFailure() {\n");
1014: buf
1015: .append(" final ExceptionTestCase test = new ThrowRuntimeExceptionTestCase(\n");
1016: buf
1017: .append(" \"test\", IndexOutOfBoundsException.class); //$NON-NLS-1$\n");
1018: buf.append(" final TestResult result = test.run();\n");
1019: buf
1020: .append(" Assert.assertEquals(1, result.runCount());\n");
1021: buf
1022: .append(" Assert.assertEquals(1, result.errorCount());\n");
1023: buf.append(" }\n");
1024: buf.append(" public void testNoException() {\n");
1025: buf
1026: .append(" final ExceptionTestCase test = new ThrowNoExceptionTestCase(\n");
1027: buf
1028: .append(" \"test\", Exception.class); //$NON-NLS-1$\n");
1029: buf.append(" final TestResult result = test.run();\n");
1030: buf
1031: .append(" Assert.assertEquals(1, result.runCount());\n");
1032: buf
1033: .append(" Assert.assertEquals(1, result.failureCount());\n");
1034: buf.append(" }\n");
1035: buf.append(" public void testWrongException() {\n");
1036: buf
1037: .append(" final ExceptionTestCase test = new ThrowRuntimeExceptionTestCase(\n");
1038: buf
1039: .append(" \"test\", IndexOutOfBoundsException.class); //$NON-NLS-1$\n");
1040: buf.append(" final TestResult result = test.run();\n");
1041: buf
1042: .append(" Assert.assertEquals(1, result.runCount());\n");
1043: buf
1044: .append(" Assert.assertEquals(1, result.errorCount());\n");
1045: buf.append(" }\n");
1046: buf.append("}");
1047: fExpectedChangesAllTests.put(
1048: "junit.tests.extensions.ExceptionTestCaseTest.java",
1049: buf.toString());
1050: buf = new StringBuffer();
1051: buf.append("package junit.tests.framework;\n");
1052: buf.append("\n");
1053: buf.append("/**\n");
1054: buf.append(" * Test class used in SuiteTest\n");
1055: buf.append(" */\n");
1056: buf.append("import junit.framework.Assert;\n");
1057: buf.append("import junit.framework.AssertionFailedError;\n");
1058: buf.append("import junit.framework.Test;\n");
1059: buf.append("import junit.framework.TestCase;\n");
1060: buf.append("import junit.framework.TestListener;\n");
1061: buf.append("import junit.framework.TestResult;\n");
1062: buf.append("\n");
1063: buf
1064: .append("public class TestListenerTest extends TestCase implements TestListener {\n");
1065: buf.append(" private int fEndCount;\n");
1066: buf.append(" private int fErrorCount;\n");
1067: buf.append(" private int fFailureCount;\n");
1068: buf.append(" private TestResult fResult;\n");
1069: buf.append(" private int fStartCount;\n");
1070: buf.append("\n");
1071: buf
1072: .append(" public void addError(final Test test, final Throwable t) {\n");
1073: buf.append(" this.fErrorCount++;\n");
1074: buf.append(" }\n");
1075: buf
1076: .append(" public void addFailure(final Test test, final AssertionFailedError t) {\n");
1077: buf.append(" this.fFailureCount++;\n");
1078: buf.append(" }\n");
1079: buf.append(" public void endTest(final Test test) {\n");
1080: buf.append(" this.fEndCount++;\n");
1081: buf.append(" }\n");
1082: buf.append(" @Override\n");
1083: buf.append(" protected void setUp() {\n");
1084: buf.append(" this.fResult = new TestResult();\n");
1085: buf.append(" this.fResult.addListener(this);\n");
1086: buf.append("\n");
1087: buf.append(" this.fStartCount = 0;\n");
1088: buf.append(" this.fEndCount = 0;\n");
1089: buf.append(" this.fFailureCount = 0;\n");
1090: buf.append(" }\n");
1091: buf.append(" public void startTest(final Test test) {\n");
1092: buf.append(" this.fStartCount++;\n");
1093: buf.append(" }\n");
1094: buf.append(" public void testError() {\n");
1095: buf
1096: .append(" final TestCase test = new TestCase(\"noop\") { //$NON-NLS-1$\n");
1097: buf.append(" @Override\n");
1098: buf.append(" public void runTest() {\n");
1099: buf.append(" throw new Error();\n");
1100: buf.append(" }\n");
1101: buf.append(" };\n");
1102: buf.append(" test.run(this.fResult);\n");
1103: buf
1104: .append(" Assert.assertEquals(1, this.fErrorCount);\n");
1105: buf.append(" Assert.assertEquals(1, this.fEndCount);\n");
1106: buf.append(" }\n");
1107: buf.append(" public void testFailure() {\n");
1108: buf
1109: .append(" final TestCase test = new TestCase(\"noop\") { //$NON-NLS-1$\n");
1110: buf.append(" @Override\n");
1111: buf.append(" public void runTest() {\n");
1112: buf.append(" Assert.fail();\n");
1113: buf.append(" }\n");
1114: buf.append(" };\n");
1115: buf.append(" test.run(this.fResult);\n");
1116: buf
1117: .append(" Assert.assertEquals(1, this.fFailureCount);\n");
1118: buf.append(" Assert.assertEquals(1, this.fEndCount);\n");
1119: buf.append(" }\n");
1120: buf.append(" public void testStartStop() {\n");
1121: buf
1122: .append(" final TestCase test = new TestCase(\"noop\") { //$NON-NLS-1$\n");
1123: buf.append(" @Override\n");
1124: buf.append(" public void runTest() {\n");
1125: buf.append(" }\n");
1126: buf.append(" };\n");
1127: buf.append(" test.run(this.fResult);\n");
1128: buf
1129: .append(" Assert.assertEquals(1, this.fStartCount);\n");
1130: buf.append(" Assert.assertEquals(1, this.fEndCount);\n");
1131: buf.append(" }\n");
1132: buf.append("}");
1133: fExpectedChangesAllTests.put(
1134: "junit.tests.framework.TestListenerTest.java", buf
1135: .toString());
1136: buf = new StringBuffer();
1137: buf.append("package junit.tests.runner;\n");
1138: buf.append("\n");
1139: buf.append("import java.util.Vector;\n");
1140: buf.append("\n");
1141: buf.append("import junit.framework.Assert;\n");
1142: buf.append("import junit.framework.TestCase;\n");
1143: buf.append("import junit.runner.Sorter;\n");
1144: buf.append("\n");
1145: buf.append("public class SorterTest extends TestCase {\n");
1146: buf.append("\n");
1147: buf
1148: .append(" static class Swapper implements Sorter.Swapper {\n");
1149: buf
1150: .append(" public void swap(final Vector values, final int left, final int right) {\n");
1151: buf
1152: .append(" final Object tmp = values.elementAt(left);\n");
1153: buf
1154: .append(" values.setElementAt(values.elementAt(right), left);\n");
1155: buf.append(" values.setElementAt(tmp, right);\n");
1156: buf.append(" }\n");
1157: buf.append(" }\n");
1158: buf.append("\n");
1159: buf.append(" public void testSort() throws Exception {\n");
1160: buf.append(" final Vector v = new Vector();\n");
1161: buf.append(" v.addElement(\"c\"); //$NON-NLS-1$\n");
1162: buf.append(" v.addElement(\"b\"); //$NON-NLS-1$\n");
1163: buf.append(" v.addElement(\"a\"); //$NON-NLS-1$\n");
1164: buf
1165: .append(" Sorter.sortStrings(v, 0, v.size() - 1, new Swapper());\n");
1166: buf
1167: .append(" Assert.assertEquals(v.elementAt(0), \"a\"); //$NON-NLS-1$\n");
1168: buf
1169: .append(" Assert.assertEquals(v.elementAt(1), \"b\"); //$NON-NLS-1$\n");
1170: buf
1171: .append(" Assert.assertEquals(v.elementAt(2), \"c\"); //$NON-NLS-1$\n");
1172: buf.append(" }\n");
1173: buf.append("}");
1174: fExpectedChangesAllTests.put(
1175: "junit.tests.runner.SorterTest.java", buf.toString());
1176: buf = new StringBuffer();
1177: buf.append("package junit.tests.framework;\n");
1178: buf.append("\n");
1179: buf.append("/**\n");
1180: buf.append(" * Test class used in SuiteTest\n");
1181: buf.append(" */\n");
1182: buf.append("import junit.framework.TestCase;\n");
1183: buf.append("\n");
1184: buf.append("public class OneTestCase extends TestCase {\n");
1185: buf.append(" public void noTestCase() {\n");
1186: buf.append(" }\n");
1187: buf.append(" public void testCase() {\n");
1188: buf.append(" }\n");
1189: buf.append(" public void testCase(final int arg) {\n");
1190: buf.append(" }\n");
1191: buf.append("}");
1192: fExpectedChangesAllTests.put(
1193: "junit.tests.framework.OneTestCase.java", buf
1194: .toString());
1195: buf = new StringBuffer();
1196: buf.append("package junit.tests.framework;\n");
1197: buf.append("\n");
1198: buf.append("import junit.framework.Assert;\n");
1199: buf.append("import junit.framework.Protectable;\n");
1200: buf.append("import junit.framework.Test;\n");
1201: buf.append("import junit.framework.TestCase;\n");
1202: buf.append("import junit.framework.TestResult;\n");
1203: buf.append("\n");
1204: buf.append("/**\n");
1205: buf
1206: .append(" * Test an implementor of junit.framework.Test other than TestCase or TestSuite\n");
1207: buf.append(" */\n");
1208: buf
1209: .append("public class TestImplementorTest extends TestCase {\n");
1210: buf
1211: .append(" public static class DoubleTestCase implements Test {\n");
1212: buf.append(" private final TestCase fTestCase;\n");
1213: buf.append("\n");
1214: buf
1215: .append(" public DoubleTestCase(final TestCase testCase) {\n");
1216: buf.append(" this.fTestCase = testCase;\n");
1217: buf.append(" }\n");
1218: buf.append("\n");
1219: buf.append(" public int countTestCases() {\n");
1220: buf.append(" return 2;\n");
1221: buf.append(" }\n");
1222: buf.append("\n");
1223: buf
1224: .append(" public void run(final TestResult result) {\n");
1225: buf.append(" result.startTest(this);\n");
1226: buf
1227: .append(" final Protectable p = new Protectable() {\n");
1228: buf
1229: .append(" public void protect() throws Throwable {\n");
1230: buf
1231: .append(" DoubleTestCase.this.fTestCase.runBare();\n");
1232: buf
1233: .append(" DoubleTestCase.this.fTestCase.runBare();\n");
1234: buf.append(" }\n");
1235: buf.append(" };\n");
1236: buf.append(" result.runProtected(this, p);\n");
1237: buf.append(" result.endTest(this);\n");
1238: buf.append(" }\n");
1239: buf.append(" }\n");
1240: buf.append("\n");
1241: buf.append(" private final DoubleTestCase fTest;\n");
1242: buf.append("\n");
1243: buf.append(" public TestImplementorTest() {\n");
1244: buf
1245: .append(" final TestCase testCase = new TestCase() {\n");
1246: buf.append(" @Override\n");
1247: buf.append(" public void runTest() {\n");
1248: buf.append(" }\n");
1249: buf.append(" };\n");
1250: buf
1251: .append(" this.fTest = new DoubleTestCase(testCase);\n");
1252: buf.append(" }\n");
1253: buf.append("\n");
1254: buf.append(" public void testSuccessfulRun() {\n");
1255: buf
1256: .append(" final TestResult result = new TestResult();\n");
1257: buf.append(" this.fTest.run(result);\n");
1258: buf
1259: .append(" Assert.assertEquals(this.fTest.countTestCases(), result.runCount());\n");
1260: buf
1261: .append(" Assert.assertEquals(0, result.errorCount());\n");
1262: buf
1263: .append(" Assert.assertEquals(0, result.failureCount());\n");
1264: buf.append(" }\n");
1265: buf.append("}\n");
1266: buf.append("");
1267: fExpectedChangesAllTests.put(
1268: "junit.tests.framework.TestImplementorTest.java", buf
1269: .toString());
1270: buf = new StringBuffer();
1271: buf.append("package junit.extensions;\n");
1272: buf.append("\n");
1273: buf.append("import junit.framework.Assert;\n");
1274: buf.append("import junit.framework.Test;\n");
1275: buf.append("import junit.framework.TestResult;\n");
1276: buf.append("\n");
1277: buf.append("/**\n");
1278: buf
1279: .append(" * A Decorator for Tests. Use TestDecorator as the base class for defining new\n");
1280: buf
1281: .append(" * test decorators. Test decorator subclasses can be introduced to add behaviour\n");
1282: buf.append(" * before or after a test is run.\n");
1283: buf.append(" * \n");
1284: buf.append(" */\n");
1285: buf
1286: .append("public class TestDecorator extends Assert implements Test {\n");
1287: buf.append(" protected Test fTest;\n");
1288: buf.append("\n");
1289: buf.append(" public TestDecorator(final Test test) {\n");
1290: buf.append(" this.fTest = test;\n");
1291: buf.append(" }\n");
1292: buf.append(" /**\n");
1293: buf.append(" * The basic run behaviour.\n");
1294: buf.append(" */\n");
1295: buf
1296: .append(" public void basicRun(final TestResult result) {\n");
1297: buf.append(" this.fTest.run(result);\n");
1298: buf.append(" }\n");
1299: buf.append(" public int countTestCases() {\n");
1300: buf.append(" return this.fTest.countTestCases();\n");
1301: buf.append(" }\n");
1302: buf.append(" public Test getTest() {\n");
1303: buf.append(" return this.fTest;\n");
1304: buf.append(" }\n");
1305: buf.append("\n");
1306: buf.append(" public void run(final TestResult result) {\n");
1307: buf.append(" this.basicRun(result);\n");
1308: buf.append(" }\n");
1309: buf.append("\n");
1310: buf.append(" @Override\n");
1311: buf.append(" public String toString() {\n");
1312: buf.append(" return this.fTest.toString();\n");
1313: buf.append(" }\n");
1314: buf.append("}");
1315: fExpectedChangesAllTests.put(
1316: "junit.extensions.TestDecorator.java", buf.toString());
1317: buf = new StringBuffer();
1318: buf.append("package junit.runner;\n");
1319: buf.append("\n");
1320: buf.append("/**\n");
1321: buf
1322: .append(" * An interface to define how a test suite should be loaded.\n");
1323: buf.append(" */\n");
1324: buf.append("public interface TestSuiteLoader {\n");
1325: buf
1326: .append(" abstract public Class load(String suiteClassName)\n");
1327: buf.append(" throws ClassNotFoundException;\n");
1328: buf
1329: .append(" abstract public Class reload(Class aClass) throws ClassNotFoundException;\n");
1330: buf.append("}");
1331: fExpectedChangesAllTests.put(
1332: "junit.runner.TestSuiteLoader.java", buf.toString());
1333: buf = new StringBuffer();
1334: buf.append("package junit.framework;\n");
1335: buf.append("\n");
1336: buf.append("import java.util.Enumeration;\n");
1337: buf.append("import java.util.Vector;\n");
1338: buf.append("\n");
1339: buf.append("/**\n");
1340: buf
1341: .append(" * A <code>TestResult</code> collects the results of executing a test case. It\n");
1342: buf
1343: .append(" * is an instance of the Collecting Parameter pattern. The test framework\n");
1344: buf
1345: .append(" * distinguishes between <i>failures</i> and <i>errors</i>. A failure is\n");
1346: buf
1347: .append(" * anticipated and checked for with assertions. Errors are unanticipated\n");
1348: buf
1349: .append(" * problems like an <code>ArrayIndexOutOfBoundsException</code>.\n");
1350: buf.append(" * \n");
1351: buf.append(" * @see Test\n");
1352: buf.append(" */\n");
1353: buf.append("public class TestResult extends Object {\n");
1354: buf.append(" protected Vector fErrors;\n");
1355: buf.append(" protected Vector fFailures;\n");
1356: buf.append(" protected Vector fListeners;\n");
1357: buf.append(" protected int fRunTests;\n");
1358: buf.append(" private boolean fStop;\n");
1359: buf.append("\n");
1360: buf.append(" public TestResult() {\n");
1361: buf.append(" this.fFailures = new Vector();\n");
1362: buf.append(" this.fErrors = new Vector();\n");
1363: buf.append(" this.fListeners = new Vector();\n");
1364: buf.append(" this.fRunTests = 0;\n");
1365: buf.append(" this.fStop = false;\n");
1366: buf.append(" }\n");
1367: buf.append(" /**\n");
1368: buf
1369: .append(" * Adds an error to the list of errors. The passed in exception caused the\n");
1370: buf.append(" * error.\n");
1371: buf.append(" */\n");
1372: buf
1373: .append(" public synchronized void addError(final Test test, final Throwable t) {\n");
1374: buf
1375: .append(" this.fErrors.addElement(new TestFailure(test, t));\n");
1376: buf
1377: .append(" for (final Enumeration e = this.cloneListeners().elements(); e\n");
1378: buf.append(" .hasMoreElements();) {\n");
1379: buf
1380: .append(" ((TestListener) e.nextElement()).addError(test, t);\n");
1381: buf.append(" }\n");
1382: buf.append(" }\n");
1383: buf.append(" /**\n");
1384: buf
1385: .append(" * Adds a failure to the list of failures. The passed in exception caused\n");
1386: buf.append(" * the failure.\n");
1387: buf.append(" */\n");
1388: buf
1389: .append(" public synchronized void addFailure(final Test test,\n");
1390: buf.append(" final AssertionFailedError t) {\n");
1391: buf
1392: .append(" this.fFailures.addElement(new TestFailure(test, t));\n");
1393: buf
1394: .append(" for (final Enumeration e = this.cloneListeners().elements(); e\n");
1395: buf.append(" .hasMoreElements();) {\n");
1396: buf
1397: .append(" ((TestListener) e.nextElement()).addFailure(test, t);\n");
1398: buf.append(" }\n");
1399: buf.append(" }\n");
1400: buf.append(" /**\n");
1401: buf.append(" * Registers a TestListener\n");
1402: buf.append(" */\n");
1403: buf
1404: .append(" public synchronized void addListener(final TestListener listener) {\n");
1405: buf.append(" this.fListeners.addElement(listener);\n");
1406: buf.append(" }\n");
1407: buf.append(" /**\n");
1408: buf.append(" * Returns a copy of the listeners.\n");
1409: buf.append(" */\n");
1410: buf
1411: .append(" private synchronized Vector cloneListeners() {\n");
1412: buf
1413: .append(" return (Vector) this.fListeners.clone();\n");
1414: buf.append(" }\n");
1415: buf.append(" /**\n");
1416: buf
1417: .append(" * Informs the result that a test was completed.\n");
1418: buf.append(" */\n");
1419: buf.append(" public void endTest(final Test test) {\n");
1420: buf
1421: .append(" for (final Enumeration e = this.cloneListeners().elements(); e\n");
1422: buf.append(" .hasMoreElements();) {\n");
1423: buf
1424: .append(" ((TestListener) e.nextElement()).endTest(test);\n");
1425: buf.append(" }\n");
1426: buf.append(" }\n");
1427: buf.append(" /**\n");
1428: buf.append(" * Gets the number of detected errors.\n");
1429: buf.append(" */\n");
1430: buf.append(" public synchronized int errorCount() {\n");
1431: buf.append(" return this.fErrors.size();\n");
1432: buf.append(" }\n");
1433: buf.append(" /**\n");
1434: buf.append(" * Returns an Enumeration for the errors\n");
1435: buf.append(" */\n");
1436: buf.append(" public synchronized Enumeration errors() {\n");
1437: buf.append(" return this.fErrors.elements();\n");
1438: buf.append(" }\n");
1439: buf.append(" /**\n");
1440: buf.append(" * Gets the number of detected failures.\n");
1441: buf.append(" */\n");
1442: buf.append(" public synchronized int failureCount() {\n");
1443: buf.append(" return this.fFailures.size();\n");
1444: buf.append(" }\n");
1445: buf.append(" /**\n");
1446: buf.append(" * Returns an Enumeration for the failures\n");
1447: buf.append(" */\n");
1448: buf
1449: .append(" public synchronized Enumeration failures() {\n");
1450: buf.append(" return this.fFailures.elements();\n");
1451: buf.append(" }\n");
1452: buf.append(" /**\n");
1453: buf.append(" * Unregisters a TestListener\n");
1454: buf.append(" */\n");
1455: buf
1456: .append(" public synchronized void removeListener(final TestListener listener) {\n");
1457: buf
1458: .append(" this.fListeners.removeElement(listener);\n");
1459: buf.append(" }\n");
1460: buf.append(" /**\n");
1461: buf.append(" * Runs a TestCase.\n");
1462: buf.append(" */\n");
1463: buf.append(" protected void run(final TestCase test) {\n");
1464: buf.append(" this.startTest(test);\n");
1465: buf
1466: .append(" final Protectable p = new Protectable() {\n");
1467: buf
1468: .append(" public void protect() throws Throwable {\n");
1469: buf.append(" test.runBare();\n");
1470: buf.append(" }\n");
1471: buf.append(" };\n");
1472: buf.append(" this.runProtected(test, p);\n");
1473: buf.append("\n");
1474: buf.append(" this.endTest(test);\n");
1475: buf.append(" }\n");
1476: buf.append(" /**\n");
1477: buf.append(" * Gets the number of run tests.\n");
1478: buf.append(" */\n");
1479: buf.append(" public synchronized int runCount() {\n");
1480: buf.append(" return this.fRunTests;\n");
1481: buf.append(" }\n");
1482: buf.append(" /**\n");
1483: buf.append(" * Runs a TestCase.\n");
1484: buf.append(" */\n");
1485: buf
1486: .append(" public void runProtected(final Test test, final Protectable p) {\n");
1487: buf.append(" try {\n");
1488: buf.append(" p.protect();\n");
1489: buf
1490: .append(" } catch (final AssertionFailedError e) {\n");
1491: buf.append(" this.addFailure(test, e);\n");
1492: buf
1493: .append(" } catch (final ThreadDeath e) { // don't catch ThreadDeath by accident\n");
1494: buf.append(" throw e;\n");
1495: buf.append(" } catch (final Throwable e) {\n");
1496: buf.append(" this.addError(test, e);\n");
1497: buf.append(" }\n");
1498: buf.append(" }\n");
1499: buf.append(" /**\n");
1500: buf.append(" * Checks whether the test run should stop\n");
1501: buf.append(" */\n");
1502: buf.append(" public synchronized boolean shouldStop() {\n");
1503: buf.append(" return this.fStop;\n");
1504: buf.append(" }\n");
1505: buf.append(" /**\n");
1506: buf
1507: .append(" * Informs the result that a test will be started.\n");
1508: buf.append(" */\n");
1509: buf.append(" public void startTest(final Test test) {\n");
1510: buf
1511: .append(" final int count = test.countTestCases();\n");
1512: buf.append(" synchronized (this) {\n");
1513: buf.append(" this.fRunTests += count;\n");
1514: buf.append(" }\n");
1515: buf
1516: .append(" for (final Enumeration e = this.cloneListeners().elements(); e\n");
1517: buf.append(" .hasMoreElements();) {\n");
1518: buf
1519: .append(" ((TestListener) e.nextElement()).startTest(test);\n");
1520: buf.append(" }\n");
1521: buf.append(" }\n");
1522: buf.append(" /**\n");
1523: buf.append(" * Marks that the test run should stop.\n");
1524: buf.append(" */\n");
1525: buf.append(" public synchronized void stop() {\n");
1526: buf.append(" this.fStop = true;\n");
1527: buf.append(" }\n");
1528: buf.append(" /**\n");
1529: buf
1530: .append(" * Returns whether the entire test was successful or not.\n");
1531: buf.append(" */\n");
1532: buf
1533: .append(" public synchronized boolean wasSuccessful() {\n");
1534: buf
1535: .append(" return (this.failureCount() == 0) && (this.errorCount() == 0);\n");
1536: buf.append(" }\n");
1537: buf.append("}");
1538: fExpectedChangesAllTests.put("junit.framework.TestResult.java",
1539: buf.toString());
1540: buf = new StringBuffer();
1541: buf.append("package junit.tests.framework;\n");
1542: buf.append("\n");
1543: buf.append("/**\n");
1544: buf.append(" * Test class used in SuiteTest\n");
1545: buf.append(" */\n");
1546: buf.append("import junit.framework.TestCase;\n");
1547: buf.append("\n");
1548: buf
1549: .append("public class NotPublicTestCase extends TestCase {\n");
1550: buf.append(" protected void testNotPublic() {\n");
1551: buf.append(" }\n");
1552: buf.append(" public void testPublic() {\n");
1553: buf.append(" }\n");
1554: buf.append("}");
1555: fExpectedChangesAllTests.put(
1556: "junit.tests.framework.NotPublicTestCase.java", buf
1557: .toString());
1558: buf = new StringBuffer();
1559: buf.append("package junit.extensions;\n");
1560: buf.append("\n");
1561: buf.append("import junit.framework.Test;\n");
1562: buf.append("import junit.framework.TestResult;\n");
1563: buf.append("import junit.framework.TestSuite;\n");
1564: buf.append("\n");
1565: buf.append("/**\n");
1566: buf
1567: .append(" * A TestSuite for active Tests. It runs each test in a separate thread and\n");
1568: buf
1569: .append(" * waits until all threads have terminated. -- Aarhus Radisson Scandinavian\n");
1570: buf.append(" * Center 11th floor\n");
1571: buf.append(" */\n");
1572: buf
1573: .append("public class ActiveTestSuite extends TestSuite {\n");
1574: buf.append(" private volatile int fActiveTestDeathCount;\n");
1575: buf.append("\n");
1576: buf.append(" public ActiveTestSuite() {\n");
1577: buf.append(" }\n");
1578: buf.append("\n");
1579: buf
1580: .append(" public ActiveTestSuite(final Class theClass) {\n");
1581: buf.append(" super(theClass);\n");
1582: buf.append(" }\n");
1583: buf.append("\n");
1584: buf
1585: .append(" public ActiveTestSuite(final Class theClass, final String name) {\n");
1586: buf.append(" super(theClass, name);\n");
1587: buf.append(" }\n");
1588: buf.append("\n");
1589: buf.append(" public ActiveTestSuite(final String name) {\n");
1590: buf.append(" super(name);\n");
1591: buf.append(" }\n");
1592: buf.append("\n");
1593: buf.append(" @Override\n");
1594: buf.append(" public void run(final TestResult result) {\n");
1595: buf.append(" this.fActiveTestDeathCount = 0;\n");
1596: buf.append(" super.run(result);\n");
1597: buf.append(" this.waitUntilFinished();\n");
1598: buf.append(" }\n");
1599: buf.append("\n");
1600: buf
1601: .append(" synchronized public void runFinished(final Test test) {\n");
1602: buf.append(" this.fActiveTestDeathCount++;\n");
1603: buf.append(" this.notifyAll();\n");
1604: buf.append(" }\n");
1605: buf.append("\n");
1606: buf.append(" @Override\n");
1607: buf
1608: .append(" public void runTest(final Test test, final TestResult result) {\n");
1609: buf.append(" final Thread t = new Thread() {\n");
1610: buf.append(" @Override\n");
1611: buf.append(" public void run() {\n");
1612: buf.append(" try {\n");
1613: buf
1614: .append(" // inlined due to limitation in VA/Java\n");
1615: buf
1616: .append(" // ActiveTestSuite.super.runTest(test, result);\n");
1617: buf.append(" test.run(result);\n");
1618: buf.append(" } finally {\n");
1619: buf
1620: .append(" ActiveTestSuite.this.runFinished(test);\n");
1621: buf.append(" }\n");
1622: buf.append(" }\n");
1623: buf.append(" };\n");
1624: buf.append(" t.start();\n");
1625: buf.append(" }\n");
1626: buf.append("\n");
1627: buf.append(" synchronized void waitUntilFinished() {\n");
1628: buf
1629: .append(" while (this.fActiveTestDeathCount < this.testCount()) {\n");
1630: buf.append(" try {\n");
1631: buf.append(" this.wait();\n");
1632: buf
1633: .append(" } catch (final InterruptedException e) {\n");
1634: buf.append(" return; // ignore\n");
1635: buf.append(" }\n");
1636: buf.append(" }\n");
1637: buf.append(" }\n");
1638: buf.append("}");
1639: fExpectedChangesAllTests
1640: .put("junit.extensions.ActiveTestSuite.java", buf
1641: .toString());
1642: buf = new StringBuffer();
1643: buf.append("package junit.tests.framework;\n");
1644: buf.append("\n");
1645: buf.append("import junit.framework.Assert;\n");
1646: buf.append("import junit.framework.Test;\n");
1647: buf.append("import junit.framework.TestCase;\n");
1648: buf.append("import junit.framework.TestResult;\n");
1649: buf.append("import junit.framework.TestSuite;\n");
1650: buf.append("\n");
1651: buf.append("/**\n");
1652: buf
1653: .append(" * A fixture for testing the \"auto\" test suite feature.\n");
1654: buf.append(" * \n");
1655: buf.append(" */\n");
1656: buf.append("public class SuiteTest extends TestCase {\n");
1657: buf.append(" public static Test suite() {\n");
1658: buf
1659: .append(" final TestSuite suite = new TestSuite(\"Suite Tests\"); //$NON-NLS-1$\n");
1660: buf
1661: .append(" // build the suite manually, because some of the suites are testing\n");
1662: buf
1663: .append(" // the functionality that automatically builds suites\n");
1664: buf
1665: .append(" suite.addTest(new SuiteTest(\"testNoTestCaseClass\")); //$NON-NLS-1$\n");
1666: buf
1667: .append(" suite.addTest(new SuiteTest(\"testNoTestCases\")); //$NON-NLS-1$\n");
1668: buf
1669: .append(" suite.addTest(new SuiteTest(\"testOneTestCase\")); //$NON-NLS-1$\n");
1670: buf
1671: .append(" suite.addTest(new SuiteTest(\"testNotPublicTestCase\")); //$NON-NLS-1$\n");
1672: buf
1673: .append(" suite.addTest(new SuiteTest(\"testNotVoidTestCase\")); //$NON-NLS-1$\n");
1674: buf
1675: .append(" suite.addTest(new SuiteTest(\"testNotExistingTestCase\")); //$NON-NLS-1$\n");
1676: buf
1677: .append(" suite.addTest(new SuiteTest(\"testInheritedTests\")); //$NON-NLS-1$\n");
1678: buf
1679: .append(" suite.addTest(new SuiteTest(\"testShadowedTests\")); //$NON-NLS-1$\n");
1680: buf
1681: .append(" suite.addTest(new SuiteTest(\"testAddTestSuite\")); //$NON-NLS-1$\n");
1682: buf.append("\n");
1683: buf.append(" return suite;\n");
1684: buf.append(" }\n");
1685: buf.append(" protected TestResult fResult;\n");
1686: buf.append(" public SuiteTest(final String name) {\n");
1687: buf.append(" super(name);\n");
1688: buf.append(" }\n");
1689: buf.append(" @Override\n");
1690: buf.append(" protected void setUp() {\n");
1691: buf.append(" this.fResult = new TestResult();\n");
1692: buf.append(" }\n");
1693: buf.append(" public void testAddTestSuite() {\n");
1694: buf
1695: .append(" final TestSuite suite = new TestSuite();\n");
1696: buf.append(" suite.addTestSuite(OneTestCase.class);\n");
1697: buf.append(" suite.run(this.fResult);\n");
1698: buf
1699: .append(" Assert.assertEquals(1, this.fResult.runCount());\n");
1700: buf.append(" }\n");
1701: buf.append(" public void testInheritedTests() {\n");
1702: buf
1703: .append(" final TestSuite suite = new TestSuite(InheritedTestCase.class);\n");
1704: buf.append(" suite.run(this.fResult);\n");
1705: buf
1706: .append(" Assert.assertTrue(this.fResult.wasSuccessful());\n");
1707: buf
1708: .append(" Assert.assertEquals(2, this.fResult.runCount());\n");
1709: buf.append(" }\n");
1710: buf.append(" public void testNoTestCaseClass() {\n");
1711: buf
1712: .append(" final Test t = new TestSuite(NoTestCaseClass.class);\n");
1713: buf.append(" t.run(this.fResult);\n");
1714: buf
1715: .append(" Assert.assertEquals(1, this.fResult.runCount()); // warning test\n");
1716: buf
1717: .append(" Assert.assertTrue(!this.fResult.wasSuccessful());\n");
1718: buf.append(" }\n");
1719: buf.append(" public void testNoTestCases() {\n");
1720: buf
1721: .append(" final Test t = new TestSuite(NoTestCases.class);\n");
1722: buf.append(" t.run(this.fResult);\n");
1723: buf
1724: .append(" Assert.assertTrue(this.fResult.runCount() == 1); // warning test\n");
1725: buf
1726: .append(" Assert.assertTrue(this.fResult.failureCount() == 1);\n");
1727: buf
1728: .append(" Assert.assertTrue(!this.fResult.wasSuccessful());\n");
1729: buf.append(" }\n");
1730: buf.append(" public void testNotExistingTestCase() {\n");
1731: buf
1732: .append(" final Test t = new SuiteTest(\"notExistingMethod\"); //$NON-NLS-1$\n");
1733: buf.append(" t.run(this.fResult);\n");
1734: buf
1735: .append(" Assert.assertTrue(this.fResult.runCount() == 1);\n");
1736: buf
1737: .append(" Assert.assertTrue(this.fResult.failureCount() == 1);\n");
1738: buf
1739: .append(" Assert.assertTrue(this.fResult.errorCount() == 0);\n");
1740: buf.append(" }\n");
1741: buf.append(" public void testNotPublicTestCase() {\n");
1742: buf
1743: .append(" final TestSuite suite = new TestSuite(NotPublicTestCase.class);\n");
1744: buf
1745: .append(" // 1 public test case + 1 warning for the non-public test case\n");
1746: buf
1747: .append(" Assert.assertEquals(2, suite.countTestCases());\n");
1748: buf.append(" }\n");
1749: buf.append(" public void testNotVoidTestCase() {\n");
1750: buf
1751: .append(" final TestSuite suite = new TestSuite(NotVoidTestCase.class);\n");
1752: buf
1753: .append(" Assert.assertTrue(suite.countTestCases() == 1);\n");
1754: buf.append(" }\n");
1755: buf.append(" public void testOneTestCase() {\n");
1756: buf
1757: .append(" final Test t = new TestSuite(OneTestCase.class);\n");
1758: buf.append(" t.run(this.fResult);\n");
1759: buf
1760: .append(" Assert.assertTrue(this.fResult.runCount() == 1);\n");
1761: buf
1762: .append(" Assert.assertTrue(this.fResult.failureCount() == 0);\n");
1763: buf
1764: .append(" Assert.assertTrue(this.fResult.errorCount() == 0);\n");
1765: buf
1766: .append(" Assert.assertTrue(this.fResult.wasSuccessful());\n");
1767: buf.append(" }\n");
1768: buf.append(" public void testShadowedTests() {\n");
1769: buf
1770: .append(" final TestSuite suite = new TestSuite(OverrideTestCase.class);\n");
1771: buf.append(" suite.run(this.fResult);\n");
1772: buf
1773: .append(" Assert.assertEquals(1, this.fResult.runCount());\n");
1774: buf.append(" }\n");
1775: buf.append("}");
1776: fExpectedChangesAllTests.put(
1777: "junit.tests.framework.SuiteTest.java", buf.toString());
1778: buf = new StringBuffer();
1779: buf.append("package junit.runner;\n");
1780: buf.append("\n");
1781: buf.append("/**\n");
1782: buf
1783: .append(" * An implementation of a TestCollector that considers a class to be a test\n");
1784: buf
1785: .append(" * class when it contains the pattern \"Test\" in its name\n");
1786: buf.append(" * \n");
1787: buf.append(" * @see TestCollector\n");
1788: buf.append(" */\n");
1789: buf
1790: .append("public class SimpleTestCollector extends ClassPathTestCollector {\n");
1791: buf.append("\n");
1792: buf.append(" public SimpleTestCollector() {\n");
1793: buf.append(" }\n");
1794: buf.append("\n");
1795: buf.append(" @Override\n");
1796: buf
1797: .append(" protected boolean isTestClass(final String classFileName) {\n");
1798: buf
1799: .append(" return classFileName.endsWith(\".class\") && //$NON-NLS-1$\n");
1800: buf
1801: .append(" (classFileName.indexOf('$') < 0)\n");
1802: buf
1803: .append(" && (classFileName.indexOf(\"Test\") > 0); //$NON-NLS-1$\n");
1804: buf.append(" }\n");
1805: buf.append("}\n");
1806: buf.append("");
1807: fExpectedChangesAllTests
1808: .put("junit.runner.SimpleTestCollector.java", buf
1809: .toString());
1810: buf = new StringBuffer();
1811: buf.append("package junit.framework;\n");
1812: buf.append("\n");
1813: buf.append("/**\n");
1814: buf
1815: .append(" * A <em>Test</em> can be run and collect its results.\n");
1816: buf.append(" * \n");
1817: buf.append(" * @see TestResult\n");
1818: buf.append(" */\n");
1819: buf.append("public interface Test {\n");
1820: buf.append(" /**\n");
1821: buf
1822: .append(" * Counts the number of test cases that will be run by this test.\n");
1823: buf.append(" */\n");
1824: buf.append(" public abstract int countTestCases();\n");
1825: buf.append(" /**\n");
1826: buf
1827: .append(" * Runs a test and collects its result in a TestResult instance.\n");
1828: buf.append(" */\n");
1829: buf
1830: .append(" public abstract void run(TestResult result);\n");
1831: buf.append("}");
1832: fExpectedChangesAllTests.put("junit.framework.Test.java", buf
1833: .toString());
1834: buf = new StringBuffer();
1835: buf.append("package junit.tests.framework;\n");
1836: buf.append("\n");
1837: buf.append("/**\n");
1838: buf.append(" * Test class used in SuiteTest\n");
1839: buf.append(" */\n");
1840: buf.append("\n");
1841: buf.append("public class NoTestCaseClass extends Object {\n");
1842: buf.append(" public void testSuccess() {\n");
1843: buf.append(" }\n");
1844: buf.append("}");
1845: fExpectedChangesAllTests.put(
1846: "junit.tests.framework.NoTestCaseClass.java", buf
1847: .toString());
1848: buf = new StringBuffer();
1849: buf.append("package junit.tests.framework;\n");
1850: buf.append("\n");
1851: buf.append("import junit.framework.TestCase;\n");
1852: buf.append("\n");
1853: buf.append("/**\n");
1854: buf.append(" * A test case testing the testing framework.\n");
1855: buf.append(" * \n");
1856: buf.append(" */\n");
1857: buf.append("public class Success extends TestCase {\n");
1858: buf.append("\n");
1859: buf.append(" @Override\n");
1860: buf.append(" public void runTest() {\n");
1861: buf.append(" }\n");
1862: buf.append("\n");
1863: buf.append(" public void testSuccess() {\n");
1864: buf.append(" }\n");
1865: buf.append("}");
1866: fExpectedChangesAllTests.put(
1867: "junit.tests.framework.Success.java", buf.toString());
1868: buf = new StringBuffer();
1869: buf.append("package junit.runner;\n");
1870: buf.append("\n");
1871: buf.append("import java.lang.reflect.Modifier;\n");
1872: buf.append("\n");
1873: buf.append("import junit.framework.Test;\n");
1874: buf.append("import junit.framework.TestSuite;\n");
1875: buf.append("\n");
1876: buf.append("/**\n");
1877: buf
1878: .append(" * An implementation of a TestCollector that loads all classes on the class path\n");
1879: buf
1880: .append(" * and tests whether it is assignable from Test or provides a static suite\n");
1881: buf.append(" * method.\n");
1882: buf.append(" * \n");
1883: buf.append(" * @see TestCollector\n");
1884: buf.append(" */\n");
1885: buf
1886: .append("public class LoadingTestCollector extends ClassPathTestCollector {\n");
1887: buf.append("\n");
1888: buf.append(" TestCaseClassLoader fLoader;\n");
1889: buf.append("\n");
1890: buf.append(" public LoadingTestCollector() {\n");
1891: buf
1892: .append(" this.fLoader = new TestCaseClassLoader();\n");
1893: buf.append(" }\n");
1894: buf.append("\n");
1895: buf
1896: .append(" Class classFromFile(final String classFileName)\n");
1897: buf.append(" throws ClassNotFoundException {\n");
1898: buf
1899: .append(" final String className = this.classNameFromFile(classFileName);\n");
1900: buf
1901: .append(" if (!this.fLoader.isExcluded(className)) {\n");
1902: buf
1903: .append(" return this.fLoader.loadClass(className, false);\n");
1904: buf.append(" }\n");
1905: buf.append(" return null;\n");
1906: buf.append(" }\n");
1907: buf.append("\n");
1908: buf
1909: .append(" boolean hasPublicConstructor(final Class testClass) {\n");
1910: buf.append(" try {\n");
1911: buf
1912: .append(" TestSuite.getTestConstructor(testClass);\n");
1913: buf
1914: .append(" } catch (final NoSuchMethodException e) {\n");
1915: buf.append(" return false;\n");
1916: buf.append(" }\n");
1917: buf.append(" return true;\n");
1918: buf.append(" }\n");
1919: buf.append("\n");
1920: buf
1921: .append(" boolean hasSuiteMethod(final Class testClass) {\n");
1922: buf.append(" try {\n");
1923: buf
1924: .append(" testClass.getMethod(BaseTestRunner.SUITE_METHODNAME, new Class[0]);\n");
1925: buf.append(" } catch (final Exception e) {\n");
1926: buf.append(" return false;\n");
1927: buf.append(" }\n");
1928: buf.append(" return true;\n");
1929: buf.append(" }\n");
1930: buf.append("\n");
1931: buf
1932: .append(" boolean isTestClass(final Class testClass) {\n");
1933: buf.append(" if (this.hasSuiteMethod(testClass)) {\n");
1934: buf.append(" return true;\n");
1935: buf.append(" }\n");
1936: buf
1937: .append(" if (Test.class.isAssignableFrom(testClass)\n");
1938: buf
1939: .append(" && Modifier.isPublic(testClass.getModifiers())\n");
1940: buf
1941: .append(" && this.hasPublicConstructor(testClass)) {\n");
1942: buf.append(" return true;\n");
1943: buf.append(" }\n");
1944: buf.append(" return false;\n");
1945: buf.append(" }\n");
1946: buf.append("\n");
1947: buf.append(" @Override\n");
1948: buf
1949: .append(" protected boolean isTestClass(final String classFileName) {\n");
1950: buf.append(" try {\n");
1951: buf
1952: .append(" if (classFileName.endsWith(\".class\")) { //$NON-NLS-1$\n");
1953: buf
1954: .append(" final Class testClass = this.classFromFile(classFileName);\n");
1955: buf
1956: .append(" return (testClass != null) && this.isTestClass(testClass);\n");
1957: buf.append(" }\n");
1958: buf
1959: .append(" } catch (final ClassNotFoundException expected) {\n");
1960: buf
1961: .append(" } catch (final NoClassDefFoundError notFatal) {\n");
1962: buf.append(" }\n");
1963: buf.append(" return false;\n");
1964: buf.append(" }\n");
1965: buf.append("}\n");
1966: buf.append("");
1967: fExpectedChangesAllTests.put(
1968: "junit.runner.LoadingTestCollector.java", buf
1969: .toString());
1970: buf = new StringBuffer();
1971: buf.append("package junit.runner;\n");
1972: buf.append("\n");
1973: buf.append("import java.io.ByteArrayOutputStream;\n");
1974: buf.append("import java.io.File;\n");
1975: buf.append("import java.io.FileInputStream;\n");
1976: buf.append("import java.io.IOException;\n");
1977: buf.append("import java.io.InputStream;\n");
1978: buf.append("import java.net.URL;\n");
1979: buf.append("import java.util.Enumeration;\n");
1980: buf.append("import java.util.Properties;\n");
1981: buf.append("import java.util.StringTokenizer;\n");
1982: buf.append("import java.util.Vector;\n");
1983: buf.append("import java.util.zip.ZipEntry;\n");
1984: buf.append("import java.util.zip.ZipFile;\n");
1985: buf.append("\n");
1986: buf.append("/**\n");
1987: buf
1988: .append(" * A custom class loader which enables the reloading of classes for each test\n");
1989: buf
1990: .append(" * run. The class loader can be configured with a list of package paths that\n");
1991: buf
1992: .append(" * should be excluded from loading. The loading of these packages is delegated\n");
1993: buf
1994: .append(" * to the system class loader. They will be shared across test runs.\n");
1995: buf.append(" * <p>\n");
1996: buf
1997: .append(" * The list of excluded package paths is specified in a properties file\n");
1998: buf
1999: .append(" * \"excluded.properties\" that is located in the same place as the\n");
2000: buf.append(" * TestCaseClassLoader class.\n");
2001: buf.append(" * <p>\n");
2002: buf
2003: .append(" * <b>Known limitation:</b> the TestCaseClassLoader cannot load classes from\n");
2004: buf.append(" * jar files.\n");
2005: buf.append(" */\n");
2006: buf.append("\n");
2007: buf
2008: .append("public class TestCaseClassLoader extends ClassLoader {\n");
2009: buf.append(" /** name of excluded properties file */\n");
2010: buf
2011: .append(" static final String EXCLUDED_FILE = \"excluded.properties\"; //$NON-NLS-1$\n");
2012: buf.append(" /** default excluded paths */\n");
2013: buf
2014: .append(" private final String[] defaultExclusions = {\"junit.framework.\", //$NON-NLS-1$\n");
2015: buf
2016: .append(" \"junit.extensions.\", //$NON-NLS-1$\n");
2017: buf.append(" \"junit.runner.\" //$NON-NLS-1$\n");
2018: buf.append(" };\n");
2019: buf.append(" /** excluded paths */\n");
2020: buf.append(" private Vector fExcluded;\n");
2021: buf.append(" /** scanned class path */\n");
2022: buf.append(" private Vector fPathItems;\n");
2023: buf.append("\n");
2024: buf.append(" /**\n");
2025: buf
2026: .append(" * Constructs a TestCaseLoader. It scans the class path and the excluded\n");
2027: buf.append(" * package paths\n");
2028: buf.append(" */\n");
2029: buf.append(" public TestCaseClassLoader() {\n");
2030: buf
2031: .append(" this(System.getProperty(\"java.class.path\")); //$NON-NLS-1$\n");
2032: buf.append(" }\n");
2033: buf.append("\n");
2034: buf.append(" /**\n");
2035: buf
2036: .append(" * Constructs a TestCaseLoader. It scans the class path and the excluded\n");
2037: buf.append(" * package paths\n");
2038: buf.append(" */\n");
2039: buf
2040: .append(" public TestCaseClassLoader(final String classPath) {\n");
2041: buf.append(" this.scanPath(classPath);\n");
2042: buf.append(" this.readExcludedPackages();\n");
2043: buf.append(" }\n");
2044: buf.append("\n");
2045: buf.append(" private byte[] getClassData(final File f) {\n");
2046: buf.append(" try {\n");
2047: buf
2048: .append(" final FileInputStream stream = new FileInputStream(f);\n");
2049: buf
2050: .append(" final ByteArrayOutputStream out = new ByteArrayOutputStream(1000);\n");
2051: buf.append(" final byte[] b = new byte[1000];\n");
2052: buf.append(" int n;\n");
2053: buf
2054: .append(" while ((n = stream.read(b)) != -1) {\n");
2055: buf.append(" out.write(b, 0, n);\n");
2056: buf.append(" }\n");
2057: buf.append(" stream.close();\n");
2058: buf.append(" out.close();\n");
2059: buf.append(" return out.toByteArray();\n");
2060: buf.append("\n");
2061: buf.append(" } catch (final IOException e) {\n");
2062: buf.append(" }\n");
2063: buf.append(" return null;\n");
2064: buf.append(" }\n");
2065: buf.append("\n");
2066: buf.append(" @Override\n");
2067: buf.append(" public URL getResource(final String name) {\n");
2068: buf
2069: .append(" return ClassLoader.getSystemResource(name);\n");
2070: buf.append(" }\n");
2071: buf.append("\n");
2072: buf.append(" @Override\n");
2073: buf
2074: .append(" public InputStream getResourceAsStream(final String name) {\n");
2075: buf
2076: .append(" return ClassLoader.getSystemResourceAsStream(name);\n");
2077: buf.append(" }\n");
2078: buf.append("\n");
2079: buf
2080: .append(" public boolean isExcluded(final String name) {\n");
2081: buf
2082: .append(" for (int i = 0; i < this.fExcluded.size(); i++) {\n");
2083: buf
2084: .append(" if (name.startsWith((String) this.fExcluded.elementAt(i))) {\n");
2085: buf.append(" return true;\n");
2086: buf.append(" }\n");
2087: buf.append(" }\n");
2088: buf.append(" return false;\n");
2089: buf.append(" }\n");
2090: buf.append("\n");
2091: buf.append(" boolean isJar(final String pathEntry) {\n");
2092: buf
2093: .append(" return pathEntry.endsWith(\".jar\") || pathEntry.endsWith(\".zip\"); //$NON-NLS-1$ //$NON-NLS-2$\n");
2094: buf.append(" }\n");
2095: buf.append("\n");
2096: buf.append(" @Override\n");
2097: buf
2098: .append(" public synchronized Class loadClass(final String name, final boolean resolve)\n");
2099: buf.append(" throws ClassNotFoundException {\n");
2100: buf.append("\n");
2101: buf.append(" Class c = this.findLoadedClass(name);\n");
2102: buf.append(" if (c != null) {\n");
2103: buf.append(" return c;\n");
2104: buf.append(" }\n");
2105: buf.append(" //\n");
2106: buf
2107: .append(" // Delegate the loading of excluded classes to the\n");
2108: buf.append(" // standard class loader.\n");
2109: buf.append(" //\n");
2110: buf.append(" if (this.isExcluded(name)) {\n");
2111: buf.append(" try {\n");
2112: buf.append(" c = this.findSystemClass(name);\n");
2113: buf.append(" return c;\n");
2114: buf
2115: .append(" } catch (final ClassNotFoundException e) {\n");
2116: buf.append(" // keep searching\n");
2117: buf.append(" }\n");
2118: buf.append(" }\n");
2119: buf.append(" if (c == null) {\n");
2120: buf
2121: .append(" final byte[] data = this.lookupClassData(name);\n");
2122: buf.append(" if (data == null) {\n");
2123: buf
2124: .append(" throw new ClassNotFoundException();\n");
2125: buf.append(" }\n");
2126: buf
2127: .append(" c = this.defineClass(name, data, 0, data.length);\n");
2128: buf.append(" }\n");
2129: buf.append(" if (resolve) {\n");
2130: buf.append(" this.resolveClass(c);\n");
2131: buf.append(" }\n");
2132: buf.append(" return c;\n");
2133: buf.append(" }\n");
2134: buf.append("\n");
2135: buf
2136: .append(" private byte[] loadFileData(final String path, final String fileName) {\n");
2137: buf
2138: .append(" final File file = new File(path, fileName);\n");
2139: buf.append(" if (file.exists()) {\n");
2140: buf.append(" return this.getClassData(file);\n");
2141: buf.append(" }\n");
2142: buf.append(" return null;\n");
2143: buf.append(" }\n");
2144: buf.append("\n");
2145: buf
2146: .append(" private byte[] loadJarData(final String path, final String fileName) {\n");
2147: buf.append(" ZipFile zipFile = null;\n");
2148: buf.append(" InputStream stream = null;\n");
2149: buf.append(" final File archive = new File(path);\n");
2150: buf.append(" if (!archive.exists()) {\n");
2151: buf.append(" return null;\n");
2152: buf.append(" }\n");
2153: buf.append(" try {\n");
2154: buf.append(" zipFile = new ZipFile(archive);\n");
2155: buf.append(" } catch (final IOException io) {\n");
2156: buf.append(" return null;\n");
2157: buf.append(" }\n");
2158: buf
2159: .append(" final ZipEntry entry = zipFile.getEntry(fileName);\n");
2160: buf.append(" if (entry == null) {\n");
2161: buf.append(" return null;\n");
2162: buf.append(" }\n");
2163: buf.append(" final int size = (int) entry.getSize();\n");
2164: buf.append(" try {\n");
2165: buf
2166: .append(" stream = zipFile.getInputStream(entry);\n");
2167: buf.append(" final byte[] data = new byte[size];\n");
2168: buf.append(" int pos = 0;\n");
2169: buf.append(" while (pos < size) {\n");
2170: buf
2171: .append(" final int n = stream.read(data, pos, data.length - pos);\n");
2172: buf.append(" pos += n;\n");
2173: buf.append(" }\n");
2174: buf.append(" zipFile.close();\n");
2175: buf.append(" return data;\n");
2176: buf.append(" } catch (final IOException e) {\n");
2177: buf.append(" } finally {\n");
2178: buf.append(" try {\n");
2179: buf.append(" if (stream != null) {\n");
2180: buf.append(" stream.close();\n");
2181: buf.append(" }\n");
2182: buf.append(" } catch (final IOException e) {\n");
2183: buf.append(" }\n");
2184: buf.append(" }\n");
2185: buf.append(" return null;\n");
2186: buf.append(" }\n");
2187: buf.append("\n");
2188: buf
2189: .append(" private byte[] lookupClassData(final String className)\n");
2190: buf.append(" throws ClassNotFoundException {\n");
2191: buf.append(" byte[] data = null;\n");
2192: buf
2193: .append(" for (int i = 0; i < this.fPathItems.size(); i++) {\n");
2194: buf
2195: .append(" final String path = (String) this.fPathItems.elementAt(i);\n");
2196: buf
2197: .append(" final String fileName = className.replace('.', '/') + \".class\"; //$NON-NLS-1$\n");
2198: buf.append(" if (this.isJar(path)) {\n");
2199: buf
2200: .append(" data = this.loadJarData(path, fileName);\n");
2201: buf.append(" } else {\n");
2202: buf
2203: .append(" data = this.loadFileData(path, fileName);\n");
2204: buf.append(" }\n");
2205: buf.append(" if (data != null) {\n");
2206: buf.append(" return data;\n");
2207: buf.append(" }\n");
2208: buf.append(" }\n");
2209: buf
2210: .append(" throw new ClassNotFoundException(className);\n");
2211: buf.append(" }\n");
2212: buf.append("\n");
2213: buf.append(" private void readExcludedPackages() {\n");
2214: buf.append(" this.fExcluded = new Vector(10);\n");
2215: buf
2216: .append(" for (final String element : this.defaultExclusions) {\n");
2217: buf.append(" this.fExcluded.addElement(element);\n");
2218: buf.append(" }\n");
2219: buf.append("\n");
2220: buf
2221: .append(" final InputStream is = this.getClass().getResourceAsStream(\n");
2222: buf
2223: .append(" TestCaseClassLoader.EXCLUDED_FILE);\n");
2224: buf.append(" if (is == null) {\n");
2225: buf.append(" return;\n");
2226: buf.append(" }\n");
2227: buf.append(" final Properties p = new Properties();\n");
2228: buf.append(" try {\n");
2229: buf.append(" p.load(is);\n");
2230: buf.append(" } catch (final IOException e) {\n");
2231: buf.append(" return;\n");
2232: buf.append(" } finally {\n");
2233: buf.append(" try {\n");
2234: buf.append(" is.close();\n");
2235: buf.append(" } catch (final IOException e) {\n");
2236: buf.append(" }\n");
2237: buf.append(" }\n");
2238: buf
2239: .append(" for (final Enumeration e = p.propertyNames(); e.hasMoreElements();) {\n");
2240: buf
2241: .append(" final String key = (String) e.nextElement();\n");
2242: buf
2243: .append(" if (key.startsWith(\"excluded.\")) { //$NON-NLS-1$\n");
2244: buf
2245: .append(" String path = p.getProperty(key);\n");
2246: buf.append(" path = path.trim();\n");
2247: buf.append(" if (path.endsWith(\"*\")) {\n");
2248: buf
2249: .append(" path = path.substring(0, path.length() - 1);\n");
2250: buf.append(" }\n");
2251: buf.append(" if (path.length() > 0) {\n");
2252: buf
2253: .append(" this.fExcluded.addElement(path);\n");
2254: buf.append(" }\n");
2255: buf.append(" }\n");
2256: buf.append(" }\n");
2257: buf.append(" }\n");
2258: buf.append("\n");
2259: buf
2260: .append(" private void scanPath(final String classPath) {\n");
2261: buf
2262: .append(" final String separator = System.getProperty(\"path.separator\"); //$NON-NLS-1$\n");
2263: buf.append(" this.fPathItems = new Vector(10);\n");
2264: buf
2265: .append(" final StringTokenizer st = new StringTokenizer(classPath, separator);\n");
2266: buf.append(" while (st.hasMoreTokens()) {\n");
2267: buf
2268: .append(" this.fPathItems.addElement(st.nextToken());\n");
2269: buf.append(" }\n");
2270: buf.append(" }\n");
2271: buf.append("}");
2272: fExpectedChangesAllTests
2273: .put("junit.runner.TestCaseClassLoader.java", buf
2274: .toString());
2275: buf = new StringBuffer();
2276: buf.append("package junit.framework;\n");
2277: buf.append("\n");
2278: buf.append("/**\n");
2279: buf.append(" * Thrown when an assertion failed.\n");
2280: buf.append(" */\n");
2281: buf
2282: .append("public class AssertionFailedError extends Error {\n");
2283: buf.append("\n");
2284: buf.append(" /* Test */\n");
2285: buf
2286: .append(" private static final long serialVersionUID = 1L;\n");
2287: buf.append(" public AssertionFailedError() {\n");
2288: buf.append(" }\n");
2289: buf
2290: .append(" public AssertionFailedError(final String message) {\n");
2291: buf.append(" super(message);\n");
2292: buf.append(" }\n");
2293: buf.append("}");
2294: fExpectedChangesAllTests.put(
2295: "junit.framework.AssertionFailedError.java", buf
2296: .toString());
2297: buf = new StringBuffer();
2298: buf.append("package junit.tests.framework;\n");
2299: buf.append("\n");
2300: buf.append("/**\n");
2301: buf.append(" * Test class used in SuiteTest\n");
2302: buf.append(" */\n");
2303: buf
2304: .append("public class InheritedTestCase extends OneTestCase {\n");
2305: buf.append(" public void test2() {\n");
2306: buf.append(" }\n");
2307: buf.append("}");
2308: fExpectedChangesAllTests.put(
2309: "junit.tests.framework.InheritedTestCase.java", buf
2310: .toString());
2311: buf = new StringBuffer();
2312: buf.append("package junit.samples;\n");
2313: buf.append("\n");
2314: buf.append("import junit.framework.Assert;\n");
2315: buf.append("import junit.framework.Test;\n");
2316: buf.append("import junit.framework.TestCase;\n");
2317: buf.append("import junit.framework.TestSuite;\n");
2318: buf.append("\n");
2319: buf.append("/**\n");
2320: buf.append(" * Some simple tests.\n");
2321: buf.append(" * \n");
2322: buf.append(" */\n");
2323: buf.append("public class SimpleTest extends TestCase {\n");
2324: buf
2325: .append(" public static void main(final String[] args) {\n");
2326: buf
2327: .append(" junit.textui.TestRunner.run(SimpleTest.suite());\n");
2328: buf.append(" }\n");
2329: buf.append(" public static Test suite() {\n");
2330: buf.append("\n");
2331: buf.append(" /*\n");
2332: buf.append(" * the type safe way\n");
2333: buf.append(" * \n");
2334: buf
2335: .append(" * TestSuite suite= new TestSuite(); suite.addTest( new\n");
2336: buf
2337: .append(" * SimpleTest(\"add\") { protected void runTest() { testAdd(); } } );\n");
2338: buf.append(" * \n");
2339: buf
2340: .append(" * suite.addTest( new SimpleTest(\"testDivideByZero\") { protected void\n");
2341: buf
2342: .append(" * runTest() { testDivideByZero(); } } ); return suite;\n");
2343: buf.append(" */\n");
2344: buf.append("\n");
2345: buf.append(" /*\n");
2346: buf.append(" * the dynamic way\n");
2347: buf.append(" */\n");
2348: buf.append(" return new TestSuite(SimpleTest.class);\n");
2349: buf.append(" }\n");
2350: buf.append("\n");
2351: buf.append(" protected int fValue1;\n");
2352: buf.append(" protected int fValue2;\n");
2353: buf.append(" @Override\n");
2354: buf.append(" protected void setUp() {\n");
2355: buf.append(" this.fValue1 = 2;\n");
2356: buf.append(" this.fValue2 = 3;\n");
2357: buf.append(" }\n");
2358: buf.append(" public void testAdd() {\n");
2359: buf
2360: .append(" final double result = this.fValue1 + this.fValue2;\n");
2361: buf.append(" // forced failure result == 5\n");
2362: buf.append(" Assert.assertTrue(result == 6);\n");
2363: buf.append(" }\n");
2364: buf.append(" public void testDivideByZero() {\n");
2365: buf.append(" final int zero = 0;\n");
2366: buf.append(" }\n");
2367: buf.append(" public void testEquals() {\n");
2368: buf.append(" Assert.assertEquals(12, 12);\n");
2369: buf.append(" Assert.assertEquals(12L, 12L);\n");
2370: buf
2371: .append(" Assert.assertEquals(new Long(12), new Long(12));\n");
2372: buf.append("\n");
2373: buf
2374: .append(" Assert.assertEquals(\"Size\", 12, 13); //$NON-NLS-1$\n");
2375: buf
2376: .append(" Assert.assertEquals(\"Capacity\", 12.0, 11.99, 0.0); //$NON-NLS-1$\n");
2377: buf.append(" }\n");
2378: buf.append("}");
2379: fExpectedChangesAllTests.put("junit.samples.SimpleTest.java",
2380: buf.toString());
2381: buf = new StringBuffer();
2382: buf.append("package junit.runner;\n");
2383: buf.append("\n");
2384: buf.append("/**\n");
2385: buf
2386: .append(" * This class defines the current version of JUnit\n");
2387: buf.append(" */\n");
2388: buf.append("public class Version {\n");
2389: buf.append(" public static String id() {\n");
2390: buf.append(" return \"3.8.1\"; //$NON-NLS-1$\n");
2391: buf.append(" }\n");
2392: buf.append("\n");
2393: buf.append(" private Version() {\n");
2394: buf.append(" // don't instantiate\n");
2395: buf.append(" }\n");
2396: buf.append("}\n");
2397: buf.append("");
2398: fExpectedChangesAllTests.put("junit.runner.Version.java", buf
2399: .toString());
2400: buf = new StringBuffer();
2401: buf.append("package junit.tests.runner;\n");
2402: buf.append("\n");
2403: buf.append("import junit.framework.Test;\n");
2404: buf.append("import junit.framework.TestCase;\n");
2405: buf.append("import junit.runner.BaseTestRunner;\n");
2406: buf.append("\n");
2407: buf
2408: .append("public class BaseTestRunnerTest extends TestCase {\n");
2409: buf.append("\n");
2410: buf
2411: .append(" public class MockRunner extends BaseTestRunner {\n");
2412: buf.append(" @Override\n");
2413: buf
2414: .append(" protected void runFailed(final String message) {\n");
2415: buf.append(" }\n");
2416: buf.append("\n");
2417: buf.append(" @Override\n");
2418: buf
2419: .append(" public void testEnded(final String testName) {\n");
2420: buf.append(" }\n");
2421: buf.append("\n");
2422: buf.append(" @Override\n");
2423: buf
2424: .append(" public void testFailed(final int status, final Test test,\n");
2425: buf.append(" final Throwable t) {\n");
2426: buf.append(" }\n");
2427: buf.append("\n");
2428: buf.append(" @Override\n");
2429: buf
2430: .append(" public void testStarted(final String testName) {\n");
2431: buf.append(" }\n");
2432: buf.append(" }\n");
2433: buf.append("\n");
2434: buf.append(" public static class NonStatic {\n");
2435: buf.append(" public Test suite() {\n");
2436: buf.append(" return null;\n");
2437: buf.append(" }\n");
2438: buf.append(" }\n");
2439: buf.append("\n");
2440: buf.append(" public void testInvokeNonStaticSuite() {\n");
2441: buf
2442: .append(" final BaseTestRunner runner = new MockRunner();\n");
2443: buf
2444: .append(" runner.getTest(\"junit.tests.runner.BaseTestRunnerTest$NonStatic\"); // Used\n");
2445: buf
2446: .append(" // to\n");
2447: buf
2448: .append(" // throw\n");
2449: buf
2450: .append(" // NullPointerException\n");
2451: buf
2452: .append(" // //$NON-NLS-1$\n");
2453: buf.append(" }\n");
2454: buf.append("}\n");
2455: buf.append("");
2456: fExpectedChangesAllTests.put(
2457: "junit.tests.runner.BaseTestRunnerTest.java", buf
2458: .toString());
2459: buf = new StringBuffer();
2460: buf.append("package junit.tests;\n");
2461: buf.append("\n");
2462: buf.append("import junit.framework.TestCase;\n");
2463: buf.append("\n");
2464: buf.append("/**\n");
2465: buf
2466: .append(" * A helper test case for testing whether the testing method is run.\n");
2467: buf.append(" */\n");
2468: buf.append("public class WasRun extends TestCase {\n");
2469: buf.append(" public boolean fWasRun = false;\n");
2470: buf.append(" @Override\n");
2471: buf.append(" protected void runTest() {\n");
2472: buf.append(" this.fWasRun = true;\n");
2473: buf.append(" }\n");
2474: buf.append("}");
2475: fExpectedChangesAllTests.put("junit.tests.WasRun.java", buf
2476: .toString());
2477: buf = new StringBuffer();
2478: buf.append("package junit.framework;\n");
2479: buf.append("\n");
2480: buf.append("import java.io.PrintWriter;\n");
2481: buf.append("import java.io.StringWriter;\n");
2482: buf.append("import java.lang.reflect.Constructor;\n");
2483: buf
2484: .append("import java.lang.reflect.InvocationTargetException;\n");
2485: buf.append("import java.lang.reflect.Method;\n");
2486: buf.append("import java.lang.reflect.Modifier;\n");
2487: buf.append("import java.util.Enumeration;\n");
2488: buf.append("import java.util.Vector;\n");
2489: buf.append("\n");
2490: buf.append("/**\n");
2491: buf
2492: .append(" * A <code>TestSuite</code> is a <code>Composite</code> of Tests. It runs a\n");
2493: buf
2494: .append(" * collection of test cases. Here is an example using the dynamic test\n");
2495: buf.append(" * definition.\n");
2496: buf.append(" * \n");
2497: buf.append(" * <pre>\n");
2498: buf.append(" * TestSuite suite = new TestSuite();\n");
2499: buf
2500: .append(" * suite.addTest(new MathTest("testAdd"));\n");
2501: buf
2502: .append(" * suite.addTest(new MathTest("testDivideByZero"));\n");
2503: buf.append(" * </pre>\n");
2504: buf.append(" * \n");
2505: buf
2506: .append(" * Alternatively, a TestSuite can extract the tests to be run automatically. To\n");
2507: buf
2508: .append(" * do so you pass the class of your TestCase class to the TestSuite constructor.\n");
2509: buf.append(" * \n");
2510: buf.append(" * <pre>\n");
2511: buf
2512: .append(" * TestSuite suite = new TestSuite(MathTest.class);\n");
2513: buf.append(" * </pre>\n");
2514: buf.append(" * \n");
2515: buf
2516: .append(" * This constructor creates a suite with all the methods starting with \"test\"\n");
2517: buf.append(" * that take no arguments.\n");
2518: buf.append(" * \n");
2519: buf.append(" * @see Test\n");
2520: buf.append(" */\n");
2521: buf.append("public class TestSuite implements Test {\n");
2522: buf.append("\n");
2523: buf.append(" /**\n");
2524: buf
2525: .append(" * ...as the moon sets over the early morning Merlin, Oregon mountains, our\n");
2526: buf.append(" * intrepid adventurers type...\n");
2527: buf.append(" */\n");
2528: buf
2529: .append(" static public Test createTest(final Class theClass, final String name) {\n");
2530: buf.append(" Constructor constructor;\n");
2531: buf.append(" try {\n");
2532: buf
2533: .append(" constructor = TestSuite.getTestConstructor(theClass);\n");
2534: buf
2535: .append(" } catch (final NoSuchMethodException e) {\n");
2536: buf.append(" return TestSuite\n");
2537: buf
2538: .append(" .warning(\"Class \" + theClass.getName() + \" has no public constructor TestCase(String name) or TestCase()\"); //$NON-NLS-1$ //$NON-NLS-2$\n");
2539: buf.append(" }\n");
2540: buf.append(" Object test;\n");
2541: buf.append(" try {\n");
2542: buf
2543: .append(" if (constructor.getParameterTypes().length == 0) {\n");
2544: buf
2545: .append(" test = constructor.newInstance(new Object[0]);\n");
2546: buf.append(" if (test instanceof TestCase) {\n");
2547: buf
2548: .append(" ((TestCase) test).setName(name);\n");
2549: buf.append(" }\n");
2550: buf.append(" } else {\n");
2551: buf
2552: .append(" test = constructor.newInstance(new Object[]{name});\n");
2553: buf.append(" }\n");
2554: buf
2555: .append(" } catch (final InstantiationException e) {\n");
2556: buf.append(" return (TestSuite\n");
2557: buf
2558: .append(" .warning(\"Cannot instantiate test case: \" + name + \" (\" + TestSuite.exceptionToString(e) + \")\")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\n");
2559: buf
2560: .append(" } catch (final InvocationTargetException e) {\n");
2561: buf.append(" return (TestSuite\n");
2562: buf
2563: .append(" .warning(\"Exception in constructor: \" + name + \" (\" + TestSuite.exceptionToString(e.getTargetException()) + \")\")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\n");
2564: buf
2565: .append(" } catch (final IllegalAccessException e) {\n");
2566: buf.append(" return (TestSuite\n");
2567: buf
2568: .append(" .warning(\"Cannot access test case: \" + name + \" (\" + TestSuite.exceptionToString(e) + \")\")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\n");
2569: buf.append(" }\n");
2570: buf.append(" return (Test) test;\n");
2571: buf.append(" }\n");
2572: buf.append(" /**\n");
2573: buf.append(" * Converts the stack trace into a string\n");
2574: buf.append(" */\n");
2575: buf
2576: .append(" private static String exceptionToString(final Throwable t) {\n");
2577: buf
2578: .append(" final StringWriter stringWriter = new StringWriter();\n");
2579: buf
2580: .append(" final PrintWriter writer = new PrintWriter(stringWriter);\n");
2581: buf.append(" t.printStackTrace(writer);\n");
2582: buf.append(" return stringWriter.toString();\n");
2583: buf.append("\n");
2584: buf.append(" }\n");
2585: buf.append("\n");
2586: buf.append(" /**\n");
2587: buf
2588: .append(" * Gets a constructor which takes a single String as its argument or a no\n");
2589: buf.append(" * arg constructor.\n");
2590: buf.append(" */\n");
2591: buf
2592: .append(" public static Constructor getTestConstructor(final Class theClass)\n");
2593: buf.append(" throws NoSuchMethodException {\n");
2594: buf.append(" final Class[] args = {String.class};\n");
2595: buf.append(" try {\n");
2596: buf
2597: .append(" return theClass.getConstructor(args);\n");
2598: buf
2599: .append(" } catch (final NoSuchMethodException e) {\n");
2600: buf.append(" // fall through\n");
2601: buf.append(" }\n");
2602: buf
2603: .append(" return theClass.getConstructor(new Class[0]);\n");
2604: buf.append(" }\n");
2605: buf.append("\n");
2606: buf.append(" /**\n");
2607: buf
2608: .append(" * Returns a test which will fail and log a warning message.\n");
2609: buf.append(" */\n");
2610: buf
2611: .append(" private static Test warning(final String message) {\n");
2612: buf
2613: .append(" return new TestCase(\"warning\") { //$NON-NLS-1$\n");
2614: buf.append(" @Override\n");
2615: buf.append(" protected void runTest() {\n");
2616: buf.append(" Assert.fail(message);\n");
2617: buf.append(" }\n");
2618: buf.append(" };\n");
2619: buf.append(" }\n");
2620: buf.append("\n");
2621: buf.append(" private String fName;\n");
2622: buf.append("\n");
2623: buf
2624: .append(" private final Vector fTests = new Vector(10);\n");
2625: buf.append("\n");
2626: buf.append(" /**\n");
2627: buf.append(" * Constructs an empty TestSuite.\n");
2628: buf.append(" */\n");
2629: buf.append(" public TestSuite() {\n");
2630: buf.append(" }\n");
2631: buf.append("\n");
2632: buf.append(" /**\n");
2633: buf
2634: .append(" * Constructs a TestSuite from the given class. Adds all the methods\n");
2635: buf
2636: .append(" * starting with \"test\" as test cases to the suite. Parts of this method was\n");
2637: buf
2638: .append(" * written at 2337 meters in the Hüffihütte, Kanton Uri\n");
2639: buf.append(" */\n");
2640: buf.append(" public TestSuite(final Class theClass) {\n");
2641: buf.append(" this.fName = theClass.getName();\n");
2642: buf.append(" try {\n");
2643: buf
2644: .append(" TestSuite.getTestConstructor(theClass); // Avoid generating multiple\n");
2645: buf.append(" // error messages\n");
2646: buf
2647: .append(" } catch (final NoSuchMethodException e) {\n");
2648: buf.append(" this\n");
2649: buf.append(" .addTest(TestSuite\n");
2650: buf
2651: .append(" .warning(\"Class \" + theClass.getName() + \" has no public constructor TestCase(String name) or TestCase()\")); //$NON-NLS-1$ //$NON-NLS-2$\n");
2652: buf.append(" return;\n");
2653: buf.append(" }\n");
2654: buf.append("\n");
2655: buf
2656: .append(" if (!Modifier.isPublic(theClass.getModifiers())) {\n");
2657: buf.append(" this.addTest(TestSuite\n");
2658: buf
2659: .append(" .warning(\"Class \" + theClass.getName() + \" is not public\")); //$NON-NLS-1$ //$NON-NLS-2$\n");
2660: buf.append(" return;\n");
2661: buf.append(" }\n");
2662: buf.append("\n");
2663: buf.append(" Class superClass = theClass;\n");
2664: buf.append(" final Vector names = new Vector();\n");
2665: buf
2666: .append(" while (Test.class.isAssignableFrom(superClass)) {\n");
2667: buf
2668: .append(" final Method[] methods = superClass.getDeclaredMethods();\n");
2669: buf
2670: .append(" for (final Method element : methods) {\n");
2671: buf
2672: .append(" this.addTestMethod(element, names, theClass);\n");
2673: buf.append(" }\n");
2674: buf
2675: .append(" superClass = superClass.getSuperclass();\n");
2676: buf.append(" }\n");
2677: buf.append(" if (this.fTests.size() == 0) {\n");
2678: buf.append(" this.addTest(TestSuite\n");
2679: buf
2680: .append(" .warning(\"No tests found in \" + theClass.getName())); //$NON-NLS-1$\n");
2681: buf.append(" }\n");
2682: buf.append(" }\n");
2683: buf.append("\n");
2684: buf.append(" /**\n");
2685: buf
2686: .append(" * Constructs a TestSuite from the given class with the given name.\n");
2687: buf.append(" * \n");
2688: buf.append(" * @see TestSuite#TestSuite(Class)\n");
2689: buf.append(" */\n");
2690: buf
2691: .append(" public TestSuite(final Class theClass, final String name) {\n");
2692: buf.append(" this(theClass);\n");
2693: buf.append(" this.setName(name);\n");
2694: buf.append(" }\n");
2695: buf.append("\n");
2696: buf.append(" /**\n");
2697: buf.append(" * Constructs an empty TestSuite.\n");
2698: buf.append(" */\n");
2699: buf.append(" public TestSuite(final String name) {\n");
2700: buf.append(" this.setName(name);\n");
2701: buf.append(" }\n");
2702: buf.append("\n");
2703: buf.append(" /**\n");
2704: buf.append(" * Adds a test to the suite.\n");
2705: buf.append(" */\n");
2706: buf.append(" public void addTest(final Test test) {\n");
2707: buf.append(" this.fTests.addElement(test);\n");
2708: buf.append(" }\n");
2709: buf.append("\n");
2710: buf
2711: .append(" private void addTestMethod(final Method m, final Vector names,\n");
2712: buf.append(" final Class theClass) {\n");
2713: buf.append(" final String name = m.getName();\n");
2714: buf.append(" if (names.contains(name)) {\n");
2715: buf.append(" return;\n");
2716: buf.append(" }\n");
2717: buf.append(" if (!this.isPublicTestMethod(m)) {\n");
2718: buf.append(" if (this.isTestMethod(m)) {\n");
2719: buf.append(" this.addTest(TestSuite\n");
2720: buf
2721: .append(" .warning(\"Test method isn't public: \" + m.getName())); //$NON-NLS-1$\n");
2722: buf.append(" }\n");
2723: buf.append(" return;\n");
2724: buf.append(" }\n");
2725: buf.append(" names.addElement(name);\n");
2726: buf
2727: .append(" this.addTest(TestSuite.createTest(theClass, name));\n");
2728: buf.append(" }\n");
2729: buf.append("\n");
2730: buf.append(" /**\n");
2731: buf
2732: .append(" * Adds the tests from the given class to the suite\n");
2733: buf.append(" */\n");
2734: buf
2735: .append(" public void addTestSuite(final Class testClass) {\n");
2736: buf.append(" this.addTest(new TestSuite(testClass));\n");
2737: buf.append(" }\n");
2738: buf.append("\n");
2739: buf.append(" /**\n");
2740: buf
2741: .append(" * Counts the number of test cases that will be run by this test.\n");
2742: buf.append(" */\n");
2743: buf.append(" public int countTestCases() {\n");
2744: buf.append(" int count = 0;\n");
2745: buf
2746: .append(" for (final Enumeration e = this.tests(); e.hasMoreElements();) {\n");
2747: buf
2748: .append(" final Test test = (Test) e.nextElement();\n");
2749: buf
2750: .append(" count = count + test.countTestCases();\n");
2751: buf.append(" }\n");
2752: buf.append(" return count;\n");
2753: buf.append(" }\n");
2754: buf.append("\n");
2755: buf.append(" /**\n");
2756: buf
2757: .append(" * Returns the name of the suite. Not all test suites have a name and this\n");
2758: buf.append(" * method can return null.\n");
2759: buf.append(" */\n");
2760: buf.append(" public String getName() {\n");
2761: buf.append(" return this.fName;\n");
2762: buf.append(" }\n");
2763: buf.append("\n");
2764: buf
2765: .append(" private boolean isPublicTestMethod(final Method m) {\n");
2766: buf
2767: .append(" return this.isTestMethod(m) && Modifier.isPublic(m.getModifiers());\n");
2768: buf.append(" }\n");
2769: buf.append("\n");
2770: buf
2771: .append(" private boolean isTestMethod(final Method m) {\n");
2772: buf.append(" final String name = m.getName();\n");
2773: buf
2774: .append(" final Class[] parameters = m.getParameterTypes();\n");
2775: buf
2776: .append(" final Class returnType = m.getReturnType();\n");
2777: buf.append(" return (parameters.length == 0)\n");
2778: buf
2779: .append(" && name.startsWith(\"test\") && returnType.equals(Void.TYPE); //$NON-NLS-1$\n");
2780: buf.append(" }\n");
2781: buf.append("\n");
2782: buf.append(" /**\n");
2783: buf
2784: .append(" * Runs the tests and collects their result in a TestResult.\n");
2785: buf.append(" */\n");
2786: buf.append(" public void run(final TestResult result) {\n");
2787: buf
2788: .append(" for (final Enumeration e = this.tests(); e.hasMoreElements();) {\n");
2789: buf.append(" if (result.shouldStop()) {\n");
2790: buf.append(" break;\n");
2791: buf.append(" }\n");
2792: buf
2793: .append(" final Test test = (Test) e.nextElement();\n");
2794: buf.append(" this.runTest(test, result);\n");
2795: buf.append(" }\n");
2796: buf.append(" }\n");
2797: buf.append("\n");
2798: buf
2799: .append(" public void runTest(final Test test, final TestResult result) {\n");
2800: buf.append(" test.run(result);\n");
2801: buf.append(" }\n");
2802: buf.append("\n");
2803: buf.append(" /**\n");
2804: buf.append(" * Sets the name of the suite.\n");
2805: buf.append(" * \n");
2806: buf.append(" * @param name\n");
2807: buf.append(" * The name to set\n");
2808: buf.append(" */\n");
2809: buf.append(" public void setName(final String name) {\n");
2810: buf.append(" this.fName = name;\n");
2811: buf.append(" }\n");
2812: buf.append("\n");
2813: buf.append(" /**\n");
2814: buf.append(" * Returns the test at the given index\n");
2815: buf.append(" */\n");
2816: buf.append(" public Test testAt(final int index) {\n");
2817: buf
2818: .append(" return (Test) this.fTests.elementAt(index);\n");
2819: buf.append(" }\n");
2820: buf.append("\n");
2821: buf.append(" /**\n");
2822: buf
2823: .append(" * Returns the number of tests in this suite\n");
2824: buf.append(" */\n");
2825: buf.append(" public int testCount() {\n");
2826: buf.append(" return this.fTests.size();\n");
2827: buf.append(" }\n");
2828: buf.append("\n");
2829: buf.append(" /**\n");
2830: buf.append(" * Returns the tests as an enumeration\n");
2831: buf.append(" */\n");
2832: buf.append(" public Enumeration tests() {\n");
2833: buf.append(" return this.fTests.elements();\n");
2834: buf.append(" }\n");
2835: buf.append("\n");
2836: buf.append(" /**\n");
2837: buf.append(" */\n");
2838: buf.append(" @Override\n");
2839: buf.append(" public String toString() {\n");
2840: buf.append(" if (this.getName() != null) {\n");
2841: buf.append(" return this.getName();\n");
2842: buf.append(" }\n");
2843: buf.append(" return super.toString();\n");
2844: buf.append(" }\n");
2845: buf.append("}");
2846: fExpectedChangesAllTests.put("junit.framework.TestSuite.java",
2847: buf.toString());
2848: buf = new StringBuffer();
2849: buf.append("package junit.extensions;\n");
2850: buf.append("\n");
2851: buf.append("import junit.framework.Assert;\n");
2852: buf.append("import junit.framework.TestCase;\n");
2853: buf.append("\n");
2854: buf.append("/**\n");
2855: buf
2856: .append(" * A TestCase that expects an Exception of class fExpected to be thrown. The\n");
2857: buf
2858: .append(" * other way to check that an expected exception is thrown is:\n");
2859: buf.append(" * \n");
2860: buf.append(" * <pre>\n");
2861: buf.append(" * try {\n");
2862: buf.append(" * shouldThrow();\n");
2863: buf.append(" * } catch (SpecialException e) {\n");
2864: buf.append(" * return;\n");
2865: buf.append(" * }\n");
2866: buf.append(" * fail("Expected SpecialException");\n");
2867: buf.append(" * </pre>\n");
2868: buf.append(" * \n");
2869: buf
2870: .append(" * To use ExceptionTestCase, create a TestCase like:\n");
2871: buf.append(" * \n");
2872: buf.append(" * <pre>\n");
2873: buf
2874: .append(" * new ExceptionTestCase("testShouldThrow", SpecialException.class);\n");
2875: buf.append(" * </pre>\n");
2876: buf.append(" */\n");
2877: buf
2878: .append("public class ExceptionTestCase extends TestCase {\n");
2879: buf.append(" Class fExpected;\n");
2880: buf.append("\n");
2881: buf
2882: .append(" public ExceptionTestCase(final String name, final Class exception) {\n");
2883: buf.append(" super(name);\n");
2884: buf.append(" this.fExpected = exception;\n");
2885: buf.append(" }\n");
2886: buf.append(" /**\n");
2887: buf
2888: .append(" * Execute the test method expecting that an Exception of class fExpected or\n");
2889: buf.append(" * one of its subclasses will be thrown\n");
2890: buf.append(" */\n");
2891: buf.append(" @Override\n");
2892: buf.append(" protected void runTest() throws Throwable {\n");
2893: buf.append(" try {\n");
2894: buf.append(" super.runTest();\n");
2895: buf.append(" } catch (final Exception e) {\n");
2896: buf
2897: .append(" if (this.fExpected.isAssignableFrom(e.getClass())) {\n");
2898: buf.append(" return;\n");
2899: buf.append(" } else {\n");
2900: buf.append(" throw e;\n");
2901: buf.append(" }\n");
2902: buf.append(" }\n");
2903: buf
2904: .append(" Assert.fail(\"Expected exception \" + this.fExpected); //$NON-NLS-1$\n");
2905: buf.append(" }\n");
2906: buf.append("}");
2907: fExpectedChangesAllTests.put(
2908: "junit.extensions.ExceptionTestCase.java", buf
2909: .toString());
2910: buf = new StringBuffer();
2911: buf.append("package junit.framework;\n");
2912: buf.append("\n");
2913: buf.append("/**\n");
2914: buf
2915: .append(" * A set of assert methods. Messages are only displayed when an assert fails.\n");
2916: buf.append(" */\n");
2917: buf.append("\n");
2918: buf.append("public class Assert {\n");
2919: buf.append(" /**\n");
2920: buf.append(" * Asserts that two booleans are equal.\n");
2921: buf.append(" */\n");
2922: buf
2923: .append(" static public void assertEquals(final boolean expected, final boolean actual) {\n");
2924: buf
2925: .append(" Assert.assertEquals(null, expected, actual);\n");
2926: buf.append(" }\n");
2927: buf.append("\n");
2928: buf.append(" /**\n");
2929: buf.append(" * Asserts that two bytes are equal.\n");
2930: buf.append(" */\n");
2931: buf
2932: .append(" static public void assertEquals(final byte expected, final byte actual) {\n");
2933: buf
2934: .append(" Assert.assertEquals(null, expected, actual);\n");
2935: buf.append(" }\n");
2936: buf.append(" /**\n");
2937: buf.append(" * Asserts that two chars are equal.\n");
2938: buf.append(" */\n");
2939: buf
2940: .append(" static public void assertEquals(final char expected, final char actual) {\n");
2941: buf
2942: .append(" Assert.assertEquals(null, expected, actual);\n");
2943: buf.append(" }\n");
2944: buf.append(" /**\n");
2945: buf
2946: .append(" * Asserts that two doubles are equal concerning a delta. If the expected\n");
2947: buf
2948: .append(" * value is infinity then the delta value is ignored.\n");
2949: buf.append(" */\n");
2950: buf
2951: .append(" static public void assertEquals(final double expected, final double actual,\n");
2952: buf.append(" final double delta) {\n");
2953: buf
2954: .append(" Assert.assertEquals(null, expected, actual, delta);\n");
2955: buf.append(" }\n");
2956: buf.append(" /**\n");
2957: buf
2958: .append(" * Asserts that two floats are equal concerning a delta. If the expected\n");
2959: buf
2960: .append(" * value is infinity then the delta value is ignored.\n");
2961: buf.append(" */\n");
2962: buf
2963: .append(" static public void assertEquals(final float expected, final float actual,\n");
2964: buf.append(" final float delta) {\n");
2965: buf
2966: .append(" Assert.assertEquals(null, expected, actual, delta);\n");
2967: buf.append(" }\n");
2968: buf.append(" /**\n");
2969: buf.append(" * Asserts that two ints are equal.\n");
2970: buf.append(" */\n");
2971: buf
2972: .append(" static public void assertEquals(final int expected, final int actual) {\n");
2973: buf
2974: .append(" Assert.assertEquals(null, expected, actual);\n");
2975: buf.append(" }\n");
2976: buf.append(" /**\n");
2977: buf.append(" * Asserts that two longs are equal.\n");
2978: buf.append(" */\n");
2979: buf
2980: .append(" static public void assertEquals(final long expected, final long actual) {\n");
2981: buf
2982: .append(" Assert.assertEquals(null, expected, actual);\n");
2983: buf.append(" }\n");
2984: buf.append(" /**\n");
2985: buf
2986: .append(" * Asserts that two objects are equal. If they are not an\n");
2987: buf.append(" * AssertionFailedError is thrown.\n");
2988: buf.append(" */\n");
2989: buf
2990: .append(" static public void assertEquals(final Object expected, final Object actual) {\n");
2991: buf
2992: .append(" Assert.assertEquals(null, expected, actual);\n");
2993: buf.append(" }\n");
2994: buf.append(" /**\n");
2995: buf.append(" * Asserts that two shorts are equal.\n");
2996: buf.append(" */\n");
2997: buf
2998: .append(" static public void assertEquals(final short expected, final short actual) {\n");
2999: buf
3000: .append(" Assert.assertEquals(null, expected, actual);\n");
3001: buf.append(" }\n");
3002: buf.append(" /**\n");
3003: buf
3004: .append(" * Asserts that two booleans are equal. If they are not an\n");
3005: buf
3006: .append(" * AssertionFailedError is thrown with the given message.\n");
3007: buf.append(" */\n");
3008: buf
3009: .append(" static public void assertEquals(final String message,\n");
3010: buf
3011: .append(" final boolean expected, final boolean actual) {\n");
3012: buf.append(" Assert\n");
3013: buf
3014: .append(" .assertEquals(message, new Boolean(expected), new Boolean(\n");
3015: buf.append(" actual));\n");
3016: buf.append(" }\n");
3017: buf.append(" /**\n");
3018: buf
3019: .append(" * Asserts that two bytes are equal. If they are not an AssertionFailedError\n");
3020: buf.append(" * is thrown with the given message.\n");
3021: buf.append(" */\n");
3022: buf
3023: .append(" static public void assertEquals(final String message, final byte expected,\n");
3024: buf.append(" final byte actual) {\n");
3025: buf
3026: .append(" Assert.assertEquals(message, new Byte(expected), new Byte(actual));\n");
3027: buf.append(" }\n");
3028: buf.append(" /**\n");
3029: buf
3030: .append(" * Asserts that two chars are equal. If they are not an AssertionFailedError\n");
3031: buf.append(" * is thrown with the given message.\n");
3032: buf.append(" */\n");
3033: buf
3034: .append(" static public void assertEquals(final String message, final char expected,\n");
3035: buf.append(" final char actual) {\n");
3036: buf
3037: .append(" Assert.assertEquals(message, new Character(expected), new Character(\n");
3038: buf.append(" actual));\n");
3039: buf.append(" }\n");
3040: buf.append(" /**\n");
3041: buf
3042: .append(" * Asserts that two doubles are equal concerning a delta. If they are not an\n");
3043: buf
3044: .append(" * AssertionFailedError is thrown with the given message. If the expected\n");
3045: buf
3046: .append(" * value is infinity then the delta value is ignored.\n");
3047: buf.append(" */\n");
3048: buf
3049: .append(" static public void assertEquals(final String message,\n");
3050: buf
3051: .append(" final double expected, final double actual, final double delta) {\n");
3052: buf
3053: .append(" // handle infinity specially since subtracting to infinite values gives\n");
3054: buf.append(" // NaN and the\n");
3055: buf.append(" // the following test fails\n");
3056: buf.append(" if (Double.isInfinite(expected)) {\n");
3057: buf.append(" if (!(expected == actual)) {\n");
3058: buf
3059: .append(" Assert.failNotEquals(message, new Double(expected), new Double(\n");
3060: buf.append(" actual));\n");
3061: buf.append(" }\n");
3062: buf
3063: .append(" } else if (!(Math.abs(expected - actual) <= delta)) {\n");
3064: buf
3065: .append(" Assert.failNotEquals(message, new Double(expected), new Double(\n");
3066: buf.append(" actual));\n");
3067: buf.append(" }\n");
3068: buf.append(" }\n");
3069: buf.append(" /**\n");
3070: buf
3071: .append(" * Asserts that two floats are equal concerning a delta. If they are not an\n");
3072: buf
3073: .append(" * AssertionFailedError is thrown with the given message. If the expected\n");
3074: buf
3075: .append(" * value is infinity then the delta value is ignored.\n");
3076: buf.append(" */\n");
3077: buf
3078: .append(" static public void assertEquals(final String message, final float expected,\n");
3079: buf
3080: .append(" final float actual, final float delta) {\n");
3081: buf
3082: .append(" // handle infinity specially since subtracting to infinite values gives\n");
3083: buf.append(" // NaN and the\n");
3084: buf.append(" // the following test fails\n");
3085: buf.append(" if (Float.isInfinite(expected)) {\n");
3086: buf.append(" if (!(expected == actual)) {\n");
3087: buf
3088: .append(" Assert.failNotEquals(message, new Float(expected), new Float(\n");
3089: buf.append(" actual));\n");
3090: buf.append(" }\n");
3091: buf
3092: .append(" } else if (!(Math.abs(expected - actual) <= delta)) {\n");
3093: buf
3094: .append(" Assert.failNotEquals(message, new Float(expected),\n");
3095: buf.append(" new Float(actual));\n");
3096: buf.append(" }\n");
3097: buf.append(" }\n");
3098: buf.append(" /**\n");
3099: buf
3100: .append(" * Asserts that two ints are equal. If they are not an AssertionFailedError\n");
3101: buf.append(" * is thrown with the given message.\n");
3102: buf.append(" */\n");
3103: buf
3104: .append(" static public void assertEquals(final String message, final int expected,\n");
3105: buf.append(" final int actual) {\n");
3106: buf.append(" Assert\n");
3107: buf
3108: .append(" .assertEquals(message, new Integer(expected), new Integer(\n");
3109: buf.append(" actual));\n");
3110: buf.append(" }\n");
3111: buf.append(" /**\n");
3112: buf
3113: .append(" * Asserts that two longs are equal. If they are not an AssertionFailedError\n");
3114: buf.append(" * is thrown with the given message.\n");
3115: buf.append(" */\n");
3116: buf
3117: .append(" static public void assertEquals(final String message, final long expected,\n");
3118: buf.append(" final long actual) {\n");
3119: buf
3120: .append(" Assert.assertEquals(message, new Long(expected), new Long(actual));\n");
3121: buf.append(" }\n");
3122: buf.append(" /**\n");
3123: buf
3124: .append(" * Asserts that two objects are equal. If they are not an\n");
3125: buf
3126: .append(" * AssertionFailedError is thrown with the given message.\n");
3127: buf.append(" */\n");
3128: buf
3129: .append(" static public void assertEquals(final String message,\n");
3130: buf
3131: .append(" final Object expected, final Object actual) {\n");
3132: buf
3133: .append(" if ((expected == null) && (actual == null)) {\n");
3134: buf.append(" return;\n");
3135: buf.append(" }\n");
3136: buf
3137: .append(" if ((expected != null) && expected.equals(actual)) {\n");
3138: buf.append(" return;\n");
3139: buf.append(" }\n");
3140: buf
3141: .append(" Assert.failNotEquals(message, expected, actual);\n");
3142: buf.append(" }\n");
3143: buf.append(" /**\n");
3144: buf
3145: .append(" * Asserts that two shorts are equal. If they are not an\n");
3146: buf
3147: .append(" * AssertionFailedError is thrown with the given message.\n");
3148: buf.append(" */\n");
3149: buf
3150: .append(" static public void assertEquals(final String message, final short expected,\n");
3151: buf.append(" final short actual) {\n");
3152: buf
3153: .append(" Assert.assertEquals(message, new Short(expected), new Short(actual));\n");
3154: buf.append(" }\n");
3155: buf.append(" /**\n");
3156: buf.append(" * Asserts that two Strings are equal.\n");
3157: buf.append(" */\n");
3158: buf
3159: .append(" static public void assertEquals(final String expected, final String actual) {\n");
3160: buf
3161: .append(" Assert.assertEquals(null, expected, actual);\n");
3162: buf.append(" }\n");
3163: buf.append(" /**\n");
3164: buf.append(" * Asserts that two Strings are equal.\n");
3165: buf.append(" */\n");
3166: buf
3167: .append(" static public void assertEquals(final String message,\n");
3168: buf
3169: .append(" final String expected, final String actual) {\n");
3170: buf
3171: .append(" if ((expected == null) && (actual == null)) {\n");
3172: buf.append(" return;\n");
3173: buf.append(" }\n");
3174: buf
3175: .append(" if ((expected != null) && expected.equals(actual)) {\n");
3176: buf.append(" return;\n");
3177: buf.append(" }\n");
3178: buf
3179: .append(" throw new ComparisonFailure(message, expected, actual);\n");
3180: buf.append(" }\n");
3181: buf.append(" /**\n");
3182: buf
3183: .append(" * Asserts that a condition is false. If it isn't it throws an\n");
3184: buf.append(" * AssertionFailedError.\n");
3185: buf.append(" */\n");
3186: buf
3187: .append(" static public void assertFalse(final boolean condition) {\n");
3188: buf.append(" Assert.assertFalse(null, condition);\n");
3189: buf.append(" }\n");
3190: buf.append(" /**\n");
3191: buf
3192: .append(" * Asserts that a condition is false. If it isn't it throws an\n");
3193: buf
3194: .append(" * AssertionFailedError with the given message.\n");
3195: buf.append(" */\n");
3196: buf
3197: .append(" static public void assertFalse(final String message, final boolean condition) {\n");
3198: buf.append(" Assert.assertTrue(message, !condition);\n");
3199: buf.append(" }\n");
3200: buf.append(" /**\n");
3201: buf.append(" * Asserts that an object isn't null.\n");
3202: buf.append(" */\n");
3203: buf
3204: .append(" static public void assertNotNull(final Object object) {\n");
3205: buf.append(" Assert.assertNotNull(null, object);\n");
3206: buf.append(" }\n");
3207: buf.append(" /**\n");
3208: buf
3209: .append(" * Asserts that an object isn't null. If it is an AssertionFailedError is\n");
3210: buf.append(" * thrown with the given message.\n");
3211: buf.append(" */\n");
3212: buf
3213: .append(" static public void assertNotNull(final String message, final Object object) {\n");
3214: buf
3215: .append(" Assert.assertTrue(message, object != null);\n");
3216: buf.append(" }\n");
3217: buf.append(" /**\n");
3218: buf
3219: .append(" * Asserts that two objects refer to the same object. If they are not the\n");
3220: buf.append(" * same an AssertionFailedError is thrown.\n");
3221: buf.append(" */\n");
3222: buf
3223: .append(" static public void assertNotSame(final Object expected, final Object actual) {\n");
3224: buf
3225: .append(" Assert.assertNotSame(null, expected, actual);\n");
3226: buf.append(" }\n");
3227: buf.append(" /**\n");
3228: buf
3229: .append(" * Asserts that two objects refer to the same object. If they are not an\n");
3230: buf
3231: .append(" * AssertionFailedError is thrown with the given message.\n");
3232: buf.append(" */\n");
3233: buf
3234: .append(" static public void assertNotSame(final String message,\n");
3235: buf
3236: .append(" final Object expected, final Object actual) {\n");
3237: buf.append(" if (expected == actual) {\n");
3238: buf.append(" Assert.failSame(message);\n");
3239: buf.append(" }\n");
3240: buf.append(" }\n");
3241: buf.append(" /**\n");
3242: buf.append(" * Asserts that an object is null.\n");
3243: buf.append(" */\n");
3244: buf
3245: .append(" static public void assertNull(final Object object) {\n");
3246: buf.append(" Assert.assertNull(null, object);\n");
3247: buf.append(" }\n");
3248: buf.append(" /**\n");
3249: buf
3250: .append(" * Asserts that an object is null. If it is not an AssertionFailedError is\n");
3251: buf.append(" * thrown with the given message.\n");
3252: buf.append(" */\n");
3253: buf
3254: .append(" static public void assertNull(final String message, final Object object) {\n");
3255: buf
3256: .append(" Assert.assertTrue(message, object == null);\n");
3257: buf.append(" }\n");
3258: buf.append(" /**\n");
3259: buf
3260: .append(" * Asserts that two objects refer to the same object. If they are not the\n");
3261: buf.append(" * same an AssertionFailedError is thrown.\n");
3262: buf.append(" */\n");
3263: buf
3264: .append(" static public void assertSame(final Object expected, final Object actual) {\n");
3265: buf
3266: .append(" Assert.assertSame(null, expected, actual);\n");
3267: buf.append(" }\n");
3268: buf.append(" /**\n");
3269: buf
3270: .append(" * Asserts that two objects refer to the same object. If they are not an\n");
3271: buf
3272: .append(" * AssertionFailedError is thrown with the given message.\n");
3273: buf.append(" */\n");
3274: buf
3275: .append(" static public void assertSame(final String message, final Object expected,\n");
3276: buf.append(" final Object actual) {\n");
3277: buf.append(" if (expected == actual) {\n");
3278: buf.append(" return;\n");
3279: buf.append(" }\n");
3280: buf
3281: .append(" Assert.failNotSame(message, expected, actual);\n");
3282: buf.append(" }\n");
3283: buf.append(" /**\n");
3284: buf
3285: .append(" * Asserts that a condition is true. If it isn't it throws an\n");
3286: buf.append(" * AssertionFailedError.\n");
3287: buf.append(" */\n");
3288: buf
3289: .append(" static public void assertTrue(final boolean condition) {\n");
3290: buf.append(" Assert.assertTrue(null, condition);\n");
3291: buf.append(" }\n");
3292: buf.append(" /**\n");
3293: buf
3294: .append(" * Asserts that a condition is true. If it isn't it throws an\n");
3295: buf
3296: .append(" * AssertionFailedError with the given message.\n");
3297: buf.append(" */\n");
3298: buf
3299: .append(" static public void assertTrue(final String message, final boolean condition) {\n");
3300: buf.append(" if (!condition) {\n");
3301: buf.append(" Assert.fail(message);\n");
3302: buf.append(" }\n");
3303: buf.append(" }\n");
3304: buf.append(" /**\n");
3305: buf.append(" * Fails a test with no message.\n");
3306: buf.append(" */\n");
3307: buf.append(" static public void fail() {\n");
3308: buf.append(" Assert.fail(null);\n");
3309: buf.append(" }\n");
3310: buf.append(" /**\n");
3311: buf.append(" * Fails a test with the given message.\n");
3312: buf.append(" */\n");
3313: buf
3314: .append(" static public void fail(final String message) {\n");
3315: buf
3316: .append(" throw new AssertionFailedError(message);\n");
3317: buf.append(" }\n");
3318: buf
3319: .append(" static private void failNotEquals(final String message,\n");
3320: buf
3321: .append(" final Object expected, final Object actual) {\n");
3322: buf
3323: .append(" Assert.fail(Assert.format(message, expected, actual));\n");
3324: buf.append(" }\n");
3325: buf.append("\n");
3326: buf
3327: .append(" static private void failNotSame(final String message,\n");
3328: buf
3329: .append(" final Object expected, final Object actual) {\n");
3330: buf.append(" String formatted = \"\"; //$NON-NLS-1$\n");
3331: buf.append(" if (message != null) {\n");
3332: buf
3333: .append(" formatted = message + \" \"; //$NON-NLS-1$\n");
3334: buf.append(" }\n");
3335: buf.append(" Assert.fail(formatted\n");
3336: buf
3337: .append(" + \"expected same:<\" + expected + \"> was not:<\" + actual + \">\"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\n");
3338: buf.append(" }\n");
3339: buf.append("\n");
3340: buf
3341: .append(" static private void failSame(final String message) {\n");
3342: buf.append(" String formatted = \"\"; //$NON-NLS-1$\n");
3343: buf.append(" if (message != null) {\n");
3344: buf
3345: .append(" formatted = message + \" \"; //$NON-NLS-1$\n");
3346: buf.append(" }\n");
3347: buf
3348: .append(" Assert.fail(formatted + \"expected not same\"); //$NON-NLS-1$\n");
3349: buf.append(" }\n");
3350: buf.append("\n");
3351: buf
3352: .append(" static String format(final String message, final Object expected,\n");
3353: buf.append(" final Object actual) {\n");
3354: buf.append(" String formatted = \"\"; //$NON-NLS-1$\n");
3355: buf.append(" if (message != null) {\n");
3356: buf
3357: .append(" formatted = message + \" \"; //$NON-NLS-1$\n");
3358: buf.append(" }\n");
3359: buf.append(" return formatted\n");
3360: buf
3361: .append(" + \"expected:<\" + expected + \"> but was:<\" + actual + \">\"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\n");
3362: buf.append(" }\n");
3363: buf.append("\n");
3364: buf.append(" /**\n");
3365: buf
3366: .append(" * Protect constructor since it is a static only class\n");
3367: buf.append(" */\n");
3368: buf.append(" protected Assert() {\n");
3369: buf.append(" }\n");
3370: buf.append("}");
3371: fExpectedChangesAllTests.put("junit.framework.Assert.java", buf
3372: .toString());
3373: buf = new StringBuffer();
3374: buf.append("package junit.runner;\n");
3375: buf.append("\n");
3376: buf.append("import java.io.File;\n");
3377: buf.append("import java.util.Enumeration;\n");
3378: buf.append("import java.util.Hashtable;\n");
3379: buf.append("import java.util.StringTokenizer;\n");
3380: buf.append("import java.util.Vector;\n");
3381: buf.append("\n");
3382: buf.append("/**\n");
3383: buf
3384: .append(" * An implementation of a TestCollector that consults the class path. It\n");
3385: buf
3386: .append(" * considers all classes on the class path excluding classes in JARs. It leaves\n");
3387: buf
3388: .append(" * it up to subclasses to decide whether a class is a runnable Test.\n");
3389: buf.append(" * \n");
3390: buf.append(" * @see TestCollector\n");
3391: buf.append(" */\n");
3392: buf
3393: .append("public abstract class ClassPathTestCollector implements TestCollector {\n");
3394: buf.append("\n");
3395: buf
3396: .append(" static final int SUFFIX_LENGTH = \".class\".length(); //$NON-NLS-1$\n");
3397: buf.append("\n");
3398: buf.append(" public ClassPathTestCollector() {\n");
3399: buf.append(" }\n");
3400: buf.append("\n");
3401: buf
3402: .append(" protected String classNameFromFile(final String classFileName) {\n");
3403: buf.append(" // convert /a/b.class to a.b\n");
3404: buf
3405: .append(" final String s = classFileName.substring(0, classFileName.length()\n");
3406: buf
3407: .append(" - ClassPathTestCollector.SUFFIX_LENGTH);\n");
3408: buf
3409: .append(" final String s2 = s.replace(File.separatorChar, '.');\n");
3410: buf.append(" if (s2.startsWith(\".\")) {\n");
3411: buf.append(" return s2.substring(1);\n");
3412: buf.append(" }\n");
3413: buf.append(" return s2;\n");
3414: buf.append(" }\n");
3415: buf.append("\n");
3416: buf
3417: .append(" public Hashtable collectFilesInPath(final String classPath) {\n");
3418: buf
3419: .append(" final Hashtable result = this.collectFilesInRoots(this\n");
3420: buf.append(" .splitClassPath(classPath));\n");
3421: buf.append(" return result;\n");
3422: buf.append(" }\n");
3423: buf.append("\n");
3424: buf
3425: .append(" Hashtable collectFilesInRoots(final Vector roots) {\n");
3426: buf
3427: .append(" final Hashtable result = new Hashtable(100);\n");
3428: buf.append(" final Enumeration e = roots.elements();\n");
3429: buf.append(" while (e.hasMoreElements()) {\n");
3430: buf
3431: .append(" this.gatherFiles(new File((String) e.nextElement()), \"\", result); //$NON-NLS-1$\n");
3432: buf.append(" }\n");
3433: buf.append(" return result;\n");
3434: buf.append(" }\n");
3435: buf.append("\n");
3436: buf.append(" public Enumeration collectTests() {\n");
3437: buf
3438: .append(" final String classPath = System.getProperty(\"java.class.path\"); //$NON-NLS-1$\n");
3439: buf
3440: .append(" final Hashtable result = this.collectFilesInPath(classPath);\n");
3441: buf.append(" return result.elements();\n");
3442: buf.append(" }\n");
3443: buf.append("\n");
3444: buf
3445: .append(" void gatherFiles(final File classRoot, final String classFileName,\n");
3446: buf.append(" final Hashtable result) {\n");
3447: buf
3448: .append(" final File thisRoot = new File(classRoot, classFileName);\n");
3449: buf.append(" if (thisRoot.isFile()) {\n");
3450: buf
3451: .append(" if (this.isTestClass(classFileName)) {\n");
3452: buf
3453: .append(" final String className = this.classNameFromFile(classFileName);\n");
3454: buf
3455: .append(" result.put(className, className);\n");
3456: buf.append(" }\n");
3457: buf.append(" return;\n");
3458: buf.append(" }\n");
3459: buf
3460: .append(" final String[] contents = thisRoot.list();\n");
3461: buf.append(" if (contents != null) {\n");
3462: buf
3463: .append(" for (final String element : contents) {\n");
3464: buf
3465: .append(" this.gatherFiles(classRoot, classFileName + File.separatorChar\n");
3466: buf.append(" + element, result);\n");
3467: buf.append(" }\n");
3468: buf.append(" }\n");
3469: buf.append(" }\n");
3470: buf.append("\n");
3471: buf
3472: .append(" protected boolean isTestClass(final String classFileName) {\n");
3473: buf
3474: .append(" return classFileName.endsWith(\".class\") && //$NON-NLS-1$\n");
3475: buf
3476: .append(" (classFileName.indexOf('$') < 0)\n");
3477: buf
3478: .append(" && (classFileName.indexOf(\"Test\") > 0); //$NON-NLS-1$\n");
3479: buf.append(" }\n");
3480: buf.append("\n");
3481: buf
3482: .append(" Vector splitClassPath(final String classPath) {\n");
3483: buf.append(" final Vector result = new Vector();\n");
3484: buf
3485: .append(" final String separator = System.getProperty(\"path.separator\"); //$NON-NLS-1$\n");
3486: buf
3487: .append(" final StringTokenizer tokenizer = new StringTokenizer(classPath,\n");
3488: buf.append(" separator);\n");
3489: buf.append(" while (tokenizer.hasMoreTokens()) {\n");
3490: buf
3491: .append(" result.addElement(tokenizer.nextToken());\n");
3492: buf.append(" }\n");
3493: buf.append(" return result;\n");
3494: buf.append(" }\n");
3495: buf.append("}\n");
3496: buf.append("");
3497: fExpectedChangesAllTests.put(
3498: "junit.runner.ClassPathTestCollector.java", buf
3499: .toString());
3500: buf = new StringBuffer();
3501: buf.append("package junit.framework;\n");
3502: buf.append("\n");
3503: buf.append("/**\n");
3504: buf.append(" * A Listener for test progress\n");
3505: buf.append(" */\n");
3506: buf.append("public interface TestListener {\n");
3507: buf.append(" /**\n");
3508: buf.append(" * An error occurred.\n");
3509: buf.append(" */\n");
3510: buf
3511: .append(" public void addError(Test test, Throwable t);\n");
3512: buf.append(" /**\n");
3513: buf.append(" * A failure occurred.\n");
3514: buf.append(" */\n");
3515: buf
3516: .append(" public void addFailure(Test test, AssertionFailedError t);\n");
3517: buf.append(" /**\n");
3518: buf.append(" * A test ended.\n");
3519: buf.append(" */\n");
3520: buf.append(" public void endTest(Test test);\n");
3521: buf.append(" /**\n");
3522: buf.append(" * A test started.\n");
3523: buf.append(" */\n");
3524: buf.append(" public void startTest(Test test);\n");
3525: buf.append("}");
3526: fExpectedChangesAllTests.put(
3527: "junit.framework.TestListener.java", buf.toString());
3528: buf = new StringBuffer();
3529: buf.append("package junit.tests.extensions;\n");
3530: buf.append("\n");
3531: buf.append("import junit.extensions.ActiveTestSuite;\n");
3532: buf.append("import junit.extensions.RepeatedTest;\n");
3533: buf.append("import junit.framework.Assert;\n");
3534: buf.append("import junit.framework.Test;\n");
3535: buf.append("import junit.framework.TestCase;\n");
3536: buf.append("import junit.framework.TestResult;\n");
3537: buf.append("\n");
3538: buf.append("/**\n");
3539: buf.append(" * Testing the ActiveTest support\n");
3540: buf.append(" */\n");
3541: buf.append("\n");
3542: buf.append("public class ActiveTestTest extends TestCase {\n");
3543: buf.append("\n");
3544: buf
3545: .append(" public static class SuccessTest extends TestCase {\n");
3546: buf.append(" @Override\n");
3547: buf.append(" public void runTest() {\n");
3548: buf.append(" }\n");
3549: buf.append(" }\n");
3550: buf.append("\n");
3551: buf.append(" ActiveTestSuite createActiveTestSuite() {\n");
3552: buf
3553: .append(" final ActiveTestSuite suite = new ActiveTestSuite();\n");
3554: buf.append(" for (int i = 0; i < 100; i++) {\n");
3555: buf.append(" suite.addTest(new SuccessTest());\n");
3556: buf.append(" }\n");
3557: buf.append(" return suite;\n");
3558: buf.append(" }\n");
3559: buf.append("\n");
3560: buf.append(" public void testActiveRepeatedTest() {\n");
3561: buf
3562: .append(" final Test test = new RepeatedTest(this.createActiveTestSuite(), 5);\n");
3563: buf
3564: .append(" final TestResult result = new TestResult();\n");
3565: buf.append(" test.run(result);\n");
3566: buf
3567: .append(" Assert.assertEquals(500, result.runCount());\n");
3568: buf
3569: .append(" Assert.assertEquals(0, result.failureCount());\n");
3570: buf
3571: .append(" Assert.assertEquals(0, result.errorCount());\n");
3572: buf.append(" }\n");
3573: buf.append("\n");
3574: buf.append(" public void testActiveRepeatedTest0() {\n");
3575: buf
3576: .append(" final Test test = new RepeatedTest(this.createActiveTestSuite(), 0);\n");
3577: buf
3578: .append(" final TestResult result = new TestResult();\n");
3579: buf.append(" test.run(result);\n");
3580: buf
3581: .append(" Assert.assertEquals(0, result.runCount());\n");
3582: buf
3583: .append(" Assert.assertEquals(0, result.failureCount());\n");
3584: buf
3585: .append(" Assert.assertEquals(0, result.errorCount());\n");
3586: buf.append(" }\n");
3587: buf.append("\n");
3588: buf.append(" public void testActiveRepeatedTest1() {\n");
3589: buf
3590: .append(" final Test test = new RepeatedTest(this.createActiveTestSuite(), 1);\n");
3591: buf
3592: .append(" final TestResult result = new TestResult();\n");
3593: buf.append(" test.run(result);\n");
3594: buf
3595: .append(" Assert.assertEquals(100, result.runCount());\n");
3596: buf
3597: .append(" Assert.assertEquals(0, result.failureCount());\n");
3598: buf
3599: .append(" Assert.assertEquals(0, result.errorCount());\n");
3600: buf.append(" }\n");
3601: buf.append("\n");
3602: buf.append(" public void testActiveTest() {\n");
3603: buf
3604: .append(" final Test test = this.createActiveTestSuite();\n");
3605: buf
3606: .append(" final TestResult result = new TestResult();\n");
3607: buf.append(" test.run(result);\n");
3608: buf
3609: .append(" Assert.assertEquals(100, result.runCount());\n");
3610: buf
3611: .append(" Assert.assertEquals(0, result.failureCount());\n");
3612: buf
3613: .append(" Assert.assertEquals(0, result.errorCount());\n");
3614: buf.append(" }\n");
3615: buf.append("\n");
3616: buf.append("}");
3617: fExpectedChangesAllTests.put(
3618: "junit.tests.extensions.ActiveTestTest.java", buf
3619: .toString());
3620: buf = new StringBuffer();
3621: buf.append("package junit.framework;\n");
3622: buf.append("\n");
3623: buf.append("/**\n");
3624: buf
3625: .append(" * A <em>Protectable</em> can be run and can throw a Throwable.\n");
3626: buf.append(" * \n");
3627: buf.append(" * @see TestResult\n");
3628: buf.append(" */\n");
3629: buf.append("public interface Protectable {\n");
3630: buf.append("\n");
3631: buf.append(" /**\n");
3632: buf.append(" * Run the the following method protected.\n");
3633: buf.append(" */\n");
3634: buf
3635: .append(" public abstract void protect() throws Throwable;\n");
3636: buf.append("}");
3637: fExpectedChangesAllTests.put(
3638: "junit.framework.Protectable.java", buf.toString());
3639: buf = new StringBuffer();
3640: buf.append("package junit.samples.money;\n");
3641: buf.append("\n");
3642: buf.append("/**\n");
3643: buf
3644: .append(" * The common interface for simple Monies and MoneyBags\n");
3645: buf.append(" * \n");
3646: buf.append(" */\n");
3647: buf.append("public interface IMoney {\n");
3648: buf.append(" /**\n");
3649: buf.append(" * Adds a money to this money.\n");
3650: buf.append(" */\n");
3651: buf.append(" public abstract IMoney add(IMoney m);\n");
3652: buf.append(" /**\n");
3653: buf
3654: .append(" * Adds a simple Money to this money. This is a helper method for\n");
3655: buf.append(" * implementing double dispatch\n");
3656: buf.append(" */\n");
3657: buf.append(" public abstract IMoney addMoney(Money m);\n");
3658: buf.append(" /**\n");
3659: buf
3660: .append(" * Adds a MoneyBag to this money. This is a helper method for implementing\n");
3661: buf.append(" * double dispatch\n");
3662: buf.append(" */\n");
3663: buf
3664: .append(" public abstract IMoney addMoneyBag(MoneyBag s);\n");
3665: buf.append(" /**\n");
3666: buf.append(" * Append this to a MoneyBag m.\n");
3667: buf.append(" */\n");
3668: buf.append(" public abstract void appendTo(MoneyBag m);\n");
3669: buf.append(" /**\n");
3670: buf.append(" * Tests whether this money is zero\n");
3671: buf.append(" */\n");
3672: buf.append(" public abstract boolean isZero();\n");
3673: buf.append(" /**\n");
3674: buf.append(" * Multiplies a money by the given factor.\n");
3675: buf.append(" */\n");
3676: buf
3677: .append(" public abstract IMoney multiply(int factor);\n");
3678: buf.append(" /**\n");
3679: buf.append(" * Negates this money.\n");
3680: buf.append(" */\n");
3681: buf.append(" public abstract IMoney negate();\n");
3682: buf.append(" /**\n");
3683: buf.append(" * Subtracts a money from this money.\n");
3684: buf.append(" */\n");
3685: buf.append(" public abstract IMoney subtract(IMoney m);\n");
3686: buf.append("}");
3687: fExpectedChangesAllTests.put("junit.samples.money.IMoney.java",
3688: buf.toString());
3689: buf = new StringBuffer();
3690: buf.append("package junit.textui;\n");
3691: buf.append("\n");
3692: buf.append("import java.io.PrintStream;\n");
3693: buf.append("\n");
3694: buf.append("import junit.framework.Test;\n");
3695: buf.append("import junit.framework.TestResult;\n");
3696: buf.append("import junit.framework.TestSuite;\n");
3697: buf.append("import junit.runner.BaseTestRunner;\n");
3698: buf.append("import junit.runner.StandardTestSuiteLoader;\n");
3699: buf.append("import junit.runner.TestSuiteLoader;\n");
3700: buf.append("import junit.runner.Version;\n");
3701: buf.append("\n");
3702: buf.append("/**\n");
3703: buf.append(" * A command line based tool to run tests.\n");
3704: buf.append(" * \n");
3705: buf.append(" * <pre>\n");
3706: buf
3707: .append(" * java junit.textui.TestRunner [-wait] TestCaseClass\n");
3708: buf.append(" * </pre>\n");
3709: buf.append(" * \n");
3710: buf
3711: .append(" * TestRunner expects the name of a TestCase class as argument. If this class\n");
3712: buf
3713: .append(" * defines a static <code>suite</code> method it will be invoked and the\n");
3714: buf
3715: .append(" * returned test is run. Otherwise all the methods starting with \"test\" having\n");
3716: buf.append(" * no arguments are run.\n");
3717: buf.append(" * <p>\n");
3718: buf
3719: .append(" * When the wait command line argument is given TestRunner waits until the users\n");
3720: buf.append(" * types RETURN.\n");
3721: buf.append(" * <p>\n");
3722: buf
3723: .append(" * TestRunner prints a trace as the tests are executed followed by a summary at\n");
3724: buf.append(" * the end.\n");
3725: buf.append(" */\n");
3726: buf
3727: .append("public class TestRunner extends BaseTestRunner {\n");
3728: buf.append(" public static final int EXCEPTION_EXIT = 2;\n");
3729: buf.append("\n");
3730: buf.append(" public static final int FAILURE_EXIT = 1;\n");
3731: buf.append(" public static final int SUCCESS_EXIT = 0;\n");
3732: buf
3733: .append(" public static void main(final String args[]) {\n");
3734: buf
3735: .append(" final TestRunner aTestRunner = new TestRunner();\n");
3736: buf.append(" try {\n");
3737: buf
3738: .append(" final TestResult r = aTestRunner.start(args);\n");
3739: buf.append(" if (!r.wasSuccessful()) {\n");
3740: buf
3741: .append(" System.exit(TestRunner.FAILURE_EXIT);\n");
3742: buf.append(" }\n");
3743: buf
3744: .append(" System.exit(TestRunner.SUCCESS_EXIT);\n");
3745: buf.append(" } catch (final Exception e) {\n");
3746: buf.append(" System.err.println(e.getMessage());\n");
3747: buf
3748: .append(" System.exit(TestRunner.EXCEPTION_EXIT);\n");
3749: buf.append(" }\n");
3750: buf.append(" }\n");
3751: buf.append("\n");
3752: buf.append(" /**\n");
3753: buf
3754: .append(" * Runs a suite extracted from a TestCase subclass.\n");
3755: buf.append(" */\n");
3756: buf
3757: .append(" static public void run(final Class testClass) {\n");
3758: buf
3759: .append(" TestRunner.run(new TestSuite(testClass));\n");
3760: buf.append(" }\n");
3761: buf.append("\n");
3762: buf.append(" /**\n");
3763: buf
3764: .append(" * Runs a single test and collects its results. This method can be used to\n");
3765: buf.append(" * start a test run from your program.\n");
3766: buf.append(" * \n");
3767: buf.append(" * <pre>\n");
3768: buf.append(" * public static void main(String[] args) {\n");
3769: buf.append(" * test.textui.TestRunner.run(suite());\n");
3770: buf.append(" * }\n");
3771: buf.append(" * </pre>\n");
3772: buf.append(" */\n");
3773: buf
3774: .append(" static public TestResult run(final Test test) {\n");
3775: buf
3776: .append(" final TestRunner runner = new TestRunner();\n");
3777: buf.append(" return runner.doRun(test);\n");
3778: buf.append(" }\n");
3779: buf.append("\n");
3780: buf.append(" /**\n");
3781: buf
3782: .append(" * Runs a single test and waits until the user types RETURN.\n");
3783: buf.append(" */\n");
3784: buf
3785: .append(" static public void runAndWait(final Test suite) {\n");
3786: buf
3787: .append(" final TestRunner aTestRunner = new TestRunner();\n");
3788: buf.append(" aTestRunner.doRun(suite, true);\n");
3789: buf.append(" }\n");
3790: buf.append("\n");
3791: buf.append(" private ResultPrinter fPrinter;\n");
3792: buf.append("\n");
3793: buf.append(" /**\n");
3794: buf.append(" * Constructs a TestRunner.\n");
3795: buf.append(" */\n");
3796: buf.append(" public TestRunner() {\n");
3797: buf.append(" this(System.out);\n");
3798: buf.append(" }\n");
3799: buf.append("\n");
3800: buf.append(" /**\n");
3801: buf
3802: .append(" * Constructs a TestRunner using the given stream for all the output\n");
3803: buf.append(" */\n");
3804: buf
3805: .append(" public TestRunner(final PrintStream writer) {\n");
3806: buf.append(" this(new ResultPrinter(writer));\n");
3807: buf.append(" }\n");
3808: buf.append("\n");
3809: buf.append(" /**\n");
3810: buf
3811: .append(" * Constructs a TestRunner using the given ResultPrinter all the output\n");
3812: buf.append(" */\n");
3813: buf
3814: .append(" public TestRunner(final ResultPrinter printer) {\n");
3815: buf.append(" this.fPrinter = printer;\n");
3816: buf.append(" }\n");
3817: buf.append("\n");
3818: buf.append(" /**\n");
3819: buf
3820: .append(" * Creates the TestResult to be used for the test run.\n");
3821: buf.append(" */\n");
3822: buf.append(" protected TestResult createTestResult() {\n");
3823: buf.append(" return new TestResult();\n");
3824: buf.append(" }\n");
3825: buf.append("\n");
3826: buf.append(" public TestResult doRun(final Test test) {\n");
3827: buf.append(" return this.doRun(test, false);\n");
3828: buf.append(" }\n");
3829: buf.append("\n");
3830: buf
3831: .append(" public TestResult doRun(final Test suite, final boolean wait) {\n");
3832: buf
3833: .append(" final TestResult result = this.createTestResult();\n");
3834: buf.append(" result.addListener(this.fPrinter);\n");
3835: buf
3836: .append(" final long startTime = System.currentTimeMillis();\n");
3837: buf.append(" suite.run(result);\n");
3838: buf
3839: .append(" final long endTime = System.currentTimeMillis();\n");
3840: buf
3841: .append(" final long runTime = endTime - startTime;\n");
3842: buf.append(" this.fPrinter.print(result, runTime);\n");
3843: buf.append("\n");
3844: buf.append(" this.pause(wait);\n");
3845: buf.append(" return result;\n");
3846: buf.append(" }\n");
3847: buf.append("\n");
3848: buf.append(" /**\n");
3849: buf
3850: .append(" * Always use the StandardTestSuiteLoader. Overridden from BaseTestRunner.\n");
3851: buf.append(" */\n");
3852: buf.append(" @Override\n");
3853: buf.append(" public TestSuiteLoader getLoader() {\n");
3854: buf.append(" return new StandardTestSuiteLoader();\n");
3855: buf.append(" }\n");
3856: buf.append("\n");
3857: buf.append(" protected void pause(final boolean wait) {\n");
3858: buf.append(" if (!wait) {\n");
3859: buf.append(" return;\n");
3860: buf.append(" }\n");
3861: buf.append(" this.fPrinter.printWaitPrompt();\n");
3862: buf.append(" try {\n");
3863: buf.append(" System.in.read();\n");
3864: buf.append(" } catch (final Exception e) {\n");
3865: buf.append(" }\n");
3866: buf.append(" }\n");
3867: buf.append("\n");
3868: buf.append(" @Override\n");
3869: buf
3870: .append(" protected void runFailed(final String message) {\n");
3871: buf.append(" System.err.println(message);\n");
3872: buf.append(" System.exit(TestRunner.FAILURE_EXIT);\n");
3873: buf.append(" }\n");
3874: buf.append("\n");
3875: buf
3876: .append(" public void setPrinter(final ResultPrinter printer) {\n");
3877: buf.append(" this.fPrinter = printer;\n");
3878: buf.append(" }\n");
3879: buf.append("\n");
3880: buf.append(" /**\n");
3881: buf
3882: .append(" * Starts a test run. Analyzes the command line arguments and runs the given\n");
3883: buf.append(" * test suite.\n");
3884: buf.append(" */\n");
3885: buf
3886: .append(" protected TestResult start(final String args[]) throws Exception {\n");
3887: buf.append(" String testCase = \"\"; //$NON-NLS-1$\n");
3888: buf.append(" boolean wait = false;\n");
3889: buf.append("\n");
3890: buf.append(" for (int i = 0; i < args.length; i++) {\n");
3891: buf.append(" if (args[i].equals(\"-wait\")) {\n");
3892: buf.append(" wait = true;\n");
3893: buf
3894: .append(" } else if (args[i].equals(\"-c\")) {\n");
3895: buf
3896: .append(" testCase = this.extractClassName(args[++i]);\n");
3897: buf
3898: .append(" } else if (args[i].equals(\"-v\")) {\n");
3899: buf.append(" System.err\n");
3900: buf
3901: .append(" .println(\"JUnit \" + Version.id() + \" by Kent Beck and Erich Gamma\"); //$NON-NLS-1$ //$NON-NLS-2$\n");
3902: buf.append(" } else {\n");
3903: buf.append(" testCase = args[i];\n");
3904: buf.append(" }\n");
3905: buf.append(" }\n");
3906: buf.append("\n");
3907: buf.append(" if (testCase.equals(\"\")) {\n");
3908: buf.append(" throw new Exception(\n");
3909: buf
3910: .append(" \"Usage: TestRunner [-wait] testCaseName, where name is the name of the TestCase class\"); //$NON-NLS-1$\n");
3911: buf.append(" }\n");
3912: buf.append("\n");
3913: buf.append(" try {\n");
3914: buf
3915: .append(" final Test suite = this.getTest(testCase);\n");
3916: buf.append(" return this.doRun(suite, wait);\n");
3917: buf.append(" } catch (final Exception e) {\n");
3918: buf
3919: .append(" throw new Exception(\"Could not create and run test suite: \" + e); //$NON-NLS-1$\n");
3920: buf.append(" }\n");
3921: buf.append(" }\n");
3922: buf.append("\n");
3923: buf.append(" @Override\n");
3924: buf
3925: .append(" public void testEnded(final String testName) {\n");
3926: buf.append(" }\n");
3927: buf.append("\n");
3928: buf.append(" @Override\n");
3929: buf
3930: .append(" public void testFailed(final int status, final Test test, final Throwable t) {\n");
3931: buf.append(" }\n");
3932: buf.append("\n");
3933: buf.append(" @Override\n");
3934: buf
3935: .append(" public void testStarted(final String testName) {\n");
3936: buf.append(" }\n");
3937: buf.append("\n");
3938: buf.append("}");
3939: fExpectedChangesAllTests.put("junit.textui.TestRunner.java",
3940: buf.toString());
3941: buf = new StringBuffer();
3942: buf.append("package junit.tests.runner;\n");
3943: buf.append("\n");
3944: buf.append("/**\n");
3945: buf.append(" * Test class used in TestTestCaseClassLoader\n");
3946: buf.append(" */\n");
3947: buf.append("import junit.framework.Assert;\n");
3948: buf.append("import junit.framework.TestCase;\n");
3949: buf.append("\n");
3950: buf.append("public class ClassLoaderTest extends Assert {\n");
3951: buf.append(" public ClassLoaderTest() {\n");
3952: buf.append(" }\n");
3953: buf
3954: .append(" private boolean isTestCaseClassLoader(final ClassLoader cl) {\n");
3955: buf
3956: .append(" return ((cl != null) && cl.getClass().getName().equals(\n");
3957: buf
3958: .append(" junit.runner.TestCaseClassLoader.class.getName()));\n");
3959: buf.append(" }\n");
3960: buf.append(" public void verify() {\n");
3961: buf
3962: .append(" this.verifyApplicationClassLoadedByTestLoader();\n");
3963: buf
3964: .append(" this.verifySystemClassNotLoadedByTestLoader();\n");
3965: buf.append(" }\n");
3966: buf
3967: .append(" private void verifyApplicationClassLoadedByTestLoader() {\n");
3968: buf
3969: .append(" Assert.assertTrue(this.isTestCaseClassLoader(this.getClass()\n");
3970: buf.append(" .getClassLoader()));\n");
3971: buf.append(" }\n");
3972: buf
3973: .append(" private void verifySystemClassNotLoadedByTestLoader() {\n");
3974: buf
3975: .append(" Assert.assertTrue(!this.isTestCaseClassLoader(Object.class\n");
3976: buf.append(" .getClassLoader()));\n");
3977: buf
3978: .append(" Assert.assertTrue(!this.isTestCaseClassLoader(TestCase.class\n");
3979: buf.append(" .getClassLoader()));\n");
3980: buf.append(" }\n");
3981: buf.append("}");
3982: fExpectedChangesAllTests.put(
3983: "junit.tests.runner.ClassLoaderTest.java", buf
3984: .toString());
3985: buf = new StringBuffer();
3986: buf.append("package junit.runner;\n");
3987: buf.append("/**\n");
3988: buf
3989: .append(" * A listener interface for observing the execution of a test run. Unlike\n");
3990: buf
3991: .append(" * TestListener, this interface using only primitive objects, making it suitable\n");
3992: buf.append(" * for remote test execution.\n");
3993: buf.append(" */\n");
3994: buf.append("public interface TestRunListener {\n");
3995: buf.append(" /* test status constants */\n");
3996: buf.append(" public static final int STATUS_ERROR = 1;\n");
3997: buf.append(" public static final int STATUS_FAILURE = 2;\n");
3998: buf.append("\n");
3999: buf.append(" public void testEnded(String testName);\n");
4000: buf
4001: .append(" public void testFailed(int status, String testName, String trace);\n");
4002: buf.append(" public void testRunEnded(long elapsedTime);\n");
4003: buf
4004: .append(" public void testRunStarted(String testSuiteName, int testCount);\n");
4005: buf
4006: .append(" public void testRunStopped(long elapsedTime);\n");
4007: buf.append(" public void testStarted(String testName);\n");
4008: buf.append("}\n");
4009: buf.append("");
4010: fExpectedChangesAllTests.put(
4011: "junit.runner.TestRunListener.java", buf.toString());
4012: buf = new StringBuffer();
4013: buf.append("package junit.tests.runner;\n");
4014: buf.append("\n");
4015: buf.append("import java.io.ByteArrayOutputStream;\n");
4016: buf.append("import java.io.OutputStream;\n");
4017: buf.append("import java.io.PrintStream;\n");
4018: buf.append("\n");
4019: buf.append("import junit.framework.Assert;\n");
4020: buf.append("import junit.framework.AssertionFailedError;\n");
4021: buf.append("import junit.framework.TestCase;\n");
4022: buf.append("import junit.framework.TestResult;\n");
4023: buf.append("import junit.framework.TestSuite;\n");
4024: buf.append("import junit.textui.ResultPrinter;\n");
4025: buf.append("import junit.textui.TestRunner;\n");
4026: buf.append("\n");
4027: buf
4028: .append("public class TextFeedbackTest extends TestCase {\n");
4029: buf
4030: .append(" class TestResultPrinter extends ResultPrinter {\n");
4031: buf
4032: .append(" TestResultPrinter(final PrintStream writer) {\n");
4033: buf.append(" super(writer);\n");
4034: buf.append(" }\n");
4035: buf.append("\n");
4036: buf.append(" /*\n");
4037: buf
4038: .append(" * Spoof printing time so the tests are deterministic\n");
4039: buf.append(" */\n");
4040: buf.append(" @Override\n");
4041: buf
4042: .append(" protected String elapsedTimeAsString(final long runTime) {\n");
4043: buf.append(" return \"0\"; //$NON-NLS-1$\n");
4044: buf.append(" }\n");
4045: buf.append(" }\n");
4046: buf
4047: .append(" public static void main(final String[] args) {\n");
4048: buf.append(" TestRunner.run(TextFeedbackTest.class);\n");
4049: buf.append(" }\n");
4050: buf.append("\n");
4051: buf.append(" OutputStream output;\n");
4052: buf.append("\n");
4053: buf.append(" TestRunner runner;\n");
4054: buf.append("\n");
4055: buf
4056: .append(" private String expected(final String[] lines) {\n");
4057: buf
4058: .append(" final OutputStream expected = new ByteArrayOutputStream();\n");
4059: buf
4060: .append(" final PrintStream expectedWriter = new PrintStream(expected);\n");
4061: buf.append(" for (final String element : lines) {\n");
4062: buf.append(" expectedWriter.println(element);\n");
4063: buf.append(" }\n");
4064: buf.append(" return expected.toString();\n");
4065: buf.append(" }\n");
4066: buf.append("\n");
4067: buf.append(" @Override\n");
4068: buf.append(" public void setUp() {\n");
4069: buf
4070: .append(" this.output = new ByteArrayOutputStream();\n");
4071: buf
4072: .append(" this.runner = new TestRunner(new TestResultPrinter(new PrintStream(\n");
4073: buf.append(" this.output)));\n");
4074: buf.append(" }\n");
4075: buf.append("\n");
4076: buf.append(" public void testEmptySuite() {\n");
4077: buf
4078: .append(" final String expected = this.expected(new String[]{\n");
4079: buf
4080: .append(" \"\", \"Time: 0\", \"\", \"OK (0 tests)\", \"\"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$\n");
4081: buf.append(" this.runner.doRun(new TestSuite());\n");
4082: buf
4083: .append(" Assert.assertEquals(expected.toString(), this.output.toString());\n");
4084: buf.append(" }\n");
4085: buf.append("\n");
4086: buf.append(" public void testError() {\n");
4087: buf.append(" final String expected = this\n");
4088: buf.append(" .expected(new String[]{\n");
4089: buf
4090: .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");
4091: buf
4092: .append(" final ResultPrinter printer = new TestResultPrinter(new PrintStream(\n");
4093: buf.append(" this.output)) {\n");
4094: buf.append(" @Override\n");
4095: buf
4096: .append(" public void printErrors(TestResult result) {\n");
4097: buf
4098: .append(" this.getWriter().println(\"Errors here\"); //$NON-NLS-1$\n");
4099: buf.append(" }\n");
4100: buf.append(" };\n");
4101: buf.append(" this.runner.setPrinter(printer);\n");
4102: buf
4103: .append(" final TestSuite suite = new TestSuite();\n");
4104: buf.append(" suite.addTest(new TestCase() {\n");
4105: buf.append(" @Override\n");
4106: buf
4107: .append(" public void runTest() throws Exception {\n");
4108: buf.append(" throw new Exception();\n");
4109: buf.append(" }\n");
4110: buf.append(" });\n");
4111: buf.append(" this.runner.doRun(suite);\n");
4112: buf
4113: .append(" Assert.assertEquals(expected.toString(), this.output.toString());\n");
4114: buf.append(" }\n");
4115: buf.append("\n");
4116: buf.append(" public void testFailure() {\n");
4117: buf.append(" final String expected = this\n");
4118: buf.append(" .expected(new String[]{\n");
4119: buf
4120: .append(" \".F\", \"Time: 0\", \"Failures here\", \"\", \"FAILURES!!!\", \"Tests run: 1, Failures: 1, Errors: 0\", \"\"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$\n");
4121: buf
4122: .append(" final ResultPrinter printer = new TestResultPrinter(new PrintStream(\n");
4123: buf.append(" this.output)) {\n");
4124: buf.append(" @Override\n");
4125: buf
4126: .append(" public void printFailures(TestResult result) {\n");
4127: buf
4128: .append(" this.getWriter().println(\"Failures here\"); //$NON-NLS-1$\n");
4129: buf.append(" }\n");
4130: buf.append(" };\n");
4131: buf.append(" this.runner.setPrinter(printer);\n");
4132: buf
4133: .append(" final TestSuite suite = new TestSuite();\n");
4134: buf.append(" suite.addTest(new TestCase() {\n");
4135: buf.append(" @Override\n");
4136: buf.append(" public void runTest() {\n");
4137: buf
4138: .append(" throw new AssertionFailedError();\n");
4139: buf.append(" }\n");
4140: buf.append(" });\n");
4141: buf.append(" this.runner.doRun(suite);\n");
4142: buf
4143: .append(" Assert.assertEquals(expected.toString(), this.output.toString());\n");
4144: buf.append(" }\n");
4145: buf.append("\n");
4146: buf.append(" public void testOneTest() {\n");
4147: buf
4148: .append(" final String expected = this.expected(new String[]{\n");
4149: buf
4150: .append(" \".\", \"Time: 0\", \"\", \"OK (1 test)\", \"\"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$\n");
4151: buf
4152: .append(" final TestSuite suite = new TestSuite();\n");
4153: buf.append(" suite.addTest(new TestCase() {\n");
4154: buf.append(" @Override\n");
4155: buf.append(" public void runTest() {\n");
4156: buf.append(" }\n");
4157: buf.append(" });\n");
4158: buf.append(" this.runner.doRun(suite);\n");
4159: buf
4160: .append(" Assert.assertEquals(expected.toString(), this.output.toString());\n");
4161: buf.append(" }\n");
4162: buf.append("\n");
4163: buf.append(" public void testTwoTests() {\n");
4164: buf
4165: .append(" final String expected = this.expected(new String[]{\n");
4166: buf
4167: .append(" \"..\", \"Time: 0\", \"\", \"OK (2 tests)\", \"\"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$\n");
4168: buf
4169: .append(" final TestSuite suite = new TestSuite();\n");
4170: buf.append(" suite.addTest(new TestCase() {\n");
4171: buf.append(" @Override\n");
4172: buf.append(" public void runTest() {\n");
4173: buf.append(" }\n");
4174: buf.append(" });\n");
4175: buf.append(" suite.addTest(new TestCase() {\n");
4176: buf.append(" @Override\n");
4177: buf.append(" public void runTest() {\n");
4178: buf.append(" }\n");
4179: buf.append(" });\n");
4180: buf.append(" this.runner.doRun(suite);\n");
4181: buf
4182: .append(" Assert.assertEquals(expected.toString(), this.output.toString());\n");
4183: buf.append(" }\n");
4184: buf.append("\n");
4185: buf.append("}\n");
4186: buf.append("");
4187: fExpectedChangesAllTests.put(
4188: "junit.tests.runner.TextFeedbackTest.java", buf
4189: .toString());
4190: buf = new StringBuffer();
4191: buf.append("package junit.tests.extensions;\n");
4192: buf.append("\n");
4193: buf.append("import junit.extensions.TestSetup;\n");
4194: buf.append("import junit.framework.Assert;\n");
4195: buf.append("import junit.framework.Test;\n");
4196: buf.append("import junit.framework.TestCase;\n");
4197: buf.append("import junit.framework.TestResult;\n");
4198: buf.append("import junit.framework.TestSuite;\n");
4199: buf.append("import junit.tests.WasRun;\n");
4200: buf.append("\n");
4201: buf.append("/**\n");
4202: buf
4203: .append(" * A test case testing the extensions to the testing framework.\n");
4204: buf.append(" * \n");
4205: buf.append(" */\n");
4206: buf.append("public class ExtensionTest extends TestCase {\n");
4207: buf.append(" static class TornDown extends TestSetup {\n");
4208: buf.append(" boolean fTornDown = false;\n");
4209: buf.append("\n");
4210: buf.append(" TornDown(final Test test) {\n");
4211: buf.append(" super(test);\n");
4212: buf.append(" }\n");
4213: buf.append(" @Override\n");
4214: buf.append(" protected void tearDown() {\n");
4215: buf.append(" this.fTornDown = true;\n");
4216: buf.append(" }\n");
4217: buf.append(" }\n");
4218: buf.append(" public void testRunningErrorInTestSetup() {\n");
4219: buf
4220: .append(" final TestCase test = new TestCase(\"failure\") { //$NON-NLS-1$\n");
4221: buf.append(" @Override\n");
4222: buf.append(" public void runTest() {\n");
4223: buf.append(" Assert.fail();\n");
4224: buf.append(" }\n");
4225: buf.append(" };\n");
4226: buf.append("\n");
4227: buf
4228: .append(" final TestSetup wrapper = new TestSetup(test);\n");
4229: buf.append("\n");
4230: buf
4231: .append(" final TestResult result = new TestResult();\n");
4232: buf.append(" wrapper.run(result);\n");
4233: buf
4234: .append(" Assert.assertTrue(!result.wasSuccessful());\n");
4235: buf.append(" }\n");
4236: buf
4237: .append(" public void testRunningErrorsInTestSetup() {\n");
4238: buf
4239: .append(" final TestCase failure = new TestCase(\"failure\") { //$NON-NLS-1$\n");
4240: buf.append(" @Override\n");
4241: buf.append(" public void runTest() {\n");
4242: buf.append(" Assert.fail();\n");
4243: buf.append(" }\n");
4244: buf.append(" };\n");
4245: buf.append("\n");
4246: buf
4247: .append(" final TestCase error = new TestCase(\"error\") { //$NON-NLS-1$\n");
4248: buf.append(" @Override\n");
4249: buf.append(" public void runTest() {\n");
4250: buf.append(" throw new Error();\n");
4251: buf.append(" }\n");
4252: buf.append(" };\n");
4253: buf.append("\n");
4254: buf
4255: .append(" final TestSuite suite = new TestSuite();\n");
4256: buf.append(" suite.addTest(failure);\n");
4257: buf.append(" suite.addTest(error);\n");
4258: buf.append("\n");
4259: buf
4260: .append(" final TestSetup wrapper = new TestSetup(suite);\n");
4261: buf.append("\n");
4262: buf
4263: .append(" final TestResult result = new TestResult();\n");
4264: buf.append(" wrapper.run(result);\n");
4265: buf.append("\n");
4266: buf
4267: .append(" Assert.assertEquals(1, result.failureCount());\n");
4268: buf
4269: .append(" Assert.assertEquals(1, result.errorCount());\n");
4270: buf.append(" }\n");
4271: buf.append(" public void testSetupErrorDontTearDown() {\n");
4272: buf.append(" final WasRun test = new WasRun();\n");
4273: buf.append("\n");
4274: buf
4275: .append(" final TornDown wrapper = new TornDown(test) {\n");
4276: buf.append(" @Override\n");
4277: buf.append(" public void setUp() {\n");
4278: buf.append(" Assert.fail();\n");
4279: buf.append(" }\n");
4280: buf.append(" };\n");
4281: buf.append("\n");
4282: buf
4283: .append(" final TestResult result = new TestResult();\n");
4284: buf.append(" wrapper.run(result);\n");
4285: buf.append("\n");
4286: buf.append(" Assert.assertTrue(!wrapper.fTornDown);\n");
4287: buf.append(" }\n");
4288: buf.append(" public void testSetupErrorInTestSetup() {\n");
4289: buf.append(" final WasRun test = new WasRun();\n");
4290: buf.append("\n");
4291: buf
4292: .append(" final TestSetup wrapper = new TestSetup(test) {\n");
4293: buf.append(" @Override\n");
4294: buf.append(" public void setUp() {\n");
4295: buf.append(" Assert.fail();\n");
4296: buf.append(" }\n");
4297: buf.append(" };\n");
4298: buf.append("\n");
4299: buf
4300: .append(" final TestResult result = new TestResult();\n");
4301: buf.append(" wrapper.run(result);\n");
4302: buf.append("\n");
4303: buf.append(" Assert.assertTrue(!test.fWasRun);\n");
4304: buf
4305: .append(" Assert.assertTrue(!result.wasSuccessful());\n");
4306: buf.append(" }\n");
4307: buf.append("}");
4308: fExpectedChangesAllTests.put(
4309: "junit.tests.extensions.ExtensionTest.java", buf
4310: .toString());
4311: buf = new StringBuffer();
4312: buf.append("package junit.tests;\n");
4313: buf.append("\n");
4314: buf.append("import junit.framework.Test;\n");
4315: buf.append("import junit.framework.TestSuite;\n");
4316: buf.append("\n");
4317: buf.append("/**\n");
4318: buf.append(" * TestSuite that runs all the JUnit tests\n");
4319: buf.append(" * \n");
4320: buf.append(" */\n");
4321: buf.append("public class AllTests {\n");
4322: buf.append("\n");
4323: buf
4324: .append(" public static void main(final String[] args) {\n");
4325: buf
4326: .append(" junit.textui.TestRunner.run(AllTests.suite());\n");
4327: buf.append(" }\n");
4328: buf.append("\n");
4329: buf.append(" public static Test suite() {\n");
4330: buf
4331: .append(" final TestSuite suite = new TestSuite(\"Framework Tests\"); //$NON-NLS-1$\n");
4332: buf
4333: .append(" suite.addTest(junit.tests.framework.AllTests.suite());\n");
4334: buf
4335: .append(" suite.addTest(junit.tests.runner.AllTests.suite());\n");
4336: buf
4337: .append(" suite.addTest(junit.tests.extensions.AllTests.suite());\n");
4338: buf.append(" return suite;\n");
4339: buf.append(" }\n");
4340: buf.append("}");
4341: fExpectedChangesAllTests.put("junit.tests.AllTests.java", buf
4342: .toString());
4343: buf = new StringBuffer();
4344: buf.append("package junit.tests.runner;\n");
4345: buf.append("\n");
4346: buf.append("/**\n");
4347: buf.append(" * Test class used in TestTestCaseClassLoader\n");
4348: buf.append(" */\n");
4349: buf.append("import junit.framework.Assert;\n");
4350: buf.append("\n");
4351: buf.append("public class LoadedFromJar extends Assert {\n");
4352: buf
4353: .append(" private boolean isTestCaseClassLoader(final ClassLoader cl) {\n");
4354: buf
4355: .append(" return ((cl != null) && cl.getClass().getName().equals(\n");
4356: buf
4357: .append(" junit.runner.TestCaseClassLoader.class.getName()));\n");
4358: buf.append(" }\n");
4359: buf.append(" public void verify() {\n");
4360: buf
4361: .append(" this.verifyApplicationClassLoadedByTestLoader();\n");
4362: buf.append(" }\n");
4363: buf
4364: .append(" private void verifyApplicationClassLoadedByTestLoader() {\n");
4365: buf
4366: .append(" Assert.assertTrue(this.isTestCaseClassLoader(this.getClass()\n");
4367: buf.append(" .getClassLoader()));\n");
4368: buf.append(" }\n");
4369: buf.append("}");
4370: fExpectedChangesAllTests
4371: .put("junit.tests.runner.LoadedFromJar.java", buf
4372: .toString());
4373: buf = new StringBuffer();
4374: buf.append("package junit.tests.framework;\n");
4375: buf.append("\n");
4376: buf.append("import junit.framework.Assert;\n");
4377: buf.append("import junit.framework.ComparisonFailure;\n");
4378: buf.append("import junit.framework.TestCase;\n");
4379: buf.append("\n");
4380: buf
4381: .append("public class ComparisonFailureTest extends TestCase {\n");
4382: buf.append("\n");
4383: buf.append(" public void testComparisonErrorEndSame() {\n");
4384: buf
4385: .append(" final ComparisonFailure failure = new ComparisonFailure(null,\n");
4386: buf
4387: .append(" \"ab\", \"cb\"); //$NON-NLS-1$ //$NON-NLS-2$\n");
4388: buf.append(" Assert.assertEquals(\n");
4389: buf
4390: .append(" \"expected:<a...> but was:<c...>\", failure.getMessage()); //$NON-NLS-1$\n");
4391: buf.append(" }\n");
4392: buf.append("\n");
4393: buf
4394: .append(" public void testComparisonErrorEndSameComplete() {\n");
4395: buf
4396: .append(" final ComparisonFailure failure = new ComparisonFailure(null,\n");
4397: buf
4398: .append(" \"bc\", \"abc\"); //$NON-NLS-1$ //$NON-NLS-2$\n");
4399: buf.append(" Assert.assertEquals(\n");
4400: buf
4401: .append(" \"expected:<...> but was:<a...>\", failure.getMessage()); //$NON-NLS-1$\n");
4402: buf.append(" }\n");
4403: buf.append("\n");
4404: buf.append(" public void testComparisonErrorMessage() {\n");
4405: buf
4406: .append(" final ComparisonFailure failure = new ComparisonFailure(\"a\", \"b\", \"c\"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\n");
4407: buf
4408: .append(" Assert.assertEquals(\"a expected:<b> but was:<c>\", failure.getMessage()); //$NON-NLS-1$\n");
4409: buf.append(" }\n");
4410: buf.append("\n");
4411: buf
4412: .append(" public void testComparisonErrorOverlapingMatches() {\n");
4413: buf
4414: .append(" final ComparisonFailure failure = new ComparisonFailure(null,\n");
4415: buf
4416: .append(" \"abc\", \"abbc\"); //$NON-NLS-1$ //$NON-NLS-2$\n");
4417: buf.append(" Assert.assertEquals(\n");
4418: buf
4419: .append(" \"expected:<......> but was:<...b...>\", failure.getMessage()); //$NON-NLS-1$\n");
4420: buf.append(" }\n");
4421: buf.append("\n");
4422: buf
4423: .append(" public void testComparisonErrorOverlapingMatches2() {\n");
4424: buf
4425: .append(" final ComparisonFailure failure = new ComparisonFailure(null,\n");
4426: buf
4427: .append(" \"abcdde\", \"abcde\"); //$NON-NLS-1$ //$NON-NLS-2$\n");
4428: buf.append(" Assert.assertEquals(\n");
4429: buf
4430: .append(" \"expected:<...d...> but was:<......>\", failure.getMessage()); //$NON-NLS-1$\n");
4431: buf.append(" }\n");
4432: buf.append("\n");
4433: buf.append(" public void testComparisonErrorSame() {\n");
4434: buf
4435: .append(" final ComparisonFailure failure = new ComparisonFailure(null,\n");
4436: buf
4437: .append(" \"ab\", \"ab\"); //$NON-NLS-1$ //$NON-NLS-2$\n");
4438: buf
4439: .append(" Assert.assertEquals(\"expected:<ab> but was:<ab>\", failure.getMessage()); //$NON-NLS-1$\n");
4440: buf.append(" }\n");
4441: buf.append("\n");
4442: buf
4443: .append(" public void testComparisonErrorStartAndEndSame() {\n");
4444: buf
4445: .append(" final ComparisonFailure failure = new ComparisonFailure(null,\n");
4446: buf
4447: .append(" \"abc\", \"adc\"); //$NON-NLS-1$ //$NON-NLS-2$\n");
4448: buf.append(" Assert.assertEquals(\n");
4449: buf
4450: .append(" \"expected:<...b...> but was:<...d...>\", failure.getMessage()); //$NON-NLS-1$\n");
4451: buf.append(" }\n");
4452: buf.append("\n");
4453: buf
4454: .append(" public void testComparisonErrorStartSame() {\n");
4455: buf
4456: .append(" final ComparisonFailure failure = new ComparisonFailure(null,\n");
4457: buf
4458: .append(" \"ba\", \"bc\"); //$NON-NLS-1$ //$NON-NLS-2$\n");
4459: buf.append(" Assert.assertEquals(\n");
4460: buf
4461: .append(" \"expected:<...a> but was:<...c>\", failure.getMessage()); //$NON-NLS-1$\n");
4462: buf.append(" }\n");
4463: buf.append("\n");
4464: buf
4465: .append(" public void testComparisonErrorStartSameComplete() {\n");
4466: buf
4467: .append(" final ComparisonFailure failure = new ComparisonFailure(null,\n");
4468: buf
4469: .append(" \"ab\", \"abc\"); //$NON-NLS-1$ //$NON-NLS-2$\n");
4470: buf.append(" Assert.assertEquals(\n");
4471: buf
4472: .append(" \"expected:<...> but was:<...c>\", failure.getMessage()); //$NON-NLS-1$\n");
4473: buf.append(" }\n");
4474: buf.append("\n");
4475: buf
4476: .append(" public void testComparisonErrorWithActualNull() {\n");
4477: buf
4478: .append(" final ComparisonFailure failure = new ComparisonFailure(null, \"a\", null); //$NON-NLS-1$\n");
4479: buf.append(" Assert\n");
4480: buf.append(" .assertEquals(\n");
4481: buf
4482: .append(" \"expected:<a> but was:<null>\", failure.getMessage()); //$NON-NLS-1$\n");
4483: buf.append(" }\n");
4484: buf.append("\n");
4485: buf
4486: .append(" public void testComparisonErrorWithExpectedNull() {\n");
4487: buf
4488: .append(" final ComparisonFailure failure = new ComparisonFailure(null, null, \"a\"); //$NON-NLS-1$\n");
4489: buf.append(" Assert\n");
4490: buf.append(" .assertEquals(\n");
4491: buf
4492: .append(" \"expected:<null> but was:<a>\", failure.getMessage()); //$NON-NLS-1$\n");
4493: buf.append(" }\n");
4494: buf.append("}\n");
4495: buf.append("");
4496: fExpectedChangesAllTests.put(
4497: "junit.tests.framework.ComparisonFailureTest.java", buf
4498: .toString());
4499: buf = new StringBuffer();
4500: buf.append("package junit.textui;\n");
4501: buf.append("\n");
4502: buf.append("import java.io.PrintStream;\n");
4503: buf.append("import java.text.NumberFormat;\n");
4504: buf.append("import java.util.Enumeration;\n");
4505: buf.append("\n");
4506: buf.append("import junit.framework.AssertionFailedError;\n");
4507: buf.append("import junit.framework.Test;\n");
4508: buf.append("import junit.framework.TestFailure;\n");
4509: buf.append("import junit.framework.TestListener;\n");
4510: buf.append("import junit.framework.TestResult;\n");
4511: buf.append("import junit.runner.BaseTestRunner;\n");
4512: buf.append("\n");
4513: buf
4514: .append("public class ResultPrinter implements TestListener {\n");
4515: buf.append(" int fColumn = 0;\n");
4516: buf.append(" PrintStream fWriter;\n");
4517: buf.append("\n");
4518: buf
4519: .append(" public ResultPrinter(final PrintStream writer) {\n");
4520: buf.append(" this.fWriter = writer;\n");
4521: buf.append(" }\n");
4522: buf.append("\n");
4523: buf.append(" /*\n");
4524: buf.append(" * API for use by textui.TestRunner\n");
4525: buf.append(" */\n");
4526: buf.append("\n");
4527: buf.append(" /**\n");
4528: buf
4529: .append(" * @see junit.framework.TestListener#addError(Test, Throwable)\n");
4530: buf.append(" */\n");
4531: buf
4532: .append(" public void addError(final Test test, final Throwable t) {\n");
4533: buf
4534: .append(" this.getWriter().print(\"E\"); //$NON-NLS-1$\n");
4535: buf.append(" }\n");
4536: buf.append("\n");
4537: buf.append(" /**\n");
4538: buf
4539: .append(" * @see junit.framework.TestListener#addFailure(Test, AssertionFailedError)\n");
4540: buf.append(" */\n");
4541: buf
4542: .append(" public void addFailure(final Test test, final AssertionFailedError t) {\n");
4543: buf
4544: .append(" this.getWriter().print(\"F\"); //$NON-NLS-1$\n");
4545: buf.append(" }\n");
4546: buf.append("\n");
4547: buf.append(" /*\n");
4548: buf.append(" * Internal methods\n");
4549: buf.append(" */\n");
4550: buf.append("\n");
4551: buf.append(" /**\n");
4552: buf
4553: .append(" * Returns the formatted string of the elapsed time. Duplicated from\n");
4554: buf.append(" * BaseTestRunner. Fix it.\n");
4555: buf.append(" */\n");
4556: buf
4557: .append(" protected String elapsedTimeAsString(final long runTime) {\n");
4558: buf
4559: .append(" return NumberFormat.getInstance().format((double) runTime / 1000);\n");
4560: buf.append(" }\n");
4561: buf.append("\n");
4562: buf.append(" /**\n");
4563: buf
4564: .append(" * @see junit.framework.TestListener#endTest(Test)\n");
4565: buf.append(" */\n");
4566: buf.append(" public void endTest(final Test test) {\n");
4567: buf.append(" }\n");
4568: buf.append("\n");
4569: buf.append(" public PrintStream getWriter() {\n");
4570: buf.append(" return this.fWriter;\n");
4571: buf.append(" }\n");
4572: buf.append("\n");
4573: buf
4574: .append(" synchronized void print(final TestResult result, final long runTime) {\n");
4575: buf.append(" this.printHeader(runTime);\n");
4576: buf.append(" this.printErrors(result);\n");
4577: buf.append(" this.printFailures(result);\n");
4578: buf.append(" this.printFooter(result);\n");
4579: buf.append(" }\n");
4580: buf.append("\n");
4581: buf
4582: .append(" public void printDefect(final TestFailure booBoo, final int count) { // only\n");
4583: buf.append(" // public\n");
4584: buf.append(" // for\n");
4585: buf.append(" // testing\n");
4586: buf.append(" // purposes\n");
4587: buf.append(" this.printDefectHeader(booBoo, count);\n");
4588: buf.append(" this.printDefectTrace(booBoo);\n");
4589: buf.append(" }\n");
4590: buf.append("\n");
4591: buf
4592: .append(" protected void printDefectHeader(final TestFailure booBoo, final int count) {\n");
4593: buf
4594: .append(" // I feel like making this a println, then adding a line giving the\n");
4595: buf
4596: .append(" // throwable a chance to print something\n");
4597: buf.append(" // before we get to the stack trace.\n");
4598: buf
4599: .append(" this.getWriter().print(count + \") \" + booBoo.failedTest()); //$NON-NLS-1$\n");
4600: buf.append(" }\n");
4601: buf.append("\n");
4602: buf
4603: .append(" protected void printDefects(final Enumeration booBoos, final int count,\n");
4604: buf.append(" final String type) {\n");
4605: buf.append(" if (count == 0) {\n");
4606: buf.append(" return;\n");
4607: buf.append(" }\n");
4608: buf.append(" if (count == 1) {\n");
4609: buf
4610: .append(" this.getWriter().println(\"There was \" + count + \" \" + type + \":\"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\n");
4611: buf.append(" } else {\n");
4612: buf
4613: .append(" this.getWriter().println(\"There were \" + count + \" \" + type + \"s:\"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\n");
4614: buf.append(" }\n");
4615: buf
4616: .append(" for (int i = 1; booBoos.hasMoreElements(); i++) {\n");
4617: buf
4618: .append(" this.printDefect((TestFailure) booBoos.nextElement(), i);\n");
4619: buf.append(" }\n");
4620: buf.append(" }\n");
4621: buf.append("\n");
4622: buf
4623: .append(" protected void printDefectTrace(final TestFailure booBoo) {\n");
4624: buf
4625: .append(" this.getWriter().print(BaseTestRunner.getFilteredTrace(booBoo.trace()));\n");
4626: buf.append(" }\n");
4627: buf.append("\n");
4628: buf
4629: .append(" protected void printErrors(final TestResult result) {\n");
4630: buf
4631: .append(" this.printDefects(result.errors(), result.errorCount(), \"error\"); //$NON-NLS-1$\n");
4632: buf.append(" }\n");
4633: buf.append("\n");
4634: buf
4635: .append(" protected void printFailures(final TestResult result) {\n");
4636: buf
4637: .append(" this.printDefects(result.failures(), result.failureCount(), \"failure\"); //$NON-NLS-1$\n");
4638: buf.append(" }\n");
4639: buf
4640: .append(" protected void printFooter(final TestResult result) {\n");
4641: buf.append(" if (result.wasSuccessful()) {\n");
4642: buf.append(" this.getWriter().println();\n");
4643: buf
4644: .append(" this.getWriter().print(\"OK\"); //$NON-NLS-1$\n");
4645: buf.append(" this\n");
4646: buf.append(" .getWriter()\n");
4647: buf.append(" .println(\n");
4648: buf
4649: .append(" \" (\" + result.runCount() + \" test\" + (result.runCount() == 1 ? \"\" : \"s\") + \")\"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$\n");
4650: buf.append("\n");
4651: buf.append(" } else {\n");
4652: buf.append(" this.getWriter().println();\n");
4653: buf
4654: .append(" this.getWriter().println(\"FAILURES!!!\"); //$NON-NLS-1$\n");
4655: buf
4656: .append(" this.getWriter().println(\"Tests run: \" + result.runCount() + //$NON-NLS-1$\n");
4657: buf
4658: .append(" \", Failures: \" + result.failureCount() + //$NON-NLS-1$\n");
4659: buf
4660: .append(" \", Errors: \" + result.errorCount()); //$NON-NLS-1$\n");
4661: buf.append(" }\n");
4662: buf.append(" this.getWriter().println();\n");
4663: buf.append(" }\n");
4664: buf.append("\n");
4665: buf
4666: .append(" protected void printHeader(final long runTime) {\n");
4667: buf.append(" this.getWriter().println();\n");
4668: buf
4669: .append(" this.getWriter().println(\"Time: \" + this.elapsedTimeAsString(runTime)); //$NON-NLS-1$\n");
4670: buf.append(" }\n");
4671: buf.append("\n");
4672: buf.append(" void printWaitPrompt() {\n");
4673: buf.append(" this.getWriter().println();\n");
4674: buf
4675: .append(" this.getWriter().println(\"<RETURN> to continue\"); //$NON-NLS-1$\n");
4676: buf.append(" }\n");
4677: buf.append("\n");
4678: buf.append(" /**\n");
4679: buf
4680: .append(" * @see junit.framework.TestListener#startTest(Test)\n");
4681: buf.append(" */\n");
4682: buf.append(" public void startTest(final Test test) {\n");
4683: buf
4684: .append(" this.getWriter().print(\".\"); //$NON-NLS-1$\n");
4685: buf.append(" if (this.fColumn++ >= 40) {\n");
4686: buf.append(" this.getWriter().println();\n");
4687: buf.append(" this.fColumn = 0;\n");
4688: buf.append(" }\n");
4689: buf.append(" }\n");
4690: buf.append("\n");
4691: buf.append("}\n");
4692: buf.append("");
4693: fExpectedChangesAllTests.put("junit.textui.ResultPrinter.java",
4694: buf.toString());
4695: buf = new StringBuffer();
4696: buf.append("package junit.samples;\n");
4697: buf.append("\n");
4698: buf.append("import java.util.Vector;\n");
4699: buf.append("\n");
4700: buf.append("import junit.framework.Assert;\n");
4701: buf.append("import junit.framework.Test;\n");
4702: buf.append("import junit.framework.TestCase;\n");
4703: buf.append("import junit.framework.TestSuite;\n");
4704: buf.append("\n");
4705: buf.append("/**\n");
4706: buf
4707: .append(" * A sample test case, testing <code>java.util.Vector</code>.\n");
4708: buf.append(" * \n");
4709: buf.append(" */\n");
4710: buf.append("public class VectorTest extends TestCase {\n");
4711: buf
4712: .append(" public static void main(final String[] args) {\n");
4713: buf
4714: .append(" junit.textui.TestRunner.run(VectorTest.suite());\n");
4715: buf.append(" }\n");
4716: buf.append(" public static Test suite() {\n");
4717: buf.append(" return new TestSuite(VectorTest.class);\n");
4718: buf.append(" }\n");
4719: buf.append("\n");
4720: buf.append(" protected Vector fEmpty;\n");
4721: buf.append(" protected Vector fFull;\n");
4722: buf.append(" @Override\n");
4723: buf.append(" protected void setUp() {\n");
4724: buf.append(" this.fEmpty = new Vector();\n");
4725: buf.append(" this.fFull = new Vector();\n");
4726: buf.append(" this.fFull.addElement(new Integer(1));\n");
4727: buf.append(" this.fFull.addElement(new Integer(2));\n");
4728: buf.append(" this.fFull.addElement(new Integer(3));\n");
4729: buf.append(" }\n");
4730: buf.append(" public void testCapacity() {\n");
4731: buf.append(" final int size = this.fFull.size();\n");
4732: buf.append(" for (int i = 0; i < 100; i++) {\n");
4733: buf
4734: .append(" this.fFull.addElement(new Integer(i));\n");
4735: buf.append(" }\n");
4736: buf
4737: .append(" Assert.assertTrue(this.fFull.size() == 100 + size);\n");
4738: buf.append(" }\n");
4739: buf.append(" public void testClone() {\n");
4740: buf
4741: .append(" final Vector clone = (Vector) this.fFull.clone();\n");
4742: buf
4743: .append(" Assert.assertTrue(clone.size() == this.fFull.size());\n");
4744: buf
4745: .append(" Assert.assertTrue(clone.contains(new Integer(1)));\n");
4746: buf.append(" }\n");
4747: buf.append(" public void testContains() {\n");
4748: buf
4749: .append(" Assert.assertTrue(this.fFull.contains(new Integer(1)));\n");
4750: buf
4751: .append(" Assert.assertTrue(!this.fEmpty.contains(new Integer(1)));\n");
4752: buf.append(" }\n");
4753: buf.append(" public void testElementAt() {\n");
4754: buf
4755: .append(" final Integer i = (Integer) this.fFull.elementAt(0);\n");
4756: buf.append(" Assert.assertTrue(i.intValue() == 1);\n");
4757: buf.append("\n");
4758: buf.append(" try {\n");
4759: buf
4760: .append(" this.fFull.elementAt(this.fFull.size());\n");
4761: buf
4762: .append(" } catch (final ArrayIndexOutOfBoundsException e) {\n");
4763: buf.append(" return;\n");
4764: buf.append(" }\n");
4765: buf
4766: .append(" Assert.fail(\"Should raise an ArrayIndexOutOfBoundsException\"); //$NON-NLS-1$\n");
4767: buf.append(" }\n");
4768: buf.append(" public void testRemoveAll() {\n");
4769: buf.append(" this.fFull.removeAllElements();\n");
4770: buf.append(" this.fEmpty.removeAllElements();\n");
4771: buf
4772: .append(" Assert.assertTrue(this.fFull.isEmpty());\n");
4773: buf
4774: .append(" Assert.assertTrue(this.fEmpty.isEmpty());\n");
4775: buf.append(" }\n");
4776: buf.append(" public void testRemoveElement() {\n");
4777: buf
4778: .append(" this.fFull.removeElement(new Integer(3));\n");
4779: buf
4780: .append(" Assert.assertTrue(!this.fFull.contains(new Integer(3)));\n");
4781: buf.append(" }\n");
4782: buf.append("}");
4783: fExpectedChangesAllTests.put("junit.samples.VectorTest.java",
4784: buf.toString());
4785: buf = new StringBuffer();
4786: buf.append("package junit.framework;\n");
4787: buf.append("\n");
4788: buf.append("/**\n");
4789: buf
4790: .append(" * Thrown when an assert equals for Strings failed.\n");
4791: buf.append(" * \n");
4792: buf
4793: .append(" * Inspired by a patch from Alex Chaffee mailto:alex@purpletech.com\n");
4794: buf.append(" */\n");
4795: buf
4796: .append("public class ComparisonFailure extends AssertionFailedError {\n");
4797: buf.append(" /* Test */\n");
4798: buf
4799: .append(" private static final long serialVersionUID = 1L;\n");
4800: buf.append(" private final String fActual;\n");
4801: buf.append(" private final String fExpected;\n");
4802: buf.append("\n");
4803: buf.append(" /**\n");
4804: buf.append(" * Constructs a comparison failure.\n");
4805: buf.append(" * \n");
4806: buf.append(" * @param message\n");
4807: buf
4808: .append(" * the identifying message or null\n");
4809: buf.append(" * @param expected\n");
4810: buf.append(" * the expected string value\n");
4811: buf.append(" * @param actual\n");
4812: buf.append(" * the actual string value\n");
4813: buf.append(" */\n");
4814: buf
4815: .append(" public ComparisonFailure(final String message, final String expected,\n");
4816: buf.append(" final String actual) {\n");
4817: buf.append(" super(message);\n");
4818: buf.append(" this.fExpected = expected;\n");
4819: buf.append(" this.fActual = actual;\n");
4820: buf.append(" }\n");
4821: buf.append("\n");
4822: buf.append(" /**\n");
4823: buf
4824: .append(" * Returns \"...\" in place of common prefix and \"...\" in place of common\n");
4825: buf.append(" * suffix between expected and actual.\n");
4826: buf.append(" * \n");
4827: buf.append(" * @see java.lang.Throwable#getMessage()\n");
4828: buf.append(" */\n");
4829: buf.append(" @Override\n");
4830: buf.append(" public String getMessage() {\n");
4831: buf
4832: .append(" if ((this.fExpected == null) || (this.fActual == null)) {\n");
4833: buf
4834: .append(" return Assert.format(super.getMessage(), this.fExpected,\n");
4835: buf.append(" this.fActual);\n");
4836: buf.append(" }\n");
4837: buf.append("\n");
4838: buf.append(" final int end = Math\n");
4839: buf
4840: .append(" .min(this.fExpected.length(), this.fActual.length());\n");
4841: buf.append("\n");
4842: buf.append(" int i = 0;\n");
4843: buf.append(" for (; i < end; i++) {\n");
4844: buf
4845: .append(" if (this.fExpected.charAt(i) != this.fActual.charAt(i)) {\n");
4846: buf.append(" break;\n");
4847: buf.append(" }\n");
4848: buf.append(" }\n");
4849: buf.append(" int j = this.fExpected.length() - 1;\n");
4850: buf.append(" int k = this.fActual.length() - 1;\n");
4851: buf
4852: .append(" for (; (k >= i) && (j >= i); k--, j--) {\n");
4853: buf
4854: .append(" if (this.fExpected.charAt(j) != this.fActual.charAt(k)) {\n");
4855: buf.append(" break;\n");
4856: buf.append(" }\n");
4857: buf.append(" }\n");
4858: buf.append(" String actual, expected;\n");
4859: buf.append("\n");
4860: buf.append(" // equal strings\n");
4861: buf.append(" if ((j < i) && (k < i)) {\n");
4862: buf.append(" expected = this.fExpected;\n");
4863: buf.append(" actual = this.fActual;\n");
4864: buf.append(" } else {\n");
4865: buf
4866: .append(" expected = this.fExpected.substring(i, j + 1);\n");
4867: buf
4868: .append(" actual = this.fActual.substring(i, k + 1);\n");
4869: buf.append(" if ((i <= end) && (i > 0)) {\n");
4870: buf
4871: .append(" expected = \"...\" + expected; //$NON-NLS-1$\n");
4872: buf
4873: .append(" actual = \"...\" + actual; //$NON-NLS-1$\n");
4874: buf.append(" }\n");
4875: buf.append("\n");
4876: buf
4877: .append(" if (j < this.fExpected.length() - 1) {\n");
4878: buf
4879: .append(" expected = expected + \"...\"; //$NON-NLS-1$\n");
4880: buf.append(" }\n");
4881: buf
4882: .append(" if (k < this.fActual.length() - 1) {\n");
4883: buf
4884: .append(" actual = actual + \"...\"; //$NON-NLS-1$\n");
4885: buf.append(" }\n");
4886: buf.append(" }\n");
4887: buf
4888: .append(" return Assert.format(super.getMessage(), expected, actual);\n");
4889: buf.append(" }\n");
4890: buf.append("}");
4891: fExpectedChangesAllTests.put(
4892: "junit.framework.ComparisonFailure.java", buf
4893: .toString());
4894: buf = new StringBuffer();
4895: buf.append("package junit.tests.framework;\n");
4896: buf.append("\n");
4897: buf.append("import junit.framework.Assert;\n");
4898: buf.append("import junit.framework.AssertionFailedError;\n");
4899: buf.append("import junit.framework.Test;\n");
4900: buf.append("import junit.framework.TestCase;\n");
4901: buf.append("import junit.framework.TestFailure;\n");
4902: buf.append("import junit.framework.TestResult;\n");
4903: buf.append("import junit.framework.TestSuite;\n");
4904: buf.append("import junit.tests.WasRun;\n");
4905: buf.append("\n");
4906: buf.append("/**\n");
4907: buf.append(" * A test case testing the testing framework.\n");
4908: buf.append(" * \n");
4909: buf.append(" */\n");
4910: buf.append("public class TestCaseTest extends TestCase {\n");
4911: buf.append("\n");
4912: buf.append(" static class TornDown extends TestCase {\n");
4913: buf.append(" boolean fTornDown = false;\n");
4914: buf.append("\n");
4915: buf.append(" @Override\n");
4916: buf.append(" protected void runTest() {\n");
4917: buf.append(" throw new Error();\n");
4918: buf.append(" }\n");
4919: buf.append(" @Override\n");
4920: buf.append(" protected void tearDown() {\n");
4921: buf.append(" this.fTornDown = true;\n");
4922: buf.append(" }\n");
4923: buf.append(" }\n");
4924: buf.append("\n");
4925: buf.append(" public void testCaseToString() {\n");
4926: buf
4927: .append(" // This test wins the award for twisted snake tail eating while\n");
4928: buf
4929: .append(" // writing self tests. And you thought those weird anonymous\n");
4930: buf.append(" // inner classes were bad...\n");
4931: buf.append(" Assert\n");
4932: buf.append(" .assertEquals(\n");
4933: buf
4934: .append(" \"testCaseToString(junit.tests.framework.TestCaseTest)\", this.toString()); //$NON-NLS-1$\n");
4935: buf.append(" }\n");
4936: buf.append(" public void testError() {\n");
4937: buf
4938: .append(" final TestCase error = new TestCase(\"error\") { //$NON-NLS-1$\n");
4939: buf.append(" @Override\n");
4940: buf.append(" protected void runTest() {\n");
4941: buf.append(" throw new Error();\n");
4942: buf.append(" }\n");
4943: buf.append(" };\n");
4944: buf.append(" this.verifyError(error);\n");
4945: buf.append(" }\n");
4946: buf
4947: .append(" public void testExceptionRunningAndTearDown() {\n");
4948: buf
4949: .append(" // This test documents the current behavior. With 1.4, we should\n");
4950: buf
4951: .append(" // wrap the exception thrown while running with the exception thrown\n");
4952: buf.append(" // while tearing down\n");
4953: buf.append(" final Test t = new TornDown() {\n");
4954: buf.append(" @Override\n");
4955: buf.append(" public void tearDown() {\n");
4956: buf
4957: .append(" throw new Error(\"tearDown\"); //$NON-NLS-1$\n");
4958: buf.append(" }\n");
4959: buf.append(" };\n");
4960: buf
4961: .append(" final TestResult result = new TestResult();\n");
4962: buf.append(" t.run(result);\n");
4963: buf
4964: .append(" final TestFailure failure = (TestFailure) result.errors().nextElement();\n");
4965: buf
4966: .append(" Assert.assertEquals(\"tearDown\", failure.thrownException().getMessage()); //$NON-NLS-1$\n");
4967: buf.append(" }\n");
4968: buf.append(" public void testFailure() {\n");
4969: buf
4970: .append(" final TestCase failure = new TestCase(\"failure\") { //$NON-NLS-1$\n");
4971: buf.append(" @Override\n");
4972: buf.append(" protected void runTest() {\n");
4973: buf.append(" Assert.fail();\n");
4974: buf.append(" }\n");
4975: buf.append(" };\n");
4976: buf.append(" this.verifyFailure(failure);\n");
4977: buf.append(" }\n");
4978: buf.append(" public void testNamelessTestCase() {\n");
4979: buf.append(" final TestCase t = new TestCase() {\n");
4980: buf.append(" };\n");
4981: buf.append(" try {\n");
4982: buf.append(" t.run();\n");
4983: buf.append(" Assert.fail();\n");
4984: buf
4985: .append(" } catch (final AssertionFailedError e) {\n");
4986: buf.append(" }\n");
4987: buf.append(" }\n");
4988: buf.append(" public void testNoArgTestCasePasses() {\n");
4989: buf
4990: .append(" final Test t = new TestSuite(NoArgTestCaseTest.class);\n");
4991: buf
4992: .append(" final TestResult result = new TestResult();\n");
4993: buf.append(" t.run(result);\n");
4994: buf
4995: .append(" Assert.assertTrue(result.runCount() == 1);\n");
4996: buf
4997: .append(" Assert.assertTrue(result.failureCount() == 0);\n");
4998: buf
4999: .append(" Assert.assertTrue(result.errorCount() == 0);\n");
5000: buf.append(" }\n");
5001: buf.append("\n");
5002: buf.append(" public void testRunAndTearDownFails() {\n");
5003: buf.append(" final TornDown fails = new TornDown() {\n");
5004: buf.append(" @Override\n");
5005: buf.append(" protected void runTest() {\n");
5006: buf.append(" throw new Error();\n");
5007: buf.append(" }\n");
5008: buf.append(" @Override\n");
5009: buf.append(" protected void tearDown() {\n");
5010: buf.append(" super.tearDown();\n");
5011: buf.append(" throw new Error();\n");
5012: buf.append(" }\n");
5013: buf.append(" };\n");
5014: buf.append(" this.verifyError(fails);\n");
5015: buf.append(" Assert.assertTrue(fails.fTornDown);\n");
5016: buf.append(" }\n");
5017: buf.append("\n");
5018: buf.append(" public void testSetupFails() {\n");
5019: buf
5020: .append(" final TestCase fails = new TestCase(\"success\") { //$NON-NLS-1$\n");
5021: buf.append(" @Override\n");
5022: buf.append(" protected void runTest() {\n");
5023: buf.append(" }\n");
5024: buf.append(" @Override\n");
5025: buf.append(" protected void setUp() {\n");
5026: buf.append(" throw new Error();\n");
5027: buf.append(" }\n");
5028: buf.append(" };\n");
5029: buf.append(" this.verifyError(fails);\n");
5030: buf.append(" }\n");
5031: buf.append(" public void testSuccess() {\n");
5032: buf
5033: .append(" final TestCase success = new TestCase(\"success\") { //$NON-NLS-1$\n");
5034: buf.append(" @Override\n");
5035: buf.append(" protected void runTest() {\n");
5036: buf.append(" }\n");
5037: buf.append(" };\n");
5038: buf.append(" this.verifySuccess(success);\n");
5039: buf.append(" }\n");
5040: buf.append(" public void testTearDownAfterError() {\n");
5041: buf.append(" final TornDown fails = new TornDown();\n");
5042: buf.append(" this.verifyError(fails);\n");
5043: buf.append(" Assert.assertTrue(fails.fTornDown);\n");
5044: buf.append(" }\n");
5045: buf.append(" public void testTearDownFails() {\n");
5046: buf
5047: .append(" final TestCase fails = new TestCase(\"success\") { //$NON-NLS-1$\n");
5048: buf.append(" @Override\n");
5049: buf.append(" protected void runTest() {\n");
5050: buf.append(" }\n");
5051: buf.append(" @Override\n");
5052: buf.append(" protected void tearDown() {\n");
5053: buf.append(" throw new Error();\n");
5054: buf.append(" }\n");
5055: buf.append(" };\n");
5056: buf.append(" this.verifyError(fails);\n");
5057: buf.append(" }\n");
5058: buf.append("\n");
5059: buf.append(" public void testTearDownSetupFails() {\n");
5060: buf.append(" final TornDown fails = new TornDown() {\n");
5061: buf.append(" @Override\n");
5062: buf.append(" protected void setUp() {\n");
5063: buf.append(" throw new Error();\n");
5064: buf.append(" }\n");
5065: buf.append(" };\n");
5066: buf.append(" this.verifyError(fails);\n");
5067: buf.append(" Assert.assertTrue(!fails.fTornDown);\n");
5068: buf.append(" }\n");
5069: buf.append("\n");
5070: buf.append(" public void testWasRun() {\n");
5071: buf.append(" final WasRun test = new WasRun();\n");
5072: buf.append(" test.run();\n");
5073: buf.append(" Assert.assertTrue(test.fWasRun);\n");
5074: buf.append(" }\n");
5075: buf.append("\n");
5076: buf.append(" void verifyError(final TestCase test) {\n");
5077: buf.append(" final TestResult result = test.run();\n");
5078: buf
5079: .append(" Assert.assertTrue(result.runCount() == 1);\n");
5080: buf
5081: .append(" Assert.assertTrue(result.failureCount() == 0);\n");
5082: buf
5083: .append(" Assert.assertTrue(result.errorCount() == 1);\n");
5084: buf.append(" }\n");
5085: buf.append(" void verifyFailure(final TestCase test) {\n");
5086: buf.append(" final TestResult result = test.run();\n");
5087: buf
5088: .append(" Assert.assertTrue(result.runCount() == 1);\n");
5089: buf
5090: .append(" Assert.assertTrue(result.failureCount() == 1);\n");
5091: buf
5092: .append(" Assert.assertTrue(result.errorCount() == 0);\n");
5093: buf.append(" }\n");
5094: buf.append(" void verifySuccess(final TestCase test) {\n");
5095: buf.append(" final TestResult result = test.run();\n");
5096: buf
5097: .append(" Assert.assertTrue(result.runCount() == 1);\n");
5098: buf
5099: .append(" Assert.assertTrue(result.failureCount() == 0);\n");
5100: buf
5101: .append(" Assert.assertTrue(result.errorCount() == 0);\n");
5102: buf.append(" }\n");
5103: buf.append("}");
5104: fExpectedChangesAllTests.put(
5105: "junit.tests.framework.TestCaseTest.java", buf
5106: .toString());
5107: buf = new StringBuffer();
5108: buf.append("package junit.framework;\n");
5109: buf.append("\n");
5110: buf.append("import java.io.PrintWriter;\n");
5111: buf.append("import java.io.StringWriter;\n");
5112: buf.append("\n");
5113: buf.append("/**\n");
5114: buf
5115: .append(" * A <code>TestFailure</code> collects a failed test together with the caught\n");
5116: buf.append(" * exception.\n");
5117: buf.append(" * \n");
5118: buf.append(" * @see TestResult\n");
5119: buf.append(" */\n");
5120: buf.append("public class TestFailure extends Object {\n");
5121: buf.append(" protected Test fFailedTest;\n");
5122: buf.append(" protected Throwable fThrownException;\n");
5123: buf.append("\n");
5124: buf.append(" /**\n");
5125: buf
5126: .append(" * Constructs a TestFailure with the given test and exception.\n");
5127: buf.append(" */\n");
5128: buf
5129: .append(" public TestFailure(final Test failedTest, final Throwable thrownException) {\n");
5130: buf.append(" this.fFailedTest = failedTest;\n");
5131: buf
5132: .append(" this.fThrownException = thrownException;\n");
5133: buf.append(" }\n");
5134: buf.append(" public String exceptionMessage() {\n");
5135: buf
5136: .append(" return this.thrownException().getMessage();\n");
5137: buf.append(" }\n");
5138: buf.append(" /**\n");
5139: buf.append(" * Gets the failed test.\n");
5140: buf.append(" */\n");
5141: buf.append(" public Test failedTest() {\n");
5142: buf.append(" return this.fFailedTest;\n");
5143: buf.append(" }\n");
5144: buf.append(" public boolean isFailure() {\n");
5145: buf
5146: .append(" return this.thrownException() instanceof AssertionFailedError;\n");
5147: buf.append(" }\n");
5148: buf.append(" /**\n");
5149: buf.append(" * Gets the thrown exception.\n");
5150: buf.append(" */\n");
5151: buf.append(" public Throwable thrownException() {\n");
5152: buf.append(" return this.fThrownException;\n");
5153: buf.append(" }\n");
5154: buf.append(" /**\n");
5155: buf
5156: .append(" * Returns a short description of the failure.\n");
5157: buf.append(" */\n");
5158: buf.append(" @Override\n");
5159: buf.append(" public String toString() {\n");
5160: buf
5161: .append(" final StringBuffer buffer = new StringBuffer();\n");
5162: buf.append(" buffer.append(this.fFailedTest\n");
5163: buf
5164: .append(" + \": \" + this.fThrownException.getMessage()); //$NON-NLS-1$\n");
5165: buf.append(" return buffer.toString();\n");
5166: buf.append(" }\n");
5167: buf.append(" public String trace() {\n");
5168: buf
5169: .append(" final StringWriter stringWriter = new StringWriter();\n");
5170: buf
5171: .append(" final PrintWriter writer = new PrintWriter(stringWriter);\n");
5172: buf
5173: .append(" this.thrownException().printStackTrace(writer);\n");
5174: buf
5175: .append(" final StringBuffer buffer = stringWriter.getBuffer();\n");
5176: buf.append(" return buffer.toString();\n");
5177: buf.append(" }\n");
5178: buf.append("}");
5179: fExpectedChangesAllTests.put(
5180: "junit.framework.TestFailure.java", buf.toString());
5181: buf = new StringBuffer();
5182: buf.append("package junit.runner;\n");
5183: buf.append("\n");
5184: buf.append("/**\n");
5185: buf.append(" * A TestSuite loader that can reload classes.\n");
5186: buf.append(" */\n");
5187: buf
5188: .append("public class ReloadingTestSuiteLoader implements TestSuiteLoader {\n");
5189: buf.append("\n");
5190: buf
5191: .append(" protected TestCaseClassLoader createLoader() {\n");
5192: buf.append(" return new TestCaseClassLoader();\n");
5193: buf.append(" }\n");
5194: buf.append("\n");
5195: buf
5196: .append(" public Class load(final String suiteClassName)\n");
5197: buf.append(" throws ClassNotFoundException {\n");
5198: buf
5199: .append(" return this.createLoader().loadClass(suiteClassName, true);\n");
5200: buf.append(" }\n");
5201: buf.append("\n");
5202: buf
5203: .append(" public Class reload(final Class aClass) throws ClassNotFoundException {\n");
5204: buf
5205: .append(" return this.createLoader().loadClass(aClass.getName(), true);\n");
5206: buf.append(" }\n");
5207: buf.append("}");
5208: fExpectedChangesAllTests.put(
5209: "junit.runner.ReloadingTestSuiteLoader.java", buf
5210: .toString());
5211: buf = new StringBuffer();
5212: buf.append("package junit.runner;\n");
5213: buf.append("\n");
5214: buf.append("/**\n");
5215: buf
5216: .append(" * The standard test suite loader. It can only load the same class once.\n");
5217: buf.append(" */\n");
5218: buf
5219: .append("public class StandardTestSuiteLoader implements TestSuiteLoader {\n");
5220: buf.append(" /**\n");
5221: buf
5222: .append(" * Uses the system class loader to load the test class\n");
5223: buf.append(" */\n");
5224: buf
5225: .append(" public Class load(final String suiteClassName)\n");
5226: buf.append(" throws ClassNotFoundException {\n");
5227: buf.append(" return Class.forName(suiteClassName);\n");
5228: buf.append(" }\n");
5229: buf.append(" /**\n");
5230: buf
5231: .append(" * Uses the system class loader to load the test class\n");
5232: buf.append(" */\n");
5233: buf
5234: .append(" public Class reload(final Class aClass) throws ClassNotFoundException {\n");
5235: buf.append(" return aClass;\n");
5236: buf.append(" }\n");
5237: buf.append("}");
5238: fExpectedChangesAllTests.put(
5239: "junit.runner.StandardTestSuiteLoader.java", buf
5240: .toString());
5241: buf = new StringBuffer();
5242: buf.append("package junit.extensions;\n");
5243: buf.append("\n");
5244: buf.append("import junit.framework.Protectable;\n");
5245: buf.append("import junit.framework.Test;\n");
5246: buf.append("import junit.framework.TestResult;\n");
5247: buf.append("\n");
5248: buf.append("/**\n");
5249: buf
5250: .append(" * A Decorator to set up and tear down additional fixture state. Subclass\n");
5251: buf
5252: .append(" * TestSetup and insert it into your tests when you want to set up additional\n");
5253: buf.append(" * state once before the tests are run.\n");
5254: buf.append(" */\n");
5255: buf.append("public class TestSetup extends TestDecorator {\n");
5256: buf.append("\n");
5257: buf.append(" public TestSetup(final Test test) {\n");
5258: buf.append(" super(test);\n");
5259: buf.append(" }\n");
5260: buf.append(" @Override\n");
5261: buf.append(" public void run(final TestResult result) {\n");
5262: buf
5263: .append(" final Protectable p = new Protectable() {\n");
5264: buf
5265: .append(" public void protect() throws Exception {\n");
5266: buf.append(" TestSetup.this.setUp();\n");
5267: buf
5268: .append(" TestSetup.this.basicRun(result);\n");
5269: buf.append(" TestSetup.this.tearDown();\n");
5270: buf.append(" }\n");
5271: buf.append(" };\n");
5272: buf.append(" result.runProtected(this, p);\n");
5273: buf.append(" }\n");
5274: buf.append(" /**\n");
5275: buf
5276: .append(" * Sets up the fixture. Override to set up additional fixture state.\n");
5277: buf.append(" */\n");
5278: buf.append(" protected void setUp() throws Exception {\n");
5279: buf.append(" }\n");
5280: buf.append(" /**\n");
5281: buf
5282: .append(" * Tears down the fixture. Override to tear down the additional fixture\n");
5283: buf.append(" * state.\n");
5284: buf.append(" */\n");
5285: buf
5286: .append(" protected void tearDown() throws Exception {\n");
5287: buf.append(" }\n");
5288: buf.append("}");
5289: fExpectedChangesAllTests.put("junit.extensions.TestSetup.java",
5290: buf.toString());
5291: buf = new StringBuffer();
5292: buf.append("package junit.tests.runner;\n");
5293: buf.append("\n");
5294: buf.append("import java.io.File;\n");
5295: buf.append("import java.io.IOException;\n");
5296: buf.append("import java.io.InputStream;\n");
5297: buf.append("import java.io.OutputStream;\n");
5298: buf.append("import java.io.PrintStream;\n");
5299: buf.append("\n");
5300: buf.append("import junit.framework.Assert;\n");
5301: buf.append("import junit.framework.TestCase;\n");
5302: buf.append("import junit.framework.TestResult;\n");
5303: buf.append("import junit.framework.TestSuite;\n");
5304: buf.append("\n");
5305: buf.append("public class TextRunnerTest extends TestCase {\n");
5306: buf.append("\n");
5307: buf
5308: .append(" void execTest(final String testClass, final boolean success)\n");
5309: buf.append(" throws Exception {\n");
5310: buf
5311: .append(" final String java = System.getProperty(\"java.home\") + File.separator + \"bin\" + File.separator + \"java\"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\n");
5312: buf
5313: .append(" final String cp = System.getProperty(\"java.class.path\"); //$NON-NLS-1$\n");
5314: buf
5315: .append(" // use -classpath for JDK 1.1.7 compatibility\n");
5316: buf.append(" final String[] cmd = {java,\n");
5317: buf
5318: .append(" \"-classpath\", cp, \"junit.textui.TestRunner\", testClass}; //$NON-NLS-1$ //$NON-NLS-2$\n");
5319: buf
5320: .append(" final Process p = Runtime.getRuntime().exec(cmd);\n");
5321: buf
5322: .append(" final InputStream i = p.getInputStream();\n");
5323: buf.append(" int b;\n");
5324: buf.append(" while ((b = i.read()) != -1) {\n");
5325: buf.append(" ; // System.out.write(b);\n");
5326: buf.append(" }\n");
5327: buf
5328: .append(" Assert.assertTrue((p.waitFor() == 0) == success);\n");
5329: buf.append(" if (success) {\n");
5330: buf
5331: .append(" Assert.assertEquals(junit.textui.TestRunner.SUCCESS_EXIT, p\n");
5332: buf.append(" .exitValue());\n");
5333: buf.append(" } else {\n");
5334: buf
5335: .append(" Assert.assertEquals(junit.textui.TestRunner.FAILURE_EXIT, p\n");
5336: buf.append(" .exitValue());\n");
5337: buf.append(" }\n");
5338: buf.append(" }\n");
5339: buf.append("\n");
5340: buf.append(" public void testError() throws Exception {\n");
5341: buf
5342: .append(" this.execTest(\"junit.tests.BogusDude\", false); //$NON-NLS-1$\n");
5343: buf.append(" }\n");
5344: buf.append("\n");
5345: buf
5346: .append(" public void testFailure() throws Exception {\n");
5347: buf
5348: .append(" this.execTest(\"junit.tests.framework.Failure\", false); //$NON-NLS-1$\n");
5349: buf.append(" }\n");
5350: buf.append("\n");
5351: buf.append(" public void testRunReturnsResult() {\n");
5352: buf.append(" final PrintStream oldOut = System.out;\n");
5353: buf
5354: .append(" System.setOut(new PrintStream(new OutputStream() {\n");
5355: buf.append(" @Override\n");
5356: buf
5357: .append(" public void write(final int arg0) throws IOException {\n");
5358: buf.append(" }\n");
5359: buf.append(" }));\n");
5360: buf.append(" try {\n");
5361: buf
5362: .append(" final TestResult result = junit.textui.TestRunner\n");
5363: buf.append(" .run(new TestSuite());\n");
5364: buf
5365: .append(" Assert.assertTrue(result.wasSuccessful());\n");
5366: buf.append(" } finally {\n");
5367: buf.append(" System.setOut(oldOut);\n");
5368: buf.append(" }\n");
5369: buf.append(" }\n");
5370: buf.append("\n");
5371: buf
5372: .append(" public void testSuccess() throws Exception {\n");
5373: buf
5374: .append(" this.execTest(\"junit.tests.framework.Success\", true); //$NON-NLS-1$\n");
5375: buf.append(" }\n");
5376: buf.append("\n");
5377: buf.append("}");
5378: fExpectedChangesAllTests.put(
5379: "junit.tests.runner.TextRunnerTest.java", buf
5380: .toString());
5381: buf = new StringBuffer();
5382: buf.append("package junit.tests.framework;\n");
5383: buf.append("\n");
5384: buf.append("import junit.framework.Assert;\n");
5385: buf.append("import junit.framework.TestCase;\n");
5386: buf.append("\n");
5387: buf.append("/**\n");
5388: buf.append(" * A test case testing the testing framework.\n");
5389: buf.append(" * \n");
5390: buf.append(" */\n");
5391: buf.append("public class Failure extends TestCase {\n");
5392: buf.append(" @Override\n");
5393: buf.append(" public void runTest() {\n");
5394: buf.append(" Assert.fail();\n");
5395: buf.append(" }\n");
5396: buf.append("}");
5397: fExpectedChangesAllTests.put(
5398: "junit.tests.framework.Failure.java", buf.toString());
5399: buf = new StringBuffer();
5400: buf.append("package junit.tests.framework;\n");
5401: buf.append("\n");
5402: buf.append("/**\n");
5403: buf.append(" * Test class used in SuiteTest\n");
5404: buf.append(" */\n");
5405: buf
5406: .append("public class OverrideTestCase extends OneTestCase {\n");
5407: buf.append(" @Override\n");
5408: buf.append(" public void testCase() {\n");
5409: buf.append(" }\n");
5410: buf.append("}");
5411: fExpectedChangesAllTests.put(
5412: "junit.tests.framework.OverrideTestCase.java", buf
5413: .toString());
5414: buf = new StringBuffer();
5415: buf.append("package junit.extensions;\n");
5416: buf.append("\n");
5417: buf.append("import junit.framework.Test;\n");
5418: buf.append("import junit.framework.TestResult;\n");
5419: buf.append("\n");
5420: buf.append("/**\n");
5421: buf.append(" * A Decorator that runs a test repeatedly.\n");
5422: buf.append(" * \n");
5423: buf.append(" */\n");
5424: buf
5425: .append("public class RepeatedTest extends TestDecorator {\n");
5426: buf.append(" private final int fTimesRepeat;\n");
5427: buf.append("\n");
5428: buf
5429: .append(" public RepeatedTest(final Test test, final int repeat) {\n");
5430: buf.append(" super(test);\n");
5431: buf.append(" if (repeat < 0) {\n");
5432: buf
5433: .append(" throw new IllegalArgumentException(\"Repetition count must be > 0\"); //$NON-NLS-1$\n");
5434: buf.append(" }\n");
5435: buf.append(" this.fTimesRepeat = repeat;\n");
5436: buf.append(" }\n");
5437: buf.append(" @Override\n");
5438: buf.append(" public int countTestCases() {\n");
5439: buf
5440: .append(" return super.countTestCases() * this.fTimesRepeat;\n");
5441: buf.append(" }\n");
5442: buf.append(" @Override\n");
5443: buf.append(" public void run(final TestResult result) {\n");
5444: buf
5445: .append(" for (int i = 0; i < this.fTimesRepeat; i++) {\n");
5446: buf.append(" if (result.shouldStop()) {\n");
5447: buf.append(" break;\n");
5448: buf.append(" }\n");
5449: buf.append(" super.run(result);\n");
5450: buf.append(" }\n");
5451: buf.append(" }\n");
5452: buf.append(" @Override\n");
5453: buf.append(" public String toString() {\n");
5454: buf
5455: .append(" return super.toString() + \"(repeated)\"; //$NON-NLS-1$\n");
5456: buf.append(" }\n");
5457: buf.append("}");
5458: fExpectedChangesAllTests.put(
5459: "junit.extensions.RepeatedTest.java", buf.toString());
5460: buf = new StringBuffer();
5461: buf.append("package junit.tests.framework;\n");
5462: buf.append("\n");
5463: buf.append("import junit.framework.TestCase;\n");
5464: buf.append("\n");
5465: buf
5466: .append("public class NoArgTestCaseTest extends TestCase {\n");
5467: buf
5468: .append(" public void testNothing() { // If this compiles, the no arg ctor is there\n");
5469: buf.append(" }\n");
5470: buf.append("}\n");
5471: buf.append("");
5472: fExpectedChangesAllTests.put(
5473: "junit.tests.framework.NoArgTestCaseTest.java", buf
5474: .toString());
5475: buf = new StringBuffer();
5476: buf.append("package junit.runner;\n");
5477: buf.append("\n");
5478: buf.append("import java.util.Vector;\n");
5479: buf.append("\n");
5480: buf.append("/**\n");
5481: buf
5482: .append(" * A custom quick sort with support to customize the swap behaviour. NOTICE: We\n");
5483: buf
5484: .append(" * can't use the the sorting support from the JDK 1.2 collection classes because\n");
5485: buf.append(" * of the JDK 1.1.7 compatibility.\n");
5486: buf.append(" */\n");
5487: buf.append("public class Sorter {\n");
5488: buf.append(" public static interface Swapper {\n");
5489: buf
5490: .append(" public void swap(Vector values, int left, int right);\n");
5491: buf.append(" }\n");
5492: buf.append("\n");
5493: buf
5494: .append(" public static void sortStrings(final Vector values, int left, int right,\n");
5495: buf.append(" final Swapper swapper) {\n");
5496: buf.append(" final int oleft = left;\n");
5497: buf.append(" final int oright = right;\n");
5498: buf
5499: .append(" final String mid = (String) values.elementAt((left + right) / 2);\n");
5500: buf.append(" do {\n");
5501: buf
5502: .append(" while (((String) (values.elementAt(left))).compareTo(mid) < 0) {\n");
5503: buf.append(" left++;\n");
5504: buf.append(" }\n");
5505: buf
5506: .append(" while (mid.compareTo((String) (values.elementAt(right))) < 0) {\n");
5507: buf.append(" right--;\n");
5508: buf.append(" }\n");
5509: buf.append(" if (left <= right) {\n");
5510: buf
5511: .append(" swapper.swap(values, left, right);\n");
5512: buf.append(" left++;\n");
5513: buf.append(" right--;\n");
5514: buf.append(" }\n");
5515: buf.append(" } while (left <= right);\n");
5516: buf.append("\n");
5517: buf.append(" if (oleft < right) {\n");
5518: buf
5519: .append(" Sorter.sortStrings(values, oleft, right, swapper);\n");
5520: buf.append(" }\n");
5521: buf.append(" if (left < oright) {\n");
5522: buf
5523: .append(" Sorter.sortStrings(values, left, oright, swapper);\n");
5524: buf.append(" }\n");
5525: buf.append(" }\n");
5526: buf.append("}");
5527: fExpectedChangesAllTests.put("junit.runner.Sorter.java", buf
5528: .toString());
5529: buf = new StringBuffer();
5530: buf.append("package junit.tests.framework;\n");
5531: buf.append("\n");
5532: buf.append("import junit.framework.Test;\n");
5533: buf.append("import junit.framework.TestSuite;\n");
5534: buf.append("\n");
5535: buf.append("/**\n");
5536: buf.append(" * TestSuite that runs all the sample tests\n");
5537: buf.append(" * \n");
5538: buf.append(" */\n");
5539: buf.append("public class AllTests {\n");
5540: buf.append("\n");
5541: buf
5542: .append(" public static void main(final String[] args) {\n");
5543: buf
5544: .append(" junit.textui.TestRunner.run(AllTests.suite());\n");
5545: buf.append(" }\n");
5546: buf.append("\n");
5547: buf.append(" public static Test suite() {\n");
5548: buf
5549: .append(" final TestSuite suite = new TestSuite(\"Framework Tests\"); //$NON-NLS-1$\n");
5550: buf.append(" suite.addTestSuite(TestCaseTest.class);\n");
5551: buf
5552: .append(" suite.addTest(SuiteTest.suite()); // Tests suite building, so can't\n");
5553: buf.append(" // use automatic test extraction\n");
5554: buf
5555: .append(" suite.addTestSuite(TestListenerTest.class);\n");
5556: buf.append(" suite.addTestSuite(AssertTest.class);\n");
5557: buf
5558: .append(" suite.addTestSuite(TestImplementorTest.class);\n");
5559: buf
5560: .append(" suite.addTestSuite(NoArgTestCaseTest.class);\n");
5561: buf
5562: .append(" suite.addTestSuite(ComparisonFailureTest.class);\n");
5563: buf
5564: .append(" suite.addTestSuite(DoublePrecisionAssertTest.class);\n");
5565: buf.append(" return suite;\n");
5566: buf.append(" }\n");
5567: buf.append("\n");
5568: buf.append("}");
5569: fExpectedChangesAllTests.put(
5570: "junit.tests.framework.AllTests.java", buf.toString());
5571: buf = new StringBuffer();
5572: buf.append("package junit.tests.extensions;\n");
5573: buf.append("\n");
5574: buf.append("import junit.extensions.RepeatedTest;\n");
5575: buf.append("import junit.framework.Assert;\n");
5576: buf.append("import junit.framework.Test;\n");
5577: buf.append("import junit.framework.TestCase;\n");
5578: buf.append("import junit.framework.TestResult;\n");
5579: buf.append("import junit.framework.TestSuite;\n");
5580: buf.append("\n");
5581: buf.append("/**\n");
5582: buf.append(" * Testing the RepeatedTest support.\n");
5583: buf.append(" */\n");
5584: buf.append("\n");
5585: buf
5586: .append("public class RepeatedTestTest extends TestCase {\n");
5587: buf
5588: .append(" public static class SuccessTest extends TestCase {\n");
5589: buf.append("\n");
5590: buf.append(" @Override\n");
5591: buf.append(" public void runTest() {\n");
5592: buf.append(" }\n");
5593: buf.append(" }\n");
5594: buf.append("\n");
5595: buf.append(" private final TestSuite fSuite;\n");
5596: buf.append("\n");
5597: buf
5598: .append(" public RepeatedTestTest(final String name) {\n");
5599: buf.append(" super(name);\n");
5600: buf.append(" this.fSuite = new TestSuite();\n");
5601: buf.append(" this.fSuite.addTest(new SuccessTest());\n");
5602: buf.append(" this.fSuite.addTest(new SuccessTest());\n");
5603: buf.append(" }\n");
5604: buf.append("\n");
5605: buf.append(" public void testRepeatedMoreThanOnce() {\n");
5606: buf
5607: .append(" final Test test = new RepeatedTest(this.fSuite, 3);\n");
5608: buf
5609: .append(" Assert.assertEquals(6, test.countTestCases());\n");
5610: buf
5611: .append(" final TestResult result = new TestResult();\n");
5612: buf.append(" test.run(result);\n");
5613: buf
5614: .append(" Assert.assertEquals(6, result.runCount());\n");
5615: buf.append(" }\n");
5616: buf.append("\n");
5617: buf.append(" public void testRepeatedNegative() {\n");
5618: buf.append(" try {\n");
5619: buf.append(" new RepeatedTest(this.fSuite, -1);\n");
5620: buf
5621: .append(" } catch (final IllegalArgumentException e) {\n");
5622: buf.append(" return;\n");
5623: buf.append(" }\n");
5624: buf
5625: .append(" Assert.fail(\"Should throw an IllegalArgumentException\"); //$NON-NLS-1$\n");
5626: buf.append(" }\n");
5627: buf.append("\n");
5628: buf.append(" public void testRepeatedOnce() {\n");
5629: buf
5630: .append(" final Test test = new RepeatedTest(this.fSuite, 1);\n");
5631: buf
5632: .append(" Assert.assertEquals(2, test.countTestCases());\n");
5633: buf
5634: .append(" final TestResult result = new TestResult();\n");
5635: buf.append(" test.run(result);\n");
5636: buf
5637: .append(" Assert.assertEquals(2, result.runCount());\n");
5638: buf.append(" }\n");
5639: buf.append("\n");
5640: buf.append(" public void testRepeatedZero() {\n");
5641: buf
5642: .append(" final Test test = new RepeatedTest(this.fSuite, 0);\n");
5643: buf
5644: .append(" Assert.assertEquals(0, test.countTestCases());\n");
5645: buf
5646: .append(" final TestResult result = new TestResult();\n");
5647: buf.append(" test.run(result);\n");
5648: buf
5649: .append(" Assert.assertEquals(0, result.runCount());\n");
5650: buf.append(" }\n");
5651: buf.append("}");
5652: fExpectedChangesAllTests.put(
5653: "junit.tests.extensions.RepeatedTestTest.java", buf
5654: .toString());
5655: buf = new StringBuffer();
5656: buf.append("package junit.tests.runner;\n");
5657: buf.append("\n");
5658: buf.append("import junit.framework.Test;\n");
5659: buf.append("import junit.framework.TestSuite;\n");
5660: buf.append("import junit.runner.BaseTestRunner;\n");
5661: buf.append("\n");
5662: buf.append("/**\n");
5663: buf.append(" * TestSuite that runs all the sample tests\n");
5664: buf.append(" * \n");
5665: buf.append(" */\n");
5666: buf.append("public class AllTests {\n");
5667: buf.append("\n");
5668: buf.append(" static boolean isJDK11() {\n");
5669: buf
5670: .append(" final String version = System.getProperty(\"java.version\"); //$NON-NLS-1$\n");
5671: buf
5672: .append(" return version.startsWith(\"1.1\"); //$NON-NLS-1$\n");
5673: buf.append(" }\n");
5674: buf.append("\n");
5675: buf
5676: .append(" public static void main(final String[] args) {\n");
5677: buf
5678: .append(" junit.textui.TestRunner.run(AllTests.suite());\n");
5679: buf.append(" }\n");
5680: buf.append("\n");
5681: buf
5682: .append(" public static Test suite() { // Collect tests manually because we have to\n");
5683: buf
5684: .append(" // test class collection code\n");
5685: buf
5686: .append(" final TestSuite suite = new TestSuite(\"Framework Tests\"); //$NON-NLS-1$\n");
5687: buf
5688: .append(" suite.addTestSuite(StackFilterTest.class);\n");
5689: buf.append(" suite.addTestSuite(SorterTest.class);\n");
5690: buf
5691: .append(" suite.addTestSuite(SimpleTestCollectorTest.class);\n");
5692: buf
5693: .append(" suite.addTestSuite(BaseTestRunnerTest.class);\n");
5694: buf
5695: .append(" suite.addTestSuite(TextFeedbackTest.class);\n");
5696: buf.append(" if (!BaseTestRunner.inVAJava()) {\n");
5697: buf
5698: .append(" suite.addTestSuite(TextRunnerTest.class);\n");
5699: buf.append(" if (!AllTests.isJDK11()) {\n");
5700: buf
5701: .append(" suite.addTest(new TestSuite(TestCaseClassLoaderTest.class));\n");
5702: buf.append(" }\n");
5703: buf.append(" }\n");
5704: buf.append(" return suite;\n");
5705: buf.append(" }\n");
5706: buf.append("}");
5707: fExpectedChangesAllTests.put(
5708: "junit.tests.runner.AllTests.java", buf.toString());
5709: buf = new StringBuffer();
5710: buf.append("package junit.runner;\n");
5711: buf.append("\n");
5712: buf.append("import java.util.Enumeration;\n");
5713: buf.append("\n");
5714: buf.append("/**\n");
5715: buf
5716: .append(" * Collects Test class names to be presented by the TestSelector.\n");
5717: buf.append(" * \n");
5718: buf.append(" * @see TestSelector\n");
5719: buf.append(" */\n");
5720: buf.append("public interface TestCollector {\n");
5721: buf.append(" /**\n");
5722: buf
5723: .append(" * Returns an enumeration of Strings with qualified class names\n");
5724: buf.append(" */\n");
5725: buf.append(" public Enumeration collectTests();\n");
5726: buf.append("}\n");
5727: buf.append("");
5728: fExpectedChangesAllTests.put("junit.runner.TestCollector.java",
5729: buf.toString());
5730: buf = new StringBuffer();
5731: buf.append("package junit.samples.money;\n");
5732: buf.append("\n");
5733: buf.append("import java.util.Enumeration;\n");
5734: buf.append("import java.util.Vector;\n");
5735: buf.append("\n");
5736: buf.append("/**\n");
5737: buf
5738: .append(" * A MoneyBag defers exchange rate conversions. For example adding 12 Swiss\n");
5739: buf
5740: .append(" * Francs to 14 US Dollars is represented as a bag containing the two Monies 12\n");
5741: buf
5742: .append(" * CHF and 14 USD. Adding another 10 Swiss francs gives a bag with 22 CHF and 14\n");
5743: buf
5744: .append(" * USD. Due to the deferred exchange rate conversion we can later value a\n");
5745: buf.append(" * MoneyBag with different exchange rates.\n");
5746: buf.append(" * \n");
5747: buf
5748: .append(" * A MoneyBag is represented as a list of Monies and provides different\n");
5749: buf.append(" * constructors to create a MoneyBag.\n");
5750: buf.append(" */\n");
5751: buf.append("class MoneyBag implements IMoney {\n");
5752: buf
5753: .append(" static IMoney create(final IMoney m1, final IMoney m2) {\n");
5754: buf.append(" final MoneyBag result = new MoneyBag();\n");
5755: buf.append(" m1.appendTo(result);\n");
5756: buf.append(" m2.appendTo(result);\n");
5757: buf.append(" return result.simplify();\n");
5758: buf.append(" }\n");
5759: buf.append("\n");
5760: buf
5761: .append(" private final Vector fMonies = new Vector(5);\n");
5762: buf.append(" public IMoney add(final IMoney m) {\n");
5763: buf.append(" return m.addMoneyBag(this);\n");
5764: buf.append(" }\n");
5765: buf.append(" public IMoney addMoney(final Money m) {\n");
5766: buf.append(" return MoneyBag.create(m, this);\n");
5767: buf.append(" }\n");
5768: buf
5769: .append(" public IMoney addMoneyBag(final MoneyBag s) {\n");
5770: buf.append(" return MoneyBag.create(s, this);\n");
5771: buf.append(" }\n");
5772: buf.append(" void appendBag(final MoneyBag aBag) {\n");
5773: buf
5774: .append(" for (final Enumeration e = aBag.fMonies.elements(); e.hasMoreElements();) {\n");
5775: buf
5776: .append(" this.appendMoney((Money) e.nextElement());\n");
5777: buf.append(" }\n");
5778: buf.append(" }\n");
5779: buf.append(" void appendMoney(final Money aMoney) {\n");
5780: buf.append(" if (aMoney.isZero()) {\n");
5781: buf.append(" return;\n");
5782: buf.append(" }\n");
5783: buf
5784: .append(" final IMoney old = this.findMoney(aMoney.currency());\n");
5785: buf.append(" if (old == null) {\n");
5786: buf.append(" this.fMonies.addElement(aMoney);\n");
5787: buf.append(" return;\n");
5788: buf.append(" }\n");
5789: buf.append(" this.fMonies.removeElement(old);\n");
5790: buf.append(" final IMoney sum = old.add(aMoney);\n");
5791: buf.append(" if (sum.isZero()) {\n");
5792: buf.append(" return;\n");
5793: buf.append(" }\n");
5794: buf.append(" this.fMonies.addElement(sum);\n");
5795: buf.append(" }\n");
5796: buf.append(" public void appendTo(final MoneyBag m) {\n");
5797: buf.append(" m.appendBag(this);\n");
5798: buf.append(" }\n");
5799: buf.append(" private boolean contains(final Money m) {\n");
5800: buf
5801: .append(" final Money found = this.findMoney(m.currency());\n");
5802: buf.append(" if (found == null) {\n");
5803: buf.append(" return false;\n");
5804: buf.append(" }\n");
5805: buf.append(" return found.amount() == m.amount();\n");
5806: buf.append(" }\n");
5807: buf.append(" @Override\n");
5808: buf
5809: .append(" public boolean equals(final Object anObject) {\n");
5810: buf.append(" if (this.isZero()) {\n");
5811: buf.append(" if (anObject instanceof IMoney) {\n");
5812: buf
5813: .append(" return ((IMoney) anObject).isZero();\n");
5814: buf.append(" }\n");
5815: buf.append(" }\n");
5816: buf.append("\n");
5817: buf.append(" if (anObject instanceof MoneyBag) {\n");
5818: buf
5819: .append(" final MoneyBag aMoneyBag = (MoneyBag) anObject;\n");
5820: buf
5821: .append(" if (aMoneyBag.fMonies.size() != this.fMonies.size()) {\n");
5822: buf.append(" return false;\n");
5823: buf.append(" }\n");
5824: buf.append("\n");
5825: buf
5826: .append(" for (final Enumeration e = this.fMonies.elements(); e\n");
5827: buf.append(" .hasMoreElements();) {\n");
5828: buf
5829: .append(" final Money m = (Money) e.nextElement();\n");
5830: buf.append(" if (!aMoneyBag.contains(m)) {\n");
5831: buf.append(" return false;\n");
5832: buf.append(" }\n");
5833: buf.append(" }\n");
5834: buf.append(" return true;\n");
5835: buf.append(" }\n");
5836: buf.append(" return false;\n");
5837: buf.append(" }\n");
5838: buf
5839: .append(" private Money findMoney(final String currency) {\n");
5840: buf
5841: .append(" for (final Enumeration e = this.fMonies.elements(); e.hasMoreElements();) {\n");
5842: buf
5843: .append(" final Money m = (Money) e.nextElement();\n");
5844: buf
5845: .append(" if (m.currency().equals(currency)) {\n");
5846: buf.append(" return m;\n");
5847: buf.append(" }\n");
5848: buf.append(" }\n");
5849: buf.append(" return null;\n");
5850: buf.append(" }\n");
5851: buf.append(" @Override\n");
5852: buf.append(" public int hashCode() {\n");
5853: buf.append(" int hash = 0;\n");
5854: buf
5855: .append(" for (final Enumeration e = this.fMonies.elements(); e.hasMoreElements();) {\n");
5856: buf.append(" final Object m = e.nextElement();\n");
5857: buf.append(" hash ^= m.hashCode();\n");
5858: buf.append(" }\n");
5859: buf.append(" return hash;\n");
5860: buf.append(" }\n");
5861: buf.append(" public boolean isZero() {\n");
5862: buf.append(" return this.fMonies.size() == 0;\n");
5863: buf.append(" }\n");
5864: buf.append(" public IMoney multiply(final int factor) {\n");
5865: buf.append(" final MoneyBag result = new MoneyBag();\n");
5866: buf.append(" if (factor != 0) {\n");
5867: buf
5868: .append(" for (final Enumeration e = this.fMonies.elements(); e\n");
5869: buf.append(" .hasMoreElements();) {\n");
5870: buf
5871: .append(" final Money m = (Money) e.nextElement();\n");
5872: buf
5873: .append(" result.appendMoney((Money) m.multiply(factor));\n");
5874: buf.append(" }\n");
5875: buf.append(" }\n");
5876: buf.append(" return result;\n");
5877: buf.append(" }\n");
5878: buf.append(" public IMoney negate() {\n");
5879: buf.append(" final MoneyBag result = new MoneyBag();\n");
5880: buf
5881: .append(" for (final Enumeration e = this.fMonies.elements(); e.hasMoreElements();) {\n");
5882: buf
5883: .append(" final Money m = (Money) e.nextElement();\n");
5884: buf
5885: .append(" result.appendMoney((Money) m.negate());\n");
5886: buf.append(" }\n");
5887: buf.append(" return result;\n");
5888: buf.append(" }\n");
5889: buf.append(" private IMoney simplify() {\n");
5890: buf.append(" if (this.fMonies.size() == 1) {\n");
5891: buf
5892: .append(" return (IMoney) this.fMonies.elements().nextElement();\n");
5893: buf.append(" }\n");
5894: buf.append(" return this;\n");
5895: buf.append(" }\n");
5896: buf.append(" public IMoney subtract(final IMoney m) {\n");
5897: buf.append(" return this.add(m.negate());\n");
5898: buf.append(" }\n");
5899: buf.append(" @Override\n");
5900: buf.append(" public String toString() {\n");
5901: buf
5902: .append(" final StringBuffer buffer = new StringBuffer();\n");
5903: buf.append(" buffer.append(\"{\"); //$NON-NLS-1$\n");
5904: buf
5905: .append(" for (final Enumeration e = this.fMonies.elements(); e.hasMoreElements();) {\n");
5906: buf.append(" buffer.append(e.nextElement());\n");
5907: buf.append(" }\n");
5908: buf.append(" buffer.append(\"}\"); //$NON-NLS-1$\n");
5909: buf.append(" return buffer.toString();\n");
5910: buf.append(" }\n");
5911: buf.append("}");
5912: fExpectedChangesAllTests.put(
5913: "junit.samples.money.MoneyBag.java", buf.toString());
5914: buf = new StringBuffer();
5915: buf.append("package junit.tests.runner;\n");
5916: buf.append("\n");
5917: buf.append("import junit.framework.Assert;\n");
5918: buf.append("import junit.framework.TestCase;\n");
5919: buf.append("import junit.runner.SimpleTestCollector;\n");
5920: buf.append("\n");
5921: buf
5922: .append("public class SimpleTestCollectorTest extends TestCase {\n");
5923: buf.append("\n");
5924: buf.append(" public void testMissingDirectory() {\n");
5925: buf
5926: .append(" final SimpleTestCollector collector = new SimpleTestCollector();\n");
5927: buf.append(" Assert.assertFalse(collector\n");
5928: buf
5929: .append(" .collectFilesInPath(\"foobar\").elements().hasMoreElements()); //$NON-NLS-1$\n");
5930: buf.append(" }\n");
5931: buf.append("\n");
5932: buf.append("}\n");
5933: buf.append("");
5934: fExpectedChangesAllTests.put(
5935: "junit.tests.runner.SimpleTestCollectorTest.java", buf
5936: .toString());
5937: buf = new StringBuffer();
5938: buf.append("package junit.framework;\n");
5939: buf.append("\n");
5940: buf
5941: .append("import java.lang.reflect.InvocationTargetException;\n");
5942: buf.append("import java.lang.reflect.Method;\n");
5943: buf.append("import java.lang.reflect.Modifier;\n");
5944: buf.append("\n");
5945: buf.append("/**\n");
5946: buf
5947: .append(" * A test case defines the fixture to run multiple tests. To define a test case<br>\n");
5948: buf.append(" * 1) implement a subclass of TestCase<br>\n");
5949: buf
5950: .append(" * 2) define instance variables that store the state of the fixture<br>\n");
5951: buf
5952: .append(" * 3) initialize the fixture state by overriding <code>setUp</code><br>\n");
5953: buf
5954: .append(" * 4) clean-up after a test by overriding <code>tearDown</code>.<br>\n");
5955: buf
5956: .append(" * Each test runs in its own fixture so there can be no side effects among test\n");
5957: buf.append(" * runs. Here is an example:\n");
5958: buf.append(" * \n");
5959: buf.append(" * <pre>\n");
5960: buf.append(" * public class MathTest extends TestCase {\n");
5961: buf.append(" * protected double fValue1;\n");
5962: buf.append(" * protected double fValue2;\n");
5963: buf.append(" * \n");
5964: buf.append(" * protected void setUp() {\n");
5965: buf.append(" * fValue1 = 2.0;\n");
5966: buf.append(" * fValue2 = 3.0;\n");
5967: buf.append(" * }\n");
5968: buf.append(" * }\n");
5969: buf.append(" * </pre>\n");
5970: buf.append(" * \n");
5971: buf
5972: .append(" * For each test implement a method which interacts with the fixture. Verify the\n");
5973: buf
5974: .append(" * expected results with assertions specified by calling <code>assertTrue</code>\n");
5975: buf.append(" * with a boolean.\n");
5976: buf.append(" * \n");
5977: buf.append(" * <pre>\n");
5978: buf.append(" * public void testAdd() {\n");
5979: buf.append(" * double result = fValue1 + fValue2;\n");
5980: buf.append(" * assertTrue(result == 5.0);\n");
5981: buf.append(" * }\n");
5982: buf.append(" * </pre>\n");
5983: buf.append(" * \n");
5984: buf
5985: .append(" * Once the methods are defined you can run them. The framework supports both a\n");
5986: buf
5987: .append(" * static type safe and more dynamic way to run a test. In the static way you\n");
5988: buf
5989: .append(" * override the runTest method and define the method to be invoked. A convenient\n");
5990: buf
5991: .append(" * way to do so is with an anonymous inner class.\n");
5992: buf.append(" * \n");
5993: buf.append(" * <pre>\n");
5994: buf
5995: .append(" * TestCase test = new MathTest("add") {\n");
5996: buf.append(" * public void runTest() {\n");
5997: buf.append(" * testAdd();\n");
5998: buf.append(" * }\n");
5999: buf.append(" * };\n");
6000: buf.append(" * test.run();\n");
6001: buf.append(" * </pre>\n");
6002: buf.append(" * \n");
6003: buf
6004: .append(" * The dynamic way uses reflection to implement <code>runTest</code>. It\n");
6005: buf
6006: .append(" * dynamically finds and invokes a method. In this case the name of the test\n");
6007: buf
6008: .append(" * case has to correspond to the test method to be run.\n");
6009: buf.append(" * \n");
6010: buf.append(" * <pre>\n");
6011: buf
6012: .append(" * TestCase = new MathTest("testAdd");\n");
6013: buf.append(" * test.run();\n");
6014: buf.append(" * </pre>\n");
6015: buf.append(" * \n");
6016: buf
6017: .append(" * The tests to be run can be collected into a TestSuite. JUnit provides\n");
6018: buf
6019: .append(" * different <i>test runners</i> which can run a test suite and collect the\n");
6020: buf
6021: .append(" * results. A test runner either expects a static method <code>suite</code> as\n");
6022: buf
6023: .append(" * the entry point to get a test to run or it will extract the suite\n");
6024: buf.append(" * automatically.\n");
6025: buf.append(" * \n");
6026: buf.append(" * <pre>\n");
6027: buf.append(" * public static Test suite() {\n");
6028: buf
6029: .append(" * suite.addTest(new MathTest("testAdd"));\n");
6030: buf
6031: .append(" * suite.addTest(new MathTest("testDivideByZero"));\n");
6032: buf.append(" * return suite;\n");
6033: buf.append(" * }\n");
6034: buf.append(" * </pre>\n");
6035: buf.append(" * \n");
6036: buf.append(" * @see TestResult\n");
6037: buf.append(" * @see TestSuite\n");
6038: buf.append(" */\n");
6039: buf.append("\n");
6040: buf
6041: .append("public abstract class TestCase extends Assert implements Test {\n");
6042: buf.append(" /**\n");
6043: buf.append(" * the name of the test case\n");
6044: buf.append(" */\n");
6045: buf.append(" private String fName;\n");
6046: buf.append("\n");
6047: buf.append(" /**\n");
6048: buf
6049: .append(" * No-arg constructor to enable serialization. This method is not intended\n");
6050: buf
6051: .append(" * to be used by mere mortals without calling setName().\n");
6052: buf.append(" */\n");
6053: buf.append(" public TestCase() {\n");
6054: buf.append(" this.fName = null;\n");
6055: buf.append(" }\n");
6056: buf.append(" /**\n");
6057: buf
6058: .append(" * Constructs a test case with the given name.\n");
6059: buf.append(" */\n");
6060: buf.append(" public TestCase(final String name) {\n");
6061: buf.append(" this.fName = name;\n");
6062: buf.append(" }\n");
6063: buf.append(" /**\n");
6064: buf
6065: .append(" * Counts the number of test cases executed by run(TestResult result).\n");
6066: buf.append(" */\n");
6067: buf.append(" public int countTestCases() {\n");
6068: buf.append(" return 1;\n");
6069: buf.append(" }\n");
6070: buf.append(" /**\n");
6071: buf.append(" * Creates a default TestResult object\n");
6072: buf.append(" * \n");
6073: buf.append(" * @see TestResult\n");
6074: buf.append(" */\n");
6075: buf.append(" protected TestResult createResult() {\n");
6076: buf.append(" return new TestResult();\n");
6077: buf.append(" }\n");
6078: buf.append(" /**\n");
6079: buf.append(" * Gets the name of a TestCase\n");
6080: buf.append(" * \n");
6081: buf.append(" * @return returns a String\n");
6082: buf.append(" */\n");
6083: buf.append(" public String getName() {\n");
6084: buf.append(" return this.fName;\n");
6085: buf.append(" }\n");
6086: buf.append(" /**\n");
6087: buf
6088: .append(" * A convenience method to run this test, collecting the results with a\n");
6089: buf.append(" * default TestResult object.\n");
6090: buf.append(" * \n");
6091: buf.append(" * @see TestResult\n");
6092: buf.append(" */\n");
6093: buf.append(" public TestResult run() {\n");
6094: buf
6095: .append(" final TestResult result = this.createResult();\n");
6096: buf.append(" this.run(result);\n");
6097: buf.append(" return result;\n");
6098: buf.append(" }\n");
6099: buf.append(" /**\n");
6100: buf
6101: .append(" * Runs the test case and collects the results in TestResult.\n");
6102: buf.append(" */\n");
6103: buf.append(" public void run(final TestResult result) {\n");
6104: buf.append(" result.run(this);\n");
6105: buf.append(" }\n");
6106: buf.append(" /**\n");
6107: buf.append(" * Runs the bare test sequence.\n");
6108: buf.append(" * \n");
6109: buf.append(" * @exception Throwable\n");
6110: buf
6111: .append(" * if any exception is thrown\n");
6112: buf.append(" */\n");
6113: buf.append(" public void runBare() throws Throwable {\n");
6114: buf.append(" this.setUp();\n");
6115: buf.append(" try {\n");
6116: buf.append(" this.runTest();\n");
6117: buf.append(" } finally {\n");
6118: buf.append(" this.tearDown();\n");
6119: buf.append(" }\n");
6120: buf.append(" }\n");
6121: buf.append(" /**\n");
6122: buf
6123: .append(" * Override to run the test and assert its state.\n");
6124: buf.append(" * \n");
6125: buf.append(" * @exception Throwable\n");
6126: buf
6127: .append(" * if any exception is thrown\n");
6128: buf.append(" */\n");
6129: buf.append(" protected void runTest() throws Throwable {\n");
6130: buf.append(" Assert.assertNotNull(this.fName);\n");
6131: buf.append(" Method runMethod = null;\n");
6132: buf.append(" try {\n");
6133: buf
6134: .append(" // use getMethod to get all public inherited\n");
6135: buf
6136: .append(" // methods. getDeclaredMethods returns all\n");
6137: buf
6138: .append(" // methods of this class but excludes the\n");
6139: buf.append(" // inherited ones.\n");
6140: buf
6141: .append(" runMethod = this.getClass().getMethod(this.fName, null);\n");
6142: buf
6143: .append(" } catch (final NoSuchMethodException e) {\n");
6144: buf
6145: .append(" Assert.fail(\"Method \\\"\" + this.fName + \"\\\" not found\"); //$NON-NLS-1$ //$NON-NLS-2$\n");
6146: buf.append(" }\n");
6147: buf
6148: .append(" if (!Modifier.isPublic(runMethod.getModifiers())) {\n");
6149: buf
6150: .append(" Assert.fail(\"Method \\\"\" + this.fName + \"\\\" should be public\"); //$NON-NLS-1$ //$NON-NLS-2$\n");
6151: buf.append(" }\n");
6152: buf.append("\n");
6153: buf.append(" try {\n");
6154: buf
6155: .append(" runMethod.invoke(this, new Class[0]);\n");
6156: buf
6157: .append(" } catch (final InvocationTargetException e) {\n");
6158: buf.append(" e.fillInStackTrace();\n");
6159: buf.append(" throw e.getTargetException();\n");
6160: buf
6161: .append(" } catch (final IllegalAccessException e) {\n");
6162: buf.append(" e.fillInStackTrace();\n");
6163: buf.append(" throw e;\n");
6164: buf.append(" }\n");
6165: buf.append(" }\n");
6166: buf.append(" /**\n");
6167: buf.append(" * Sets the name of a TestCase\n");
6168: buf.append(" * \n");
6169: buf.append(" * @param name\n");
6170: buf.append(" * The name to set\n");
6171: buf.append(" */\n");
6172: buf.append(" public void setName(final String name) {\n");
6173: buf.append(" this.fName = name;\n");
6174: buf.append(" }\n");
6175: buf.append(" /**\n");
6176: buf
6177: .append(" * Sets up the fixture, for example, open a network connection. This method\n");
6178: buf.append(" * is called before a test is executed.\n");
6179: buf.append(" */\n");
6180: buf.append(" protected void setUp() throws Exception {\n");
6181: buf.append(" }\n");
6182: buf.append(" /**\n");
6183: buf
6184: .append(" * Tears down the fixture, for example, close a network connection. This\n");
6185: buf
6186: .append(" * method is called after a test is executed.\n");
6187: buf.append(" */\n");
6188: buf
6189: .append(" protected void tearDown() throws Exception {\n");
6190: buf.append(" }\n");
6191: buf.append(" /**\n");
6192: buf
6193: .append(" * Returns a string representation of the test case\n");
6194: buf.append(" */\n");
6195: buf.append(" @Override\n");
6196: buf.append(" public String toString() {\n");
6197: buf
6198: .append(" return this.getName() + \"(\" + this.getClass().getName() + \")\"; //$NON-NLS-1$ //$NON-NLS-2$\n");
6199: buf.append(" }\n");
6200: buf.append("}");
6201: fExpectedChangesAllTests.put("junit.framework.TestCase.java",
6202: buf.toString());
6203: buf = new StringBuffer();
6204: buf.append("package junit.samples.money;\n");
6205: buf.append("\n");
6206: buf.append("import junit.framework.Assert;\n");
6207: buf.append("import junit.framework.TestCase;\n");
6208: buf.append("\n");
6209: buf.append("public class MoneyTest extends TestCase {\n");
6210: buf
6211: .append(" public static void main(final String args[]) {\n");
6212: buf
6213: .append(" junit.textui.TestRunner.run(MoneyTest.class);\n");
6214: buf.append(" }\n");
6215: buf.append(" private Money f12CHF;\n");
6216: buf.append(" private Money f14CHF;\n");
6217: buf.append(" private Money f21USD;\n");
6218: buf.append("\n");
6219: buf.append(" private Money f7USD;\n");
6220: buf.append(" private IMoney fMB1;\n");
6221: buf.append("\n");
6222: buf.append(" private IMoney fMB2;\n");
6223: buf.append(" @Override\n");
6224: buf.append(" protected void setUp() {\n");
6225: buf
6226: .append(" this.f12CHF = new Money(12, \"CHF\"); //$NON-NLS-1$\n");
6227: buf
6228: .append(" this.f14CHF = new Money(14, \"CHF\"); //$NON-NLS-1$\n");
6229: buf
6230: .append(" this.f7USD = new Money(7, \"USD\"); //$NON-NLS-1$\n");
6231: buf
6232: .append(" this.f21USD = new Money(21, \"USD\"); //$NON-NLS-1$\n");
6233: buf.append("\n");
6234: buf
6235: .append(" this.fMB1 = MoneyBag.create(this.f12CHF, this.f7USD);\n");
6236: buf
6237: .append(" this.fMB2 = MoneyBag.create(this.f14CHF, this.f21USD);\n");
6238: buf.append(" }\n");
6239: buf.append(" public void testBagMultiply() {\n");
6240: buf
6241: .append(" // {[12 CHF][7 USD]} *2 == {[24 CHF][14 USD]}\n");
6242: buf
6243: .append(" final IMoney expected = MoneyBag.create(\n");
6244: buf
6245: .append(" new Money(24, \"CHF\"), new Money(14, \"USD\")); //$NON-NLS-1$ //$NON-NLS-2$\n");
6246: buf
6247: .append(" Assert.assertEquals(expected, this.fMB1.multiply(2));\n");
6248: buf
6249: .append(" Assert.assertEquals(this.fMB1, this.fMB1.multiply(1));\n");
6250: buf
6251: .append(" Assert.assertTrue(this.fMB1.multiply(0).isZero());\n");
6252: buf.append(" }\n");
6253: buf.append(" public void testBagNegate() {\n");
6254: buf
6255: .append(" // {[12 CHF][7 USD]} negate == {[-12 CHF][-7 USD]}\n");
6256: buf
6257: .append(" final IMoney expected = MoneyBag.create(\n");
6258: buf
6259: .append(" new Money(-12, \"CHF\"), new Money(-7, \"USD\")); //$NON-NLS-1$ //$NON-NLS-2$\n");
6260: buf
6261: .append(" Assert.assertEquals(expected, this.fMB1.negate());\n");
6262: buf.append(" }\n");
6263: buf.append(" public void testBagNotEquals() {\n");
6264: buf
6265: .append(" final IMoney bag = MoneyBag.create(this.f12CHF, this.f7USD);\n");
6266: buf
6267: .append(" Assert.assertFalse(bag.equals(new Money(12, \"DEM\").add(this.f7USD))); //$NON-NLS-1$\n");
6268: buf.append(" }\n");
6269: buf.append(" public void testBagSimpleAdd() {\n");
6270: buf
6271: .append(" // {[12 CHF][7 USD]} + [14 CHF] == {[26 CHF][7 USD]}\n");
6272: buf
6273: .append(" final IMoney expected = MoneyBag.create(\n");
6274: buf
6275: .append(" new Money(26, \"CHF\"), new Money(7, \"USD\")); //$NON-NLS-1$ //$NON-NLS-2$\n");
6276: buf
6277: .append(" Assert.assertEquals(expected, this.fMB1.add(this.f14CHF));\n");
6278: buf.append(" }\n");
6279: buf.append(" public void testBagSubtract() {\n");
6280: buf
6281: .append(" // {[12 CHF][7 USD]} - {[14 CHF][21 USD] == {[-2 CHF][-14 USD]}\n");
6282: buf
6283: .append(" final IMoney expected = MoneyBag.create(\n");
6284: buf
6285: .append(" new Money(-2, \"CHF\"), new Money(-14, \"USD\")); //$NON-NLS-1$ //$NON-NLS-2$\n");
6286: buf
6287: .append(" Assert.assertEquals(expected, this.fMB1.subtract(this.fMB2));\n");
6288: buf.append(" }\n");
6289: buf.append(" public void testBagSumAdd() {\n");
6290: buf
6291: .append(" // {[12 CHF][7 USD]} + {[14 CHF][21 USD]} == {[26 CHF][28 USD]}\n");
6292: buf
6293: .append(" final IMoney expected = MoneyBag.create(\n");
6294: buf
6295: .append(" new Money(26, \"CHF\"), new Money(28, \"USD\")); //$NON-NLS-1$ //$NON-NLS-2$\n");
6296: buf
6297: .append(" Assert.assertEquals(expected, this.fMB1.add(this.fMB2));\n");
6298: buf.append(" }\n");
6299: buf.append(" public void testIsZero() {\n");
6300: buf
6301: .append(" Assert.assertTrue(this.fMB1.subtract(this.fMB1).isZero());\n");
6302: buf.append(" Assert.assertTrue(MoneyBag.create(\n");
6303: buf
6304: .append(" new Money(0, \"CHF\"), new Money(0, \"USD\")).isZero()); //$NON-NLS-1$ //$NON-NLS-2$\n");
6305: buf.append(" }\n");
6306: buf.append(" public void testMixedSimpleAdd() {\n");
6307: buf
6308: .append(" // [12 CHF] + [7 USD] == {[12 CHF][7 USD]}\n");
6309: buf
6310: .append(" final IMoney expected = MoneyBag.create(this.f12CHF, this.f7USD);\n");
6311: buf
6312: .append(" Assert.assertEquals(expected, this.f12CHF.add(this.f7USD));\n");
6313: buf.append(" }\n");
6314: buf.append(" public void testMoneyBagEquals() {\n");
6315: buf
6316: .append(" Assert.assertTrue(!this.fMB1.equals(null));\n");
6317: buf.append("\n");
6318: buf
6319: .append(" Assert.assertEquals(this.fMB1, this.fMB1);\n");
6320: buf.append(" final IMoney equal = MoneyBag.create(\n");
6321: buf
6322: .append(" new Money(12, \"CHF\"), new Money(7, \"USD\")); //$NON-NLS-1$ //$NON-NLS-2$\n");
6323: buf
6324: .append(" Assert.assertTrue(this.fMB1.equals(equal));\n");
6325: buf
6326: .append(" Assert.assertTrue(!this.fMB1.equals(this.f12CHF));\n");
6327: buf
6328: .append(" Assert.assertTrue(!this.f12CHF.equals(this.fMB1));\n");
6329: buf
6330: .append(" Assert.assertTrue(!this.fMB1.equals(this.fMB2));\n");
6331: buf.append(" }\n");
6332: buf.append(" public void testMoneyBagHash() {\n");
6333: buf.append(" final IMoney equal = MoneyBag.create(\n");
6334: buf
6335: .append(" new Money(12, \"CHF\"), new Money(7, \"USD\")); //$NON-NLS-1$ //$NON-NLS-2$\n");
6336: buf
6337: .append(" Assert.assertEquals(this.fMB1.hashCode(), equal.hashCode());\n");
6338: buf.append(" }\n");
6339: buf.append(" public void testMoneyEquals() {\n");
6340: buf
6341: .append(" Assert.assertTrue(!this.f12CHF.equals(null));\n");
6342: buf
6343: .append(" final Money equalMoney = new Money(12, \"CHF\"); //$NON-NLS-1$\n");
6344: buf
6345: .append(" Assert.assertEquals(this.f12CHF, this.f12CHF);\n");
6346: buf
6347: .append(" Assert.assertEquals(this.f12CHF, equalMoney);\n");
6348: buf
6349: .append(" Assert.assertEquals(this.f12CHF.hashCode(), equalMoney.hashCode());\n");
6350: buf
6351: .append(" Assert.assertTrue(!this.f12CHF.equals(this.f14CHF));\n");
6352: buf.append(" }\n");
6353: buf.append(" public void testMoneyHash() {\n");
6354: buf
6355: .append(" Assert.assertTrue(!this.f12CHF.equals(null));\n");
6356: buf
6357: .append(" final Money equal = new Money(12, \"CHF\"); //$NON-NLS-1$\n");
6358: buf
6359: .append(" Assert.assertEquals(this.f12CHF.hashCode(), equal.hashCode());\n");
6360: buf.append(" }\n");
6361: buf.append(" public void testNormalize2() {\n");
6362: buf
6363: .append(" // {[12 CHF][7 USD]} - [12 CHF] == [7 USD]\n");
6364: buf
6365: .append(" final Money expected = new Money(7, \"USD\"); //$NON-NLS-1$\n");
6366: buf
6367: .append(" Assert.assertEquals(expected, this.fMB1.subtract(this.f12CHF));\n");
6368: buf.append(" }\n");
6369: buf.append(" public void testNormalize3() {\n");
6370: buf
6371: .append(" // {[12 CHF][7 USD]} - {[12 CHF][3 USD]} == [4 USD]\n");
6372: buf.append(" final IMoney ms1 = MoneyBag.create(\n");
6373: buf
6374: .append(" new Money(12, \"CHF\"), new Money(3, \"USD\")); //$NON-NLS-1$ //$NON-NLS-2$\n");
6375: buf
6376: .append(" final Money expected = new Money(4, \"USD\"); //$NON-NLS-1$\n");
6377: buf
6378: .append(" Assert.assertEquals(expected, this.fMB1.subtract(ms1));\n");
6379: buf.append(" }\n");
6380: buf.append(" public void testNormalize4() {\n");
6381: buf
6382: .append(" // [12 CHF] - {[12 CHF][3 USD]} == [-3 USD]\n");
6383: buf.append(" final IMoney ms1 = MoneyBag.create(\n");
6384: buf
6385: .append(" new Money(12, \"CHF\"), new Money(3, \"USD\")); //$NON-NLS-1$ //$NON-NLS-2$\n");
6386: buf
6387: .append(" final Money expected = new Money(-3, \"USD\"); //$NON-NLS-1$\n");
6388: buf
6389: .append(" Assert.assertEquals(expected, this.f12CHF.subtract(ms1));\n");
6390: buf.append(" }\n");
6391: buf.append(" public void testPrint() {\n");
6392: buf
6393: .append(" Assert.assertEquals(\"[12 CHF]\", this.f12CHF.toString()); //$NON-NLS-1$\n");
6394: buf.append(" }\n");
6395: buf.append(" public void testSimpleAdd() {\n");
6396: buf.append(" // [12 CHF] + [14 CHF] == [26 CHF]\n");
6397: buf
6398: .append(" final Money expected = new Money(26, \"CHF\"); //$NON-NLS-1$\n");
6399: buf
6400: .append(" Assert.assertEquals(expected, this.f12CHF.add(this.f14CHF));\n");
6401: buf.append(" }\n");
6402: buf.append(" public void testSimpleBagAdd() {\n");
6403: buf
6404: .append(" // [14 CHF] + {[12 CHF][7 USD]} == {[26 CHF][7 USD]}\n");
6405: buf
6406: .append(" final IMoney expected = MoneyBag.create(\n");
6407: buf
6408: .append(" new Money(26, \"CHF\"), new Money(7, \"USD\")); //$NON-NLS-1$ //$NON-NLS-2$\n");
6409: buf
6410: .append(" Assert.assertEquals(expected, this.f14CHF.add(this.fMB1));\n");
6411: buf.append(" }\n");
6412: buf.append(" public void testSimpleMultiply() {\n");
6413: buf.append(" // [14 CHF] *2 == [28 CHF]\n");
6414: buf
6415: .append(" final Money expected = new Money(28, \"CHF\"); //$NON-NLS-1$\n");
6416: buf
6417: .append(" Assert.assertEquals(expected, this.f14CHF.multiply(2));\n");
6418: buf.append(" }\n");
6419: buf.append(" public void testSimpleNegate() {\n");
6420: buf.append(" // [14 CHF] negate == [-14 CHF]\n");
6421: buf
6422: .append(" final Money expected = new Money(-14, \"CHF\"); //$NON-NLS-1$\n");
6423: buf
6424: .append(" Assert.assertEquals(expected, this.f14CHF.negate());\n");
6425: buf.append(" }\n");
6426: buf.append(" public void testSimpleSubtract() {\n");
6427: buf.append(" // [14 CHF] - [12 CHF] == [2 CHF]\n");
6428: buf
6429: .append(" final Money expected = new Money(2, \"CHF\"); //$NON-NLS-1$\n");
6430: buf
6431: .append(" Assert.assertEquals(expected, this.f14CHF.subtract(this.f12CHF));\n");
6432: buf.append(" }\n");
6433: buf.append(" public void testSimplify() {\n");
6434: buf.append(" final IMoney money = MoneyBag.create(\n");
6435: buf
6436: .append(" new Money(26, \"CHF\"), new Money(28, \"CHF\")); //$NON-NLS-1$ //$NON-NLS-2$\n");
6437: buf
6438: .append(" Assert.assertEquals(new Money(54, \"CHF\"), money); //$NON-NLS-1$\n");
6439: buf.append(" }\n");
6440: buf.append("}");
6441: fExpectedChangesAllTests.put(
6442: "junit.samples.money.MoneyTest.java", buf.toString());
6443: buf = new StringBuffer();
6444: buf.append("package junit.tests.extensions;\n");
6445: buf.append("\n");
6446: buf.append("import junit.framework.Test;\n");
6447: buf.append("import junit.framework.TestSuite;\n");
6448: buf.append("\n");
6449: buf.append("/**\n");
6450: buf.append(" * TestSuite that runs all the extension tests\n");
6451: buf.append(" * \n");
6452: buf.append(" */\n");
6453: buf.append("public class AllTests {\n");
6454: buf.append("\n");
6455: buf
6456: .append(" public static void main(final String[] args) {\n");
6457: buf
6458: .append(" junit.textui.TestRunner.run(AllTests.suite());\n");
6459: buf.append(" }\n");
6460: buf.append("\n");
6461: buf
6462: .append(" public static Test suite() { // Collect tests manually because we have to\n");
6463: buf
6464: .append(" // test class collection code\n");
6465: buf
6466: .append(" final TestSuite suite = new TestSuite(\"Framework Tests\"); //$NON-NLS-1$\n");
6467: buf
6468: .append(" suite.addTestSuite(ExtensionTest.class);\n");
6469: buf
6470: .append(" suite.addTestSuite(ExceptionTestCaseTest.class);\n");
6471: buf
6472: .append(" suite.addTestSuite(ActiveTestTest.class);\n");
6473: buf
6474: .append(" suite.addTestSuite(RepeatedTestTest.class);\n");
6475: buf.append(" return suite;\n");
6476: buf.append(" }\n");
6477: buf.append("}");
6478: fExpectedChangesAllTests.put(
6479: "junit.tests.extensions.AllTests.java", buf.toString());
6480: buf = new StringBuffer();
6481: buf.append("package junit.tests.framework;\n");
6482: buf.append("\n");
6483: buf.append("/**\n");
6484: buf.append(" * Test class used in SuiteTest\n");
6485: buf.append(" */\n");
6486: buf.append("import junit.framework.TestCase;\n");
6487: buf.append("\n");
6488: buf.append("public class NoTestCases extends TestCase {\n");
6489: buf.append(" public void noTestCase() {\n");
6490: buf.append(" }\n");
6491: buf.append("}");
6492: fExpectedChangesAllTests.put(
6493: "junit.tests.framework.NoTestCases.java", buf
6494: .toString());
6495: buf = new StringBuffer();
6496: buf.append("package junit.tests.runner;\n");
6497: buf.append("\n");
6498: buf.append("import java.lang.reflect.Method;\n");
6499: buf.append("import java.net.URL;\n");
6500: buf.append("\n");
6501: buf.append("import junit.framework.Assert;\n");
6502: buf.append("import junit.framework.TestCase;\n");
6503: buf.append("import junit.runner.TestCaseClassLoader;\n");
6504: buf.append("\n");
6505: buf.append("/**\n");
6506: buf
6507: .append(" * A TestCase for testing the TestCaseClassLoader\n");
6508: buf.append(" * \n");
6509: buf.append(" */\n");
6510: buf
6511: .append("public class TestCaseClassLoaderTest extends TestCase {\n");
6512: buf.append("\n");
6513: buf
6514: .append(" public void testClassLoading() throws Exception {\n");
6515: buf
6516: .append(" final TestCaseClassLoader loader = new TestCaseClassLoader();\n");
6517: buf
6518: .append(" final Class loadedClass = loader.loadClass(\n");
6519: buf
6520: .append(" \"junit.tests.runner.ClassLoaderTest\", true); //$NON-NLS-1$\n");
6521: buf
6522: .append(" final Object o = loadedClass.newInstance();\n");
6523: buf.append(" //\n");
6524: buf
6525: .append(" // Invoke the assertClassLoaders method via reflection.\n");
6526: buf
6527: .append(" // We use reflection since the class is loaded by\n");
6528: buf
6529: .append(" // another class loader and we can't do a successfull downcast to\n");
6530: buf.append(" // ClassLoaderTestCase.\n");
6531: buf.append(" //\n");
6532: buf
6533: .append(" final Method method = loadedClass.getDeclaredMethod(\n");
6534: buf
6535: .append(" \"verify\", new Class[0]); //$NON-NLS-1$\n");
6536: buf.append(" method.invoke(o, new Class[0]);\n");
6537: buf.append(" }\n");
6538: buf.append("\n");
6539: buf
6540: .append(" public void testJarClassLoading() throws Exception {\n");
6541: buf
6542: .append(" final URL url = this.getClass().getResource(\"test.jar\"); //$NON-NLS-1$\n");
6543: buf
6544: .append(" Assert.assertNotNull(\"Cannot find test.jar\", url); //$NON-NLS-1$\n");
6545: buf.append(" final String path = url.getFile();\n");
6546: buf
6547: .append(" final TestCaseClassLoader loader = new TestCaseClassLoader(path);\n");
6548: buf
6549: .append(" final Class loadedClass = loader.loadClass(\n");
6550: buf
6551: .append(" \"junit.tests.runner.LoadedFromJar\", true); //$NON-NLS-1$\n");
6552: buf
6553: .append(" final Object o = loadedClass.newInstance();\n");
6554: buf.append(" //\n");
6555: buf
6556: .append(" // Invoke the assertClassLoaders method via reflection.\n");
6557: buf
6558: .append(" // We use reflection since the class is loaded by\n");
6559: buf
6560: .append(" // another class loader and we can't do a successfull downcast to\n");
6561: buf.append(" // ClassLoaderTestCase.\n");
6562: buf.append(" //\n");
6563: buf
6564: .append(" final Method method = loadedClass.getDeclaredMethod(\n");
6565: buf
6566: .append(" \"verify\", new Class[0]); //$NON-NLS-1$\n");
6567: buf.append(" method.invoke(o, new Class[0]);\n");
6568: buf.append(" }\n");
6569: buf.append("}");
6570: fExpectedChangesAllTests.put(
6571: "junit.tests.runner.TestCaseClassLoaderTest.java", buf
6572: .toString());
6573: buf = new StringBuffer();
6574: buf.append("package junit.samples.money;\n");
6575: buf.append("\n");
6576: buf.append("/**\n");
6577: buf.append(" * A simple Money.\n");
6578: buf.append(" * \n");
6579: buf.append(" */\n");
6580: buf.append("public class Money implements IMoney {\n");
6581: buf.append("\n");
6582: buf.append(" private final int fAmount;\n");
6583: buf.append(" private final String fCurrency;\n");
6584: buf.append("\n");
6585: buf.append(" /**\n");
6586: buf
6587: .append(" * Constructs a money from the given amount and currency.\n");
6588: buf.append(" */\n");
6589: buf
6590: .append(" public Money(final int amount, final String currency) {\n");
6591: buf.append(" this.fAmount = amount;\n");
6592: buf.append(" this.fCurrency = currency;\n");
6593: buf.append(" }\n");
6594: buf.append(" /**\n");
6595: buf
6596: .append(" * Adds a money to this money. Forwards the request to the addMoney helper.\n");
6597: buf.append(" */\n");
6598: buf.append(" public IMoney add(final IMoney m) {\n");
6599: buf.append(" return m.addMoney(this);\n");
6600: buf.append(" }\n");
6601: buf.append(" public IMoney addMoney(final Money m) {\n");
6602: buf
6603: .append(" if (m.currency().equals(this.currency())) {\n");
6604: buf
6605: .append(" return new Money(this.amount() + m.amount(), this.currency());\n");
6606: buf.append(" }\n");
6607: buf.append(" return MoneyBag.create(this, m);\n");
6608: buf.append(" }\n");
6609: buf
6610: .append(" public IMoney addMoneyBag(final MoneyBag s) {\n");
6611: buf.append(" return s.addMoney(this);\n");
6612: buf.append(" }\n");
6613: buf.append(" public int amount() {\n");
6614: buf.append(" return this.fAmount;\n");
6615: buf.append(" }\n");
6616: buf
6617: .append(" public/* this makes no sense */void appendTo(final MoneyBag m) {\n");
6618: buf.append(" m.appendMoney(this);\n");
6619: buf.append(" }\n");
6620: buf.append(" public String currency() {\n");
6621: buf.append(" return this.fCurrency;\n");
6622: buf.append(" }\n");
6623: buf.append(" @Override\n");
6624: buf
6625: .append(" public boolean equals(final Object anObject) {\n");
6626: buf.append(" if (this.isZero()) {\n");
6627: buf.append(" if (anObject instanceof IMoney) {\n");
6628: buf
6629: .append(" return ((IMoney) anObject).isZero();\n");
6630: buf.append(" }\n");
6631: buf.append(" }\n");
6632: buf.append(" if (anObject instanceof Money) {\n");
6633: buf
6634: .append(" final Money aMoney = (Money) anObject;\n");
6635: buf
6636: .append(" return aMoney.currency().equals(this.currency())\n");
6637: buf
6638: .append(" && (this.amount() == aMoney.amount());\n");
6639: buf.append(" }\n");
6640: buf.append(" return false;\n");
6641: buf.append(" }\n");
6642: buf.append(" @Override\n");
6643: buf.append(" public int hashCode() {\n");
6644: buf
6645: .append(" return this.fCurrency.hashCode() + this.fAmount;\n");
6646: buf.append(" }\n");
6647: buf.append(" public boolean isZero() {\n");
6648: buf.append(" return this.amount() == 0;\n");
6649: buf.append(" }\n");
6650: buf.append(" public IMoney multiply(final int factor) {\n");
6651: buf
6652: .append(" return new Money(this.amount() * factor, this.currency());\n");
6653: buf.append(" }\n");
6654: buf.append(" public IMoney negate() {\n");
6655: buf
6656: .append(" return new Money(-this.amount(), this.currency());\n");
6657: buf.append(" }\n");
6658: buf.append(" public IMoney subtract(final IMoney m) {\n");
6659: buf.append(" return this.add(m.negate());\n");
6660: buf.append(" }\n");
6661: buf.append(" @Override\n");
6662: buf.append(" public String toString() {\n");
6663: buf
6664: .append(" final StringBuffer buffer = new StringBuffer();\n");
6665: buf
6666: .append(" buffer.append(\"[\" + this.amount() + \" \" + this.currency() + \"]\"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\n");
6667: buf.append(" return buffer.toString();\n");
6668: buf.append(" }\n");
6669: buf.append("}");
6670: fExpectedChangesAllTests.put("junit.samples.money.Money.java",
6671: buf.toString());
6672: }
6673:
6674: public void testAllCleanUps() throws Exception {
6675: List cus = new ArrayList();
6676: addAllCUs(fJProject1.getChildren(), cus);
6677:
6678: enable(CleanUpConstants.MEMBER_ACCESSES_NON_STATIC_FIELD_USE_THIS);
6679: enable(CleanUpConstants.MEMBER_ACCESSES_NON_STATIC_FIELD_USE_THIS_ALWAYS);
6680: enable(CleanUpConstants.MEMBER_ACCESSES_NON_STATIC_METHOD_USE_THIS);
6681: enable(CleanUpConstants.MEMBER_ACCESSES_NON_STATIC_METHOD_USE_THIS_ALWAYS);
6682: enable(CleanUpConstants.MEMBER_ACCESSES_STATIC_QUALIFY_WITH_DECLARING_CLASS);
6683: enable(CleanUpConstants.MEMBER_ACCESSES_STATIC_QUALIFY_WITH_DECLARING_CLASS_FIELD);
6684: enable(CleanUpConstants.MEMBER_ACCESSES_STATIC_QUALIFY_WITH_DECLARING_CLASS_INSTANCE_ACCESS);
6685: enable(CleanUpConstants.MEMBER_ACCESSES_STATIC_QUALIFY_WITH_DECLARING_CLASS_METHOD);
6686: enable(CleanUpConstants.MEMBER_ACCESSES_STATIC_QUALIFY_WITH_DECLARING_CLASS_SUBTYPE_ACCESS);
6687:
6688: enable(CleanUpConstants.CONTROL_STATEMENTS_USE_BLOCKS);
6689: enable(CleanUpConstants.CONTROL_STATMENTS_USE_BLOCKS_ALWAYS);
6690: enable(CleanUpConstants.CONTROL_STATMENTS_CONVERT_FOR_LOOP_TO_ENHANCED);
6691:
6692: enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES);
6693: enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_ALWAYS);
6694:
6695: enable(CleanUpConstants.ADD_MISSING_ANNOTATIONS);
6696: enable(CleanUpConstants.ADD_MISSING_ANNOTATIONS_DEPRECATED);
6697: enable(CleanUpConstants.ADD_MISSING_ANNOTATIONS_OVERRIDE);
6698:
6699: enable(CleanUpConstants.ADD_MISSING_SERIAL_VERSION_ID);
6700: enable(CleanUpConstants.ADD_MISSING_SERIAL_VERSION_ID_DEFAULT);
6701:
6702: enable(CleanUpConstants.ADD_MISSING_METHODES);
6703:
6704: enable(CleanUpConstants.ADD_MISSING_NLS_TAGS);
6705: enable(CleanUpConstants.REMOVE_UNNECESSARY_CASTS);
6706:
6707: enable(CleanUpConstants.REMOVE_UNUSED_CODE_IMPORTS);
6708: enable(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_MEMBERS);
6709: enable(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_CONSTRUCTORS);
6710: enable(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_FELDS);
6711: enable(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_METHODS);
6712: enable(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_TYPES);
6713: enable(CleanUpConstants.REMOVE_UNUSED_CODE_LOCAL_VARIABLES);
6714:
6715: enable(CleanUpConstants.VARIABLE_DECLARATIONS_USE_FINAL);
6716: enable(CleanUpConstants.VARIABLE_DECLARATIONS_USE_FINAL_LOCAL_VARIABLES);
6717: enable(CleanUpConstants.VARIABLE_DECLARATIONS_USE_FINAL_PARAMETERS);
6718: enable(CleanUpConstants.VARIABLE_DECLARATIONS_USE_FINAL_PRIVATE_FIELDS);
6719:
6720: enable(CleanUpConstants.FORMAT_SOURCE_CODE);
6721:
6722: enable(CleanUpConstants.ORGANIZE_IMPORTS);
6723:
6724: enable(CleanUpConstants.SORT_MEMBERS);
6725: enable(CleanUpConstants.SORT_MEMBERS_ALL);
6726:
6727: ICompilationUnit[] units = (ICompilationUnit[]) cus
6728: .toArray(new ICompilationUnit[cus.size()]);
6729: performRefactoring(units);
6730:
6731: // generateTable(units);
6732:
6733: for (int i = 0; i < units.length; i++) {
6734: ICompilationUnit cu = units[i];
6735: String previewContent = getNormalizedContent(new Document(
6736: cu.getBuffer().getContents()));
6737: String compilationUnitName = getCompilationUnitName(cu);
6738:
6739: String expected = (String) fExpectedChangesAllTests
6740: .get(compilationUnitName);
6741:
6742: assertTrue("No expected value in table for "
6743: + compilationUnitName, expected != null);
6744: assertEquals("Content not as expected for "
6745: + compilationUnitName, expected, previewContent);
6746: }
6747: }
6748:
6749: private static String getCompilationUnitName(ICompilationUnit cu) {
6750: StringBuffer result = new StringBuffer();
6751: JavaElementLabels.getCompilationUnitLabel(cu,
6752: JavaElementLabels.CU_QUALIFIED, result);
6753: return result.toString();
6754: }
6755:
6756: private static String getNormalizedContent(IDocument document) {
6757: StringBuffer buf = new StringBuffer();
6758: try {
6759: int selectionOffset = 0;
6760: int selectionLength = document.getLength();
6761: int startLine = document.getLineOfOffset(selectionOffset);
6762: int endLine = document.getLineOfOffset(selectionOffset
6763: + selectionLength);
6764:
6765: for (int i = startLine; i <= endLine; i++) {
6766: IRegion lineInfo = document.getLineInformation(i);
6767: String lineContent = document.get(lineInfo.getOffset(),
6768: lineInfo.getLength());
6769:
6770: for (int k = 0; k < lineContent.length(); k++) {
6771: char ch = lineContent.charAt(k);
6772: if (ch == '\t') {
6773: buf.append(" "); // 4 spaces
6774: } else {
6775: buf.append(ch);
6776: }
6777: }
6778:
6779: if (i != endLine) {
6780: buf.append('\n');
6781: }
6782: }
6783: } catch (BadLocationException e) {
6784: // ignore
6785: }
6786: return buf.toString();
6787: }
6788:
6789: // Do not remove, used to generate the table
6790: // private static final String[] CU_ORDER= new String[71];
6791: // static {
6792: // CU_ORDER[0]= "junit.runner.BaseTestRunner.java";
6793: // CU_ORDER[1]= "junit.tests.framework.NotVoidTestCase.java";
6794: // CU_ORDER[2]= "junit.tests.runner.StackFilterTest.java";
6795: // CU_ORDER[3]= "junit.tests.framework.DoublePrecisionAssertTest.java";
6796: // CU_ORDER[4]= "junit.tests.framework.AssertTest.java";
6797: // CU_ORDER[5]= "junit.samples.AllTests.java";
6798: // CU_ORDER[6]= "junit.tests.extensions.ExceptionTestCaseTest.java";
6799: // CU_ORDER[7]= "junit.tests.framework.TestListenerTest.java";
6800: // CU_ORDER[8]= "junit.tests.runner.SorterTest.java";
6801: // CU_ORDER[9]= "junit.tests.framework.OneTestCase.java";
6802: // CU_ORDER[10]= "junit.tests.framework.TestImplementorTest.java";
6803: // CU_ORDER[11]= "junit.extensions.TestDecorator.java";
6804: // CU_ORDER[12]= "junit.runner.TestSuiteLoader.java";
6805: // CU_ORDER[13]= "junit.framework.TestResult.java";
6806: // CU_ORDER[14]= "junit.tests.framework.NotPublicTestCase.java";
6807: // CU_ORDER[15]= "junit.extensions.ActiveTestSuite.java";
6808: // CU_ORDER[16]= "junit.tests.framework.SuiteTest.java";
6809: // CU_ORDER[17]= "junit.runner.SimpleTestCollector.java";
6810: // CU_ORDER[18]= "junit.framework.Test.java";
6811: // CU_ORDER[19]= "junit.tests.framework.NoTestCaseClass.java";
6812: // CU_ORDER[20]= "junit.tests.framework.Success.java";
6813: // CU_ORDER[21]= "junit.runner.LoadingTestCollector.java";
6814: // CU_ORDER[22]= "junit.runner.TestCaseClassLoader.java";
6815: // CU_ORDER[23]= "junit.framework.AssertionFailedError.java";
6816: // CU_ORDER[24]= "junit.tests.framework.InheritedTestCase.java";
6817: // CU_ORDER[25]= "junit.samples.SimpleTest.java";
6818: // CU_ORDER[26]= "junit.runner.Version.java";
6819: // CU_ORDER[27]= "junit.tests.runner.BaseTestRunnerTest.java";
6820: // CU_ORDER[28]= "junit.tests.WasRun.java";
6821: // CU_ORDER[29]= "junit.framework.TestSuite.java";
6822: // CU_ORDER[30]= "junit.extensions.ExceptionTestCase.java";
6823: // CU_ORDER[31]= "junit.framework.Assert.java";
6824: // CU_ORDER[32]= "junit.runner.ClassPathTestCollector.java";
6825: // CU_ORDER[33]= "junit.framework.TestListener.java";
6826: // CU_ORDER[34]= "junit.tests.extensions.ActiveTestTest.java";
6827: // CU_ORDER[35]= "junit.framework.Protectable.java";
6828: // CU_ORDER[36]= "junit.samples.money.IMoney.java";
6829: // CU_ORDER[37]= "junit.textui.TestRunner.java";
6830: // CU_ORDER[38]= "junit.tests.runner.ClassLoaderTest.java";
6831: // CU_ORDER[39]= "junit.runner.TestRunListener.java";
6832: // CU_ORDER[40]= "junit.tests.runner.TextFeedbackTest.java";
6833: // CU_ORDER[41]= "junit.tests.extensions.ExtensionTest.java";
6834: // CU_ORDER[42]= "junit.tests.AllTests.java";
6835: // CU_ORDER[43]= "junit.tests.runner.LoadedFromJar.java";
6836: // CU_ORDER[44]= "junit.tests.framework.ComparisonFailureTest.java";
6837: // CU_ORDER[45]= "junit.textui.ResultPrinter.java";
6838: // CU_ORDER[46]= "junit.samples.VectorTest.java";
6839: // CU_ORDER[47]= "junit.framework.ComparisonFailure.java";
6840: // CU_ORDER[48]= "junit.tests.framework.TestCaseTest.java";
6841: // CU_ORDER[49]= "junit.framework.TestFailure.java";
6842: // CU_ORDER[50]= "junit.runner.ReloadingTestSuiteLoader.java";
6843: // CU_ORDER[51]= "junit.runner.StandardTestSuiteLoader.java";
6844: // CU_ORDER[52]= "junit.extensions.TestSetup.java";
6845: // CU_ORDER[53]= "junit.tests.runner.TextRunnerTest.java";
6846: // CU_ORDER[54]= "junit.tests.framework.Failure.java";
6847: // CU_ORDER[55]= "junit.tests.framework.OverrideTestCase.java";
6848: // CU_ORDER[56]= "junit.extensions.RepeatedTest.java";
6849: // CU_ORDER[57]= "junit.tests.framework.NoArgTestCaseTest.java";
6850: // CU_ORDER[58]= "junit.runner.Sorter.java";
6851: // CU_ORDER[59]= "junit.tests.framework.AllTests.java";
6852: // CU_ORDER[60]= "junit.tests.extensions.RepeatedTestTest.java";
6853: // CU_ORDER[61]= "junit.tests.runner.AllTests.java";
6854: // CU_ORDER[62]= "junit.runner.TestCollector.java";
6855: // CU_ORDER[63]= "junit.samples.money.MoneyBag.java";
6856: // CU_ORDER[64]= "junit.tests.runner.SimpleTestCollectorTest.java";
6857: // CU_ORDER[65]= "junit.framework.TestCase.java";
6858: // CU_ORDER[66]= "junit.samples.money.MoneyTest.java";
6859: // CU_ORDER[67]= "junit.tests.extensions.AllTests.java";
6860: // CU_ORDER[68]= "junit.tests.framework.NoTestCases.java";
6861: // CU_ORDER[69]= "junit.tests.runner.TestCaseClassLoaderTest.java";
6862: // CU_ORDER[70]= "junit.samples.money.Money.java";
6863: // }
6864: //
6865: // private void generateTable(ICompilationUnit[] units) throws CoreException {
6866: //
6867: // assertNoCompileErrors(units);
6868: //
6869: // Hashtable expected= new Hashtable();
6870: // for (int i= 0; i < units.length; i++) {
6871: // expected.put(getCompilationUnitName(units[i]), units[i].getBuffer().getContents());
6872: // }
6873: //
6874: // StringBuffer buf= new StringBuffer();
6875: //
6876: // buf.append(" private static Hashtable fExpectedChangesAllTests;").append("\n");
6877: // buf.append(" static {").append("\n");
6878: // buf.append(" fExpectedChangesAllTests= new Hashtable();").append("\n");
6879: // buf.append(" StringBuffer buf= null;").append("\n");
6880: //
6881: // for (int i= 0; i < CU_ORDER.length; i++) {
6882: // String previewContent= (String)expected.get(CU_ORDER[i]);
6883: // String bufWrappedContext= getBufWrappedContext(new Document(previewContent));
6884: //
6885: // buf.append(" buf= new StringBuffer();").append("\n");
6886: // buf.append(bufWrappedContext).append("\n");
6887: // buf.append(" fExpectedChangesAllTests.put(\""+CU_ORDER[i] +"\", buf.toString());").append("\n");
6888: // }
6889: //
6890: // buf.append(" }").append("\n");
6891: //
6892: // Clipboard clipboard= new Clipboard(null);
6893: // clipboard.setContents(new Object[] { buf.toString() }, new Transfer[] { TextTransfer.getInstance() } );
6894: // clipboard.dispose();
6895: // }
6896: //
6897: // private static String getBufWrappedContext(IDocument document) {
6898: // StringBuffer buf= new StringBuffer();
6899: // try {
6900: // int selectionOffset= 0;
6901: // int selectionLength= document.getLength();
6902: // int startLine= document.getLineOfOffset(selectionOffset);
6903: // int endLine= document.getLineOfOffset(selectionOffset + selectionLength);
6904: //
6905: // for (int i= startLine; i <= endLine; i++) {
6906: // IRegion lineInfo= document.getLineInformation(i);
6907: // String lineContent= document.get(lineInfo.getOffset(), lineInfo.getLength());
6908: // buf.append(" buf.append(\"");
6909: // for (int k= 0; k < lineContent.length(); k++) {
6910: // char ch= lineContent.charAt(k);
6911: // if (ch == '\t') {
6912: // buf.append(" "); // 4 spaces
6913: // } else if (ch == '"' || ch == '\\') {
6914: // buf.append('\\').append(ch);
6915: // } else {
6916: // buf.append(ch);
6917: // }
6918: // }
6919: //
6920: // if (i != endLine) {
6921: // buf.append("\\n\");");
6922: // buf.append('\n');
6923: // } else {
6924: // buf.append("\");");
6925: // }
6926: // }
6927: // } catch (BadLocationException e) {
6928: // // ignore
6929: // }
6930: // return buf.toString();
6931: // }
6932: //
6933: // private void assertNoCompileErrors(ICompilationUnit[] units) throws JavaModelException, CoreException {
6934: // ASTParser parser= ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
6935: // parser.setResolveBindings(true);
6936: // parser.setProject(fJProject1);
6937: //
6938: // parser.createASTs(units, new String[0], new ASTRequestor() {
6939: // public void acceptAST(ICompilationUnit source, CompilationUnit ast) {
6940: // IProblem[] problems= ast.getProblems();
6941: //
6942: // StringBuffer buf= new StringBuffer();
6943: // for (int i= 0; i < problems.length; i++) {
6944: // if (problems[i].isError()) {
6945: // buf.append(problems[i].getMessage()).append('\n');
6946: // }
6947: // }
6948: // if (buf.length() != 0) {
6949: // buf.insert(0, "Found errors in " + source.getElementName() + ":\n");
6950: // try {
6951: // buf.append(source.getBuffer().getContents());
6952: // } catch (JavaModelException e) {
6953: // JavaPlugin.log(e);
6954: // }
6955: // assertTrue(buf.toString(), false);
6956: // }
6957: // }
6958: // }, new NullProgressMonitor());
6959: // }
6960: }
|