### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.ui.tests Index: performance/org/eclipse/jdt/ui/tests/performance/views/CleanUpPerfTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui.tests/performance/org/eclipse/jdt/ui/tests/performance/views/CleanUpPerfTest.java,v retrieving revision 1.23 diff -u -r1.23 CleanUpPerfTest.java --- performance/org/eclipse/jdt/ui/tests/performance/views/CleanUpPerfTest.java 22 Dec 2006 16:50:34 -0000 1.23 +++ performance/org/eclipse/jdt/ui/tests/performance/views/CleanUpPerfTest.java 24 Jan 2007 08:48:48 -0000 @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Alex Blewitt - https://bugs.eclipse.org/bugs/show_bug.cgi?id=168954 *******************************************************************************/ package org.eclipse.jdt.ui.tests.performance.views; @@ -50,6 +51,7 @@ import org.eclipse.jdt.internal.ui.fix.ExpressionsCleanUp; import org.eclipse.jdt.internal.ui.fix.ICleanUp; import org.eclipse.jdt.internal.ui.fix.Java50CleanUp; +import org.eclipse.jdt.internal.ui.fix.SortMembersCleanUp; import org.eclipse.jdt.internal.ui.fix.StringCleanUp; import org.eclipse.jdt.internal.ui.fix.UnnecessaryCodeCleanUp; import org.eclipse.jdt.internal.ui.fix.UnusedCodeCleanUp; @@ -413,6 +415,31 @@ } } + public void testSortMembersCleanUp() throws Exception { + CleanUpRefactoring cleanUpRefactoring= new CleanUpRefactoring(); + addAllCUs(cleanUpRefactoring, MyTestSetup.fJProject1.getChildren()); + + Map node= getNullSettings(); + + node.put(CleanUpConstants.SORT_MEMBERS, CleanUpConstants.TRUE); + node.put(CleanUpConstants.SORT_MEMBERS_ALL, CleanUpConstants.TRUE); + + storeSettings(node); + + cleanUpRefactoring.addCleanUp(new SortMembersCleanUp()); + + cleanUpRefactoring.checkAllConditions(new NullProgressMonitor()); + cleanUpRefactoring.createChange(null); + + joinBackgroudActivities(); + for (int i= 0; i < 10; i++) { + startMeasuring(); + cleanUpRefactoring.checkAllConditions(new NullProgressMonitor()); + cleanUpRefactoring.createChange(null); + finishMeasurements(); + } + } + public void testUnnecessaryCodeCleanUp() throws Exception { CleanUpRefactoring cleanUpRefactoring= new CleanUpRefactoring(); addAllCUs(cleanUpRefactoring, MyTestSetup.fJProject1.getChildren()); Index: ui/org/eclipse/jdt/ui/tests/quickfix/CleanUpTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/CleanUpTest.java,v retrieving revision 1.80 diff -u -r1.80 CleanUpTest.java --- ui/org/eclipse/jdt/ui/tests/quickfix/CleanUpTest.java 11 Jan 2007 09:55:43 -0000 1.80 +++ ui/org/eclipse/jdt/ui/tests/quickfix/CleanUpTest.java 24 Jan 2007 08:48:59 -0000 @@ -145,7 +145,7 @@ fProfile.getSettings().put(key, CleanUpConstants.TRUE); commitProfile(); } - + private void commitProfile() throws CoreException { List profiles= CleanUpPreferenceUtil.getBuiltInProfiles(); profiles.add(fProfile); @@ -5918,5 +5918,60 @@ assertRefactoringResultAsExpected(new ICompilationUnit[] {cu1}, new String[] {expected1}); } + + public void testSortMembers01() throws Exception { + IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); + StringBuffer buf= new StringBuffer(); + buf.append("package test;\n"); + buf.append(" public class SM01 {\n"); + buf.append(" int b;\n"); + buf.append(" int a;\n"); + buf.append(" void d() {};\n"); + buf.append(" void c() {};\n"); + buf.append("}\n"); + ICompilationUnit cu1= pack1.createCompilationUnit("SM01.java", buf.toString(), false, null); + + enable(CleanUpConstants.SORT_MEMBERS); + enable(CleanUpConstants.SORT_MEMBERS_ALL); + + buf= new StringBuffer(); + buf.append("package test;\n"); + buf.append(" public class SM01 {\n"); + buf.append(" int a;\n"); + buf.append(" int b;\n"); + buf.append(" void c() {};\n"); + buf.append(" void d() {};\n"); + buf.append("}\n"); + String expected1= buf.toString(); + + assertRefactoringResultAsExpected(new ICompilationUnit[] {cu1}, new String[] {expected1}); + } + + public void testSortMembers02() throws Exception { + IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); + StringBuffer buf= new StringBuffer(); + buf.append("package test;\n"); + buf.append(" public class SM02 {\n"); + buf.append(" int b;\n"); + buf.append(" int a;\n"); + buf.append(" void d() {};\n"); + buf.append(" void c() {};\n"); + buf.append("}\n"); + ICompilationUnit cu1= pack1.createCompilationUnit("SM02.java", buf.toString(), false, null); + + enable(CleanUpConstants.SORT_MEMBERS); + + buf= new StringBuffer(); + buf.append("package test;\n"); + buf.append(" public class SM02 {\n"); + buf.append(" int b;\n"); + buf.append(" int a;\n"); + buf.append(" void c() {};\n"); + buf.append(" void d() {};\n"); + buf.append("}\n"); + String expected1= buf.toString(); + + assertRefactoringResultAsExpected(new ICompilationUnit[] {cu1}, new String[] {expected1}); + } } Index: ui/org/eclipse/jdt/ui/tests/quickfix/CleanUpStressTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/CleanUpStressTest.java,v retrieving revision 1.14 diff -u -r1.14 CleanUpStressTest.java --- ui/org/eclipse/jdt/ui/tests/quickfix/CleanUpStressTest.java 8 Jan 2007 14:49:49 -0000 1.14 +++ ui/org/eclipse/jdt/ui/tests/quickfix/CleanUpStressTest.java 24 Jan 2007 08:48:56 -0000 @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Alex Blewitt - https://bugs.eclipse.org/bugs/show_bug.cgi?id=168954 *******************************************************************************/ package org.eclipse.jdt.ui.tests.quickfix; @@ -165,22 +166,88 @@ buf.append(" * Sardinia during XP2000.\n"); buf.append(" */\n"); buf.append("public abstract class BaseTestRunner implements TestListener {\n"); - buf.append(" public static final String SUITE_METHODNAME = \"suite\"; //$NON-NLS-1$\n"); + buf.append(" static boolean fgFilterStack = true;\n"); buf.append("\n"); - buf.append(" private static Properties fPreferences;\n"); buf.append(" static int fgMaxMessageLength = 500;\n"); - buf.append(" static boolean fgFilterStack = true;\n"); - buf.append(" boolean fLoading = true;\n"); + buf.append(" private static Properties fPreferences;\n"); + buf.append(" public static final String SUITE_METHODNAME = \"suite\"; //$NON-NLS-1$\n"); + buf.append(" static {\n"); + buf.append(" BaseTestRunner.fgMaxMessageLength = BaseTestRunner.getPreference(\n"); + buf.append(" \"maxmessage\", BaseTestRunner.fgMaxMessageLength); //$NON-NLS-1$\n"); + buf.append(" }\n"); buf.append("\n"); - buf.append(" /*\n"); - buf.append(" * Implementation of TestListener\n"); + buf.append(" static boolean filterLine(final String line) {\n"); + buf.append(" final String[] patterns = new String[]{\"junit.framework.TestCase\", //$NON-NLS-1$\n"); + buf.append(" \"junit.framework.TestResult\", //$NON-NLS-1$\n"); + buf.append(" \"junit.framework.TestSuite\", //$NON-NLS-1$\n"); + buf.append(" \"junit.framework.Assert.\", // don't filter AssertionFailure\n"); + buf.append(" // //$NON-NLS-1$\n"); + buf.append(" \"junit.swingui.TestRunner\", //$NON-NLS-1$\n"); + buf.append(" \"junit.awtui.TestRunner\", //$NON-NLS-1$\n"); + buf.append(" \"junit.textui.TestRunner\", //$NON-NLS-1$\n"); + buf.append(" \"java.lang.reflect.Method.invoke(\" //$NON-NLS-1$\n"); + buf.append(" };\n"); + buf.append(" for (final String element : patterns) {\n"); + buf.append(" if (line.indexOf(element) > 0) {\n"); + buf.append(" return true;\n"); + buf.append(" }\n"); + buf.append(" }\n"); + buf.append(" return false;\n"); + buf.append(" }\n"); + buf.append("\n"); + buf.append(" /**\n"); + buf.append(" * Filters stack frames from internal JUnit classes\n"); buf.append(" */\n"); - buf.append(" public synchronized void startTest(final Test test) {\n"); - buf.append(" this.testStarted(test.toString());\n"); + buf.append(" public static String getFilteredTrace(final String stack) {\n"); + buf.append(" if (BaseTestRunner.showStackRaw()) {\n"); + buf.append(" return stack;\n"); + buf.append(" }\n"); + buf.append("\n"); + buf.append(" final StringWriter sw = new StringWriter();\n"); + buf.append(" final PrintWriter pw = new PrintWriter(sw);\n"); + buf.append(" final StringReader sr = new StringReader(stack);\n"); + buf.append(" final BufferedReader br = new BufferedReader(sr);\n"); + buf.append("\n"); + buf.append(" String line;\n"); + buf.append(" try {\n"); + buf.append(" while ((line = br.readLine()) != null) {\n"); + buf.append(" if (!BaseTestRunner.filterLine(line)) {\n"); + buf.append(" pw.println(line);\n"); + buf.append(" }\n"); + buf.append(" }\n"); + buf.append(" } catch (final Exception IOException) {\n"); + buf.append(" return stack; // return the stack unfiltered\n"); + buf.append(" }\n"); + buf.append(" return sw.toString();\n"); buf.append(" }\n"); buf.append("\n"); - buf.append(" protected static void setPreferences(final Properties preferences) {\n"); - buf.append(" BaseTestRunner.fPreferences = preferences;\n"); + buf.append(" /**\n"); + buf.append(" * Returns a filtered stack trace\n"); + buf.append(" */\n"); + buf.append(" public static String getFilteredTrace(final Throwable t) {\n"); + buf.append(" final StringWriter stringWriter = new StringWriter();\n"); + buf.append(" final PrintWriter writer = new PrintWriter(stringWriter);\n"); + buf.append(" t.printStackTrace(writer);\n"); + buf.append(" final StringBuffer buffer = stringWriter.getBuffer();\n"); + buf.append(" final String trace = buffer.toString();\n"); + buf.append(" return BaseTestRunner.getFilteredTrace(trace);\n"); + buf.append(" }\n"); + buf.append("\n"); + buf.append(" public static String getPreference(final String key) {\n"); + buf.append(" return BaseTestRunner.getPreferences().getProperty(key);\n"); + buf.append(" }\n"); + buf.append("\n"); + buf.append(" public static int getPreference(final String key, final int dflt) {\n"); + buf.append(" final String value = BaseTestRunner.getPreference(key);\n"); + buf.append(" int intValue = dflt;\n"); + buf.append(" if (value == null) {\n"); + buf.append(" return intValue;\n"); + buf.append(" }\n"); + buf.append(" try {\n"); + buf.append(" intValue = Integer.parseInt(value);\n"); + buf.append(" } catch (final NumberFormatException ne) {\n"); + buf.append(" }\n"); + buf.append(" return intValue;\n"); buf.append(" }\n"); buf.append("\n"); buf.append(" protected static Properties getPreferences() {\n"); @@ -193,6 +260,39 @@ buf.append(" return BaseTestRunner.fPreferences;\n"); buf.append(" }\n"); buf.append("\n"); + buf.append(" private static File getPreferencesFile() {\n"); + buf.append(" final String home = System.getProperty(\"user.home\"); //$NON-NLS-1$\n"); + buf.append(" return new File(home, \"junit.properties\"); //$NON-NLS-1$\n"); + buf.append(" }\n"); + buf.append("\n"); + buf.append(" public static boolean inVAJava() {\n"); + buf.append(" try {\n"); + buf.append(" Class.forName(\"com.ibm.uvm.tools.DebugSupport\"); //$NON-NLS-1$\n"); + buf.append(" } catch (final Exception e) {\n"); + buf.append(" return false;\n"); + buf.append(" }\n"); + buf.append(" return true;\n"); + buf.append(" }\n"); + buf.append("\n"); + buf.append(" // TestRunListener implementation\n"); + buf.append("\n"); + buf.append(" private static void readPreferences() {\n"); + buf.append(" InputStream is = null;\n"); + buf.append(" try {\n"); + buf.append(" is = new FileInputStream(BaseTestRunner.getPreferencesFile());\n"); + buf.append(" BaseTestRunner.setPreferences(new Properties(BaseTestRunner\n"); + buf.append(" .getPreferences()));\n"); + buf.append(" BaseTestRunner.getPreferences().load(is);\n"); + buf.append(" } catch (final IOException e) {\n"); + buf.append(" try {\n"); + buf.append(" if (is != null) {\n"); + buf.append(" is.close();\n"); + buf.append(" }\n"); + buf.append(" } catch (final IOException e1) {\n"); + buf.append(" }\n"); + buf.append(" }\n"); + buf.append(" }\n"); + buf.append("\n"); buf.append(" public static void savePreferences() throws IOException {\n"); buf.append(" final FileOutputStream fos = new FileOutputStream(BaseTestRunner\n"); buf.append(" .getPreferencesFile());\n"); @@ -203,30 +303,71 @@ buf.append(" }\n"); buf.append(" }\n"); buf.append("\n"); - buf.append(" public void setPreference(final String key, final String value) {\n"); - buf.append(" BaseTestRunner.getPreferences().setProperty(key, value);\n"); + buf.append(" protected static void setPreferences(final Properties preferences) {\n"); + buf.append(" BaseTestRunner.fPreferences = preferences;\n"); buf.append(" }\n"); buf.append("\n"); - buf.append(" public synchronized void endTest(final Test test) {\n"); - buf.append(" this.testEnded(test.toString());\n"); + buf.append(" protected static boolean showStackRaw() {\n"); + buf.append(" return !BaseTestRunner.getPreference(\"filterstack\").equals(\"true\") || (BaseTestRunner.fgFilterStack == false); //$NON-NLS-1$ //$NON-NLS-2$\n"); + buf.append(" }\n"); + buf.append("\n"); + buf.append(" /**\n"); + buf.append(" * Truncates a String to the maximum length.\n"); + buf.append(" */\n"); + buf.append(" public static String truncate(String s) {\n"); + buf.append(" if ((BaseTestRunner.fgMaxMessageLength != -1)\n"); + buf.append(" && (s.length() > BaseTestRunner.fgMaxMessageLength)) {\n"); + buf.append(" s = s.substring(0, BaseTestRunner.fgMaxMessageLength) + \"...\"; //$NON-NLS-1$\n"); + buf.append(" }\n"); + buf.append(" return s;\n"); buf.append(" }\n"); buf.append("\n"); + buf.append(" boolean fLoading = true;\n"); + buf.append("\n"); buf.append(" public synchronized void addError(final Test test, final Throwable t) {\n"); buf.append(" this.testFailed(TestRunListener.STATUS_ERROR, test, t);\n"); buf.append(" }\n"); - buf.append("\n"); buf.append(" public synchronized void addFailure(final Test test,\n"); buf.append(" final AssertionFailedError t) {\n"); buf.append(" this.testFailed(TestRunListener.STATUS_FAILURE, test, t);\n"); buf.append(" }\n"); buf.append("\n"); - buf.append(" // TestRunListener implementation\n"); + buf.append(" /**\n"); + buf.append(" * Clears the status message.\n"); + buf.append(" */\n"); + buf.append(" protected void clearStatus() { // Belongs in the GUI TestRunner class\n"); + buf.append(" }\n"); buf.append("\n"); - buf.append(" public abstract void testStarted(String testName);\n"); + buf.append(" /**\n"); + buf.append(" * Returns the formatted string of the elapsed time.\n"); + buf.append(" */\n"); + buf.append(" public String elapsedTimeAsString(final long runTime) {\n"); + buf.append(" return NumberFormat.getInstance().format((double) runTime / 1000);\n"); + buf.append(" }\n"); buf.append("\n"); - buf.append(" public abstract void testEnded(String testName);\n"); + buf.append(" public synchronized void endTest(final Test test) {\n"); + buf.append(" this.testEnded(test.toString());\n"); + buf.append(" }\n"); buf.append("\n"); - buf.append(" public abstract void testFailed(int status, Test test, Throwable t);\n"); + buf.append(" /**\n"); + buf.append(" * Extract the class name from a String in VA/Java style\n"); + buf.append(" */\n"); + buf.append(" public String extractClassName(final String className) {\n"); + buf.append(" if (className.startsWith(\"Default package for\")) {\n"); + buf.append(" return className.substring(className.lastIndexOf(\".\") + 1); //$NON-NLS-1$\n"); + buf.append(" }\n"); + buf.append(" return className;\n"); + buf.append(" }\n"); + buf.append("\n"); + buf.append(" /**\n"); + buf.append(" * Returns the loader to be used.\n"); + buf.append(" */\n"); + buf.append(" public TestSuiteLoader getLoader() {\n"); + buf.append(" if (this.useReloadingTestSuiteLoader()) {\n"); + buf.append(" return new ReloadingTestSuiteLoader();\n"); + buf.append(" }\n"); + buf.append(" return new StandardTestSuiteLoader();\n"); + buf.append(" }\n"); buf.append("\n"); buf.append(" /**\n"); buf.append(" * Returns the Test corresponding to the given suite. This is a template\n"); @@ -285,10 +426,11 @@ buf.append(" }\n"); buf.append("\n"); buf.append(" /**\n"); - buf.append(" * Returns the formatted string of the elapsed time.\n"); + buf.append(" * Returns the loaded Class for a suite name.\n"); buf.append(" */\n"); - buf.append(" public String elapsedTimeAsString(final long runTime) {\n"); - buf.append(" return NumberFormat.getInstance().format((double) runTime / 1000);\n"); + buf.append(" protected Class loadSuiteClass(final String suiteClassName)\n"); + buf.append(" throws ClassNotFoundException {\n"); + buf.append(" return this.getLoader().load(suiteClassName);\n"); buf.append(" }\n"); buf.append("\n"); buf.append(" /**\n"); @@ -317,177 +459,36 @@ buf.append(" }\n"); buf.append("\n"); buf.append(" /**\n"); - buf.append(" * Sets the loading behaviour of the test runner\n"); - buf.append(" */\n"); - buf.append(" public void setLoading(final boolean enable) {\n"); - buf.append(" this.fLoading = enable;\n"); - buf.append(" }\n"); - buf.append(" /**\n"); - buf.append(" * Extract the class name from a String in VA/Java style\n"); - buf.append(" */\n"); - buf.append(" public String extractClassName(final String className) {\n"); - buf.append(" if (className.startsWith(\"Default package for\")) {\n"); - buf.append(" return className.substring(className.lastIndexOf(\".\") + 1); //$NON-NLS-1$\n"); - buf.append(" }\n"); - buf.append(" return className;\n"); - buf.append(" }\n"); - buf.append("\n"); - buf.append(" /**\n"); - buf.append(" * Truncates a String to the maximum length.\n"); - buf.append(" */\n"); - buf.append(" public static String truncate(String s) {\n"); - buf.append(" if ((BaseTestRunner.fgMaxMessageLength != -1)\n"); - buf.append(" && (s.length() > BaseTestRunner.fgMaxMessageLength)) {\n"); - buf.append(" s = s.substring(0, BaseTestRunner.fgMaxMessageLength) + \"...\"; //$NON-NLS-1$\n"); - buf.append(" }\n"); - buf.append(" return s;\n"); - buf.append(" }\n"); - buf.append("\n"); - buf.append(" /**\n"); buf.append(" * Override to define how to handle a failed loading of a test suite.\n"); buf.append(" */\n"); buf.append(" protected abstract void runFailed(String message);\n"); buf.append("\n"); buf.append(" /**\n"); - buf.append(" * Returns the loaded Class for a suite name.\n"); - buf.append(" */\n"); - buf.append(" protected Class loadSuiteClass(final String suiteClassName)\n"); - buf.append(" throws ClassNotFoundException {\n"); - buf.append(" return this.getLoader().load(suiteClassName);\n"); - buf.append(" }\n"); - buf.append("\n"); - buf.append(" /**\n"); - buf.append(" * Clears the status message.\n"); - buf.append(" */\n"); - buf.append(" protected void clearStatus() { // Belongs in the GUI TestRunner class\n"); - buf.append(" }\n"); - buf.append("\n"); - buf.append(" /**\n"); - buf.append(" * Returns the loader to be used.\n"); + buf.append(" * Sets the loading behaviour of the test runner\n"); buf.append(" */\n"); - buf.append(" public TestSuiteLoader getLoader() {\n"); - buf.append(" if (this.useReloadingTestSuiteLoader()) {\n"); - buf.append(" return new ReloadingTestSuiteLoader();\n"); - buf.append(" }\n"); - buf.append(" return new StandardTestSuiteLoader();\n"); - buf.append(" }\n"); - buf.append("\n"); - buf.append(" protected boolean useReloadingTestSuiteLoader() {\n"); - buf.append(" return BaseTestRunner.getPreference(\"loading\").equals(\"true\") && !BaseTestRunner.inVAJava() && this.fLoading; //$NON-NLS-1$ //$NON-NLS-2$\n"); - buf.append(" }\n"); - buf.append("\n"); - buf.append(" private static File getPreferencesFile() {\n"); - buf.append(" final String home = System.getProperty(\"user.home\"); //$NON-NLS-1$\n"); - buf.append(" return new File(home, \"junit.properties\"); //$NON-NLS-1$\n"); - buf.append(" }\n"); - buf.append("\n"); - buf.append(" private static void readPreferences() {\n"); - buf.append(" InputStream is = null;\n"); - buf.append(" try {\n"); - buf.append(" is = new FileInputStream(BaseTestRunner.getPreferencesFile());\n"); - buf.append(" BaseTestRunner.setPreferences(new Properties(BaseTestRunner\n"); - buf.append(" .getPreferences()));\n"); - buf.append(" BaseTestRunner.getPreferences().load(is);\n"); - buf.append(" } catch (final IOException e) {\n"); - buf.append(" try {\n"); - buf.append(" if (is != null) {\n"); - buf.append(" is.close();\n"); - buf.append(" }\n"); - buf.append(" } catch (final IOException e1) {\n"); - buf.append(" }\n"); - buf.append(" }\n"); - buf.append(" }\n"); - buf.append("\n"); - buf.append(" public static String getPreference(final String key) {\n"); - buf.append(" return BaseTestRunner.getPreferences().getProperty(key);\n"); - buf.append(" }\n"); - buf.append("\n"); - buf.append(" public static int getPreference(final String key, final int dflt) {\n"); - buf.append(" final String value = BaseTestRunner.getPreference(key);\n"); - buf.append(" int intValue = dflt;\n"); - buf.append(" if (value == null) {\n"); - buf.append(" return intValue;\n"); - buf.append(" }\n"); - buf.append(" try {\n"); - buf.append(" intValue = Integer.parseInt(value);\n"); - buf.append(" } catch (final NumberFormatException ne) {\n"); - buf.append(" }\n"); - buf.append(" return intValue;\n"); + buf.append(" public void setLoading(final boolean enable) {\n"); + buf.append(" this.fLoading = enable;\n"); buf.append(" }\n"); buf.append("\n"); - buf.append(" public static boolean inVAJava() {\n"); - buf.append(" try {\n"); - buf.append(" Class.forName(\"com.ibm.uvm.tools.DebugSupport\"); //$NON-NLS-1$\n"); - buf.append(" } catch (final Exception e) {\n"); - buf.append(" return false;\n"); - buf.append(" }\n"); - buf.append(" return true;\n"); + buf.append(" public void setPreference(final String key, final String value) {\n"); + buf.append(" BaseTestRunner.getPreferences().setProperty(key, value);\n"); buf.append(" }\n"); buf.append("\n"); - buf.append(" /**\n"); - buf.append(" * Returns a filtered stack trace\n"); + buf.append(" /*\n"); + buf.append(" * Implementation of TestListener\n"); buf.append(" */\n"); - buf.append(" public static String getFilteredTrace(final Throwable t) {\n"); - buf.append(" final StringWriter stringWriter = new StringWriter();\n"); - buf.append(" final PrintWriter writer = new PrintWriter(stringWriter);\n"); - buf.append(" t.printStackTrace(writer);\n"); - buf.append(" final StringBuffer buffer = stringWriter.getBuffer();\n"); - buf.append(" final String trace = buffer.toString();\n"); - buf.append(" return BaseTestRunner.getFilteredTrace(trace);\n"); + buf.append(" public synchronized void startTest(final Test test) {\n"); + buf.append(" this.testStarted(test.toString());\n"); buf.append(" }\n"); buf.append("\n"); - buf.append(" /**\n"); - buf.append(" * Filters stack frames from internal JUnit classes\n"); - buf.append(" */\n"); - buf.append(" public static String getFilteredTrace(final String stack) {\n"); - buf.append(" if (BaseTestRunner.showStackRaw()) {\n"); - buf.append(" return stack;\n"); - buf.append(" }\n"); - buf.append("\n"); - buf.append(" final StringWriter sw = new StringWriter();\n"); - buf.append(" final PrintWriter pw = new PrintWriter(sw);\n"); - buf.append(" final StringReader sr = new StringReader(stack);\n"); - buf.append(" final BufferedReader br = new BufferedReader(sr);\n"); - buf.append("\n"); - buf.append(" String line;\n"); - buf.append(" try {\n"); - buf.append(" while ((line = br.readLine()) != null) {\n"); - buf.append(" if (!BaseTestRunner.filterLine(line)) {\n"); - buf.append(" pw.println(line);\n"); - buf.append(" }\n"); - buf.append(" }\n"); - buf.append(" } catch (final Exception IOException) {\n"); - buf.append(" return stack; // return the stack unfiltered\n"); - buf.append(" }\n"); - buf.append(" return sw.toString();\n"); - buf.append(" }\n"); + buf.append(" public abstract void testEnded(String testName);\n"); buf.append("\n"); - buf.append(" protected static boolean showStackRaw() {\n"); - buf.append(" return !BaseTestRunner.getPreference(\"filterstack\").equals(\"true\") || (BaseTestRunner.fgFilterStack == false); //$NON-NLS-1$ //$NON-NLS-2$\n"); - buf.append(" }\n"); + buf.append(" public abstract void testFailed(int status, Test test, Throwable t);\n"); buf.append("\n"); - buf.append(" static boolean filterLine(final String line) {\n"); - buf.append(" final String[] patterns = new String[]{\"junit.framework.TestCase\", //$NON-NLS-1$\n"); - buf.append(" \"junit.framework.TestResult\", //$NON-NLS-1$\n"); - buf.append(" \"junit.framework.TestSuite\", //$NON-NLS-1$\n"); - buf.append(" \"junit.framework.Assert.\", // don't filter AssertionFailure\n"); - buf.append(" // //$NON-NLS-1$\n"); - buf.append(" \"junit.swingui.TestRunner\", //$NON-NLS-1$\n"); - buf.append(" \"junit.awtui.TestRunner\", //$NON-NLS-1$\n"); - buf.append(" \"junit.textui.TestRunner\", //$NON-NLS-1$\n"); - buf.append(" \"java.lang.reflect.Method.invoke(\" //$NON-NLS-1$\n"); - buf.append(" };\n"); - buf.append(" for (final String element : patterns) {\n"); - buf.append(" if (line.indexOf(element) > 0) {\n"); - buf.append(" return true;\n"); - buf.append(" }\n"); - buf.append(" }\n"); - buf.append(" return false;\n"); - buf.append(" }\n"); + buf.append(" public abstract void testStarted(String testName);\n"); buf.append("\n"); - buf.append(" static {\n"); - buf.append(" BaseTestRunner.fgMaxMessageLength = BaseTestRunner.getPreference(\n"); - buf.append(" \"maxmessage\", BaseTestRunner.fgMaxMessageLength); //$NON-NLS-1$\n"); + buf.append(" protected boolean useReloadingTestSuiteLoader() {\n"); + buf.append(" return BaseTestRunner.getPreference(\"loading\").equals(\"true\") && !BaseTestRunner.inVAJava() && this.fLoading; //$NON-NLS-1$ //$NON-NLS-2$\n"); buf.append(" }\n"); buf.append("\n"); buf.append("}"); @@ -602,35 +603,35 @@ buf.append(" Assert.fail();\n"); buf.append(" }\n"); buf.append("\n"); - buf.append(" public void testAssertPosInfinityNotEqualsNegInfinity() {\n"); + buf.append(" public void testAssertNegInfinityEqualsInfinity() {\n"); + buf.append(" Assert.assertEquals(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY,\n"); + buf.append(" 0.0);\n"); + buf.append(" }\n"); + buf.append("\n"); + buf.append(" public void testAssertPosInfinityEqualsInfinity() {\n"); + buf.append(" Assert.assertEquals(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY,\n"); + buf.append(" 0.0);\n"); + buf.append(" }\n"); + buf.append("\n"); + buf.append(" public void testAssertPosInfinityNotEquals() {\n"); buf.append(" try {\n"); - buf.append(" Assert.assertEquals(Double.POSITIVE_INFINITY,\n"); - buf.append(" Double.NEGATIVE_INFINITY, 0.0);\n"); + buf.append(" Assert.assertEquals(Double.POSITIVE_INFINITY, 1.23, 0.0);\n"); buf.append(" } catch (final AssertionFailedError e) {\n"); buf.append(" return;\n"); buf.append(" }\n"); buf.append(" Assert.fail();\n"); buf.append(" }\n"); buf.append("\n"); - buf.append(" public void testAssertPosInfinityNotEquals() {\n"); + buf.append(" public void testAssertPosInfinityNotEqualsNegInfinity() {\n"); buf.append(" try {\n"); - buf.append(" Assert.assertEquals(Double.POSITIVE_INFINITY, 1.23, 0.0);\n"); + buf.append(" Assert.assertEquals(Double.POSITIVE_INFINITY,\n"); + buf.append(" Double.NEGATIVE_INFINITY, 0.0);\n"); buf.append(" } catch (final AssertionFailedError e) {\n"); buf.append(" return;\n"); buf.append(" }\n"); buf.append(" Assert.fail();\n"); buf.append(" }\n"); buf.append("\n"); - buf.append(" public void testAssertPosInfinityEqualsInfinity() {\n"); - buf.append(" Assert.assertEquals(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY,\n"); - buf.append(" 0.0);\n"); - buf.append(" }\n"); - buf.append("\n"); - buf.append(" public void testAssertNegInfinityEqualsInfinity() {\n"); - buf.append(" Assert.assertEquals(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY,\n"); - buf.append(" 0.0);\n"); - buf.append(" }\n"); - buf.append("\n"); buf.append("}\n"); buf.append(""); fExpectedChangesAllTests.put("junit.tests.framework.DoublePrecisionAssertTest.java", buf.toString()); @@ -644,22 +645,6 @@ buf.append("\n"); buf.append("public class AssertTest extends TestCase {\n"); buf.append("\n"); - buf.append(" /*\n"); - buf.append(" * In the tests that follow, we can't use standard formatting for exception\n"); - buf.append(" * tests: try { somethingThatShouldThrow(); fail(); catch\n"); - buf.append(" * (AssertionFailedError e) { } because fail() would never be reported.\n"); - buf.append(" */\n"); - buf.append(" public void testFail() {\n"); - buf.append(" // Also, we are testing fail, so we can't rely on fail() working.\n"); - buf.append(" // We have to throw the exception manually, .\n"); - buf.append(" try {\n"); - buf.append(" Assert.fail();\n"); - buf.append(" } catch (final AssertionFailedError e) {\n"); - buf.append(" return;\n"); - buf.append(" }\n"); - buf.append(" throw new AssertionFailedError();\n"); - buf.append(" }\n"); - buf.append("\n"); buf.append(" public void testAssertEquals() {\n"); buf.append(" final Object o = new Object();\n"); buf.append(" Assert.assertEquals(o, o);\n"); @@ -675,75 +660,74 @@ buf.append(" Assert.assertEquals(null, null);\n"); buf.append(" }\n"); buf.append("\n"); - buf.append(" public void testAssertStringEquals() {\n"); - buf.append(" Assert.assertEquals(\"a\", \"a\"); //$NON-NLS-1$ //$NON-NLS-2$\n"); - buf.append(" }\n"); - buf.append("\n"); - buf.append(" public void testAssertNullNotEqualsString() {\n"); + buf.append(" public void testAssertFalse() {\n"); + buf.append(" Assert.assertFalse(false);\n"); buf.append(" try {\n"); - buf.append(" Assert.assertEquals(null, \"foo\"); //$NON-NLS-1$\n"); - buf.append(" Assert.fail();\n"); - buf.append(" } catch (final ComparisonFailure e) {\n"); + buf.append(" Assert.assertFalse(true);\n"); + buf.append(" } catch (final AssertionFailedError e) {\n"); + buf.append(" return;\n"); buf.append(" }\n"); + buf.append(" Assert.fail();\n"); buf.append(" }\n"); buf.append("\n"); - buf.append(" public void testAssertStringNotEqualsNull() {\n"); + buf.append(" public void testAssertNotNull() {\n"); + buf.append(" Assert.assertNotNull(new Object());\n"); buf.append(" try {\n"); - buf.append(" Assert.assertEquals(\"foo\", null); //$NON-NLS-1$\n"); - buf.append(" Assert.fail();\n"); - buf.append(" } catch (final ComparisonFailure e) {\n"); - buf.append(" e.getMessage(); // why no assertion?\n"); + buf.append(" Assert.assertNotNull(null);\n"); + buf.append(" } catch (final AssertionFailedError e) {\n"); + buf.append(" return;\n"); buf.append(" }\n"); + buf.append(" Assert.fail();\n"); buf.append(" }\n"); buf.append("\n"); - buf.append(" public void testAssertNullNotEqualsNull() {\n"); + buf.append(" public void testAssertNotSame() {\n"); + buf.append(" Assert.assertNotSame(new Integer(1), null);\n"); + buf.append(" Assert.assertNotSame(null, new Integer(1));\n"); + buf.append(" Assert.assertNotSame(new Integer(1), new Integer(1));\n"); buf.append(" try {\n"); - buf.append(" Assert.assertEquals(null, new Object());\n"); + buf.append(" final Integer obj = new Integer(1);\n"); + buf.append(" Assert.assertNotSame(obj, obj);\n"); buf.append(" } catch (final AssertionFailedError e) {\n"); - buf.append(" e.getMessage(); // why no assertion?\n"); buf.append(" return;\n"); buf.append(" }\n"); buf.append(" Assert.fail();\n"); buf.append(" }\n"); buf.append("\n"); - buf.append(" public void testAssertNull() {\n"); - buf.append(" Assert.assertNull(null);\n"); + buf.append(" public void testAssertNotSameFailsNull() {\n"); buf.append(" try {\n"); - buf.append(" Assert.assertNull(new Object());\n"); + buf.append(" Assert.assertNotSame(null, null);\n"); buf.append(" } catch (final AssertionFailedError e) {\n"); buf.append(" return;\n"); buf.append(" }\n"); buf.append(" Assert.fail();\n"); buf.append(" }\n"); buf.append("\n"); - buf.append(" public void testAssertNotNull() {\n"); - buf.append(" Assert.assertNotNull(new Object());\n"); + buf.append(" public void testAssertNull() {\n"); + buf.append(" Assert.assertNull(null);\n"); buf.append(" try {\n"); - buf.append(" Assert.assertNotNull(null);\n"); + buf.append(" Assert.assertNull(new Object());\n"); buf.append(" } catch (final AssertionFailedError e) {\n"); buf.append(" return;\n"); buf.append(" }\n"); buf.append(" Assert.fail();\n"); buf.append(" }\n"); buf.append("\n"); - buf.append(" public void testAssertTrue() {\n"); - buf.append(" Assert.assertTrue(true);\n"); + buf.append(" public void testAssertNullNotEqualsNull() {\n"); buf.append(" try {\n"); - buf.append(" Assert.assertTrue(false);\n"); + buf.append(" Assert.assertEquals(null, new Object());\n"); buf.append(" } catch (final AssertionFailedError e) {\n"); + buf.append(" e.getMessage(); // why no assertion?\n"); buf.append(" return;\n"); buf.append(" }\n"); buf.append(" Assert.fail();\n"); buf.append(" }\n"); buf.append("\n"); - buf.append(" public void testAssertFalse() {\n"); - buf.append(" Assert.assertFalse(false);\n"); + buf.append(" public void testAssertNullNotEqualsString() {\n"); buf.append(" try {\n"); - buf.append(" Assert.assertFalse(true);\n"); - buf.append(" } catch (final AssertionFailedError e) {\n"); - buf.append(" return;\n"); + buf.append(" Assert.assertEquals(null, \"foo\"); //$NON-NLS-1$\n"); + buf.append(" Assert.fail();\n"); + buf.append(" } catch (final ComparisonFailure e) {\n"); buf.append(" }\n"); - buf.append(" Assert.fail();\n"); buf.append(" }\n"); buf.append("\n"); buf.append(" public void testAssertSame() {\n"); @@ -757,26 +741,43 @@ buf.append(" Assert.fail();\n"); buf.append(" }\n"); buf.append("\n"); - buf.append(" public void testAssertNotSame() {\n"); - buf.append(" Assert.assertNotSame(new Integer(1), null);\n"); - buf.append(" Assert.assertNotSame(null, new Integer(1));\n"); - buf.append(" Assert.assertNotSame(new Integer(1), new Integer(1));\n"); + buf.append(" public void testAssertStringEquals() {\n"); + buf.append(" Assert.assertEquals(\"a\", \"a\"); //$NON-NLS-1$ //$NON-NLS-2$\n"); + buf.append(" }\n"); + buf.append("\n"); + buf.append(" public void testAssertStringNotEqualsNull() {\n"); buf.append(" try {\n"); - buf.append(" final Integer obj = new Integer(1);\n"); - buf.append(" Assert.assertNotSame(obj, obj);\n"); + buf.append(" Assert.assertEquals(\"foo\", null); //$NON-NLS-1$\n"); + buf.append(" Assert.fail();\n"); + buf.append(" } catch (final ComparisonFailure e) {\n"); + buf.append(" e.getMessage(); // why no assertion?\n"); + buf.append(" }\n"); + buf.append(" }\n"); + buf.append("\n"); + buf.append(" public void testAssertTrue() {\n"); + buf.append(" Assert.assertTrue(true);\n"); + buf.append(" try {\n"); + buf.append(" Assert.assertTrue(false);\n"); buf.append(" } catch (final AssertionFailedError e) {\n"); buf.append(" return;\n"); buf.append(" }\n"); buf.append(" Assert.fail();\n"); buf.append(" }\n"); buf.append("\n"); - buf.append(" public void testAssertNotSameFailsNull() {\n"); + buf.append(" /*\n"); + buf.append(" * In the tests that follow, we can't use standard formatting for exception\n"); + buf.append(" * tests: try { somethingThatShouldThrow(); fail(); catch\n"); + buf.append(" * (AssertionFailedError e) { } because fail() would never be reported.\n"); + buf.append(" */\n"); + buf.append(" public void testFail() {\n"); + buf.append(" // Also, we are testing fail, so we can't rely on fail() working.\n"); + buf.append(" // We have to throw the exception manually, .\n"); buf.append(" try {\n"); - buf.append(" Assert.assertNotSame(null, null);\n"); + buf.append(" Assert.fail();\n"); buf.append(" } catch (final AssertionFailedError e) {\n"); buf.append(" return;\n"); buf.append(" }\n"); - buf.append(" Assert.fail();\n"); + buf.append(" throw new AssertionFailedError();\n"); buf.append(" }\n"); buf.append("}"); fExpectedChangesAllTests.put("junit.tests.framework.AssertTest.java", buf.toString()); @@ -822,21 +823,21 @@ buf.append(" }\n"); buf.append(" }\n"); buf.append("\n"); - buf.append(" static public class ThrowRuntimeExceptionTestCase extends ExceptionTestCase {\n"); - buf.append(" public ThrowRuntimeExceptionTestCase(final String name,\n"); - buf.append(" final Class exception) {\n"); + buf.append(" static public class ThrowNoExceptionTestCase extends ExceptionTestCase {\n"); + buf.append(" public ThrowNoExceptionTestCase(final String name, final Class exception) {\n"); buf.append(" super(name, exception);\n"); buf.append(" }\n"); buf.append(" public void test() {\n"); - buf.append(" throw new RuntimeException();\n"); buf.append(" }\n"); buf.append(" }\n"); buf.append("\n"); - buf.append(" static public class ThrowNoExceptionTestCase extends ExceptionTestCase {\n"); - buf.append(" public ThrowNoExceptionTestCase(final String name, final Class exception) {\n"); + buf.append(" static public class ThrowRuntimeExceptionTestCase extends ExceptionTestCase {\n"); + buf.append(" public ThrowRuntimeExceptionTestCase(final String name,\n"); + buf.append(" final Class exception) {\n"); buf.append(" super(name, exception);\n"); buf.append(" }\n"); buf.append(" public void test() {\n"); + buf.append(" throw new RuntimeException();\n"); buf.append(" }\n"); buf.append(" }\n"); buf.append("\n"); @@ -891,11 +892,11 @@ buf.append("import junit.framework.TestResult;\n"); buf.append("\n"); buf.append("public class TestListenerTest extends TestCase implements TestListener {\n"); - buf.append(" private TestResult fResult;\n"); - buf.append(" private int fStartCount;\n"); buf.append(" private int fEndCount;\n"); - buf.append(" private int fFailureCount;\n"); buf.append(" private int fErrorCount;\n"); + buf.append(" private int fFailureCount;\n"); + buf.append(" private TestResult fResult;\n"); + buf.append(" private int fStartCount;\n"); buf.append("\n"); buf.append(" public void addError(final Test test, final Throwable t) {\n"); buf.append(" this.fErrorCount++;\n"); @@ -1086,6 +1087,10 @@ buf.append(" public int countTestCases() {\n"); buf.append(" return this.fTest.countTestCases();\n"); buf.append(" }\n"); + buf.append(" public Test getTest() {\n"); + buf.append(" return this.fTest;\n"); + buf.append(" }\n"); + buf.append("\n"); buf.append(" public void run(final TestResult result) {\n"); buf.append(" this.basicRun(result);\n"); buf.append(" }\n"); @@ -1094,10 +1099,6 @@ buf.append(" public String toString() {\n"); buf.append(" return this.fTest.toString();\n"); buf.append(" }\n"); - buf.append("\n"); - buf.append(" public Test getTest() {\n"); - buf.append(" return this.fTest;\n"); - buf.append(" }\n"); buf.append("}"); fExpectedChangesAllTests.put("junit.extensions.TestDecorator.java", buf.toString()); buf= new StringBuffer(); @@ -1128,8 +1129,8 @@ buf.append(" * @see Test\n"); buf.append(" */\n"); buf.append("public class TestResult extends Object {\n"); - buf.append(" protected Vector fFailures;\n"); buf.append(" protected Vector fErrors;\n"); + buf.append(" protected Vector fFailures;\n"); buf.append(" protected Vector fListeners;\n"); buf.append(" protected int fRunTests;\n"); buf.append(" private boolean fStop;\n"); @@ -1171,12 +1172,6 @@ buf.append(" this.fListeners.addElement(listener);\n"); buf.append(" }\n"); buf.append(" /**\n"); - buf.append(" * Unregisters a TestListener\n"); - buf.append(" */\n"); - buf.append(" public synchronized void removeListener(final TestListener listener) {\n"); - buf.append(" this.fListeners.removeElement(listener);\n"); - buf.append(" }\n"); - buf.append(" /**\n"); buf.append(" * Returns a copy of the listeners.\n"); buf.append(" */\n"); buf.append(" private synchronized Vector cloneListeners() {\n"); @@ -1216,6 +1211,12 @@ buf.append(" return this.fFailures.elements();\n"); buf.append(" }\n"); buf.append(" /**\n"); + buf.append(" * Unregisters a TestListener\n"); + buf.append(" */\n"); + buf.append(" public synchronized void removeListener(final TestListener listener) {\n"); + buf.append(" this.fListeners.removeElement(listener);\n"); + buf.append(" }\n"); + buf.append(" /**\n"); buf.append(" * Runs a TestCase.\n"); buf.append(" */\n"); buf.append(" protected void run(final TestCase test) {\n"); @@ -1319,14 +1320,14 @@ buf.append(" super(theClass);\n"); buf.append(" }\n"); buf.append("\n"); - buf.append(" public ActiveTestSuite(final String name) {\n"); - buf.append(" super(name);\n"); - buf.append(" }\n"); - buf.append("\n"); buf.append(" public ActiveTestSuite(final Class theClass, final String name) {\n"); buf.append(" super(theClass, name);\n"); buf.append(" }\n"); buf.append("\n"); + buf.append(" public ActiveTestSuite(final String name) {\n"); + buf.append(" super(name);\n"); + buf.append(" }\n"); + buf.append("\n"); buf.append(" @Override\n"); buf.append(" public void run(final TestResult result) {\n"); buf.append(" this.fActiveTestDeathCount = 0;\n"); @@ -1334,6 +1335,11 @@ buf.append(" this.waitUntilFinished();\n"); buf.append(" }\n"); buf.append("\n"); + buf.append(" synchronized public void runFinished(final Test test) {\n"); + buf.append(" this.fActiveTestDeathCount++;\n"); + buf.append(" this.notifyAll();\n"); + buf.append(" }\n"); + buf.append("\n"); buf.append(" @Override\n"); buf.append(" public void runTest(final Test test, final TestResult result) {\n"); buf.append(" final Thread t = new Thread() {\n"); @@ -1360,11 +1366,6 @@ buf.append(" }\n"); buf.append(" }\n"); buf.append(" }\n"); - buf.append("\n"); - buf.append(" synchronized public void runFinished(final Test test) {\n"); - buf.append(" this.fActiveTestDeathCount++;\n"); - buf.append(" this.notifyAll();\n"); - buf.append(" }\n"); buf.append("}"); fExpectedChangesAllTests.put("junit.extensions.ActiveTestSuite.java", buf.toString()); buf= new StringBuffer(); @@ -1381,14 +1382,6 @@ buf.append(" * \n"); buf.append(" */\n"); buf.append("public class SuiteTest extends TestCase {\n"); - buf.append(" protected TestResult fResult;\n"); - buf.append(" public SuiteTest(final String name) {\n"); - buf.append(" super(name);\n"); - buf.append(" }\n"); - buf.append(" @Override\n"); - buf.append(" protected void setUp() {\n"); - buf.append(" this.fResult = new TestResult();\n"); - buf.append(" }\n"); buf.append(" public static Test suite() {\n"); buf.append(" final TestSuite suite = new TestSuite(\"Suite Tests\"); //$NON-NLS-1$\n"); buf.append(" // build the suite manually, because some of the suites are testing\n"); @@ -1405,6 +1398,20 @@ buf.append("\n"); buf.append(" return suite;\n"); buf.append(" }\n"); + buf.append(" protected TestResult fResult;\n"); + buf.append(" public SuiteTest(final String name) {\n"); + buf.append(" super(name);\n"); + buf.append(" }\n"); + buf.append(" @Override\n"); + buf.append(" protected void setUp() {\n"); + buf.append(" this.fResult = new TestResult();\n"); + buf.append(" }\n"); + buf.append(" public void testAddTestSuite() {\n"); + buf.append(" final TestSuite suite = new TestSuite();\n"); + buf.append(" suite.addTestSuite(OneTestCase.class);\n"); + buf.append(" suite.run(this.fResult);\n"); + buf.append(" Assert.assertEquals(1, this.fResult.runCount());\n"); + buf.append(" }\n"); buf.append(" public void testInheritedTests() {\n"); buf.append(" final TestSuite suite = new TestSuite(InheritedTestCase.class);\n"); buf.append(" suite.run(this.fResult);\n"); @@ -1453,12 +1460,6 @@ buf.append(" suite.run(this.fResult);\n"); buf.append(" Assert.assertEquals(1, this.fResult.runCount());\n"); buf.append(" }\n"); - buf.append(" public void testAddTestSuite() {\n"); - buf.append(" final TestSuite suite = new TestSuite();\n"); - buf.append(" suite.addTestSuite(OneTestCase.class);\n"); - buf.append(" suite.run(this.fResult);\n"); - buf.append(" Assert.assertEquals(1, this.fResult.runCount());\n"); - buf.append(" }\n"); buf.append("}"); fExpectedChangesAllTests.put("junit.tests.framework.SuiteTest.java", buf.toString()); buf= new StringBuffer(); @@ -1557,19 +1558,6 @@ buf.append(" this.fLoader = new TestCaseClassLoader();\n"); buf.append(" }\n"); buf.append("\n"); - buf.append(" @Override\n"); - buf.append(" protected boolean isTestClass(final String classFileName) {\n"); - buf.append(" try {\n"); - buf.append(" if (classFileName.endsWith(\".class\")) { //$NON-NLS-1$\n"); - buf.append(" final Class testClass = this.classFromFile(classFileName);\n"); - buf.append(" return (testClass != null) && this.isTestClass(testClass);\n"); - buf.append(" }\n"); - buf.append(" } catch (final ClassNotFoundException expected) {\n"); - buf.append(" } catch (final NoClassDefFoundError notFatal) {\n"); - buf.append(" }\n"); - buf.append(" return false;\n"); - buf.append(" }\n"); - buf.append("\n"); buf.append(" Class classFromFile(final String classFileName)\n"); buf.append(" throws ClassNotFoundException {\n"); buf.append(" final String className = this.classNameFromFile(classFileName);\n"); @@ -1579,16 +1567,13 @@ buf.append(" return null;\n"); buf.append(" }\n"); buf.append("\n"); - buf.append(" boolean isTestClass(final Class testClass) {\n"); - buf.append(" if (this.hasSuiteMethod(testClass)) {\n"); - buf.append(" return true;\n"); - buf.append(" }\n"); - buf.append(" if (Test.class.isAssignableFrom(testClass)\n"); - buf.append(" && Modifier.isPublic(testClass.getModifiers())\n"); - buf.append(" && this.hasPublicConstructor(testClass)) {\n"); - buf.append(" return true;\n"); + buf.append(" boolean hasPublicConstructor(final Class testClass) {\n"); + buf.append(" try {\n"); + buf.append(" TestSuite.getTestConstructor(testClass);\n"); + buf.append(" } catch (final NoSuchMethodException e) {\n"); + buf.append(" return false;\n"); buf.append(" }\n"); - buf.append(" return false;\n"); + buf.append(" return true;\n"); buf.append(" }\n"); buf.append("\n"); buf.append(" boolean hasSuiteMethod(final Class testClass) {\n"); @@ -1600,13 +1585,29 @@ buf.append(" return true;\n"); buf.append(" }\n"); buf.append("\n"); - buf.append(" boolean hasPublicConstructor(final Class testClass) {\n"); + buf.append(" boolean isTestClass(final Class testClass) {\n"); + buf.append(" if (this.hasSuiteMethod(testClass)) {\n"); + buf.append(" return true;\n"); + buf.append(" }\n"); + buf.append(" if (Test.class.isAssignableFrom(testClass)\n"); + buf.append(" && Modifier.isPublic(testClass.getModifiers())\n"); + buf.append(" && this.hasPublicConstructor(testClass)) {\n"); + buf.append(" return true;\n"); + buf.append(" }\n"); + buf.append(" return false;\n"); + buf.append(" }\n"); + buf.append("\n"); + buf.append(" @Override\n"); + buf.append(" protected boolean isTestClass(final String classFileName) {\n"); buf.append(" try {\n"); - buf.append(" TestSuite.getTestConstructor(testClass);\n"); - buf.append(" } catch (final NoSuchMethodException e) {\n"); - buf.append(" return false;\n"); + buf.append(" if (classFileName.endsWith(\".class\")) { //$NON-NLS-1$\n"); + buf.append(" final Class testClass = this.classFromFile(classFileName);\n"); + buf.append(" return (testClass != null) && this.isTestClass(testClass);\n"); + buf.append(" }\n"); + buf.append(" } catch (final ClassNotFoundException expected) {\n"); + buf.append(" } catch (final NoClassDefFoundError notFatal) {\n"); buf.append(" }\n"); - buf.append(" return true;\n"); + buf.append(" return false;\n"); buf.append(" }\n"); buf.append("}\n"); buf.append(""); @@ -1642,17 +1643,17 @@ buf.append(" */\n"); buf.append("\n"); buf.append("public class TestCaseClassLoader extends ClassLoader {\n"); - buf.append(" /** scanned class path */\n"); - buf.append(" private Vector fPathItems;\n"); + buf.append(" /** name of excluded properties file */\n"); + buf.append(" static final String EXCLUDED_FILE = \"excluded.properties\"; //$NON-NLS-1$\n"); buf.append(" /** default excluded paths */\n"); buf.append(" private final String[] defaultExclusions = {\"junit.framework.\", //$NON-NLS-1$\n"); buf.append(" \"junit.extensions.\", //$NON-NLS-1$\n"); buf.append(" \"junit.runner.\" //$NON-NLS-1$\n"); buf.append(" };\n"); - buf.append(" /** name of excluded properties file */\n"); - buf.append(" static final String EXCLUDED_FILE = \"excluded.properties\"; //$NON-NLS-1$\n"); buf.append(" /** excluded paths */\n"); buf.append(" private Vector fExcluded;\n"); + buf.append(" /** scanned class path */\n"); + buf.append(" private Vector fPathItems;\n"); buf.append("\n"); buf.append(" /**\n"); buf.append(" * Constructs a TestCaseLoader. It scans the class path and the excluded\n"); @@ -1671,13 +1672,22 @@ buf.append(" this.readExcludedPackages();\n"); buf.append(" }\n"); buf.append("\n"); - buf.append(" private void scanPath(final String classPath) {\n"); - buf.append(" final String separator = System.getProperty(\"path.separator\"); //$NON-NLS-1$\n"); - buf.append(" this.fPathItems = new Vector(10);\n"); - buf.append(" final StringTokenizer st = new StringTokenizer(classPath, separator);\n"); - buf.append(" while (st.hasMoreTokens()) {\n"); - buf.append(" this.fPathItems.addElement(st.nextToken());\n"); + buf.append(" private byte[] getClassData(final File f) {\n"); + buf.append(" try {\n"); + buf.append(" final FileInputStream stream = new FileInputStream(f);\n"); + buf.append(" final ByteArrayOutputStream out = new ByteArrayOutputStream(1000);\n"); + buf.append(" final byte[] b = new byte[1000];\n"); + buf.append(" int n;\n"); + buf.append(" while ((n = stream.read(b)) != -1) {\n"); + buf.append(" out.write(b, 0, n);\n"); + buf.append(" }\n"); + buf.append(" stream.close();\n"); + buf.append(" out.close();\n"); + buf.append(" return out.toByteArray();\n"); + buf.append("\n"); + buf.append(" } catch (final IOException e) {\n"); buf.append(" }\n"); + buf.append(" return null;\n"); buf.append(" }\n"); buf.append("\n"); buf.append(" @Override\n"); @@ -1699,6 +1709,10 @@ buf.append(" return false;\n"); buf.append(" }\n"); buf.append("\n"); + buf.append(" boolean isJar(final String pathEntry) {\n"); + buf.append(" return pathEntry.endsWith(\".jar\") || pathEntry.endsWith(\".zip\"); //$NON-NLS-1$ //$NON-NLS-2$\n"); + buf.append(" }\n"); + buf.append("\n"); buf.append(" @Override\n"); buf.append(" public synchronized Class loadClass(final String name, final boolean resolve)\n"); buf.append(" throws ClassNotFoundException {\n"); @@ -1732,28 +1746,6 @@ buf.append(" return c;\n"); buf.append(" }\n"); buf.append("\n"); - buf.append(" private byte[] lookupClassData(final String className)\n"); - buf.append(" throws ClassNotFoundException {\n"); - buf.append(" byte[] data = null;\n"); - buf.append(" for (int i = 0; i < this.fPathItems.size(); i++) {\n"); - buf.append(" final String path = (String) this.fPathItems.elementAt(i);\n"); - buf.append(" final String fileName = className.replace('.', '/') + \".class\"; //$NON-NLS-1$\n"); - buf.append(" if (this.isJar(path)) {\n"); - buf.append(" data = this.loadJarData(path, fileName);\n"); - buf.append(" } else {\n"); - buf.append(" data = this.loadFileData(path, fileName);\n"); - buf.append(" }\n"); - buf.append(" if (data != null) {\n"); - buf.append(" return data;\n"); - buf.append(" }\n"); - buf.append(" }\n"); - buf.append(" throw new ClassNotFoundException(className);\n"); - buf.append(" }\n"); - buf.append("\n"); - buf.append(" boolean isJar(final String pathEntry) {\n"); - buf.append(" return pathEntry.endsWith(\".jar\") || pathEntry.endsWith(\".zip\"); //$NON-NLS-1$ //$NON-NLS-2$\n"); - buf.append(" }\n"); - buf.append("\n"); buf.append(" private byte[] loadFileData(final String path, final String fileName) {\n"); buf.append(" final File file = new File(path, fileName);\n"); buf.append(" if (file.exists()) {\n"); @@ -1762,24 +1754,6 @@ buf.append(" return null;\n"); buf.append(" }\n"); buf.append("\n"); - buf.append(" private byte[] getClassData(final File f) {\n"); - buf.append(" try {\n"); - buf.append(" final FileInputStream stream = new FileInputStream(f);\n"); - buf.append(" final ByteArrayOutputStream out = new ByteArrayOutputStream(1000);\n"); - buf.append(" final byte[] b = new byte[1000];\n"); - buf.append(" int n;\n"); - buf.append(" while ((n = stream.read(b)) != -1) {\n"); - buf.append(" out.write(b, 0, n);\n"); - buf.append(" }\n"); - buf.append(" stream.close();\n"); - buf.append(" out.close();\n"); - buf.append(" return out.toByteArray();\n"); - buf.append("\n"); - buf.append(" } catch (final IOException e) {\n"); - buf.append(" }\n"); - buf.append(" return null;\n"); - buf.append(" }\n"); - buf.append("\n"); buf.append(" private byte[] loadJarData(final String path, final String fileName) {\n"); buf.append(" ZipFile zipFile = null;\n"); buf.append(" InputStream stream = null;\n"); @@ -1819,6 +1793,24 @@ buf.append(" return null;\n"); buf.append(" }\n"); buf.append("\n"); + buf.append(" private byte[] lookupClassData(final String className)\n"); + buf.append(" throws ClassNotFoundException {\n"); + buf.append(" byte[] data = null;\n"); + buf.append(" for (int i = 0; i < this.fPathItems.size(); i++) {\n"); + buf.append(" final String path = (String) this.fPathItems.elementAt(i);\n"); + buf.append(" final String fileName = className.replace('.', '/') + \".class\"; //$NON-NLS-1$\n"); + buf.append(" if (this.isJar(path)) {\n"); + buf.append(" data = this.loadJarData(path, fileName);\n"); + buf.append(" } else {\n"); + buf.append(" data = this.loadFileData(path, fileName);\n"); + buf.append(" }\n"); + buf.append(" if (data != null) {\n"); + buf.append(" return data;\n"); + buf.append(" }\n"); + buf.append(" }\n"); + buf.append(" throw new ClassNotFoundException(className);\n"); + buf.append(" }\n"); + buf.append("\n"); buf.append(" private void readExcludedPackages() {\n"); buf.append(" this.fExcluded = new Vector(10);\n"); buf.append(" for (final String element : this.defaultExclusions) {\n"); @@ -1855,6 +1847,15 @@ buf.append(" }\n"); buf.append(" }\n"); buf.append(" }\n"); + buf.append("\n"); + buf.append(" private void scanPath(final String classPath) {\n"); + buf.append(" final String separator = System.getProperty(\"path.separator\"); //$NON-NLS-1$\n"); + buf.append(" this.fPathItems = new Vector(10);\n"); + buf.append(" final StringTokenizer st = new StringTokenizer(classPath, separator);\n"); + buf.append(" while (st.hasMoreTokens()) {\n"); + buf.append(" this.fPathItems.addElement(st.nextToken());\n"); + buf.append(" }\n"); + buf.append(" }\n"); buf.append("}"); fExpectedChangesAllTests.put("junit.runner.TestCaseClassLoader.java", buf.toString()); buf= new StringBuffer(); @@ -1898,13 +1899,8 @@ buf.append(" * \n"); buf.append(" */\n"); buf.append("public class SimpleTest extends TestCase {\n"); - buf.append(" protected int fValue1;\n"); - buf.append(" protected int fValue2;\n"); - buf.append("\n"); - buf.append(" @Override\n"); - buf.append(" protected void setUp() {\n"); - buf.append(" this.fValue1 = 2;\n"); - buf.append(" this.fValue2 = 3;\n"); + buf.append(" public static void main(final String[] args) {\n"); + buf.append(" junit.textui.TestRunner.run(SimpleTest.suite());\n"); buf.append(" }\n"); buf.append(" public static Test suite() {\n"); buf.append("\n"); @@ -1923,6 +1919,14 @@ buf.append(" */\n"); buf.append(" return new TestSuite(SimpleTest.class);\n"); buf.append(" }\n"); + buf.append("\n"); + buf.append(" protected int fValue1;\n"); + buf.append(" protected int fValue2;\n"); + buf.append(" @Override\n"); + buf.append(" protected void setUp() {\n"); + buf.append(" this.fValue1 = 2;\n"); + buf.append(" this.fValue2 = 3;\n"); + buf.append(" }\n"); buf.append(" public void testAdd() {\n"); buf.append(" final double result = this.fValue1 + this.fValue2;\n"); buf.append(" // forced failure result == 5\n"); @@ -1939,9 +1943,6 @@ buf.append(" Assert.assertEquals(\"Size\", 12, 13); //$NON-NLS-1$\n"); buf.append(" Assert.assertEquals(\"Capacity\", 12.0, 11.99, 0.0); //$NON-NLS-1$\n"); buf.append(" }\n"); - buf.append(" public static void main(final String[] args) {\n"); - buf.append(" junit.textui.TestRunner.run(SimpleTest.suite());\n"); - buf.append(" }\n"); buf.append("}"); fExpectedChangesAllTests.put("junit.samples.SimpleTest.java", buf.toString()); buf= new StringBuffer(); @@ -1951,13 +1952,13 @@ buf.append(" * This class defines the current version of JUnit\n"); buf.append(" */\n"); buf.append("public class Version {\n"); - buf.append(" private Version() {\n"); - buf.append(" // don't instantiate\n"); - buf.append(" }\n"); - buf.append("\n"); buf.append(" public static String id() {\n"); buf.append(" return \"3.8.1\"; //$NON-NLS-1$\n"); buf.append(" }\n"); + buf.append("\n"); + buf.append(" private Version() {\n"); + buf.append(" // don't instantiate\n"); + buf.append(" }\n"); buf.append("}\n"); buf.append(""); fExpectedChangesAllTests.put("junit.runner.Version.java", buf.toString()); @@ -2059,23 +2060,86 @@ buf.append(" */\n"); buf.append("public class TestSuite implements Test {\n"); buf.append("\n"); - buf.append(" private final Vector fTests = new Vector(10);\n"); - buf.append(" private String fName;\n"); + buf.append(" /**\n"); + buf.append(" * ...as the moon sets over the early morning Merlin, Oregon mountains, our\n"); + buf.append(" * intrepid adventurers type...\n"); + buf.append(" */\n"); + buf.append(" static public Test createTest(final Class theClass, final String name) {\n"); + buf.append(" Constructor constructor;\n"); + buf.append(" try {\n"); + buf.append(" constructor = TestSuite.getTestConstructor(theClass);\n"); + buf.append(" } catch (final NoSuchMethodException e) {\n"); + buf.append(" return TestSuite\n"); + buf.append(" .warning(\"Class \" + theClass.getName() + \" has no public constructor TestCase(String name) or TestCase()\"); //$NON-NLS-1$ //$NON-NLS-2$\n"); + buf.append(" }\n"); + buf.append(" Object test;\n"); + buf.append(" try {\n"); + buf.append(" if (constructor.getParameterTypes().length == 0) {\n"); + buf.append(" test = constructor.newInstance(new Object[0]);\n"); + buf.append(" if (test instanceof TestCase) {\n"); + buf.append(" ((TestCase) test).setName(name);\n"); + buf.append(" }\n"); + buf.append(" } else {\n"); + buf.append(" test = constructor.newInstance(new Object[]{name});\n"); + buf.append(" }\n"); + buf.append(" } catch (final InstantiationException e) {\n"); + buf.append(" return (TestSuite\n"); + buf.append(" .warning(\"Cannot instantiate test case: \" + name + \" (\" + TestSuite.exceptionToString(e) + \")\")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\n"); + buf.append(" } catch (final InvocationTargetException e) {\n"); + buf.append(" return (TestSuite\n"); + buf.append(" .warning(\"Exception in constructor: \" + name + \" (\" + TestSuite.exceptionToString(e.getTargetException()) + \")\")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\n"); + buf.append(" } catch (final IllegalAccessException e) {\n"); + buf.append(" return (TestSuite\n"); + buf.append(" .warning(\"Cannot access test case: \" + name + \" (\" + TestSuite.exceptionToString(e) + \")\")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\n"); + buf.append(" }\n"); + buf.append(" return (Test) test;\n"); + buf.append(" }\n"); + buf.append(" /**\n"); + buf.append(" * Converts the stack trace into a string\n"); + buf.append(" */\n"); + buf.append(" private static String exceptionToString(final Throwable t) {\n"); + buf.append(" final StringWriter stringWriter = new StringWriter();\n"); + buf.append(" final PrintWriter writer = new PrintWriter(stringWriter);\n"); + buf.append(" t.printStackTrace(writer);\n"); + buf.append(" return stringWriter.toString();\n"); + buf.append("\n"); + buf.append(" }\n"); buf.append("\n"); buf.append(" /**\n"); - buf.append(" * Constructs an empty TestSuite.\n"); + buf.append(" * Gets a constructor which takes a single String as its argument or a no\n"); + buf.append(" * arg constructor.\n"); buf.append(" */\n"); - buf.append(" public TestSuite() {\n"); + buf.append(" public static Constructor getTestConstructor(final Class theClass)\n"); + buf.append(" throws NoSuchMethodException {\n"); + buf.append(" final Class[] args = {String.class};\n"); + buf.append(" try {\n"); + buf.append(" return theClass.getConstructor(args);\n"); + buf.append(" } catch (final NoSuchMethodException e) {\n"); + buf.append(" // fall through\n"); + buf.append(" }\n"); + buf.append(" return theClass.getConstructor(new Class[0]);\n"); buf.append(" }\n"); buf.append("\n"); buf.append(" /**\n"); - buf.append(" * Constructs a TestSuite from the given class with the given name.\n"); - buf.append(" * \n"); - buf.append(" * @see TestSuite#TestSuite(Class)\n"); + buf.append(" * Returns a test which will fail and log a warning message.\n"); buf.append(" */\n"); - buf.append(" public TestSuite(final Class theClass, final String name) {\n"); - buf.append(" this(theClass);\n"); - buf.append(" this.setName(name);\n"); + buf.append(" private static Test warning(final String message) {\n"); + buf.append(" return new TestCase(\"warning\") { //$NON-NLS-1$\n"); + buf.append(" @Override\n"); + buf.append(" protected void runTest() {\n"); + buf.append(" Assert.fail(message);\n"); + buf.append(" }\n"); + buf.append(" };\n"); + buf.append(" }\n"); + buf.append("\n"); + buf.append(" private String fName;\n"); + buf.append("\n"); + buf.append(" private final Vector fTests = new Vector(10);\n"); + buf.append("\n"); + buf.append(" /**\n"); + buf.append(" * Constructs an empty TestSuite.\n"); + buf.append(" */\n"); + buf.append(" public TestSuite() {\n"); buf.append(" }\n"); buf.append("\n"); buf.append(" /**\n"); @@ -2117,6 +2181,16 @@ buf.append(" }\n"); buf.append("\n"); buf.append(" /**\n"); + buf.append(" * Constructs a TestSuite from the given class with the given name.\n"); + buf.append(" * \n"); + buf.append(" * @see TestSuite#TestSuite(Class)\n"); + buf.append(" */\n"); + buf.append(" public TestSuite(final Class theClass, final String name) {\n"); + buf.append(" this(theClass);\n"); + buf.append(" this.setName(name);\n"); + buf.append(" }\n"); + buf.append("\n"); + buf.append(" /**\n"); buf.append(" * Constructs an empty TestSuite.\n"); buf.append(" */\n"); buf.append(" public TestSuite(final String name) {\n"); @@ -2130,13 +2204,6 @@ buf.append(" this.fTests.addElement(test);\n"); buf.append(" }\n"); buf.append("\n"); - buf.append(" /**\n"); - buf.append(" * Adds the tests from the given class to the suite\n"); - buf.append(" */\n"); - buf.append(" public void addTestSuite(final Class testClass) {\n"); - buf.append(" this.addTest(new TestSuite(testClass));\n"); - buf.append(" }\n"); - buf.append("\n"); buf.append(" private void addTestMethod(final Method m, final Vector names,\n"); buf.append(" final Class theClass) {\n"); buf.append(" final String name = m.getName();\n"); @@ -2155,49 +2222,10 @@ buf.append(" }\n"); buf.append("\n"); buf.append(" /**\n"); - buf.append(" * ...as the moon sets over the early morning Merlin, Oregon mountains, our\n"); - buf.append(" * intrepid adventurers type...\n"); - buf.append(" */\n"); - buf.append(" static public Test createTest(final Class theClass, final String name) {\n"); - buf.append(" Constructor constructor;\n"); - buf.append(" try {\n"); - buf.append(" constructor = TestSuite.getTestConstructor(theClass);\n"); - buf.append(" } catch (final NoSuchMethodException e) {\n"); - buf.append(" return TestSuite\n"); - buf.append(" .warning(\"Class \" + theClass.getName() + \" has no public constructor TestCase(String name) or TestCase()\"); //$NON-NLS-1$ //$NON-NLS-2$\n"); - buf.append(" }\n"); - buf.append(" Object test;\n"); - buf.append(" try {\n"); - buf.append(" if (constructor.getParameterTypes().length == 0) {\n"); - buf.append(" test = constructor.newInstance(new Object[0]);\n"); - buf.append(" if (test instanceof TestCase) {\n"); - buf.append(" ((TestCase) test).setName(name);\n"); - buf.append(" }\n"); - buf.append(" } else {\n"); - buf.append(" test = constructor.newInstance(new Object[]{name});\n"); - buf.append(" }\n"); - buf.append(" } catch (final InstantiationException e) {\n"); - buf.append(" return (TestSuite\n"); - buf.append(" .warning(\"Cannot instantiate test case: \" + name + \" (\" + TestSuite.exceptionToString(e) + \")\")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\n"); - buf.append(" } catch (final InvocationTargetException e) {\n"); - buf.append(" return (TestSuite\n"); - buf.append(" .warning(\"Exception in constructor: \" + name + \" (\" + TestSuite.exceptionToString(e.getTargetException()) + \")\")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\n"); - buf.append(" } catch (final IllegalAccessException e) {\n"); - buf.append(" return (TestSuite\n"); - buf.append(" .warning(\"Cannot access test case: \" + name + \" (\" + TestSuite.exceptionToString(e) + \")\")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\n"); - buf.append(" }\n"); - buf.append(" return (Test) test;\n"); - buf.append(" }\n"); - buf.append("\n"); - buf.append(" /**\n"); - buf.append(" * Converts the stack trace into a string\n"); + buf.append(" * Adds the tests from the given class to the suite\n"); buf.append(" */\n"); - buf.append(" private static String exceptionToString(final Throwable t) {\n"); - buf.append(" final StringWriter stringWriter = new StringWriter();\n"); - buf.append(" final PrintWriter writer = new PrintWriter(stringWriter);\n"); - buf.append(" t.printStackTrace(writer);\n"); - buf.append(" return stringWriter.toString();\n"); - buf.append("\n"); + buf.append(" public void addTestSuite(final Class testClass) {\n"); + buf.append(" this.addTest(new TestSuite(testClass));\n"); buf.append(" }\n"); buf.append("\n"); buf.append(" /**\n"); @@ -2213,18 +2241,11 @@ buf.append(" }\n"); buf.append("\n"); buf.append(" /**\n"); - buf.append(" * Gets a constructor which takes a single String as its argument or a no\n"); - buf.append(" * arg constructor.\n"); + buf.append(" * Returns the name of the suite. Not all test suites have a name and this\n"); + buf.append(" * method can return null.\n"); buf.append(" */\n"); - buf.append(" public static Constructor getTestConstructor(final Class theClass)\n"); - buf.append(" throws NoSuchMethodException {\n"); - buf.append(" final Class[] args = {String.class};\n"); - buf.append(" try {\n"); - buf.append(" return theClass.getConstructor(args);\n"); - buf.append(" } catch (final NoSuchMethodException e) {\n"); - buf.append(" // fall through\n"); - buf.append(" }\n"); - buf.append(" return theClass.getConstructor(new Class[0]);\n"); + buf.append(" public String getName() {\n"); + buf.append(" return this.fName;\n"); buf.append(" }\n"); buf.append("\n"); buf.append(" private boolean isPublicTestMethod(final Method m) {\n"); @@ -2257,6 +2278,16 @@ buf.append(" }\n"); buf.append("\n"); buf.append(" /**\n"); + buf.append(" * Sets the name of the suite.\n"); + buf.append(" * \n"); + buf.append(" * @param name\n"); + buf.append(" * The name to set\n"); + buf.append(" */\n"); + buf.append(" public void setName(final String name) {\n"); + buf.append(" this.fName = name;\n"); + buf.append(" }\n"); + buf.append("\n"); + buf.append(" /**\n"); buf.append(" * Returns the test at the given index\n"); buf.append(" */\n"); buf.append(" public Test testAt(final int index) {\n"); @@ -2286,36 +2317,6 @@ buf.append(" }\n"); buf.append(" return super.toString();\n"); buf.append(" }\n"); - buf.append("\n"); - buf.append(" /**\n"); - buf.append(" * Sets the name of the suite.\n"); - buf.append(" * \n"); - buf.append(" * @param name\n"); - buf.append(" * The name to set\n"); - buf.append(" */\n"); - buf.append(" public void setName(final String name) {\n"); - buf.append(" this.fName = name;\n"); - buf.append(" }\n"); - buf.append("\n"); - buf.append(" /**\n"); - buf.append(" * Returns the name of the suite. Not all test suites have a name and this\n"); - buf.append(" * method can return null.\n"); - buf.append(" */\n"); - buf.append(" public String getName() {\n"); - buf.append(" return this.fName;\n"); - buf.append(" }\n"); - buf.append("\n"); - buf.append(" /**\n"); - buf.append(" * Returns a test which will fail and log a warning message.\n"); - buf.append(" */\n"); - buf.append(" private static Test warning(final String message) {\n"); - buf.append(" return new TestCase(\"warning\") { //$NON-NLS-1$\n"); - buf.append(" @Override\n"); - buf.append(" protected void runTest() {\n"); - buf.append(" Assert.fail(message);\n"); - buf.append(" }\n"); - buf.append(" };\n"); - buf.append(" }\n"); buf.append("}"); fExpectedChangesAllTests.put("junit.framework.TestSuite.java", buf.toString()); buf= new StringBuffer(); @@ -2378,66 +2379,51 @@ buf.append("\n"); buf.append("public class Assert {\n"); buf.append(" /**\n"); - buf.append(" * Protect constructor since it is a static only class\n"); + buf.append(" * Asserts that two booleans are equal.\n"); buf.append(" */\n"); - buf.append(" protected Assert() {\n"); + buf.append(" static public void assertEquals(final boolean expected, final boolean actual) {\n"); + buf.append(" Assert.assertEquals(null, expected, actual);\n"); buf.append(" }\n"); buf.append("\n"); buf.append(" /**\n"); - buf.append(" * Asserts that a condition is true. If it isn't it throws an\n"); - buf.append(" * AssertionFailedError with the given message.\n"); - buf.append(" */\n"); - buf.append(" static public void assertTrue(final String message, boolean condition) {\n"); - buf.append(" if (!condition) {\n"); - buf.append(" Assert.fail(message);\n"); - buf.append(" }\n"); - buf.append(" }\n"); - buf.append(" /**\n"); - buf.append(" * Asserts that a condition is true. If it isn't it throws an\n"); - buf.append(" * AssertionFailedError.\n"); + buf.append(" * Asserts that two bytes are equal.\n"); buf.append(" */\n"); - buf.append(" static public void assertTrue(final boolean condition) {\n"); - buf.append(" Assert.assertTrue(null, condition);\n"); + buf.append(" static public void assertEquals(final byte expected, final byte actual) {\n"); + buf.append(" Assert.assertEquals(null, expected, actual);\n"); buf.append(" }\n"); buf.append(" /**\n"); - buf.append(" * Asserts that a condition is false. If it isn't it throws an\n"); - buf.append(" * AssertionFailedError with the given message.\n"); + buf.append(" * Asserts that two chars are equal.\n"); buf.append(" */\n"); - buf.append(" static public void assertFalse(final String message, boolean condition) {\n"); - buf.append(" Assert.assertTrue(message, !condition);\n"); + buf.append(" static public void assertEquals(final char expected, final char actual) {\n"); + buf.append(" Assert.assertEquals(null, expected, actual);\n"); buf.append(" }\n"); buf.append(" /**\n"); - buf.append(" * Asserts that a condition is false. If it isn't it throws an\n"); - buf.append(" * AssertionFailedError.\n"); + buf.append(" * Asserts that two doubles are equal concerning a delta. If the expected\n"); + buf.append(" * value is infinity then the delta value is ignored.\n"); buf.append(" */\n"); - buf.append(" static public void assertFalse(final boolean condition) {\n"); - buf.append(" Assert.assertFalse(null, condition);\n"); + buf.append(" static public void assertEquals(final double expected, final double actual,\n"); + buf.append(" final double delta) {\n"); + buf.append(" Assert.assertEquals(null, expected, actual, delta);\n"); buf.append(" }\n"); buf.append(" /**\n"); - buf.append(" * Fails a test with the given message.\n"); + buf.append(" * Asserts that two floats are equal concerning a delta. If the expected\n"); + buf.append(" * value is infinity then the delta value is ignored.\n"); buf.append(" */\n"); - buf.append(" static public void fail(final String message) {\n"); - buf.append(" throw new AssertionFailedError(message);\n"); + buf.append(" static public void assertEquals(final float expected, final float actual,\n"); + buf.append(" final float delta) {\n"); + buf.append(" Assert.assertEquals(null, expected, actual, delta);\n"); buf.append(" }\n"); buf.append(" /**\n"); - buf.append(" * Fails a test with no message.\n"); + buf.append(" * Asserts that two ints are equal.\n"); buf.append(" */\n"); - buf.append(" static public void fail() {\n"); - buf.append(" Assert.fail(null);\n"); + buf.append(" static public void assertEquals(final int expected, final int actual) {\n"); + buf.append(" Assert.assertEquals(null, expected, actual);\n"); buf.append(" }\n"); buf.append(" /**\n"); - buf.append(" * Asserts that two objects are equal. If they are not an\n"); - buf.append(" * AssertionFailedError is thrown with the given message.\n"); + buf.append(" * Asserts that two longs are equal.\n"); buf.append(" */\n"); - buf.append(" static public void assertEquals(final String message,\n"); - buf.append(" final Object expected, final Object actual) {\n"); - buf.append(" if ((expected == null) && (actual == null)) {\n"); - buf.append(" return;\n"); - buf.append(" }\n"); - buf.append(" if ((expected != null) && expected.equals(actual)) {\n"); - buf.append(" return;\n"); - buf.append(" }\n"); - buf.append(" Assert.failNotEquals(message, expected, actual);\n"); + buf.append(" static public void assertEquals(final long expected, final long actual) {\n"); + buf.append(" Assert.assertEquals(null, expected, actual);\n"); buf.append(" }\n"); buf.append(" /**\n"); buf.append(" * Asserts that two objects are equal. If they are not an\n"); @@ -2447,23 +2433,37 @@ buf.append(" Assert.assertEquals(null, expected, actual);\n"); buf.append(" }\n"); buf.append(" /**\n"); - buf.append(" * Asserts that two Strings are equal.\n"); + buf.append(" * Asserts that two shorts are equal.\n"); + buf.append(" */\n"); + buf.append(" static public void assertEquals(final short expected, final short actual) {\n"); + buf.append(" Assert.assertEquals(null, expected, actual);\n"); + buf.append(" }\n"); + buf.append(" /**\n"); + buf.append(" * Asserts that two booleans are equal. If they are not an\n"); + buf.append(" * AssertionFailedError is thrown with the given message.\n"); buf.append(" */\n"); buf.append(" static public void assertEquals(final String message,\n"); - buf.append(" final String expected, final String actual) {\n"); - buf.append(" if ((expected == null) && (actual == null)) {\n"); - buf.append(" return;\n"); - buf.append(" }\n"); - buf.append(" if ((expected != null) && expected.equals(actual)) {\n"); - buf.append(" return;\n"); - buf.append(" }\n"); - buf.append(" throw new ComparisonFailure(message, expected, actual);\n"); + buf.append(" final boolean expected, final boolean actual) {\n"); + buf.append(" Assert\n"); + buf.append(" .assertEquals(message, new Boolean(expected), new Boolean(\n"); + buf.append(" actual));\n"); buf.append(" }\n"); buf.append(" /**\n"); - buf.append(" * Asserts that two Strings are equal.\n"); + buf.append(" * Asserts that two bytes are equal. If they are not an AssertionFailedError\n"); + buf.append(" * is thrown with the given message.\n"); buf.append(" */\n"); - buf.append(" static public void assertEquals(final String expected, final String actual) {\n"); - buf.append(" Assert.assertEquals(null, expected, actual);\n"); + buf.append(" static public void assertEquals(final String message, final byte expected,\n"); + buf.append(" final byte actual) {\n"); + buf.append(" Assert.assertEquals(message, new Byte(expected), new Byte(actual));\n"); + buf.append(" }\n"); + buf.append(" /**\n"); + buf.append(" * Asserts that two chars are equal. If they are not an AssertionFailedError\n"); + buf.append(" * is thrown with the given message.\n"); + buf.append(" */\n"); + buf.append(" static public void assertEquals(final String message, final char expected,\n"); + buf.append(" final char actual) {\n"); + buf.append(" Assert.assertEquals(message, new Character(expected), new Character(\n"); + buf.append(" actual));\n"); buf.append(" }\n"); buf.append(" /**\n"); buf.append(" * Asserts that two doubles are equal concerning a delta. If they are not an\n"); @@ -2486,14 +2486,6 @@ buf.append(" }\n"); buf.append(" }\n"); buf.append(" /**\n"); - buf.append(" * Asserts that two doubles are equal concerning a delta. If the expected\n"); - buf.append(" * value is infinity then the delta value is ignored.\n"); - buf.append(" */\n"); - buf.append(" static public void assertEquals(final double expected, final double actual,\n"); - buf.append(" final double delta) {\n"); - buf.append(" Assert.assertEquals(null, expected, actual, delta);\n"); - buf.append(" }\n"); - buf.append(" /**\n"); buf.append(" * Asserts that two floats are equal concerning a delta. If they are not an\n"); buf.append(" * AssertionFailedError is thrown with the given message. If the expected\n"); buf.append(" * value is infinity then the delta value is ignored.\n"); @@ -2514,12 +2506,14 @@ buf.append(" }\n"); buf.append(" }\n"); buf.append(" /**\n"); - buf.append(" * Asserts that two floats are equal concerning a delta. If the expected\n"); - buf.append(" * value is infinity then the delta value is ignored.\n"); + buf.append(" * Asserts that two ints are equal. If they are not an AssertionFailedError\n"); + buf.append(" * is thrown with the given message.\n"); buf.append(" */\n"); - buf.append(" static public void assertEquals(final float expected, final float actual,\n"); - buf.append(" final float delta) {\n"); - buf.append(" Assert.assertEquals(null, expected, actual, delta);\n"); + buf.append(" static public void assertEquals(final String message, final int expected,\n"); + buf.append(" final int actual) {\n"); + buf.append(" Assert\n"); + buf.append(" .assertEquals(message, new Integer(expected), new Integer(\n"); + buf.append(" actual));\n"); buf.append(" }\n"); buf.append(" /**\n"); buf.append(" * Asserts that two longs are equal. If they are not an AssertionFailedError\n"); @@ -2530,55 +2524,18 @@ buf.append(" Assert.assertEquals(message, new Long(expected), new Long(actual));\n"); buf.append(" }\n"); buf.append(" /**\n"); - buf.append(" * Asserts that two longs are equal.\n"); - buf.append(" */\n"); - buf.append(" static public void assertEquals(final long expected, final long actual) {\n"); - buf.append(" Assert.assertEquals(null, expected, actual);\n"); - buf.append(" }\n"); - buf.append(" /**\n"); - buf.append(" * Asserts that two booleans are equal. If they are not an\n"); + buf.append(" * Asserts that two objects are equal. If they are not an\n"); buf.append(" * AssertionFailedError is thrown with the given message.\n"); buf.append(" */\n"); buf.append(" static public void assertEquals(final String message,\n"); - buf.append(" final boolean expected, final boolean actual) {\n"); - buf.append(" Assert\n"); - buf.append(" .assertEquals(message, new Boolean(expected), new Boolean(\n"); - buf.append(" actual));\n"); - buf.append(" }\n"); - buf.append(" /**\n"); - buf.append(" * Asserts that two booleans are equal.\n"); - buf.append(" */\n"); - buf.append(" static public void assertEquals(final boolean expected, final boolean actual) {\n"); - buf.append(" Assert.assertEquals(null, expected, actual);\n"); - buf.append(" }\n"); - buf.append(" /**\n"); - buf.append(" * Asserts that two bytes are equal. If they are not an AssertionFailedError\n"); - buf.append(" * is thrown with the given message.\n"); - buf.append(" */\n"); - buf.append(" static public void assertEquals(final String message, final byte expected,\n"); - buf.append(" final byte actual) {\n"); - buf.append(" Assert.assertEquals(message, new Byte(expected), new Byte(actual));\n"); - buf.append(" }\n"); - buf.append(" /**\n"); - buf.append(" * Asserts that two bytes are equal.\n"); - buf.append(" */\n"); - buf.append(" static public void assertEquals(final byte expected, final byte actual) {\n"); - buf.append(" Assert.assertEquals(null, expected, actual);\n"); - buf.append(" }\n"); - buf.append(" /**\n"); - buf.append(" * Asserts that two chars are equal. If they are not an AssertionFailedError\n"); - buf.append(" * is thrown with the given message.\n"); - buf.append(" */\n"); - buf.append(" static public void assertEquals(final String message, final char expected,\n"); - buf.append(" final char actual) {\n"); - buf.append(" Assert.assertEquals(message, new Character(expected), new Character(\n"); - buf.append(" actual));\n"); - buf.append(" }\n"); - buf.append(" /**\n"); - buf.append(" * Asserts that two chars are equal.\n"); - buf.append(" */\n"); - buf.append(" static public void assertEquals(final char expected, final char actual) {\n"); - buf.append(" Assert.assertEquals(null, expected, actual);\n"); + buf.append(" final Object expected, final Object actual) {\n"); + buf.append(" if ((expected == null) && (actual == null)) {\n"); + buf.append(" return;\n"); + buf.append(" }\n"); + buf.append(" if ((expected != null) && expected.equals(actual)) {\n"); + buf.append(" return;\n"); + buf.append(" }\n"); + buf.append(" Assert.failNotEquals(message, expected, actual);\n"); buf.append(" }\n"); buf.append(" /**\n"); buf.append(" * Asserts that two shorts are equal. If they are not an\n"); @@ -2589,26 +2546,37 @@ buf.append(" Assert.assertEquals(message, new Short(expected), new Short(actual));\n"); buf.append(" }\n"); buf.append(" /**\n"); - buf.append(" * Asserts that two shorts are equal.\n"); + buf.append(" * Asserts that two Strings are equal.\n"); buf.append(" */\n"); - buf.append(" static public void assertEquals(final short expected, final short actual) {\n"); + buf.append(" static public void assertEquals(final String expected, final String actual) {\n"); buf.append(" Assert.assertEquals(null, expected, actual);\n"); buf.append(" }\n"); buf.append(" /**\n"); - buf.append(" * Asserts that two ints are equal. If they are not an AssertionFailedError\n"); - buf.append(" * is thrown with the given message.\n"); + buf.append(" * Asserts that two Strings are equal.\n"); buf.append(" */\n"); - buf.append(" static public void assertEquals(final String message, final int expected,\n"); - buf.append(" final int actual) {\n"); - buf.append(" Assert\n"); - buf.append(" .assertEquals(message, new Integer(expected), new Integer(\n"); - buf.append(" actual));\n"); + buf.append(" static public void assertEquals(final String message,\n"); + buf.append(" final String expected, final String actual) {\n"); + buf.append(" if ((expected == null) && (actual == null)) {\n"); + buf.append(" return;\n"); + buf.append(" }\n"); + buf.append(" if ((expected != null) && expected.equals(actual)) {\n"); + buf.append(" return;\n"); + buf.append(" }\n"); + buf.append(" throw new ComparisonFailure(message, expected, actual);\n"); buf.append(" }\n"); buf.append(" /**\n"); - buf.append(" * Asserts that two ints are equal.\n"); + buf.append(" * Asserts that a condition is false. If it isn't it throws an\n"); + buf.append(" * AssertionFailedError.\n"); buf.append(" */\n"); - buf.append(" static public void assertEquals(final int expected, final int actual) {\n"); - buf.append(" Assert.assertEquals(null, expected, actual);\n"); + buf.append(" static public void assertFalse(final boolean condition) {\n"); + buf.append(" Assert.assertFalse(null, condition);\n"); + buf.append(" }\n"); + buf.append(" /**\n"); + buf.append(" * Asserts that a condition is false. If it isn't it throws an\n"); + buf.append(" * AssertionFailedError with the given message.\n"); + buf.append(" */\n"); + buf.append(" static public void assertFalse(final String message, boolean condition) {\n"); + buf.append(" Assert.assertTrue(message, !condition);\n"); buf.append(" }\n"); buf.append(" /**\n"); buf.append(" * Asserts that an object isn't null.\n"); @@ -2624,6 +2592,23 @@ buf.append(" Assert.assertTrue(message, object != null);\n"); buf.append(" }\n"); buf.append(" /**\n"); + buf.append(" * Asserts that two objects refer to the same object. If they are not the\n"); + buf.append(" * same an AssertionFailedError is thrown.\n"); + buf.append(" */\n"); + buf.append(" static public void assertNotSame(final Object expected, final Object actual) {\n"); + buf.append(" Assert.assertNotSame(null, expected, actual);\n"); + buf.append(" }\n"); + buf.append(" /**\n"); + buf.append(" * Asserts that two objects refer to the same object. If they are not an\n"); + buf.append(" * AssertionFailedError is thrown with the given message.\n"); + buf.append(" */\n"); + buf.append(" static public void assertNotSame(final String message,\n"); + buf.append(" final Object expected, final Object actual) {\n"); + buf.append(" if (expected == actual) {\n"); + buf.append(" Assert.failSame(message);\n"); + buf.append(" }\n"); + buf.append(" }\n"); + buf.append(" /**\n"); buf.append(" * Asserts that an object is null.\n"); buf.append(" */\n"); buf.append(" static public void assertNull(final Object object) {\n"); @@ -2637,6 +2622,13 @@ buf.append(" Assert.assertTrue(message, object == null);\n"); buf.append(" }\n"); buf.append(" /**\n"); + buf.append(" * Asserts that two objects refer to the same object. If they are not the\n"); + buf.append(" * same an AssertionFailedError is thrown.\n"); + buf.append(" */\n"); + buf.append(" static public void assertSame(final Object expected, final Object actual) {\n"); + buf.append(" Assert.assertSame(null, expected, actual);\n"); + buf.append(" }\n"); + buf.append(" /**\n"); buf.append(" * Asserts that two objects refer to the same object. If they are not an\n"); buf.append(" * AssertionFailedError is thrown with the given message.\n"); buf.append(" */\n"); @@ -2648,36 +2640,36 @@ buf.append(" Assert.failNotSame(message, expected, actual);\n"); buf.append(" }\n"); buf.append(" /**\n"); - buf.append(" * Asserts that two objects refer to the same object. If they are not the\n"); - buf.append(" * same an AssertionFailedError is thrown.\n"); + buf.append(" * Asserts that a condition is true. If it isn't it throws an\n"); + buf.append(" * AssertionFailedError.\n"); buf.append(" */\n"); - buf.append(" static public void assertSame(final Object expected, final Object actual) {\n"); - buf.append(" Assert.assertSame(null, expected, actual);\n"); + buf.append(" static public void assertTrue(final boolean condition) {\n"); + buf.append(" Assert.assertTrue(null, condition);\n"); buf.append(" }\n"); buf.append(" /**\n"); - buf.append(" * Asserts that two objects refer to the same object. If they are not an\n"); - buf.append(" * AssertionFailedError is thrown with the given message.\n"); + buf.append(" * Asserts that a condition is true. If it isn't it throws an\n"); + buf.append(" * AssertionFailedError with the given message.\n"); buf.append(" */\n"); - buf.append(" static public void assertNotSame(final String message,\n"); - buf.append(" final Object expected, final Object actual) {\n"); - buf.append(" if (expected == actual) {\n"); - buf.append(" Assert.failSame(message);\n"); + buf.append(" static public void assertTrue(final String message, boolean condition) {\n"); + buf.append(" if (!condition) {\n"); + buf.append(" Assert.fail(message);\n"); buf.append(" }\n"); buf.append(" }\n"); buf.append(" /**\n"); - buf.append(" * Asserts that two objects refer to the same object. If they are not the\n"); - buf.append(" * same an AssertionFailedError is thrown.\n"); + buf.append(" * Fails a test with no message.\n"); buf.append(" */\n"); - buf.append(" static public void assertNotSame(final Object expected, final Object actual) {\n"); - buf.append(" Assert.assertNotSame(null, expected, actual);\n"); + buf.append(" static public void fail() {\n"); + buf.append(" Assert.fail(null);\n"); buf.append(" }\n"); - buf.append("\n"); - buf.append(" static private void failSame(final String message) {\n"); - buf.append(" String formatted = \"\"; //$NON-NLS-1$\n"); - buf.append(" if (message != null) {\n"); - buf.append(" formatted = message + \" \"; //$NON-NLS-1$\n"); - buf.append(" }\n"); - buf.append(" Assert.fail(formatted + \"expected not same\"); //$NON-NLS-1$\n"); + buf.append(" /**\n"); + buf.append(" * Fails a test with the given message.\n"); + buf.append(" */\n"); + buf.append(" static public void fail(final String message) {\n"); + buf.append(" throw new AssertionFailedError(message);\n"); + buf.append(" }\n"); + buf.append(" static private void failNotEquals(final String message,\n"); + buf.append(" final Object expected, final Object actual) {\n"); + buf.append(" Assert.fail(Assert.format(message, expected, actual));\n"); buf.append(" }\n"); buf.append("\n"); buf.append(" static private void failNotSame(final String message,\n"); @@ -2690,9 +2682,12 @@ buf.append(" + \"expected same:<\" + expected + \"> was not:<\" + actual + \">\"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\n"); buf.append(" }\n"); buf.append("\n"); - buf.append(" static private void failNotEquals(final String message,\n"); - buf.append(" final Object expected, final Object actual) {\n"); - buf.append(" Assert.fail(Assert.format(message, expected, actual));\n"); + buf.append(" static private void failSame(final String message) {\n"); + buf.append(" String formatted = \"\"; //$NON-NLS-1$\n"); + buf.append(" if (message != null) {\n"); + buf.append(" formatted = message + \" \"; //$NON-NLS-1$\n"); + buf.append(" }\n"); + buf.append(" Assert.fail(formatted + \"expected not same\"); //$NON-NLS-1$\n"); buf.append(" }\n"); buf.append("\n"); buf.append(" static String format(final String message, final Object expected,\n"); @@ -2704,6 +2699,12 @@ buf.append(" return formatted\n"); buf.append(" + \"expected:<\" + expected + \"> but was:<\" + actual + \">\"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\n"); buf.append(" }\n"); + buf.append("\n"); + buf.append(" /**\n"); + buf.append(" * Protect constructor since it is a static only class\n"); + buf.append(" */\n"); + buf.append(" protected Assert() {\n"); + buf.append(" }\n"); buf.append("}"); fExpectedChangesAllTests.put("junit.framework.Assert.java", buf.toString()); buf= new StringBuffer(); @@ -2729,10 +2730,15 @@ buf.append(" public ClassPathTestCollector() {\n"); buf.append(" }\n"); buf.append("\n"); - buf.append(" public Enumeration collectTests() {\n"); - buf.append(" final String classPath = System.getProperty(\"java.class.path\"); //$NON-NLS-1$\n"); - buf.append(" final Hashtable result = this.collectFilesInPath(classPath);\n"); - buf.append(" return result.elements();\n"); + buf.append(" protected String classNameFromFile(final String classFileName) {\n"); + buf.append(" // convert /a/b.class to a.b\n"); + buf.append(" final String s = classFileName.substring(0, classFileName.length()\n"); + buf.append(" - ClassPathTestCollector.SUFFIX_LENGTH);\n"); + buf.append(" final String s2 = s.replace(File.separatorChar, '.');\n"); + buf.append(" if (s2.startsWith(\".\")) {\n"); + buf.append(" return s2.substring(1);\n"); + buf.append(" }\n"); + buf.append(" return s2;\n"); buf.append(" }\n"); buf.append("\n"); buf.append(" public Hashtable collectFilesInPath(final String classPath) {\n"); @@ -2750,6 +2756,12 @@ buf.append(" return result;\n"); buf.append(" }\n"); buf.append("\n"); + buf.append(" public Enumeration collectTests() {\n"); + buf.append(" final String classPath = System.getProperty(\"java.class.path\"); //$NON-NLS-1$\n"); + buf.append(" final Hashtable result = this.collectFilesInPath(classPath);\n"); + buf.append(" return result.elements();\n"); + buf.append(" }\n"); + buf.append("\n"); buf.append(" void gatherFiles(final File classRoot, final String classFileName,\n"); buf.append(" final Hashtable result) {\n"); buf.append(" final File thisRoot = new File(classRoot, classFileName);\n"); @@ -2769,6 +2781,12 @@ buf.append(" }\n"); buf.append(" }\n"); buf.append("\n"); + buf.append(" protected boolean isTestClass(final String classFileName) {\n"); + buf.append(" return classFileName.endsWith(\".class\") && //$NON-NLS-1$\n"); + buf.append(" (classFileName.indexOf('$') < 0)\n"); + buf.append(" && (classFileName.indexOf(\"Test\") > 0); //$NON-NLS-1$\n"); + buf.append(" }\n"); + buf.append("\n"); buf.append(" Vector splitClassPath(final String classPath) {\n"); buf.append(" final Vector result = new Vector();\n"); buf.append(" final String separator = System.getProperty(\"path.separator\"); //$NON-NLS-1$\n"); @@ -2779,23 +2797,6 @@ buf.append(" }\n"); buf.append(" return result;\n"); buf.append(" }\n"); - buf.append("\n"); - buf.append(" protected boolean isTestClass(final String classFileName) {\n"); - buf.append(" return classFileName.endsWith(\".class\") && //$NON-NLS-1$\n"); - buf.append(" (classFileName.indexOf('$') < 0)\n"); - buf.append(" && (classFileName.indexOf(\"Test\") > 0); //$NON-NLS-1$\n"); - buf.append(" }\n"); - buf.append("\n"); - buf.append(" protected String classNameFromFile(final String classFileName) {\n"); - buf.append(" // convert /a/b.class to a.b\n"); - buf.append(" final String s = classFileName.substring(0, classFileName.length()\n"); - buf.append(" - ClassPathTestCollector.SUFFIX_LENGTH);\n"); - buf.append(" final String s2 = s.replace(File.separatorChar, '.');\n"); - buf.append(" if (s2.startsWith(\".\")) {\n"); - buf.append(" return s2.substring(1);\n"); - buf.append(" }\n"); - buf.append(" return s2;\n"); - buf.append(" }\n"); buf.append("}\n"); buf.append(""); fExpectedChangesAllTests.put("junit.runner.ClassPathTestCollector.java", buf.toString()); @@ -2846,13 +2847,12 @@ buf.append(" }\n"); buf.append(" }\n"); buf.append("\n"); - buf.append(" public void testActiveTest() {\n"); - buf.append(" final Test test = this.createActiveTestSuite();\n"); - buf.append(" final TestResult result = new TestResult();\n"); - buf.append(" test.run(result);\n"); - buf.append(" Assert.assertEquals(100, result.runCount());\n"); - buf.append(" Assert.assertEquals(0, result.failureCount());\n"); - buf.append(" Assert.assertEquals(0, result.errorCount());\n"); + buf.append(" ActiveTestSuite createActiveTestSuite() {\n"); + buf.append(" final ActiveTestSuite suite = new ActiveTestSuite();\n"); + buf.append(" for (int i = 0; i < 100; i++) {\n"); + buf.append(" suite.addTest(new SuccessTest());\n"); + buf.append(" }\n"); + buf.append(" return suite;\n"); buf.append(" }\n"); buf.append("\n"); buf.append(" public void testActiveRepeatedTest() {\n"); @@ -2882,12 +2882,13 @@ buf.append(" Assert.assertEquals(0, result.errorCount());\n"); buf.append(" }\n"); buf.append("\n"); - buf.append(" ActiveTestSuite createActiveTestSuite() {\n"); - buf.append(" final ActiveTestSuite suite = new ActiveTestSuite();\n"); - buf.append(" for (int i = 0; i < 100; i++) {\n"); - buf.append(" suite.addTest(new SuccessTest());\n"); - buf.append(" }\n"); - buf.append(" return suite;\n"); + buf.append(" public void testActiveTest() {\n"); + buf.append(" final Test test = this.createActiveTestSuite();\n"); + buf.append(" final TestResult result = new TestResult();\n"); + buf.append(" test.run(result);\n"); + buf.append(" Assert.assertEquals(100, result.runCount());\n"); + buf.append(" Assert.assertEquals(0, result.failureCount());\n"); + buf.append(" Assert.assertEquals(0, result.errorCount());\n"); buf.append(" }\n"); buf.append("\n"); buf.append("}"); @@ -2931,6 +2932,10 @@ buf.append(" */\n"); buf.append(" public abstract IMoney addMoneyBag(MoneyBag s);\n"); buf.append(" /**\n"); + buf.append(" * Append this to a MoneyBag m.\n"); + buf.append(" */\n"); + buf.append(" public abstract void appendTo(MoneyBag m);\n"); + buf.append(" /**\n"); buf.append(" * Tests whether this money is zero\n"); buf.append(" */\n"); buf.append(" public abstract boolean isZero();\n"); @@ -2946,10 +2951,6 @@ buf.append(" * Subtracts a money from this money.\n"); buf.append(" */\n"); buf.append(" public abstract IMoney subtract(IMoney m);\n"); - buf.append(" /**\n"); - buf.append(" * Append this to a MoneyBag m.\n"); - buf.append(" */\n"); - buf.append(" public abstract void appendTo(MoneyBag m);\n"); buf.append("}"); fExpectedChangesAllTests.put("junit.samples.money.IMoney.java", buf.toString()); buf= new StringBuffer(); @@ -2984,31 +2985,22 @@ buf.append(" * the end.\n"); buf.append(" */\n"); buf.append("public class TestRunner extends BaseTestRunner {\n"); - buf.append(" private ResultPrinter fPrinter;\n"); - buf.append("\n"); - buf.append(" public static final int SUCCESS_EXIT = 0;\n"); - buf.append(" public static final int FAILURE_EXIT = 1;\n"); buf.append(" public static final int EXCEPTION_EXIT = 2;\n"); buf.append("\n"); - buf.append(" /**\n"); - buf.append(" * Constructs a TestRunner.\n"); - buf.append(" */\n"); - buf.append(" public TestRunner() {\n"); - buf.append(" this(System.out);\n"); - buf.append(" }\n"); - buf.append("\n"); - buf.append(" /**\n"); - buf.append(" * Constructs a TestRunner using the given stream for all the output\n"); - buf.append(" */\n"); - buf.append(" public TestRunner(final PrintStream writer) {\n"); - buf.append(" this(new ResultPrinter(writer));\n"); - buf.append(" }\n"); - buf.append("\n"); - buf.append(" /**\n"); - buf.append(" * Constructs a TestRunner using the given ResultPrinter all the output\n"); - buf.append(" */\n"); - buf.append(" public TestRunner(final ResultPrinter printer) {\n"); - buf.append(" this.fPrinter = printer;\n"); + buf.append(" public static final int FAILURE_EXIT = 1;\n"); + buf.append(" public static final int SUCCESS_EXIT = 0;\n"); + buf.append(" public static void main(final String args[]) {\n"); + buf.append(" final TestRunner aTestRunner = new TestRunner();\n"); + buf.append(" try {\n"); + buf.append(" final TestResult r = aTestRunner.start(args);\n"); + buf.append(" if (!r.wasSuccessful()) {\n"); + buf.append(" System.exit(TestRunner.FAILURE_EXIT);\n"); + buf.append(" }\n"); + buf.append(" System.exit(TestRunner.SUCCESS_EXIT);\n"); + buf.append(" } catch (final Exception e) {\n"); + buf.append(" System.err.println(e.getMessage());\n"); + buf.append(" System.exit(TestRunner.EXCEPTION_EXIT);\n"); + buf.append(" }\n"); buf.append(" }\n"); buf.append("\n"); buf.append(" /**\n"); @@ -3041,24 +3033,27 @@ buf.append(" aTestRunner.doRun(suite, true);\n"); buf.append(" }\n"); buf.append("\n"); + buf.append(" private ResultPrinter fPrinter;\n"); + buf.append("\n"); buf.append(" /**\n"); - buf.append(" * Always use the StandardTestSuiteLoader. Overridden from BaseTestRunner.\n"); + buf.append(" * Constructs a TestRunner.\n"); buf.append(" */\n"); - buf.append(" @Override\n"); - buf.append(" public TestSuiteLoader getLoader() {\n"); - buf.append(" return new StandardTestSuiteLoader();\n"); - buf.append(" }\n"); - buf.append("\n"); - buf.append(" @Override\n"); - buf.append(" public void testFailed(final int status, final Test test, final Throwable t) {\n"); + buf.append(" public TestRunner() {\n"); + buf.append(" this(System.out);\n"); buf.append(" }\n"); buf.append("\n"); - buf.append(" @Override\n"); - buf.append(" public void testStarted(final String testName) {\n"); + buf.append(" /**\n"); + buf.append(" * Constructs a TestRunner using the given stream for all the output\n"); + buf.append(" */\n"); + buf.append(" public TestRunner(final PrintStream writer) {\n"); + buf.append(" this(new ResultPrinter(writer));\n"); buf.append(" }\n"); buf.append("\n"); - buf.append(" @Override\n"); - buf.append(" public void testEnded(final String testName) {\n"); + buf.append(" /**\n"); + buf.append(" * Constructs a TestRunner using the given ResultPrinter all the output\n"); + buf.append(" */\n"); + buf.append(" public TestRunner(final ResultPrinter printer) {\n"); + buf.append(" this.fPrinter = printer;\n"); buf.append(" }\n"); buf.append("\n"); buf.append(" /**\n"); @@ -3085,6 +3080,14 @@ buf.append(" return result;\n"); buf.append(" }\n"); buf.append("\n"); + buf.append(" /**\n"); + buf.append(" * Always use the StandardTestSuiteLoader. Overridden from BaseTestRunner.\n"); + buf.append(" */\n"); + buf.append(" @Override\n"); + buf.append(" public TestSuiteLoader getLoader() {\n"); + buf.append(" return new StandardTestSuiteLoader();\n"); + buf.append(" }\n"); + buf.append("\n"); buf.append(" protected void pause(boolean wait) {\n"); buf.append(" if (!wait) {\n"); buf.append(" return;\n"); @@ -3096,18 +3099,14 @@ buf.append(" }\n"); buf.append(" }\n"); buf.append("\n"); - buf.append(" public static void main(final String args[]) {\n"); - buf.append(" final TestRunner aTestRunner = new TestRunner();\n"); - buf.append(" try {\n"); - buf.append(" final TestResult r = aTestRunner.start(args);\n"); - buf.append(" if (!r.wasSuccessful()) {\n"); - buf.append(" System.exit(TestRunner.FAILURE_EXIT);\n"); - buf.append(" }\n"); - buf.append(" System.exit(TestRunner.SUCCESS_EXIT);\n"); - buf.append(" } catch (final Exception e) {\n"); - buf.append(" System.err.println(e.getMessage());\n"); - buf.append(" System.exit(TestRunner.EXCEPTION_EXIT);\n"); - buf.append(" }\n"); + buf.append(" @Override\n"); + buf.append(" protected void runFailed(final String message) {\n"); + buf.append(" System.err.println(message);\n"); + buf.append(" System.exit(TestRunner.FAILURE_EXIT);\n"); + buf.append(" }\n"); + buf.append("\n"); + buf.append(" public void setPrinter(final ResultPrinter printer) {\n"); + buf.append(" this.fPrinter = printer;\n"); buf.append(" }\n"); buf.append("\n"); buf.append(" /**\n"); @@ -3145,13 +3144,15 @@ buf.append(" }\n"); buf.append("\n"); buf.append(" @Override\n"); - buf.append(" protected void runFailed(final String message) {\n"); - buf.append(" System.err.println(message);\n"); - buf.append(" System.exit(TestRunner.FAILURE_EXIT);\n"); + buf.append(" public void testEnded(final String testName) {\n"); buf.append(" }\n"); buf.append("\n"); - buf.append(" public void setPrinter(final ResultPrinter printer) {\n"); - buf.append(" this.fPrinter = printer;\n"); + buf.append(" @Override\n"); + buf.append(" public void testFailed(final int status, final Test test, final Throwable t) {\n"); + buf.append(" }\n"); + buf.append("\n"); + buf.append(" @Override\n"); + buf.append(" public void testStarted(final String testName) {\n"); buf.append(" }\n"); buf.append("\n"); buf.append("}"); @@ -3168,14 +3169,14 @@ buf.append("public class ClassLoaderTest extends Assert {\n"); buf.append(" public ClassLoaderTest() {\n"); buf.append(" }\n"); - buf.append(" public void verify() {\n"); - buf.append(" this.verifyApplicationClassLoadedByTestLoader();\n"); - buf.append(" this.verifySystemClassNotLoadedByTestLoader();\n"); - buf.append(" }\n"); buf.append(" private boolean isTestCaseClassLoader(final ClassLoader cl) {\n"); buf.append(" return ((cl != null) && cl.getClass().getName().equals(\n"); buf.append(" junit.runner.TestCaseClassLoader.class.getName()));\n"); buf.append(" }\n"); + buf.append(" public void verify() {\n"); + buf.append(" this.verifyApplicationClassLoadedByTestLoader();\n"); + buf.append(" this.verifySystemClassNotLoadedByTestLoader();\n"); + buf.append(" }\n"); buf.append(" private void verifyApplicationClassLoadedByTestLoader() {\n"); buf.append(" Assert.assertTrue(this.isTestCaseClassLoader(this.getClass()\n"); buf.append(" .getClassLoader()));\n"); @@ -3200,12 +3201,12 @@ buf.append(" public static final int STATUS_ERROR = 1;\n"); buf.append(" public static final int STATUS_FAILURE = 2;\n"); buf.append("\n"); - buf.append(" public void testRunStarted(String testSuiteName, int testCount);\n"); + buf.append(" public void testEnded(String testName);\n"); + buf.append(" public void testFailed(int status, String testName, String trace);\n"); buf.append(" public void testRunEnded(long elapsedTime);\n"); + buf.append(" public void testRunStarted(String testSuiteName, int testCount);\n"); buf.append(" public void testRunStopped(long elapsedTime);\n"); buf.append(" public void testStarted(String testName);\n"); - buf.append(" public void testEnded(String testName);\n"); - buf.append(" public void testFailed(int status, String testName, String trace);\n"); buf.append("}\n"); buf.append(""); fExpectedChangesAllTests.put("junit.runner.TestRunListener.java", buf.toString()); @@ -3225,9 +3226,6 @@ buf.append("import junit.textui.TestRunner;\n"); buf.append("\n"); buf.append("public class TextFeedbackTest extends TestCase {\n"); - buf.append(" OutputStream output;\n"); - buf.append(" TestRunner runner;\n"); - buf.append("\n"); buf.append(" class TestResultPrinter extends ResultPrinter {\n"); buf.append(" TestResultPrinter(final PrintStream writer) {\n"); buf.append(" super(writer);\n"); @@ -3241,11 +3239,23 @@ buf.append(" return \"0\"; //$NON-NLS-1$\n"); buf.append(" }\n"); buf.append(" }\n"); - buf.append("\n"); buf.append(" public static void main(final String[] args) {\n"); buf.append(" TestRunner.run(TextFeedbackTest.class);\n"); buf.append(" }\n"); buf.append("\n"); + buf.append(" OutputStream output;\n"); + buf.append("\n"); + buf.append(" TestRunner runner;\n"); + buf.append("\n"); + buf.append(" private String expected(final String[] lines) {\n"); + buf.append(" final OutputStream expected = new ByteArrayOutputStream();\n"); + buf.append(" final PrintStream expectedWriter = new PrintStream(expected);\n"); + buf.append(" for (final String element : lines) {\n"); + buf.append(" expectedWriter.println(element);\n"); + buf.append(" }\n"); + buf.append(" return expected.toString();\n"); + buf.append(" }\n"); + buf.append("\n"); buf.append(" @Override\n"); buf.append(" public void setUp() {\n"); buf.append(" this.output = new ByteArrayOutputStream();\n"); @@ -3260,31 +3270,23 @@ buf.append(" Assert.assertEquals(expected.toString(), this.output.toString());\n"); buf.append(" }\n"); buf.append("\n"); - buf.append(" public void testOneTest() {\n"); - buf.append(" final String expected = this.expected(new String[]{\n"); - buf.append(" \".\", \"Time: 0\", \"\", \"OK (1 test)\", \"\"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$\n"); - buf.append(" final TestSuite suite = new TestSuite();\n"); - buf.append(" suite.addTest(new TestCase() {\n"); + buf.append(" public void testError() {\n"); + buf.append(" final String expected = this\n"); + buf.append(" .expected(new String[]{\n"); + buf.append(" \".E\", \"Time: 0\", \"Errors here\", \"\", \"FAILURES!!!\", \"Tests run: 1, Failures: 0, Errors: 1\", \"\"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$\n"); + buf.append(" final ResultPrinter printer = new TestResultPrinter(new PrintStream(\n"); + buf.append(" this.output)) {\n"); buf.append(" @Override\n"); - buf.append(" public void runTest() {\n"); + buf.append(" public void printErrors(TestResult result) {\n"); + buf.append(" this.getWriter().println(\"Errors here\"); //$NON-NLS-1$\n"); buf.append(" }\n"); - buf.append(" });\n"); - buf.append(" this.runner.doRun(suite);\n"); - buf.append(" Assert.assertEquals(expected.toString(), this.output.toString());\n"); - buf.append(" }\n"); - buf.append("\n"); - buf.append(" public void testTwoTests() {\n"); - buf.append(" final String expected = this.expected(new String[]{\n"); - buf.append(" \"..\", \"Time: 0\", \"\", \"OK (2 tests)\", \"\"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$\n"); + buf.append(" };\n"); + buf.append(" this.runner.setPrinter(printer);\n"); buf.append(" final TestSuite suite = new TestSuite();\n"); buf.append(" suite.addTest(new TestCase() {\n"); buf.append(" @Override\n"); - buf.append(" public void runTest() {\n"); - buf.append(" }\n"); - buf.append(" });\n"); - buf.append(" suite.addTest(new TestCase() {\n"); - buf.append(" @Override\n"); - buf.append(" public void runTest() {\n"); + buf.append(" public void runTest() throws Exception {\n"); + buf.append(" throw new Exception();\n"); buf.append(" }\n"); buf.append(" });\n"); buf.append(" this.runner.doRun(suite);\n"); @@ -3314,36 +3316,35 @@ buf.append(" Assert.assertEquals(expected.toString(), this.output.toString());\n"); buf.append(" }\n"); buf.append("\n"); - buf.append(" public void testError() {\n"); - buf.append(" final String expected = this\n"); - buf.append(" .expected(new String[]{\n"); - buf.append(" \".E\", \"Time: 0\", \"Errors here\", \"\", \"FAILURES!!!\", \"Tests run: 1, Failures: 0, Errors: 1\", \"\"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$\n"); - buf.append(" final ResultPrinter printer = new TestResultPrinter(new PrintStream(\n"); - buf.append(" this.output)) {\n"); - buf.append(" @Override\n"); - buf.append(" public void printErrors(TestResult result) {\n"); - buf.append(" this.getWriter().println(\"Errors here\"); //$NON-NLS-1$\n"); - buf.append(" }\n"); - buf.append(" };\n"); - buf.append(" this.runner.setPrinter(printer);\n"); + buf.append(" public void testOneTest() {\n"); + buf.append(" final String expected = this.expected(new String[]{\n"); + buf.append(" \".\", \"Time: 0\", \"\", \"OK (1 test)\", \"\"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$\n"); buf.append(" final TestSuite suite = new TestSuite();\n"); buf.append(" suite.addTest(new TestCase() {\n"); buf.append(" @Override\n"); - buf.append(" public void runTest() throws Exception {\n"); - buf.append(" throw new Exception();\n"); + buf.append(" public void runTest() {\n"); buf.append(" }\n"); buf.append(" });\n"); buf.append(" this.runner.doRun(suite);\n"); buf.append(" Assert.assertEquals(expected.toString(), this.output.toString());\n"); buf.append(" }\n"); buf.append("\n"); - buf.append(" private String expected(final String[] lines) {\n"); - buf.append(" final OutputStream expected = new ByteArrayOutputStream();\n"); - buf.append(" final PrintStream expectedWriter = new PrintStream(expected);\n"); - buf.append(" for (final String element : lines) {\n"); - buf.append(" expectedWriter.println(element);\n"); - buf.append(" }\n"); - buf.append(" return expected.toString();\n"); + buf.append(" public void testTwoTests() {\n"); + buf.append(" final String expected = this.expected(new String[]{\n"); + buf.append(" \"..\", \"Time: 0\", \"\", \"OK (2 tests)\", \"\"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$\n"); + buf.append(" final TestSuite suite = new TestSuite();\n"); + buf.append(" suite.addTest(new TestCase() {\n"); + buf.append(" @Override\n"); + buf.append(" public void runTest() {\n"); + buf.append(" }\n"); + buf.append(" });\n"); + buf.append(" suite.addTest(new TestCase() {\n"); + buf.append(" @Override\n"); + buf.append(" public void runTest() {\n"); + buf.append(" }\n"); + buf.append(" });\n"); + buf.append(" this.runner.doRun(suite);\n"); + buf.append(" Assert.assertEquals(expected.toString(), this.output.toString());\n"); buf.append(" }\n"); buf.append("\n"); buf.append("}\n"); @@ -3484,13 +3485,13 @@ buf.append("import junit.framework.Assert;\n"); buf.append("\n"); buf.append("public class LoadedFromJar extends Assert {\n"); - buf.append(" public void verify() {\n"); - buf.append(" this.verifyApplicationClassLoadedByTestLoader();\n"); - buf.append(" }\n"); buf.append(" private boolean isTestCaseClassLoader(final ClassLoader cl) {\n"); buf.append(" return ((cl != null) && cl.getClass().getName().equals(\n"); buf.append(" junit.runner.TestCaseClassLoader.class.getName()));\n"); buf.append(" }\n"); + buf.append(" public void verify() {\n"); + buf.append(" this.verifyApplicationClassLoadedByTestLoader();\n"); + buf.append(" }\n"); buf.append(" private void verifyApplicationClassLoadedByTestLoader() {\n"); buf.append(" Assert.assertTrue(this.isTestCaseClassLoader(this.getClass()\n"); buf.append(" .getClassLoader()));\n"); @@ -3506,23 +3507,37 @@ buf.append("\n"); buf.append("public class ComparisonFailureTest extends TestCase {\n"); buf.append("\n"); + buf.append(" public void testComparisonErrorEndSame() {\n"); + buf.append(" final ComparisonFailure failure = new ComparisonFailure(null,\n"); + buf.append(" \"ab\", \"cb\"); //$NON-NLS-1$ //$NON-NLS-2$\n"); + buf.append(" Assert.assertEquals(\n"); + buf.append(" \"expected: but was:\", failure.getMessage()); //$NON-NLS-1$\n"); + buf.append(" }\n"); + buf.append("\n"); + buf.append(" public void testComparisonErrorEndSameComplete() {\n"); + buf.append(" final ComparisonFailure failure = new ComparisonFailure(null,\n"); + buf.append(" \"bc\", \"abc\"); //$NON-NLS-1$ //$NON-NLS-2$\n"); + buf.append(" Assert.assertEquals(\n"); + buf.append(" \"expected:<...> but was:\", failure.getMessage()); //$NON-NLS-1$\n"); + buf.append(" }\n"); + buf.append("\n"); buf.append(" public void testComparisonErrorMessage() {\n"); buf.append(" final ComparisonFailure failure = new ComparisonFailure(\"a\", \"b\", \"c\"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\n"); buf.append(" Assert.assertEquals(\"a expected: but was:\", failure.getMessage()); //$NON-NLS-1$\n"); buf.append(" }\n"); buf.append("\n"); - buf.append(" public void testComparisonErrorStartSame() {\n"); + buf.append(" public void testComparisonErrorOverlapingMatches() {\n"); buf.append(" final ComparisonFailure failure = new ComparisonFailure(null,\n"); - buf.append(" \"ba\", \"bc\"); //$NON-NLS-1$ //$NON-NLS-2$\n"); + buf.append(" \"abc\", \"abbc\"); //$NON-NLS-1$ //$NON-NLS-2$\n"); buf.append(" Assert.assertEquals(\n"); - buf.append(" \"expected:<...a> but was:<...c>\", failure.getMessage()); //$NON-NLS-1$\n"); + buf.append(" \"expected:<......> but was:<...b...>\", failure.getMessage()); //$NON-NLS-1$\n"); buf.append(" }\n"); buf.append("\n"); - buf.append(" public void testComparisonErrorEndSame() {\n"); + buf.append(" public void testComparisonErrorOverlapingMatches2() {\n"); buf.append(" final ComparisonFailure failure = new ComparisonFailure(null,\n"); - buf.append(" \"ab\", \"cb\"); //$NON-NLS-1$ //$NON-NLS-2$\n"); + buf.append(" \"abcdde\", \"abcde\"); //$NON-NLS-1$ //$NON-NLS-2$\n"); buf.append(" Assert.assertEquals(\n"); - buf.append(" \"expected: but was:\", failure.getMessage()); //$NON-NLS-1$\n"); + buf.append(" \"expected:<...d...> but was:<......>\", failure.getMessage()); //$NON-NLS-1$\n"); buf.append(" }\n"); buf.append("\n"); buf.append(" public void testComparisonErrorSame() {\n"); @@ -3538,32 +3553,18 @@ buf.append(" \"expected:<...b...> but was:<...d...>\", failure.getMessage()); //$NON-NLS-1$\n"); buf.append(" }\n"); buf.append("\n"); - buf.append(" public void testComparisonErrorStartSameComplete() {\n"); - buf.append(" final ComparisonFailure failure = new ComparisonFailure(null,\n"); - buf.append(" \"ab\", \"abc\"); //$NON-NLS-1$ //$NON-NLS-2$\n"); - buf.append(" Assert.assertEquals(\n"); - buf.append(" \"expected:<...> but was:<...c>\", failure.getMessage()); //$NON-NLS-1$\n"); - buf.append(" }\n"); - buf.append("\n"); - buf.append(" public void testComparisonErrorEndSameComplete() {\n"); - buf.append(" final ComparisonFailure failure = new ComparisonFailure(null,\n"); - buf.append(" \"bc\", \"abc\"); //$NON-NLS-1$ //$NON-NLS-2$\n"); - buf.append(" Assert.assertEquals(\n"); - buf.append(" \"expected:<...> but was:\", failure.getMessage()); //$NON-NLS-1$\n"); - buf.append(" }\n"); - buf.append("\n"); - buf.append(" public void testComparisonErrorOverlapingMatches() {\n"); + buf.append(" public void testComparisonErrorStartSame() {\n"); buf.append(" final ComparisonFailure failure = new ComparisonFailure(null,\n"); - buf.append(" \"abc\", \"abbc\"); //$NON-NLS-1$ //$NON-NLS-2$\n"); + buf.append(" \"ba\", \"bc\"); //$NON-NLS-1$ //$NON-NLS-2$\n"); buf.append(" Assert.assertEquals(\n"); - buf.append(" \"expected:<......> but was:<...b...>\", failure.getMessage()); //$NON-NLS-1$\n"); + buf.append(" \"expected:<...a> but was:<...c>\", failure.getMessage()); //$NON-NLS-1$\n"); buf.append(" }\n"); buf.append("\n"); - buf.append(" public void testComparisonErrorOverlapingMatches2() {\n"); + buf.append(" public void testComparisonErrorStartSameComplete() {\n"); buf.append(" final ComparisonFailure failure = new ComparisonFailure(null,\n"); - buf.append(" \"abcdde\", \"abcde\"); //$NON-NLS-1$ //$NON-NLS-2$\n"); + buf.append(" \"ab\", \"abc\"); //$NON-NLS-1$ //$NON-NLS-2$\n"); buf.append(" Assert.assertEquals(\n"); - buf.append(" \"expected:<...d...> but was:<......>\", failure.getMessage()); //$NON-NLS-1$\n"); + buf.append(" \"expected:<...> but was:<...c>\", failure.getMessage()); //$NON-NLS-1$\n"); buf.append(" }\n"); buf.append("\n"); buf.append(" public void testComparisonErrorWithActualNull() {\n"); @@ -3597,8 +3598,8 @@ buf.append("import junit.runner.BaseTestRunner;\n"); buf.append("\n"); buf.append("public class ResultPrinter implements TestListener {\n"); - buf.append(" PrintStream fWriter;\n"); buf.append(" int fColumn = 0;\n"); + buf.append(" PrintStream fWriter;\n"); buf.append("\n"); buf.append(" public ResultPrinter(final PrintStream writer) {\n"); buf.append(" this.fWriter = writer;\n"); @@ -3608,48 +3609,47 @@ buf.append(" * API for use by textui.TestRunner\n"); buf.append(" */\n"); buf.append("\n"); - buf.append(" synchronized void print(final TestResult result, final long runTime) {\n"); - buf.append(" this.printHeader(runTime);\n"); - buf.append(" this.printErrors(result);\n"); - buf.append(" this.printFailures(result);\n"); - buf.append(" this.printFooter(result);\n"); + buf.append(" /**\n"); + buf.append(" * @see junit.framework.TestListener#addError(Test, Throwable)\n"); + buf.append(" */\n"); + buf.append(" public void addError(final Test test, final Throwable t) {\n"); + buf.append(" this.getWriter().print(\"E\"); //$NON-NLS-1$\n"); buf.append(" }\n"); buf.append("\n"); - buf.append(" void printWaitPrompt() {\n"); - buf.append(" this.getWriter().println();\n"); - buf.append(" this.getWriter().println(\" to continue\"); //$NON-NLS-1$\n"); + buf.append(" /**\n"); + buf.append(" * @see junit.framework.TestListener#addFailure(Test, AssertionFailedError)\n"); + buf.append(" */\n"); + buf.append(" public void addFailure(final Test test, final AssertionFailedError t) {\n"); + buf.append(" this.getWriter().print(\"F\"); //$NON-NLS-1$\n"); buf.append(" }\n"); buf.append("\n"); buf.append(" /*\n"); buf.append(" * Internal methods\n"); buf.append(" */\n"); buf.append("\n"); - buf.append(" protected void printHeader(final long runTime) {\n"); - buf.append(" this.getWriter().println();\n"); - buf.append(" this.getWriter().println(\"Time: \" + this.elapsedTimeAsString(runTime)); //$NON-NLS-1$\n"); + buf.append(" /**\n"); + buf.append(" * Returns the formatted string of the elapsed time. Duplicated from\n"); + buf.append(" * BaseTestRunner. Fix it.\n"); + buf.append(" */\n"); + buf.append(" protected String elapsedTimeAsString(final long runTime) {\n"); + buf.append(" return NumberFormat.getInstance().format((double) runTime / 1000);\n"); buf.append(" }\n"); buf.append("\n"); - buf.append(" protected void printErrors(final TestResult result) {\n"); - buf.append(" this.printDefects(result.errors(), result.errorCount(), \"error\"); //$NON-NLS-1$\n"); + buf.append(" /**\n"); + buf.append(" * @see junit.framework.TestListener#endTest(Test)\n"); + buf.append(" */\n"); + buf.append(" public void endTest(final Test test) {\n"); buf.append(" }\n"); buf.append("\n"); - buf.append(" protected void printFailures(final TestResult result) {\n"); - buf.append(" this.printDefects(result.failures(), result.failureCount(), \"failure\"); //$NON-NLS-1$\n"); + buf.append(" public PrintStream getWriter() {\n"); + buf.append(" return this.fWriter;\n"); buf.append(" }\n"); buf.append("\n"); - buf.append(" protected void printDefects(final Enumeration booBoos, final int count,\n"); - buf.append(" final String type) {\n"); - buf.append(" if (count == 0) {\n"); - buf.append(" return;\n"); - buf.append(" }\n"); - buf.append(" if (count == 1) {\n"); - buf.append(" this.getWriter().println(\"There was \" + count + \" \" + type + \":\"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\n"); - buf.append(" } else {\n"); - buf.append(" this.getWriter().println(\"There were \" + count + \" \" + type + \"s:\"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\n"); - buf.append(" }\n"); - buf.append(" for (int i = 1; booBoos.hasMoreElements(); i++) {\n"); - buf.append(" this.printDefect((TestFailure) booBoos.nextElement(), i);\n"); - buf.append(" }\n"); + buf.append(" synchronized void print(final TestResult result, final long runTime) {\n"); + buf.append(" this.printHeader(runTime);\n"); + buf.append(" this.printErrors(result);\n"); + buf.append(" this.printFailures(result);\n"); + buf.append(" this.printFooter(result);\n"); buf.append(" }\n"); buf.append("\n"); buf.append(" public void printDefect(final TestFailure booBoo, final int count) { // only\n"); @@ -3668,10 +3668,32 @@ buf.append(" this.getWriter().print(count + \") \" + booBoo.failedTest()); //$NON-NLS-1$\n"); buf.append(" }\n"); buf.append("\n"); + buf.append(" protected void printDefects(final Enumeration booBoos, final int count,\n"); + buf.append(" final String type) {\n"); + buf.append(" if (count == 0) {\n"); + buf.append(" return;\n"); + buf.append(" }\n"); + buf.append(" if (count == 1) {\n"); + buf.append(" this.getWriter().println(\"There was \" + count + \" \" + type + \":\"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\n"); + buf.append(" } else {\n"); + buf.append(" this.getWriter().println(\"There were \" + count + \" \" + type + \"s:\"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\n"); + buf.append(" }\n"); + buf.append(" for (int i = 1; booBoos.hasMoreElements(); i++) {\n"); + buf.append(" this.printDefect((TestFailure) booBoos.nextElement(), i);\n"); + buf.append(" }\n"); + buf.append(" }\n"); + buf.append("\n"); buf.append(" protected void printDefectTrace(final TestFailure booBoo) {\n"); buf.append(" this.getWriter().print(BaseTestRunner.getFilteredTrace(booBoo.trace()));\n"); buf.append(" }\n"); buf.append("\n"); + buf.append(" protected void printErrors(final TestResult result) {\n"); + buf.append(" this.printDefects(result.errors(), result.errorCount(), \"error\"); //$NON-NLS-1$\n"); + buf.append(" }\n"); + buf.append("\n"); + buf.append(" protected void printFailures(final TestResult result) {\n"); + buf.append(" this.printDefects(result.failures(), result.failureCount(), \"failure\"); //$NON-NLS-1$\n"); + buf.append(" }\n"); buf.append(" protected void printFooter(final TestResult result) {\n"); buf.append(" if (result.wasSuccessful()) {\n"); buf.append(" this.getWriter().println();\n"); @@ -3691,35 +3713,14 @@ buf.append(" this.getWriter().println();\n"); buf.append(" }\n"); buf.append("\n"); - buf.append(" /**\n"); - buf.append(" * Returns the formatted string of the elapsed time. Duplicated from\n"); - buf.append(" * BaseTestRunner. Fix it.\n"); - buf.append(" */\n"); - buf.append(" protected String elapsedTimeAsString(final long runTime) {\n"); - buf.append(" return NumberFormat.getInstance().format((double) runTime / 1000);\n"); - buf.append(" }\n"); - buf.append("\n"); - buf.append(" public PrintStream getWriter() {\n"); - buf.append(" return this.fWriter;\n"); - buf.append(" }\n"); - buf.append(" /**\n"); - buf.append(" * @see junit.framework.TestListener#addError(Test, Throwable)\n"); - buf.append(" */\n"); - buf.append(" public void addError(final Test test, final Throwable t) {\n"); - buf.append(" this.getWriter().print(\"E\"); //$NON-NLS-1$\n"); - buf.append(" }\n"); - buf.append("\n"); - buf.append(" /**\n"); - buf.append(" * @see junit.framework.TestListener#addFailure(Test, AssertionFailedError)\n"); - buf.append(" */\n"); - buf.append(" public void addFailure(final Test test, final AssertionFailedError t) {\n"); - buf.append(" this.getWriter().print(\"F\"); //$NON-NLS-1$\n"); + buf.append(" protected void printHeader(final long runTime) {\n"); + buf.append(" this.getWriter().println();\n"); + buf.append(" this.getWriter().println(\"Time: \" + this.elapsedTimeAsString(runTime)); //$NON-NLS-1$\n"); buf.append(" }\n"); buf.append("\n"); - buf.append(" /**\n"); - buf.append(" * @see junit.framework.TestListener#endTest(Test)\n"); - buf.append(" */\n"); - buf.append(" public void endTest(final Test test) {\n"); + buf.append(" void printWaitPrompt() {\n"); + buf.append(" this.getWriter().println();\n"); + buf.append(" this.getWriter().println(\" to continue\"); //$NON-NLS-1$\n"); buf.append(" }\n"); buf.append("\n"); buf.append(" /**\n"); @@ -3751,12 +3752,15 @@ buf.append(" * \n"); buf.append(" */\n"); buf.append("public class VectorTest extends TestCase {\n"); - buf.append(" protected Vector fEmpty;\n"); - buf.append(" protected Vector fFull;\n"); - buf.append("\n"); buf.append(" public static void main(final String[] args) {\n"); buf.append(" junit.textui.TestRunner.run(VectorTest.suite());\n"); buf.append(" }\n"); + buf.append(" public static Test suite() {\n"); + buf.append(" return new TestSuite(VectorTest.class);\n"); + buf.append(" }\n"); + buf.append("\n"); + buf.append(" protected Vector fEmpty;\n"); + buf.append(" protected Vector fFull;\n"); buf.append(" @Override\n"); buf.append(" protected void setUp() {\n"); buf.append(" this.fEmpty = new Vector();\n"); @@ -3765,9 +3769,6 @@ buf.append(" this.fFull.addElement(new Integer(2));\n"); buf.append(" this.fFull.addElement(new Integer(3));\n"); buf.append(" }\n"); - buf.append(" public static Test suite() {\n"); - buf.append(" return new TestSuite(VectorTest.class);\n"); - buf.append(" }\n"); buf.append(" public void testCapacity() {\n"); buf.append(" final int size = this.fFull.size();\n"); buf.append(" for (int i = 0; i < 100; i++) {\n"); @@ -3818,8 +3819,8 @@ buf.append("public class ComparisonFailure extends AssertionFailedError {\n"); buf.append(" /* Test */\n"); buf.append(" private static final long serialVersionUID = 1L;\n"); - buf.append(" private final String fExpected;\n"); buf.append(" private final String fActual;\n"); + buf.append(" private final String fExpected;\n"); buf.append("\n"); buf.append(" /**\n"); buf.append(" * Constructs a comparison failure.\n"); @@ -3914,13 +3915,13 @@ buf.append(" boolean fTornDown = false;\n"); buf.append("\n"); buf.append(" @Override\n"); - buf.append(" protected void tearDown() {\n"); - buf.append(" this.fTornDown = true;\n"); - buf.append(" }\n"); - buf.append(" @Override\n"); buf.append(" protected void runTest() {\n"); buf.append(" throw new Error();\n"); buf.append(" }\n"); + buf.append(" @Override\n"); + buf.append(" protected void tearDown() {\n"); + buf.append(" this.fTornDown = true;\n"); + buf.append(" }\n"); buf.append(" }\n"); buf.append("\n"); buf.append(" public void testCaseToString() {\n"); @@ -3940,29 +3941,72 @@ buf.append(" };\n"); buf.append(" this.verifyError(error);\n"); buf.append(" }\n"); + buf.append(" public void testExceptionRunningAndTearDown() {\n"); + buf.append(" // This test documents the current behavior. With 1.4, we should\n"); + buf.append(" // wrap the exception thrown while running with the exception thrown\n"); + buf.append(" // while tearing down\n"); + buf.append(" final Test t = new TornDown() {\n"); + buf.append(" @Override\n"); + buf.append(" public void tearDown() {\n"); + buf.append(" throw new Error(\"tearDown\"); //$NON-NLS-1$\n"); + buf.append(" }\n"); + buf.append(" };\n"); + buf.append(" final TestResult result = new TestResult();\n"); + buf.append(" t.run(result);\n"); + buf.append(" final TestFailure failure = (TestFailure) result.errors().nextElement();\n"); + buf.append(" Assert.assertEquals(\"tearDown\", failure.thrownException().getMessage()); //$NON-NLS-1$\n"); + buf.append(" }\n"); + buf.append(" public void testFailure() {\n"); + buf.append(" final TestCase failure = new TestCase(\"failure\") { //$NON-NLS-1$\n"); + buf.append(" @Override\n"); + buf.append(" protected void runTest() {\n"); + buf.append(" Assert.fail();\n"); + buf.append(" }\n"); + buf.append(" };\n"); + buf.append(" this.verifyFailure(failure);\n"); + buf.append(" }\n"); + buf.append(" public void testNamelessTestCase() {\n"); + buf.append(" final TestCase t = new TestCase() {\n"); + buf.append(" };\n"); + buf.append(" try {\n"); + buf.append(" t.run();\n"); + buf.append(" Assert.fail();\n"); + buf.append(" } catch (final AssertionFailedError e) {\n"); + buf.append(" }\n"); + buf.append(" }\n"); + buf.append(" public void testNoArgTestCasePasses() {\n"); + buf.append(" final Test t = new TestSuite(NoArgTestCaseTest.class);\n"); + buf.append(" final TestResult result = new TestResult();\n"); + buf.append(" t.run(result);\n"); + buf.append(" Assert.assertTrue(result.runCount() == 1);\n"); + buf.append(" Assert.assertTrue(result.failureCount() == 0);\n"); + buf.append(" Assert.assertTrue(result.errorCount() == 0);\n"); + buf.append(" }\n"); + buf.append("\n"); buf.append(" public void testRunAndTearDownFails() {\n"); buf.append(" final TornDown fails = new TornDown() {\n"); buf.append(" @Override\n"); - buf.append(" protected void tearDown() {\n"); - buf.append(" super.tearDown();\n"); + buf.append(" protected void runTest() {\n"); buf.append(" throw new Error();\n"); buf.append(" }\n"); buf.append(" @Override\n"); - buf.append(" protected void runTest() {\n"); + buf.append(" protected void tearDown() {\n"); + buf.append(" super.tearDown();\n"); buf.append(" throw new Error();\n"); buf.append(" }\n"); buf.append(" };\n"); buf.append(" this.verifyError(fails);\n"); buf.append(" Assert.assertTrue(fails.fTornDown);\n"); buf.append(" }\n"); + buf.append("\n"); buf.append(" public void testSetupFails() {\n"); buf.append(" final TestCase fails = new TestCase(\"success\") { //$NON-NLS-1$\n"); buf.append(" @Override\n"); - buf.append(" protected void setUp() {\n"); - buf.append(" throw new Error();\n"); + buf.append(" protected void runTest() {\n"); buf.append(" }\n"); buf.append(" @Override\n"); - buf.append(" protected void runTest() {\n"); + buf.append(" protected void setUp() {\n"); + buf.append(" throw new Error();\n"); buf.append(" }\n"); buf.append(" };\n"); buf.append(" this.verifyError(fails);\n"); @@ -3975,34 +4019,24 @@ buf.append(" };\n"); buf.append(" this.verifySuccess(success);\n"); buf.append(" }\n"); - buf.append(" public void testFailure() {\n"); - buf.append(" final TestCase failure = new TestCase(\"failure\") { //$NON-NLS-1$\n"); - buf.append(" @Override\n"); - buf.append(" protected void runTest() {\n"); - buf.append(" Assert.fail();\n"); - buf.append(" }\n"); - buf.append(" };\n"); - buf.append(" this.verifyFailure(failure);\n"); - buf.append(" }\n"); - buf.append("\n"); buf.append(" public void testTearDownAfterError() {\n"); buf.append(" final TornDown fails = new TornDown();\n"); buf.append(" this.verifyError(fails);\n"); buf.append(" Assert.assertTrue(fails.fTornDown);\n"); buf.append(" }\n"); - buf.append("\n"); buf.append(" public void testTearDownFails() {\n"); buf.append(" final TestCase fails = new TestCase(\"success\") { //$NON-NLS-1$\n"); buf.append(" @Override\n"); - buf.append(" protected void tearDown() {\n"); - buf.append(" throw new Error();\n"); + buf.append(" protected void runTest() {\n"); buf.append(" }\n"); buf.append(" @Override\n"); - buf.append(" protected void runTest() {\n"); + buf.append(" protected void tearDown() {\n"); + buf.append(" throw new Error();\n"); buf.append(" }\n"); buf.append(" };\n"); buf.append(" this.verifyError(fails);\n"); buf.append(" }\n"); + buf.append("\n"); buf.append(" public void testTearDownSetupFails() {\n"); buf.append(" final TornDown fails = new TornDown() {\n"); buf.append(" @Override\n"); @@ -4013,45 +4047,12 @@ buf.append(" this.verifyError(fails);\n"); buf.append(" Assert.assertTrue(!fails.fTornDown);\n"); buf.append(" }\n"); + buf.append("\n"); buf.append(" public void testWasRun() {\n"); buf.append(" final WasRun test = new WasRun();\n"); buf.append(" test.run();\n"); buf.append(" Assert.assertTrue(test.fWasRun);\n"); buf.append(" }\n"); - buf.append(" public void testExceptionRunningAndTearDown() {\n"); - buf.append(" // This test documents the current behavior. With 1.4, we should\n"); - buf.append(" // wrap the exception thrown while running with the exception thrown\n"); - buf.append(" // while tearing down\n"); - buf.append(" final Test t = new TornDown() {\n"); - buf.append(" @Override\n"); - buf.append(" public void tearDown() {\n"); - buf.append(" throw new Error(\"tearDown\"); //$NON-NLS-1$\n"); - buf.append(" }\n"); - buf.append(" };\n"); - buf.append(" final TestResult result = new TestResult();\n"); - buf.append(" t.run(result);\n"); - buf.append(" final TestFailure failure = (TestFailure) result.errors().nextElement();\n"); - buf.append(" Assert.assertEquals(\"tearDown\", failure.thrownException().getMessage()); //$NON-NLS-1$\n"); - buf.append(" }\n"); - buf.append("\n"); - buf.append(" public void testNoArgTestCasePasses() {\n"); - buf.append(" final Test t = new TestSuite(NoArgTestCaseTest.class);\n"); - buf.append(" final TestResult result = new TestResult();\n"); - buf.append(" t.run(result);\n"); - buf.append(" Assert.assertTrue(result.runCount() == 1);\n"); - buf.append(" Assert.assertTrue(result.failureCount() == 0);\n"); - buf.append(" Assert.assertTrue(result.errorCount() == 0);\n"); - buf.append(" }\n"); - buf.append("\n"); - buf.append(" public void testNamelessTestCase() {\n"); - buf.append(" final TestCase t = new TestCase() {\n"); - buf.append(" };\n"); - buf.append(" try {\n"); - buf.append(" t.run();\n"); - buf.append(" Assert.fail();\n"); - buf.append(" } catch (final AssertionFailedError e) {\n"); - buf.append(" }\n"); - buf.append(" }\n"); buf.append("\n"); buf.append(" void verifyError(final TestCase test) {\n"); buf.append(" final TestResult result = test.run();\n"); @@ -4096,12 +4097,18 @@ buf.append(" this.fFailedTest = failedTest;\n"); buf.append(" this.fThrownException = thrownException;\n"); buf.append(" }\n"); + buf.append(" public String exceptionMessage() {\n"); + buf.append(" return this.thrownException().getMessage();\n"); + buf.append(" }\n"); buf.append(" /**\n"); buf.append(" * Gets the failed test.\n"); buf.append(" */\n"); buf.append(" public Test failedTest() {\n"); buf.append(" return this.fFailedTest;\n"); buf.append(" }\n"); + buf.append(" public boolean isFailure() {\n"); + buf.append(" return this.thrownException() instanceof AssertionFailedError;\n"); + buf.append(" }\n"); buf.append(" /**\n"); buf.append(" * Gets the thrown exception.\n"); buf.append(" */\n"); @@ -4125,12 +4132,6 @@ buf.append(" final StringBuffer buffer = stringWriter.getBuffer();\n"); buf.append(" return buffer.toString();\n"); buf.append(" }\n"); - buf.append(" public String exceptionMessage() {\n"); - buf.append(" return this.thrownException().getMessage();\n"); - buf.append(" }\n"); - buf.append(" public boolean isFailure() {\n"); - buf.append(" return this.thrownException() instanceof AssertionFailedError;\n"); - buf.append(" }\n"); buf.append("}"); fExpectedChangesAllTests.put("junit.framework.TestFailure.java", buf.toString()); buf= new StringBuffer(); @@ -4141,6 +4142,10 @@ buf.append(" */\n"); buf.append("public class ReloadingTestSuiteLoader implements TestSuiteLoader {\n"); buf.append("\n"); + buf.append(" protected TestCaseClassLoader createLoader() {\n"); + buf.append(" return new TestCaseClassLoader();\n"); + buf.append(" }\n"); + buf.append("\n"); buf.append(" public Class load(final String suiteClassName)\n"); buf.append(" throws ClassNotFoundException {\n"); buf.append(" return this.createLoader().loadClass(suiteClassName, true);\n"); @@ -4149,10 +4154,6 @@ buf.append(" public Class reload(final Class aClass) throws ClassNotFoundException {\n"); buf.append(" return this.createLoader().loadClass(aClass.getName(), true);\n"); buf.append(" }\n"); - buf.append("\n"); - buf.append(" protected TestCaseClassLoader createLoader() {\n"); - buf.append(" return new TestCaseClassLoader();\n"); - buf.append(" }\n"); buf.append("}"); fExpectedChangesAllTests.put("junit.runner.ReloadingTestSuiteLoader.java", buf.toString()); buf= new StringBuffer(); @@ -4234,18 +4235,6 @@ buf.append("\n"); buf.append("public class TextRunnerTest extends TestCase {\n"); buf.append("\n"); - buf.append(" public void testFailure() throws Exception {\n"); - buf.append(" this.execTest(\"junit.tests.framework.Failure\", false); //$NON-NLS-1$\n"); - buf.append(" }\n"); - buf.append("\n"); - buf.append(" public void testSuccess() throws Exception {\n"); - buf.append(" this.execTest(\"junit.tests.framework.Success\", true); //$NON-NLS-1$\n"); - buf.append(" }\n"); - buf.append("\n"); - buf.append(" public void testError() throws Exception {\n"); - buf.append(" this.execTest(\"junit.tests.BogusDude\", false); //$NON-NLS-1$\n"); - buf.append(" }\n"); - buf.append("\n"); buf.append(" void execTest(final String testClass, final boolean success)\n"); buf.append(" throws Exception {\n"); buf.append(" final String java = System.getProperty(\"java.home\") + File.separator + \"bin\" + File.separator + \"java\"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\n"); @@ -4269,6 +4258,14 @@ buf.append(" }\n"); buf.append(" }\n"); buf.append("\n"); + buf.append(" public void testError() throws Exception {\n"); + buf.append(" this.execTest(\"junit.tests.BogusDude\", false); //$NON-NLS-1$\n"); + buf.append(" }\n"); + buf.append("\n"); + buf.append(" public void testFailure() throws Exception {\n"); + buf.append(" this.execTest(\"junit.tests.framework.Failure\", false); //$NON-NLS-1$\n"); + buf.append(" }\n"); + buf.append("\n"); buf.append(" public void testRunReturnsResult() {\n"); buf.append(" final PrintStream oldOut = System.out;\n"); buf.append(" System.setOut(new PrintStream(new OutputStream() {\n"); @@ -4285,6 +4282,10 @@ buf.append(" }\n"); buf.append(" }\n"); buf.append("\n"); + buf.append(" public void testSuccess() throws Exception {\n"); + buf.append(" this.execTest(\"junit.tests.framework.Success\", true); //$NON-NLS-1$\n"); + buf.append(" }\n"); + buf.append("\n"); buf.append("}"); fExpectedChangesAllTests.put("junit.tests.runner.TextRunnerTest.java", buf.toString()); buf= new StringBuffer(); @@ -4456,8 +4457,6 @@ buf.append(" */\n"); buf.append("\n"); buf.append("public class RepeatedTestTest extends TestCase {\n"); - buf.append(" private final TestSuite fSuite;\n"); - buf.append("\n"); buf.append(" public static class SuccessTest extends TestCase {\n"); buf.append("\n"); buf.append(" @Override\n"); @@ -4465,6 +4464,8 @@ buf.append(" }\n"); buf.append(" }\n"); buf.append("\n"); + buf.append(" private final TestSuite fSuite;\n"); + buf.append("\n"); buf.append(" public RepeatedTestTest(final String name) {\n"); buf.append(" super(name);\n"); buf.append(" this.fSuite = new TestSuite();\n"); @@ -4472,14 +4473,6 @@ buf.append(" this.fSuite.addTest(new SuccessTest());\n"); buf.append(" }\n"); buf.append("\n"); - buf.append(" public void testRepeatedOnce() {\n"); - buf.append(" final Test test = new RepeatedTest(this.fSuite, 1);\n"); - buf.append(" Assert.assertEquals(2, test.countTestCases());\n"); - buf.append(" final TestResult result = new TestResult();\n"); - buf.append(" test.run(result);\n"); - buf.append(" Assert.assertEquals(2, result.runCount());\n"); - buf.append(" }\n"); - buf.append("\n"); buf.append(" public void testRepeatedMoreThanOnce() {\n"); buf.append(" final Test test = new RepeatedTest(this.fSuite, 3);\n"); buf.append(" Assert.assertEquals(6, test.countTestCases());\n"); @@ -4488,14 +4481,6 @@ buf.append(" Assert.assertEquals(6, result.runCount());\n"); buf.append(" }\n"); buf.append("\n"); - buf.append(" public void testRepeatedZero() {\n"); - buf.append(" final Test test = new RepeatedTest(this.fSuite, 0);\n"); - buf.append(" Assert.assertEquals(0, test.countTestCases());\n"); - buf.append(" final TestResult result = new TestResult();\n"); - buf.append(" test.run(result);\n"); - buf.append(" Assert.assertEquals(0, result.runCount());\n"); - buf.append(" }\n"); - buf.append("\n"); buf.append(" public void testRepeatedNegative() {\n"); buf.append(" try {\n"); buf.append(" new RepeatedTest(this.fSuite, -1);\n"); @@ -4504,6 +4489,22 @@ buf.append(" }\n"); buf.append(" Assert.fail(\"Should throw an IllegalArgumentException\"); //$NON-NLS-1$\n"); buf.append(" }\n"); + buf.append("\n"); + buf.append(" public void testRepeatedOnce() {\n"); + buf.append(" final Test test = new RepeatedTest(this.fSuite, 1);\n"); + buf.append(" Assert.assertEquals(2, test.countTestCases());\n"); + buf.append(" final TestResult result = new TestResult();\n"); + buf.append(" test.run(result);\n"); + buf.append(" Assert.assertEquals(2, result.runCount());\n"); + buf.append(" }\n"); + buf.append("\n"); + buf.append(" public void testRepeatedZero() {\n"); + buf.append(" final Test test = new RepeatedTest(this.fSuite, 0);\n"); + buf.append(" Assert.assertEquals(0, test.countTestCases());\n"); + buf.append(" final TestResult result = new TestResult();\n"); + buf.append(" test.run(result);\n"); + buf.append(" Assert.assertEquals(0, result.runCount());\n"); + buf.append(" }\n"); buf.append("}"); fExpectedChangesAllTests.put("junit.tests.extensions.RepeatedTestTest.java", buf.toString()); buf= new StringBuffer(); @@ -4519,6 +4520,11 @@ buf.append(" */\n"); buf.append("public class AllTests {\n"); buf.append("\n"); + buf.append(" static boolean isJDK11() {\n"); + buf.append(" final String version = System.getProperty(\"java.version\"); //$NON-NLS-1$\n"); + buf.append(" return version.startsWith(\"1.1\"); //$NON-NLS-1$\n"); + buf.append(" }\n"); + buf.append("\n"); buf.append(" public static void main(final String[] args) {\n"); buf.append(" junit.textui.TestRunner.run(AllTests.suite());\n"); buf.append(" }\n"); @@ -4539,11 +4545,6 @@ buf.append(" }\n"); buf.append(" return suite;\n"); buf.append(" }\n"); - buf.append("\n"); - buf.append(" static boolean isJDK11() {\n"); - buf.append(" final String version = System.getProperty(\"java.version\"); //$NON-NLS-1$\n"); - buf.append(" return version.startsWith(\"1.1\"); //$NON-NLS-1$\n"); - buf.append(" }\n"); buf.append("}"); fExpectedChangesAllTests.put("junit.tests.runner.AllTests.java", buf.toString()); buf= new StringBuffer(); @@ -4581,14 +4582,14 @@ buf.append(" * constructors to create a MoneyBag.\n"); buf.append(" */\n"); buf.append("class MoneyBag implements IMoney {\n"); - buf.append(" private final Vector fMonies = new Vector(5);\n"); - buf.append("\n"); buf.append(" static IMoney create(final IMoney m1, final IMoney m2) {\n"); buf.append(" final MoneyBag result = new MoneyBag();\n"); buf.append(" m1.appendTo(result);\n"); buf.append(" m2.appendTo(result);\n"); buf.append(" return result.simplify();\n"); buf.append(" }\n"); + buf.append("\n"); + buf.append(" private final Vector fMonies = new Vector(5);\n"); buf.append(" public IMoney add(final IMoney m) {\n"); buf.append(" return m.addMoneyBag(this);\n"); buf.append(" }\n"); @@ -4619,6 +4620,16 @@ buf.append(" }\n"); buf.append(" this.fMonies.addElement(sum);\n"); buf.append(" }\n"); + buf.append(" public void appendTo(final MoneyBag m) {\n"); + buf.append(" m.appendBag(this);\n"); + buf.append(" }\n"); + buf.append(" private boolean contains(final Money m) {\n"); + buf.append(" final Money found = this.findMoney(m.currency());\n"); + buf.append(" if (found == null) {\n"); + buf.append(" return false;\n"); + buf.append(" }\n"); + buf.append(" return found.amount() == m.amount();\n"); + buf.append(" }\n"); buf.append(" @Override\n"); buf.append(" public boolean equals(final Object anObject) {\n"); buf.append(" if (this.isZero()) {\n"); @@ -4653,13 +4664,6 @@ buf.append(" }\n"); buf.append(" return null;\n"); buf.append(" }\n"); - buf.append(" private boolean contains(final Money m) {\n"); - buf.append(" final Money found = this.findMoney(m.currency());\n"); - buf.append(" if (found == null) {\n"); - buf.append(" return false;\n"); - buf.append(" }\n"); - buf.append(" return found.amount() == m.amount();\n"); - buf.append(" }\n"); buf.append(" @Override\n"); buf.append(" public int hashCode() {\n"); buf.append(" int hash = 0;\n"); @@ -4710,9 +4714,6 @@ buf.append(" buffer.append(\"}\"); //$NON-NLS-1$\n"); buf.append(" return buffer.toString();\n"); buf.append(" }\n"); - buf.append(" public void appendTo(final MoneyBag m) {\n"); - buf.append(" m.appendBag(this);\n"); - buf.append(" }\n"); buf.append("}"); fExpectedChangesAllTests.put("junit.samples.money.MoneyBag.java", buf.toString()); buf= new StringBuffer(); @@ -4847,6 +4848,14 @@ buf.append(" return new TestResult();\n"); buf.append(" }\n"); buf.append(" /**\n"); + buf.append(" * Gets the name of a TestCase\n"); + buf.append(" * \n"); + buf.append(" * @return returns a String\n"); + buf.append(" */\n"); + buf.append(" public String getName() {\n"); + buf.append(" return this.fName;\n"); + buf.append(" }\n"); + buf.append(" /**\n"); buf.append(" * A convenience method to run this test, collecting the results with a\n"); buf.append(" * default TestResult object.\n"); buf.append(" * \n"); @@ -4910,6 +4919,15 @@ buf.append(" }\n"); buf.append(" }\n"); buf.append(" /**\n"); + buf.append(" * Sets the name of a TestCase\n"); + buf.append(" * \n"); + buf.append(" * @param name\n"); + buf.append(" * The name to set\n"); + buf.append(" */\n"); + buf.append(" public void setName(final String name) {\n"); + buf.append(" this.fName = name;\n"); + buf.append(" }\n"); + buf.append(" /**\n"); buf.append(" * Sets up the fixture, for example, open a network connection. This method\n"); buf.append(" * is called before a test is executed.\n"); buf.append(" */\n"); @@ -4928,23 +4946,6 @@ buf.append(" public String toString() {\n"); buf.append(" return this.getName() + \"(\" + this.getClass().getName() + \")\"; //$NON-NLS-1$ //$NON-NLS-2$\n"); buf.append(" }\n"); - buf.append(" /**\n"); - buf.append(" * Gets the name of a TestCase\n"); - buf.append(" * \n"); - buf.append(" * @return returns a String\n"); - buf.append(" */\n"); - buf.append(" public String getName() {\n"); - buf.append(" return this.fName;\n"); - buf.append(" }\n"); - buf.append(" /**\n"); - buf.append(" * Sets the name of a TestCase\n"); - buf.append(" * \n"); - buf.append(" * @param name\n"); - buf.append(" * The name to set\n"); - buf.append(" */\n"); - buf.append(" public void setName(final String name) {\n"); - buf.append(" this.fName = name;\n"); - buf.append(" }\n"); buf.append("}"); fExpectedChangesAllTests.put("junit.framework.TestCase.java", buf.toString()); buf= new StringBuffer(); @@ -4954,17 +4955,17 @@ buf.append("import junit.framework.TestCase;\n"); buf.append("\n"); buf.append("public class MoneyTest extends TestCase {\n"); + buf.append(" public static void main(final String args[]) {\n"); + buf.append(" junit.textui.TestRunner.run(MoneyTest.class);\n"); + buf.append(" }\n"); buf.append(" private Money f12CHF;\n"); buf.append(" private Money f14CHF;\n"); - buf.append(" private Money f7USD;\n"); buf.append(" private Money f21USD;\n"); buf.append("\n"); + buf.append(" private Money f7USD;\n"); buf.append(" private IMoney fMB1;\n"); - buf.append(" private IMoney fMB2;\n"); buf.append("\n"); - buf.append(" public static void main(final String args[]) {\n"); - buf.append(" junit.textui.TestRunner.run(MoneyTest.class);\n"); - buf.append(" }\n"); + buf.append(" private IMoney fMB2;\n"); buf.append(" @Override\n"); buf.append(" protected void setUp() {\n"); buf.append(" this.f12CHF = new Money(12, \"CHF\"); //$NON-NLS-1$\n"); @@ -4989,6 +4990,10 @@ buf.append(" new Money(-12, \"CHF\"), new Money(-7, \"USD\")); //$NON-NLS-1$ //$NON-NLS-2$\n"); buf.append(" Assert.assertEquals(expected, this.fMB1.negate());\n"); buf.append(" }\n"); + buf.append(" public void testBagNotEquals() {\n"); + buf.append(" final IMoney bag = MoneyBag.create(this.f12CHF, this.f7USD);\n"); + buf.append(" Assert.assertFalse(bag.equals(new Money(12, \"DEM\").add(this.f7USD))); //$NON-NLS-1$\n"); + buf.append(" }\n"); buf.append(" public void testBagSimpleAdd() {\n"); buf.append(" // {[12 CHF][7 USD]} + [14 CHF] == {[26 CHF][7 USD]}\n"); buf.append(" final IMoney expected = MoneyBag.create(\n"); @@ -5017,10 +5022,6 @@ buf.append(" final IMoney expected = MoneyBag.create(this.f12CHF, this.f7USD);\n"); buf.append(" Assert.assertEquals(expected, this.f12CHF.add(this.f7USD));\n"); buf.append(" }\n"); - buf.append(" public void testBagNotEquals() {\n"); - buf.append(" final IMoney bag = MoneyBag.create(this.f12CHF, this.f7USD);\n"); - buf.append(" Assert.assertFalse(bag.equals(new Money(12, \"DEM\").add(this.f7USD))); //$NON-NLS-1$\n"); - buf.append(" }\n"); buf.append(" public void testMoneyBagEquals() {\n"); buf.append(" Assert.assertTrue(!this.fMB1.equals(null));\n"); buf.append("\n"); @@ -5050,11 +5051,6 @@ buf.append(" final Money equal = new Money(12, \"CHF\"); //$NON-NLS-1$\n"); buf.append(" Assert.assertEquals(this.f12CHF.hashCode(), equal.hashCode());\n"); buf.append(" }\n"); - buf.append(" public void testSimplify() {\n"); - buf.append(" final IMoney money = MoneyBag.create(\n"); - buf.append(" new Money(26, \"CHF\"), new Money(28, \"CHF\")); //$NON-NLS-1$ //$NON-NLS-2$\n"); - buf.append(" Assert.assertEquals(new Money(54, \"CHF\"), money); //$NON-NLS-1$\n"); - buf.append(" }\n"); buf.append(" public void testNormalize2() {\n"); buf.append(" // {[12 CHF][7 USD]} - [12 CHF] == [7 USD]\n"); buf.append(" final Money expected = new Money(7, \"USD\"); //$NON-NLS-1$\n"); @@ -5103,6 +5099,11 @@ buf.append(" final Money expected = new Money(2, \"CHF\"); //$NON-NLS-1$\n"); buf.append(" Assert.assertEquals(expected, this.f14CHF.subtract(this.f12CHF));\n"); buf.append(" }\n"); + buf.append(" public void testSimplify() {\n"); + buf.append(" final IMoney money = MoneyBag.create(\n"); + buf.append(" new Money(26, \"CHF\"), new Money(28, \"CHF\")); //$NON-NLS-1$ //$NON-NLS-2$\n"); + buf.append(" Assert.assertEquals(new Money(54, \"CHF\"), money); //$NON-NLS-1$\n"); + buf.append(" }\n"); buf.append("}"); fExpectedChangesAllTests.put("junit.samples.money.MoneyTest.java", buf.toString()); buf= new StringBuffer(); @@ -5234,6 +5235,9 @@ buf.append(" public int amount() {\n"); buf.append(" return this.fAmount;\n"); buf.append(" }\n"); + buf.append(" public/* this makes no sense */void appendTo(final MoneyBag m) {\n"); + buf.append(" m.appendMoney(this);\n"); + buf.append(" }\n"); buf.append(" public String currency() {\n"); buf.append(" return this.fCurrency;\n"); buf.append(" }\n"); @@ -5273,9 +5277,6 @@ buf.append(" buffer.append(\"[\" + this.amount() + \" \" + this.currency() + \"]\"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\n"); buf.append(" return buffer.toString();\n"); buf.append(" }\n"); - buf.append(" public/* this makes no sense */void appendTo(final MoneyBag m) {\n"); - buf.append(" m.appendMoney(this);\n"); - buf.append(" }\n"); buf.append("}"); fExpectedChangesAllTests.put("junit.samples.money.Money.java", buf.toString()); } @@ -5341,6 +5342,9 @@ node.put(CleanUpConstants.ORGANIZE_IMPORTS, CleanUpConstants.TRUE); + node.put(CleanUpConstants.SORT_MEMBERS, CleanUpConstants.TRUE); + node.put(CleanUpConstants.SORT_MEMBERS_ALL, CleanUpConstants.TRUE); + ProfileManager.CustomProfile profile= new ProfileManager.CustomProfile("testProfile", node, CleanUpProfileVersioner.CURRENT_VERSION, CleanUpProfileVersioner.PROFILE_KIND); new InstanceScope().getNode(JavaUI.ID_PLUGIN).put(CleanUpConstants.CLEANUP_PROFILE, profile.getID()); #P org.eclipse.jdt.ui Index: ui/org/eclipse/jdt/internal/ui/fix/MultiFixMessages.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/fix/MultiFixMessages.java,v retrieving revision 1.43 diff -u -r1.43 MultiFixMessages.java --- ui/org/eclipse/jdt/internal/ui/fix/MultiFixMessages.java 10 Jan 2007 17:16:22 -0000 1.43 +++ ui/org/eclipse/jdt/internal/ui/fix/MultiFixMessages.java 24 Jan 2007 08:49:08 -0000 @@ -43,6 +43,8 @@ public static String CodeFormatCleanUp_RemoveTrailingNoEmpty_description; public static String CodeFormatFix_RemoveTrailingWhitespace_changeDescription; public static String ImportsCleanUp_OrganizeImports_Description; + public static String SortMembersCleanUp_AllMembers_description; + public static String SortMembersCleanUp_Excluding_description; public static String StringMultiFix_AddMissingNonNls_description; public static String StringMultiFix_RemoveUnnecessaryNonNls_description; Index: ui/org/eclipse/jdt/internal/ui/fix/MultiFixMessages.properties =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/fix/MultiFixMessages.properties,v retrieving revision 1.62 diff -u -r1.62 MultiFixMessages.properties --- ui/org/eclipse/jdt/internal/ui/fix/MultiFixMessages.properties 10 Jan 2007 17:16:22 -0000 1.62 +++ ui/org/eclipse/jdt/internal/ui/fix/MultiFixMessages.properties 24 Jan 2007 08:49:08 -0000 @@ -81,3 +81,5 @@ CleanUpSaveParticipantPreferenceConfiguration_use_clean_up_profile_label=Use Clean &Up profile: CleanUpSaveParticipantPreferenceConfiguration_unknown_profile_name=unknown CleanUpSaveParticipantPreferenceConfiguration_edit_button_label=&Edit... +SortMembersCleanUp_AllMembers_description=Sort all members +SortMembersCleanUp_Excluding_description=Sort members excluding fields, enum constants, and initializers Index: ui/org/eclipse/jdt/internal/ui/preferences/cleanup/CleanUpMessages.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/cleanup/CleanUpMessages.java,v retrieving revision 1.6 diff -u -r1.6 CleanUpMessages.java --- ui/org/eclipse/jdt/internal/ui/preferences/cleanup/CleanUpMessages.java 22 Dec 2006 16:50:21 -0000 1.6 +++ ui/org/eclipse/jdt/internal/ui/preferences/cleanup/CleanUpMessages.java 24 Jan 2007 08:49:08 -0000 @@ -39,6 +39,10 @@ public static String CodeFormatingTabPage_Imports_GroupName; public static String CodeFormatingTabPage_OrganizeImports_CheckBoxLable; public static String CodeFormatingTabPage_OrganizeImportsSettings_Description; + public static String CodeFormatingTabPage_SortMembers_GroupName; + public static String CodeFormatingTabPage_SortMembers_CheckBoxLabel; + public static String CodeFormatingTabPage_SortMembers_Description; + public static String CodeFormatingTabPage_SortMembersFields_CheckBoxLabel; public static String CodeFormatingTabPage_RemoveTrailingWhitespace_all_radio; Index: ui/org/eclipse/jdt/internal/ui/preferences/cleanup/CleanUpMessages.properties =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/cleanup/CleanUpMessages.properties,v retrieving revision 1.8 diff -u -r1.8 CleanUpMessages.properties --- ui/org/eclipse/jdt/internal/ui/preferences/cleanup/CleanUpMessages.properties 22 Dec 2006 16:50:21 -0000 1.8 +++ ui/org/eclipse/jdt/internal/ui/preferences/cleanup/CleanUpMessages.properties 24 Jan 2007 08:49:08 -0000 @@ -20,6 +20,10 @@ CodeFormatingTabPage_CheckboxName_FormatMultiLineComments=Mul&ti line comments CodeFormatingTabPage_OrganizeImportsSettings_Description=The settings for organizing imports can be changed on the Organize Imports preference page. CodeFormatingTabPage_CheckboxName_FormatSingleLineComments=&Single line comments +CodeFormatingTabPage_SortMembers_GroupName=Members +CodeFormatingTabPage_SortMembers_CheckBoxLabel=Sort members +CodeFormatingTabPage_SortMembers_Description=The settings for sorting members can be changed on the Members Sort Order preference page. +CodeFormatingTabPage_SortMembersFields_CheckBoxLabel=Also sort fields, enum constants, and initializers CodeFormatingTabPage_RemoveTrailingWhitespace_checkbox_text=Remove trailing &whitespace CodeFormatingTabPage_RemoveTrailingWhitespace_ignoreEmpty_radio=&Ignore empty lines Index: ui/org/eclipse/jdt/internal/ui/preferences/cleanup/CodeFormatingTabPage.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/cleanup/CodeFormatingTabPage.java,v retrieving revision 1.5 diff -u -r1.5 CodeFormatingTabPage.java --- ui/org/eclipse/jdt/internal/ui/preferences/cleanup/CodeFormatingTabPage.java 10 Jan 2007 17:18:55 -0000 1.5 +++ ui/org/eclipse/jdt/internal/ui/preferences/cleanup/CodeFormatingTabPage.java 24 Jan 2007 08:49:08 -0000 @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Alex Blewitt - https://bugs.eclipse.org/bugs/show_bug.cgi?id=168954 *******************************************************************************/ package org.eclipse.jdt.internal.ui.preferences.cleanup; @@ -27,6 +28,7 @@ import org.eclipse.jdt.internal.ui.fix.CommentFormatCleanUp; import org.eclipse.jdt.internal.ui.fix.ICleanUp; import org.eclipse.jdt.internal.ui.fix.ImportsCleanUp; +import org.eclipse.jdt.internal.ui.fix.SortMembersCleanUp; import org.eclipse.jdt.internal.ui.preferences.formatter.JavaPreview; import org.eclipse.jdt.internal.ui.preferences.formatter.ModifyDialog; import org.eclipse.jdt.internal.ui.preferences.formatter.ModifyDialogTabPage; @@ -49,7 +51,7 @@ } protected JavaPreview doCreateJavaPreview(Composite parent) { - fCleanUpPreview= new CleanUpPreview(parent, new ICleanUp[] {new ImportsCleanUp(fValues), new CodeFormatCleanUp(fValues), new CommentFormatCleanUp(fValues)}, false); + fCleanUpPreview= new CleanUpPreview(parent, new ICleanUp[] {new ImportsCleanUp(fValues), new CodeFormatCleanUp(fValues), new CommentFormatCleanUp(fValues), new SortMembersCleanUp(fValues)}, false); return fCleanUpPreview; } @@ -63,13 +65,13 @@ final CheckboxPreference formatCommentsPref= createCheckboxPref(group, numColumns, CleanUpMessages.CodeFormatingTabPage_CheckboxName_FormatComments, CleanUpConstants.FORMAT_COMMENT, CleanUpModifyDialog.FALSE_TRUE); - intent(group); + indent(group); final CheckboxPreference javadocPref= createCheckboxPref(group, numColumns - 1, CleanUpMessages.CodeFormatingTabPage_CheckboxName_FormatJavadocComments, CleanUpConstants.FORMAT_JAVADOC, CleanUpModifyDialog.FALSE_TRUE); - intent(group); + indent(group); final CheckboxPreference multiLinePref= createCheckboxPref(group, numColumns - 1, CleanUpMessages.CodeFormatingTabPage_CheckboxName_FormatMultiLineComments, CleanUpConstants.FORMAT_MULTI_LINE_COMMENT, CleanUpModifyDialog.FALSE_TRUE); - intent(group); + indent(group); final CheckboxPreference singleLinePref= createCheckboxPref(group, numColumns - 1, CleanUpMessages.CodeFormatingTabPage_CheckboxName_FormatSingleLineComments, CleanUpConstants.FORMAT_SINGLE_LINE_COMMENT, CleanUpModifyDialog.FALSE_TRUE); formatCommentsPref.addObserver(new Observer() { @@ -96,7 +98,7 @@ layout.marginWidth= 0; sub.setLayout(layout); - intent(sub); + indent(sub); final RadioPreference allPref= createRadioPref(sub, 1, CleanUpMessages.CodeFormatingTabPage_RemoveTrailingWhitespace_all_radio, CleanUpConstants.FORMAT_REMOVE_TRAILING_WHITESPACES_ALL, CleanUpModifyDialog.FALSE_TRUE); final RadioPreference ignoreEmptyPref= createRadioPref(sub, 1, CleanUpMessages.CodeFormatingTabPage_RemoveTrailingWhitespace_ignoreEmpty_radio, CleanUpConstants.FORMAT_REMOVE_TRAILING_WHITESPACES_IGNORE_EMPTY, CleanUpModifyDialog.FALSE_TRUE); @@ -111,8 +113,8 @@ allPref.setEnabled(whiteSpace.getChecked()); ignoreEmptyPref.setEnabled(whiteSpace.getChecked()); - PixelConverter pixelConverter= new PixelConverter(composite); - + PixelConverter pixelConverter= new PixelConverter(composite); + if (!fIsSaveParticipantConfiguration) { createLabel(CleanUpMessages.CodeFormatingTabPage_FormatterSettings_Description, group, numColumns, pixelConverter).setFont(composite.getFont()); @@ -121,7 +123,22 @@ createLabel(CleanUpMessages.CodeFormatingTabPage_OrganizeImportsSettings_Description, importsGroup, numColumns, pixelConverter).setFont(composite.getFont()); } - } + + Group sortMembersGroup = createGroup(numColumns, composite, CleanUpMessages.CodeFormatingTabPage_SortMembers_GroupName); + final CheckboxPreference sortMembersPref = createCheckboxPref(sortMembersGroup, numColumns, CleanUpMessages.CodeFormatingTabPage_SortMembers_CheckBoxLabel, CleanUpConstants.SORT_MEMBERS, CleanUpModifyDialog.FALSE_TRUE); + + indent(sortMembersGroup); + final CheckboxPreference sortMembersFieldsPref = createCheckboxPref(sortMembersGroup, numColumns - 1, CleanUpMessages.CodeFormatingTabPage_SortMembersFields_CheckBoxLabel, CleanUpConstants.SORT_MEMBERS_ALL, CleanUpModifyDialog.FALSE_TRUE); + + sortMembersPref.addObserver( new Observer() { + public void update(Observable o, Object arg) { + sortMembersFieldsPref.setEnabled(sortMembersPref.getChecked()); + } + }); + sortMembersFieldsPref.setEnabled(sortMembersPref.getChecked()); + + createLabel(CleanUpMessages.CodeFormatingTabPage_SortMembers_Description, sortMembersGroup, numColumns, pixelConverter).setFont(composite.getFont()); + } private Label createLabel(String text, Group group, int numColumns, PixelConverter pixelConverter) { Label label= new Label(group, SWT.WRAP); @@ -132,7 +149,7 @@ return label; } - private void intent(Composite composite) { + private void indent(Composite composite) { Label l= new Label(composite, SWT.NONE); GridData gd= new GridData(); gd.widthHint= fPixelConverter.convertWidthInCharsToPixels(4); Index: core extension/org/eclipse/jdt/internal/corext/fix/CleanUpConstants.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/fix/CleanUpConstants.java,v retrieving revision 1.16 diff -u -r1.16 CleanUpConstants.java --- core extension/org/eclipse/jdt/internal/corext/fix/CleanUpConstants.java 10 Jan 2007 17:18:55 -0000 1.16 +++ core extension/org/eclipse/jdt/internal/corext/fix/CleanUpConstants.java 24 Jan 2007 08:49:07 -0000 @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Alex Blewitt - https://bugs.eclipse.org/bugs/show_bug.cgi?id=168954 *******************************************************************************/ package org.eclipse.jdt.internal.corext.fix; @@ -948,6 +949,37 @@ public static final String ORGANIZE_IMPORTS= "cleanup.organize_imports"; //$NON-NLS-1$ /** + * Should members be sorted? + *

