Permalink
Browse files

finished support for no-arg constructor.

tweaks to the Swing UI
  • Loading branch information...
1 parent b6a023c commit 86b71cb1b9784a9b87c86b4f3f12632ae6773d1f egamma committed Mar 30, 2002
Showing with 218 additions and 309 deletions.
  1. +2 −1 .project
  2. +8 −12 junit/awtui/TestRunner.java
  3. BIN junit/awtui/logo.gif
  4. BIN junit/awtui/smalllogo.gif
  5. +10 −12 junit/framework/TestSuite.java
  6. +2 −5 junit/runner/LoadingTestCollector.java
  7. +13 −13 junit/runner/Version.java
  8. +1 −3 junit/samples/SimpleTest.java
  9. +0 −3 junit/samples/VectorTest.java
  10. +3 −3 junit/samples/money/IMoney.java
  11. +0 −3 junit/samples/money/MoneyTest.java
  12. +5 −5 junit/swingui/AboutDialog.java
  13. +13 −11 junit/swingui/CounterPanel.java
  14. +70 −15 junit/swingui/DefaultFailureDetailView.java
  15. +13 −13 junit/swingui/FailureRunView.java
  16. +14 −54 junit/swingui/ProgressBar.java
  17. +2 −1 junit/swingui/StatusLine.java
  18. +2 −3 junit/swingui/TestHierarchyRunView.java
  19. +1 −2 junit/swingui/TestRunView.java
  20. +27 −30 junit/swingui/TestRunner.java
  21. +2 −3 junit/swingui/TestSelector.java
  22. +2 −3 junit/swingui/TestSuitePanel.java
  23. +2 −2 junit/swingui/TestTreeModel.java
  24. +0 −3 junit/tests/WasRun.java
  25. +4 −12 junit/tests/extensions/ActiveTestTest.java
  26. +0 −3 junit/tests/extensions/ExceptionTestCaseTest.java
  27. +3 −6 junit/tests/extensions/ExtensionTest.java
  28. +3 −6 junit/tests/extensions/RepeatedTestTest.java
  29. +1 −5 junit/tests/framework/AssertTest.java
  30. +1 −5 junit/tests/framework/Failure.java
  31. +1 −4 junit/tests/framework/InheritedTestCase.java
  32. +0 −2 junit/tests/framework/NoTestCaseClass.java
  33. +0 −3 junit/tests/framework/NoTestCases.java
  34. +0 −3 junit/tests/framework/NotPublicTestCase.java
  35. +0 −3 junit/tests/framework/NotVoidTestCase.java
  36. +0 −3 junit/tests/framework/OneTestCase.java
  37. +0 −3 junit/tests/framework/OverrideTestCase.java
  38. +3 −3 junit/tests/framework/Success.java
  39. +1 −1 junit/tests/framework/SuiteTest.java
  40. +5 −11 junit/tests/framework/TestCaseTest.java
  41. +2 −7 junit/tests/framework/TestImplementorTest.java
  42. +1 −3 junit/tests/framework/TestListenerTest.java
  43. +0 −4 junit/tests/runner/BaseTestRunnerTest.java
  44. +0 −7 junit/tests/runner/SimpleTestCollectorTest.java
  45. +0 −4 junit/tests/runner/SorterTest.java
  46. +0 −4 junit/tests/runner/StackFilterTest.java
  47. +0 −3 junit/tests/runner/TestCaseClassLoaderTest.java
  48. +0 −3 junit/tests/runner/TextRunnerTest.java
  49. +1 −1 stylesheet.css
