Skip to content

Commit

Permalink
finished support for no-arg constructor.
Browse files Browse the repository at this point in the history
tweaks to the Swing UI
  • Loading branch information
egamma committed Mar 30, 2002
1 parent b6a023c commit 86b71cb
Show file tree
Hide file tree
Showing 49 changed files with 218 additions and 309 deletions.
3 changes: 2 additions & 1 deletion .project
Expand Up @@ -15,4 +15,5 @@
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.team.cvs.core.cvsnature</nature>
</natures>
</projectDescription>
</projectDescription>

20 changes: 8 additions & 12 deletions junit/awtui/TestRunner.java
@@ -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.
Expand Down Expand Up @@ -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;
Expand Down
Binary file removed junit/awtui/logo.gif
Binary file not shown.
Binary file removed junit/awtui/smalllogo.gif
Binary file not shown.
22 changes: 10 additions & 12 deletions junit/framework/TestSuite.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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)+")"));
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 2 additions & 5 deletions junit/runner/LoadingTestCollector.java
Expand Up @@ -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;
}

}
26 changes: 13 additions & 13 deletions junit/runner/Version.java
@@ -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";
}
}
4 changes: 1 addition & 3 deletions junit/samples/SimpleTest.java
Expand Up @@ -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;
Expand Down
3 changes: 0 additions & 3 deletions junit/samples/VectorTest.java
Expand Up @@ -12,9 +12,6 @@ public class VectorTest extends TestCase {
protected Vector fEmpty;
protected Vector fFull;

public VectorTest(String name) {
super(name);
}
public static void main (String[] args) {
junit.textui.TestRunner.run (suite());
}
Expand Down
6 changes: 3 additions & 3 deletions junit/samples/money/IMoney.java
Expand Up @@ -13,12 +13,12 @@ interface IMoney {
* 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
*/
Expand All @@ -38,5 +38,5 @@ interface IMoney {
/**
* Append this to a MoneyBag m.
*/
void appendTo(MoneyBag m);
public abstract void appendTo(MoneyBag m);
}
3 changes: 0 additions & 3 deletions junit/samples/money/MoneyTest.java
Expand Up @@ -11,9 +11,6 @@ public class MoneyTest extends TestCase {
private IMoney fMB1;
private IMoney fMB2;

public MoneyTest(String name) {
super(name);
}
public static void main(String args[]) {
junit.textui.TestRunner.run(MoneyTest.class);
}
Expand Down
10 changes: 5 additions & 5 deletions junit/swingui/AboutDialog.java
Expand Up @@ -2,8 +2,8 @@

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

import javax.swing.*;
import junit.runner.*;

/**
Expand All @@ -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));

Expand All @@ -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;
Expand Down
24 changes: 13 additions & 11 deletions junit/swingui/CounterPanel.java
@@ -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
Expand All @@ -12,23 +11,26 @@ public class CounterPanel extends JPanel {
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);
Expand Down

0 comments on commit 86b71cb

Please sign in to comment.