|
From: Steve F. <sm...@us...> - 2002-08-17 20:43:39
|
Update of /cvsroot/mockobjects/no-stone-unturned/src/nostone/junitrunner
In directory usw-pr-cvs1:/tmp/cvs-serv6267/src/nostone/junitrunner
Modified Files:
SwingRunner.java SwingRunnerTest.java CounterPanel.java
Log Message:
One failing test
Index: SwingRunner.java
===================================================================
RCS file: /cvsroot/mockobjects/no-stone-unturned/src/nostone/junitrunner/SwingRunner.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- SwingRunner.java 17 Aug 2002 20:35:51 -0000 1.4
+++ SwingRunner.java 17 Aug 2002 20:43:37 -0000 1.5
@@ -1,7 +1,6 @@
package nostone.junitrunner;
-import junit.framework.Test;
-import junit.framework.TestResult;
+import junit.framework.*;
import javax.swing.*;
import java.awt.*;
@@ -11,8 +10,6 @@
public SwingRunner( Test test ) {
super("Swing Runner");
- TestResult result = new TestResult();
-
JButton quitButton = new JButton("Quit");
quitButton.setName("quit");
quitButton.addActionListener(new ActionListener() {
@@ -21,20 +18,50 @@
}
});
- JProgressBar progressBar = new JProgressBar();
- progressBar.setName("progress bar");
- progressBar.setForeground(Color.GREEN);
- progressBar.setValue( test.countTestCases() );
- progressBar.setMaximum( test.countTestCases() );
+ final JProgressBar progressBar = createProgressBar(test);
+ final CounterPanel counters = new CounterPanel(test);
getContentPane().setLayout(new FlowLayout());
getContentPane().add(progressBar);
- CounterPanel counters = new CounterPanel(test);
getContentPane().add(counters);
getContentPane().add(quitButton);
pack();
+ TestResult result = new TestResult();
+ result.addListener( new TestListener() {
+ private boolean hasNotGoneWrong;
+
+ public void addError(Test test, Throwable t) {
+ }
+
+ public void addFailure(Test test, AssertionFailedError t) {
+ progressBar.setForeground( Color.RED );
+ counters.addFailure();
+ hasNotGoneWrong = false;
+ }
+
+ public void endTest(Test test) {
+ if (hasNotGoneWrong) {
+ counters.addPass();
+ }
+ }
+
+ public void startTest(Test test) {
+ hasNotGoneWrong = true;
+ }
+
+ } );
+
test.run(result);
+ }
+
+ private JProgressBar createProgressBar(Test test) {
+ JProgressBar progressBar = new JProgressBar();
+ progressBar.setName("progress bar");
+ progressBar.setForeground(Color.GREEN);
+ progressBar.setValue( test.countTestCases() );
+ progressBar.setMaximum( test.countTestCases() );
+ return progressBar;
}
static public void main(String[] args) {
Index: SwingRunnerTest.java
===================================================================
RCS file: /cvsroot/mockobjects/no-stone-unturned/src/nostone/junitrunner/SwingRunnerTest.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- SwingRunnerTest.java 17 Aug 2002 20:35:51 -0000 1.5
+++ SwingRunnerTest.java 17 Aug 2002 20:43:37 -0000 1.6
@@ -47,6 +47,7 @@
return 1;
}
public void run(TestResult result) {
+ result.startTest( this );
result.endTest( this );
}
} );
@@ -69,6 +70,9 @@
return 2;
}
public void run(TestResult result) {
+ result.startTest( this );
+ result.endTest( this );
+ result.startTest( this );
result.endTest( this );
}
} );
@@ -85,7 +89,7 @@
checkLabelText("error count", "0");
}
- public void xtestOneFailingTest() {
+ public void testOneFailingTest() {
runner = new SwingRunner( new Test() {
public int countTestCases() {
return 1;
Index: CounterPanel.java
===================================================================
RCS file: /cvsroot/mockobjects/no-stone-unturned/src/nostone/junitrunner/CounterPanel.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- CounterPanel.java 17 Aug 2002 20:35:51 -0000 1.1
+++ CounterPanel.java 17 Aug 2002 20:43:37 -0000 1.2
@@ -5,19 +5,37 @@
import javax.swing.*;
import java.awt.*;
-class CounterPanel extends JPanel {
+public class CounterPanel extends JPanel {
+ private int passes = 0;
+ private JLabel passesLabel;
+ private int failures = 0;
+ private JLabel failureLabel;
+
public CounterPanel(Test test) {
super(new FlowLayout());
- addLabel(Integer.toString(test.countTestCases()), "total count");
- addLabel(Integer.toString(test.countTestCases()), "success count");
- addLabel("0", "failure count");
- addLabel("0", "error count");
+ addPromptLabel("Total:", Integer.toString(test.countTestCases()), "total count");
+ passesLabel = addPromptLabel(" Passes:", "0", "success count");
+ failureLabel = addPromptLabel(" Failures:", "0", "failure count");
+ addPromptLabel(" Errors:", "0", "error count");
}
- private void addLabel(String initialValue, String name) {
+ private JLabel addPromptLabel(String prompt, String initialValue, String name) {
JLabel label = new JLabel(initialValue);
label.setName(name);
+ add(new JLabel(prompt));
add(label);
+
+ return label;
+ }
+
+ public void addFailure() {
+ failures++;
+ failureLabel.setText( Integer.toString(failures) );
+ }
+
+ public void addPass() {
+ passes++;
+ passesLabel.setText( Integer.toString(passes) );
}
}
|