View
@@ -15,4 +15,5 @@
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.team.cvs.core.cvsnature</nature>
</natures>
-</projectDescription>
+</projectDescription>
+
@@ -1,14 +1,12 @@
package junit.awtui;
-import junit.framework.*;
-import junit.runner.*;
-
-import java.util.Vector;
-import java.lang.reflect.*;
import java.awt.*;
import java.awt.event.*;
-import java.awt.image.*;
-import java.io.*;
+import java.awt.image.ImageProducer;
+import java.util.Vector;
+
+import junit.framework.*;
+import junit.runner.*;
/**
* An AWT based user interface to run tests.
@@ -342,12 +340,10 @@ private void rerunTest(Test test) {
return;
}
Test reloadedTest= null;
+ TestCase rerunTest= (TestCase)test;
try {
- Class reloadedTestClass= getLoader().reload(test.getClass());
- Class[] classArgs= { String.class };
- Constructor constructor= reloadedTestClass.getConstructor(classArgs);
- Object[] args= new Object[]{((TestCase)test).getName()};
- reloadedTest= (Test)constructor.newInstance(args);
+ Class reloadedTestClass= getLoader().reload(test.getClass());
+ reloadedTest= TestSuite.createTest(reloadedTestClass, rerunTest.getName());
} catch(Exception e) {
showInfo("Could not reload "+ test.toString());
return;
View
Deleted file not rendered
View
Deleted file not rendered
@@ -54,7 +54,7 @@ public TestSuite(Class theClass, String name) {
public TestSuite(final Class theClass) {
fName= theClass.getName();
try {
- getConstructor(theClass); // Avoid generating multiple error messages
+ getTestConstructor(theClass); // Avoid generating multiple error messages
} catch (NoSuchMethodException e) {
addTest(warning("Class "+theClass.getName()+" has no public constructor TestCase(String name) or TestCase()"));
return;
@@ -108,27 +108,25 @@ private void addTestMethod(Method m, Vector names, Class theClass) {
addTest(warning("Test method isn't public: "+m.getName()));
return;
}
-
names.addElement(name);
-
addTest(createTest(theClass, name));
}
- public Test createTest(Class theClass, String name) throws IllegalArgumentException {
- Constructor c;
+ static public Test createTest(Class theClass, String name) {
+ Constructor constructor;
try {
- c= getConstructor(theClass);
+ constructor= getTestConstructor(theClass);
} catch (NoSuchMethodException e) {
return warning("Class "+theClass.getName()+" has no public constructor TestCase(String name) or TestCase()");
}
Object test;
try {
- if (c.getParameterTypes().length == 0) {
- test= c.newInstance(new Object[0]);
+ if (constructor.getParameterTypes().length == 0) {
+ test= constructor.newInstance(new Object[0]);
if (test instanceof TestCase)
((TestCase) test).setName(name);
} else {
- test= c.newInstance(new Object[]{name});
+ test= constructor.newInstance(new Object[]{name});
}
} catch (InstantiationException e) {
return(warning("Cannot instantiate test case: "+name+" ("+exceptionToString(e)+")"));
@@ -143,7 +141,7 @@ public Test createTest(Class theClass, String name) throws IllegalArgumentExcept
/**
* Converts the stack trace into a string
*/
- private String exceptionToString(Throwable t) {
+ private static String exceptionToString(Throwable t) {
StringWriter stringWriter= new StringWriter();
PrintWriter writer= new PrintWriter(stringWriter);
t.printStackTrace(writer);
@@ -167,7 +165,7 @@ public int countTestCases() {
* Gets a constructor which takes a single String as
* its argument or a no arg constructor.
*/
- private Constructor getConstructor(Class theClass) throws NoSuchMethodException {
+ public static Constructor getTestConstructor(Class theClass) throws NoSuchMethodException {
Class[] args= { String.class };
try {
return theClass.getConstructor(args);
@@ -253,7 +251,7 @@ public String getName() {
/**
* Returns a test which will fail and log a warning message.
*/
- private Test warning(final String message) {
+ private static Test warning(final String message) {
return new TestCase("warning") {
protected void runTest() {
fail(message);
@@ -59,14 +59,11 @@ boolean hasSuiteMethod(Class testClass) {
}
boolean hasPublicConstructor(Class testClass) {
- Class[] args= { String.class };
- Constructor c= null;
try {
- c= testClass.getConstructor(args);
- } catch(Exception e) {
+ TestSuite.getTestConstructor(testClass);
+ } catch(NoSuchMethodException e) {
return false;
}
return true;
}
-
}
View
@@ -1,14 +1,14 @@
-package junit.runner;
+package junit.runner;
+
+/**
+ * This class defines the current version of JUnit
+ */
+public class Version {
+ private Version() {
+ // don't instantiate
+ }
-/**
- * This class defines the current version of JUnit
- */
-public class Version {
- private Version() {
- // don't instantiate
- }
-
- public static String id() {
- return "@version@";
- }
-}
+ public static String id() {
+ return "3.7";
+ }
+}
@@ -9,9 +9,7 @@
public class SimpleTest extends TestCase {
protected int fValue1;
protected int fValue2;
- public SimpleTest(String name) {
- super(name);
- }
+
protected void setUp() {
fValue1= 2;
fValue2= 3;
@@ -12,9 +12,6 @@
protected Vector fEmpty;
protected Vector fFull;
- public VectorTest(String name) {
- super(name);
- }
public static void main (String[] args) {
junit.textui.TestRunner.run (suite());
}
@@ -13,12 +13,12 @@
* Adds a simple Money to this money. This is a helper method for
* implementing double dispatch
*/
- IMoney addMoney(Money m);
+ public abstract IMoney addMoney(Money m);
/**
* Adds a MoneyBag to this money. This is a helper method for
* implementing double dispatch
*/
- IMoney addMoneyBag(MoneyBag s);
+ public abstract IMoney addMoneyBag(MoneyBag s);
/**
* Tests whether this money is zero
*/
@@ -38,5 +38,5 @@
/**
* Append this to a MoneyBag m.
*/
- void appendTo(MoneyBag m);
+ public abstract void appendTo(MoneyBag m);
}
@@ -11,9 +11,6 @@
private IMoney fMB1;
private IMoney fMB2;
- public MoneyTest(String name) {
- super(name);
- }
public static void main(String args[]) {
junit.textui.TestRunner.run(MoneyTest.class);
}
@@ -2,8 +2,8 @@
import java.awt.*;
import java.awt.event.*;
-import javax.swing.*;
+import javax.swing.*;
import junit.runner.*;
/**
@@ -19,15 +19,15 @@ public AboutDialog(JFrame parent) {
setTitle("About");
setLocationRelativeTo(parent);
- JButton button= new JButton("Close");
- button.addActionListener(
+ JButton close= new JButton("Close");
+ close.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
dispose();
}
}
);
-
+ getRootPane().setDefaultButton(close);
JLabel label1= new JLabel("JUnit");
label1.setFont(new Font("dialog", Font.PLAIN, 36));
@@ -53,7 +53,7 @@ public void actionPerformed(ActionEvent e) {
constraintsButton1.gridwidth = 2; constraintsButton1.gridheight = 1;
constraintsButton1.anchor = GridBagConstraints.CENTER;
constraintsButton1.insets= new Insets(8, 0, 8, 0);
- getContentPane().add(button, constraintsButton1);
+ getContentPane().add(close, constraintsButton1);
GridBagConstraints constraintsLogo1= new GridBagConstraints();
constraintsLogo1.gridx = 2; constraintsLogo1.gridy = 0;
@@ -1,9 +1,8 @@
package junit.swingui;
+import java.awt.GridLayout;
+
import javax.swing.*;
-import javax.swing.event.*;
-import javax.swing.border.*;
-import java.awt.*;
/**
* A panel with test run counters
@@ -12,23 +11,26 @@
private JTextField fNumberOfErrors;
private JTextField fNumberOfFailures;
private JTextField fNumberOfRuns;
+ private Icon fFailureIcon= TestRunner.getIconResource(getClass(), "icons/failure.gif");
+ private Icon fErrorIcon= TestRunner.getIconResource(getClass(), "icons/error.gif");
+
private int fTotal;
public CounterPanel() {
- super(new GridLayout(2, 3));
+ super(new GridLayout(1, 6));
+ fNumberOfErrors= createOutputField(8);
+ fNumberOfFailures= createOutputField(5);
+ fNumberOfRuns= createOutputField(5);
add(new JLabel("Runs:"));
- add(new JLabel("Errors:"));
- add(new JLabel("Failures: "));
- fNumberOfErrors= createOutputField();
- fNumberOfFailures= createOutputField();
- fNumberOfRuns= createOutputField();
add(fNumberOfRuns);
+ add(new JLabel("Errors:", fErrorIcon, SwingConstants.LEFT));
add(fNumberOfErrors);
+ add(new JLabel("Failures: ", fFailureIcon, SwingConstants.LEFT));
add(fNumberOfFailures);
}
- private JTextField createOutputField() {
- JTextField field= new JTextField("0", 10);
+ private JTextField createOutputField(int width) {
+ JTextField field= new JTextField("0", width);
field.setHorizontalAlignment(JTextField.LEFT);
field.setFont(StatusLine.BOLD_FONT);
field.setEditable(false);
Oops, something went wrong.

0 comments on commit 86b71cb

Please sign in to comment.