|
From: Steve F. <sm...@us...> - 2002-08-17 20:35:53
|
Update of /cvsroot/mockobjects/no-stone-unturned/src/nostone/junitrunner
In directory usw-pr-cvs1:/tmp/cvs-serv4513/src/nostone/junitrunner
Modified Files:
Tasks.java SwingRunner.java SwingRunnerTest.java
Added Files:
CounterPanel.java
Log Message:
Extracted CounterPanel
--- NEW FILE: CounterPanel.java ---
package nostone.junitrunner;
import junit.framework.Test;
import javax.swing.*;
import java.awt.*;
class CounterPanel extends JPanel {
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");
}
private void addLabel(String initialValue, String name) {
JLabel label = new JLabel(initialValue);
label.setName(name);
add(label);
}
}
Index: Tasks.java
===================================================================
RCS file: /cvsroot/mockobjects/no-stone-unturned/src/nostone/junitrunner/Tasks.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Tasks.java 17 Aug 2002 20:29:18 -0000 1.3
+++ Tasks.java 17 Aug 2002 20:35:50 -0000 1.4
@@ -3,7 +3,7 @@
public class Tasks {
// Open GUI, close
// Hardcoded testcase, one passing test, show green bar, show test counts
- // TODO Hardcoded testcases, two passing test, show green bar, show test counts
+ // Hardcoded testcases, two passing test, show green bar, show test counts
// TODO Hardcoded testcase, one failing test, show red bar, show test counts, failure message
// TODO Hardcoded testcase, one error test, show red bar, show test counts, error message
// TODO Hardcoded testcases, passing + failing, show red bar, show test counts, failure message
Index: SwingRunner.java
===================================================================
RCS file: /cvsroot/mockobjects/no-stone-unturned/src/nostone/junitrunner/SwingRunner.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- SwingRunner.java 17 Aug 2002 20:31:42 -0000 1.3
+++ SwingRunner.java 17 Aug 2002 20:35:51 -0000 1.4
@@ -11,6 +11,8 @@
public SwingRunner( Test test ) {
super("Swing Runner");
+ TestResult result = new TestResult();
+
JButton quitButton = new JButton("Quit");
quitButton.setName("quit");
quitButton.addActionListener(new ActionListener() {
@@ -27,18 +29,12 @@
getContentPane().setLayout(new FlowLayout());
getContentPane().add(progressBar);
- addLabel(Integer.toString(test.countTestCases()), "total count");
- addLabel(Integer.toString(test.countTestCases()), "success count");
- addLabel("0", "failure count");
- addLabel("0", "error count");
+ CounterPanel counters = new CounterPanel(test);
+ getContentPane().add(counters);
getContentPane().add(quitButton);
pack();
- }
- private void addLabel(String initialValue, String name) {
- JLabel label = new JLabel(initialValue);
- label.setName(name);
- getContentPane().add(label);
+ test.run(result);
}
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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- SwingRunnerTest.java 17 Aug 2002 20:31:42 -0000 1.4
+++ SwingRunnerTest.java 17 Aug 2002 20:35:51 -0000 1.5
@@ -85,6 +85,29 @@
checkLabelText("error count", "0");
}
+ public void xtestOneFailingTest() {
+ runner = new SwingRunner( new Test() {
+ public int countTestCases() {
+ return 1;
+ }
+ public void run(TestResult result) {
+ result.addFailure( this, new AssertionFailedError("test failure"));
+ result.endTest( this );
+ }
+ } );
+
+ JProgressBar progressBar = (JProgressBar)find("progress bar");
+ assertNotNull("should have progress bar", progressBar);
+ assertEquals("progress bar colour", Color.RED, progressBar.getForeground());
+ assertEquals("progress bar value", 1, progressBar.getValue());
+ assertEquals("progress bar max", 1, progressBar.getMaximum());
+
+ checkLabelText("total count", "1");
+ checkLabelText("success count", "0");
+ checkLabelText("failure count", "1");
+ checkLabelText("error count", "0");
+ }
+
private void checkLabelText(String name, String expectedText) {
JLabel label = (JLabel) find(name);
assertNotNull("Should have " + name, label);
|