+ * Possible values: {TRUE, FALSE}
+ * Default value: Value returned by {@link #getEclipseDefaultSettings()}
+ *
+ * + * @see #SORT_MEMBERS_ALL + * @see #TRUE + * @see #FALSE + * @since 3.3 + */ + public static final String SORT_MEMBERS = "cleanup.sort_members"; //$NON-NLS-1$ + + /** + * If sorting members, should fields, enum constants and initializers also be sorted? + *
+ * This has only an effect if {@link #SORT_MEMBERS} is also enabled. + *
+ *
+ * Possible values: {TRUE, FALSE}
+ * Default value: Value returned by {@link #getEclipseDefaultSettings()}
+ *
+ * + * @see #SORT_MEMBERS + * @see #TRUE + * @see #FALSE + * @since 3.3 + */ + public static final String SORT_MEMBERS_ALL = "cleanup.sort_members_all"; //$NON-NLS-1$ + + /** * Should the Clean Up Wizard be shown when executing the Clean Up Action? *
*
@@ -1042,7 +1074,6 @@ * @since 3.3 */ public final static String DEFAULT_SAVE_PARTICIPANT_PROFILE= SAVE_PARTICIPANT_PROFILE; - public static Map getEclipseDefaultSettings() { final HashMap result= new HashMap(); @@ -1109,14 +1140,17 @@ result.put(FORMAT_SOURCE_CODE, FALSE); result.put(FORMAT_COMMENT, FALSE); - result.put(FORMAT_SINGLE_LINE_COMMENT, TRUE); + result.put(FORMAT_SINGLE_LINE_COMMENT, FALSE); result.put(FORMAT_MULTI_LINE_COMMENT, FALSE); - result.put(FORMAT_JAVADOC, FALSE); + result.put(FORMAT_JAVADOC, TRUE); result.put(FORMAT_REMOVE_TRAILING_WHITESPACES, FALSE); result.put(FORMAT_REMOVE_TRAILING_WHITESPACES_ALL, TRUE); result.put(FORMAT_REMOVE_TRAILING_WHITESPACES_IGNORE_EMPTY, FALSE); result.put(ORGANIZE_IMPORTS, FALSE); + + result.put(SORT_MEMBERS, FALSE); + result.put(SORT_MEMBERS_ALL, FALSE); return result; } @@ -1194,6 +1228,9 @@ result.put(FORMAT_REMOVE_TRAILING_WHITESPACES_IGNORE_EMPTY, FALSE); result.put(ORGANIZE_IMPORTS, TRUE); + + result.put(SORT_MEMBERS, FALSE); + result.put(SORT_MEMBERS_ALL, FALSE); result.put(CLEANUP_ON_SAVE_ADDITIONAL_OPTIONS, FALSE); Index: core extension/org/eclipse/jdt/internal/corext/fix/FixMessages.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/fix/FixMessages.java,v retrieving revision 1.31 diff -u -r1.31 FixMessages.java --- core extension/org/eclipse/jdt/internal/corext/fix/FixMessages.java 11 Jan 2007 17:49:30 -0000 1.31 +++ core extension/org/eclipse/jdt/internal/corext/fix/FixMessages.java 24 Jan 2007 08:49:07 -0000 @@ -45,6 +45,8 @@ public static String PotentialProgrammingProblemsFix_calculatingUIDFailed_binding; public static String PotentialProgrammingProblemsFix_calculatingUIDFailed_exception; public static String PotentialProgrammingProblemsFix_calculatingUIDFailed_unknown; + public static String SortMembersFix_Change_description; + public static String SortMembersFix_Fix_description; public static String UnusedCodeFix_change_name; public static String UnusedCodeFix_RemoveFieldOrLocal_description; Index: core extension/org/eclipse/jdt/internal/corext/fix/FixMessages.properties =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/fix/FixMessages.properties,v retrieving revision 1.35 diff -u -r1.35 FixMessages.properties --- core extension/org/eclipse/jdt/internal/corext/fix/FixMessages.properties 11 Jan 2007 17:49:30 -0000 1.35 +++ core extension/org/eclipse/jdt/internal/corext/fix/FixMessages.properties 24 Jan 2007 08:49:08 -0000 @@ -90,3 +90,5 @@ CleanUpPostSaveListener_unknown_profile_error_message=Clean Up save participant could not retrieve profile with id ''{0}'' CodeStyleFix_change_name=Code Style Clean Up ControlStatementsFix_change_name=Control Statements Clean Up +SortMembersFix_Change_description=Sort Members +SortMembersFix_Fix_description=Sort Members Index: core extension/org/eclipse/jdt/internal/corext/fix/CleanUpRefactoring.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/fix/CleanUpRefactoring.java,v retrieving revision 1.43 diff -u -r1.43 CleanUpRefactoring.java --- core extension/org/eclipse/jdt/internal/corext/fix/CleanUpRefactoring.java 15 Jan 2007 15:36:03 -0000 1.43 +++ core extension/org/eclipse/jdt/internal/corext/fix/CleanUpRefactoring.java 24 Jan 2007 08:49:07 -0000 @@ -80,6 +80,7 @@ import org.eclipse.jdt.internal.ui.fix.ImportsCleanUp; import org.eclipse.jdt.internal.ui.fix.Java50CleanUp; import org.eclipse.jdt.internal.ui.fix.PotentialProgrammingProblemsCleanUp; +import org.eclipse.jdt.internal.ui.fix.SortMembersCleanUp; import org.eclipse.jdt.internal.ui.fix.StringCleanUp; import org.eclipse.jdt.internal.ui.fix.UnnecessaryCodeCleanUp; import org.eclipse.jdt.internal.ui.fix.UnusedCodeCleanUp; @@ -1014,11 +1015,38 @@ } public static ICleanUp[] createCleanUps() { - return new ICleanUp[] {new CodeStyleCleanUp(), new ControlStatementsCleanUp(), new ConvertLoopCleanUp(), new VariableDeclarationCleanUp(), new ExpressionsCleanUp(), new UnusedCodeCleanUp(), new Java50CleanUp(), new PotentialProgrammingProblemsCleanUp(), new UnnecessaryCodeCleanUp(), new StringCleanUp(), new ImportsCleanUp(), new CodeFormatCleanUp(), new CommentFormatCleanUp()}; + return new ICleanUp[] { + new CodeStyleCleanUp(), + new ControlStatementsCleanUp(), + new ConvertLoopCleanUp(), + new VariableDeclarationCleanUp(), + new ExpressionsCleanUp(), + new UnusedCodeCleanUp(), + new Java50CleanUp(), + new PotentialProgrammingProblemsCleanUp(), + new UnnecessaryCodeCleanUp(), + new StringCleanUp(), + new SortMembersCleanUp(), + new ImportsCleanUp(), + new CodeFormatCleanUp(), + new CommentFormatCleanUp()}; } public static ICleanUp[] createCleanUps(Map settings) { - return new ICleanUp[] {new CodeStyleCleanUp(settings), new ControlStatementsCleanUp(settings), new ConvertLoopCleanUp(settings), new VariableDeclarationCleanUp(settings), new ExpressionsCleanUp(settings), new UnusedCodeCleanUp(settings), new Java50CleanUp(settings), new PotentialProgrammingProblemsCleanUp(settings), new UnnecessaryCodeCleanUp(settings), new StringCleanUp(settings), - new ImportsCleanUp(settings), new CodeFormatCleanUp(settings), new CommentFormatCleanUp(settings)}; + return new ICleanUp[] { + new CodeStyleCleanUp(settings), + new ControlStatementsCleanUp(settings), + new ConvertLoopCleanUp(settings), + new VariableDeclarationCleanUp(settings), + new ExpressionsCleanUp(settings), + new UnusedCodeCleanUp(settings), + new Java50CleanUp(settings), + new PotentialProgrammingProblemsCleanUp(settings), + new UnnecessaryCodeCleanUp(settings), + new StringCleanUp(settings), + new SortMembersCleanUp(settings), + new ImportsCleanUp(settings), + new CodeFormatCleanUp(settings), + new CommentFormatCleanUp(settings)}; } } Index: ui/org/eclipse/jdt/internal/ui/fix/SortMembersCleanUp.java =================================================================== RCS file: ui/org/eclipse/jdt/internal/ui/fix/SortMembersCleanUp.java diff -N ui/org/eclipse/jdt/internal/ui/fix/SortMembersCleanUp.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ui/org/eclipse/jdt/internal/ui/fix/SortMembersCleanUp.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,109 @@ +/******************************************************************************* + * Copyright (c) 2000, 2006 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * Alex Blewitt - https://bugs.eclipse.org/bugs/show_bug.cgi?id=168954 + *******************************************************************************/ +package org.eclipse.jdt.internal.ui.fix; + +import java.util.Map; + +import org.eclipse.core.runtime.CoreException; + +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jdt.core.dom.CompilationUnit; +import org.eclipse.jdt.internal.corext.fix.CleanUpConstants; +import org.eclipse.jdt.internal.corext.fix.IFix; +import org.eclipse.jdt.internal.corext.fix.SortMembersFix; + +import org.eclipse.jdt.ui.text.java.IProblemLocation; + +public class SortMembersCleanUp extends AbstractCleanUp { + + public SortMembersCleanUp() { + super(); + } + + public SortMembersCleanUp(Map options) { + super(options); + } + + public IFix createFix(CompilationUnit compilationUnit) throws CoreException { + if (compilationUnit == null) + return null; + + boolean sortMembers= isEnabled(CleanUpConstants.SORT_MEMBERS); + return SortMembersFix.createCleanUp(compilationUnit, sortMembers, sortMembers && isEnabled(CleanUpConstants.SORT_MEMBERS_ALL)); + } + + /** + * {@inheritDoc} + */ + public IFix createFix(CompilationUnit compilationUnit, IProblemLocation[] problems) throws CoreException { + return null; + } + + public Map getRequiredOptions() { + return null; + } + + /** + * {@inheritDoc} + */ + public String[] getDescriptions() { + if (isEnabled(CleanUpConstants.SORT_MEMBERS)) { + if (isEnabled(CleanUpConstants.SORT_MEMBERS_ALL)) { + return new String[] {MultiFixMessages.SortMembersCleanUp_AllMembers_description}; + } else { + return new String[] {MultiFixMessages.SortMembersCleanUp_Excluding_description}; + } + } + return null; + } + + public String getPreview() { + StringBuffer buf= new StringBuffer(); + + buf.append("public class SortExample {\n"); //$NON-NLS-1$ + + if ((isEnabled(CleanUpConstants.SORT_MEMBERS) && isEnabled(CleanUpConstants.SORT_MEMBERS_ALL))) { + buf.append(" private String bar;\n"); //$NON-NLS-1$ + buf.append(" private String foo;\n"); //$NON-NLS-1$ + } else { + buf.append(" private String foo;\n"); //$NON-NLS-1$ + buf.append(" private String bar;\n"); //$NON-NLS-1$ + } + + if (isEnabled(CleanUpConstants.SORT_MEMBERS)) { + buf.append(" private void bar();\n"); //$NON-NLS-1$ + buf.append(" private void foo();\n"); //$NON-NLS-1$ + } else { + buf.append(" private void foo();\n"); //$NON-NLS-1$ + buf.append(" private void bar();\n"); //$NON-NLS-1$ + } + + buf.append("}\n"); //$NON-NLS-1$ + + return buf.toString(); + } + + /** + * {@inheritDoc} + */ + public int maximalNumberOfFixes(CompilationUnit compilationUnit) { + return -1; + } + + public boolean canFix(CompilationUnit compilationUnit, IProblemLocation problem) throws CoreException { + return false; + } + + public boolean requireAST(ICompilationUnit unit) throws CoreException { + return isEnabled(CleanUpConstants.SORT_MEMBERS); + } +} Index: core extension/org/eclipse/jdt/internal/corext/fix/SortMembersFix.java =================================================================== RCS file: core extension/org/eclipse/jdt/internal/corext/fix/SortMembersFix.java diff -N core extension/org/eclipse/jdt/internal/corext/fix/SortMembersFix.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ core extension/org/eclipse/jdt/internal/corext/fix/SortMembersFix.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,94 @@ +/******************************************************************************* + * Copyright (c) 2000, 2006 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * Alex Blewitt - https://bugs.eclipse.org/bugs/show_bug.cgi?id=168954 + *******************************************************************************/ +package org.eclipse.jdt.internal.corext.fix; + +import org.eclipse.text.edits.TextEdit; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; + +import org.eclipse.ltk.core.refactoring.CategorizedTextEditGroup; +import org.eclipse.ltk.core.refactoring.GroupCategory; +import org.eclipse.ltk.core.refactoring.GroupCategorySet; +import org.eclipse.ltk.core.refactoring.TextChange; + +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jdt.core.dom.CompilationUnit; +import org.eclipse.jdt.core.util.CompilationUnitSorter; + +import org.eclipse.jdt.internal.corext.codemanipulation.SortMembersOperation.DefaultJavaElementComparator; +import org.eclipse.jdt.internal.corext.refactoring.changes.CompilationUnitChange; + +import org.eclipse.jdt.internal.ui.dialogs.StatusInfo; + +public class SortMembersFix implements IFix { + + public static IFix createCleanUp(CompilationUnit compilationUnit, boolean sortMembers, boolean sortFields) throws CoreException { + if (!sortMembers && !sortFields) + return null; + + ICompilationUnit cu= (ICompilationUnit)compilationUnit.getJavaElement(); + cu.becomeWorkingCopy(null, null); + + IProgressMonitor monitor = null; + + String label= FixMessages.SortMembersFix_Change_description; + CategorizedTextEditGroup group= new CategorizedTextEditGroup(label, new GroupCategorySet(new GroupCategory(label, label, label))); + + TextEdit edit = CompilationUnitSorter.sort(compilationUnit, new DefaultJavaElementComparator(!sortFields), 0, group, monitor); + if (edit == null) + return null; + + TextChange change= new CompilationUnitChange(label, cu); + change.setEdit(edit); + change.addTextEditGroup(group); + + return new SortMembersFix(change, cu); + } + + private final ICompilationUnit fCompilationUnit; + private final TextChange fChange; + + public SortMembersFix(TextChange change, ICompilationUnit compilationUnit) { + fChange= change; + fCompilationUnit= compilationUnit; + } + + /** + * {@inheritDoc} + */ + public TextChange createChange() throws CoreException { + return fChange; + } + + /** + * {@inheritDoc} + */ + public ICompilationUnit getCompilationUnit() { + return fCompilationUnit; + } + + /** + * {@inheritDoc} + */ + public String getDescription() { + return FixMessages.SortMembersFix_Fix_description; + } + + /** + * {@inheritDoc} + */ + public IStatus getStatus() { + return StatusInfo.OK_STATUS; + } +}