|
From: Steve F. <sm...@us...> - 2002-08-17 20:29:21
|
Update of /cvsroot/mockobjects/no-stone-unturned/src/nostone/junitrunner
In directory usw-pr-cvs1:/tmp/cvs-serv2364/src/nostone/junitrunner
Modified Files:
Tasks.java SwingRunner.java SwingRunnerTest.java
Log Message:
test one passing test
Index: Tasks.java
===================================================================
RCS file: /cvsroot/mockobjects/no-stone-unturned/src/nostone/junitrunner/Tasks.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Tasks.java 17 Aug 2002 20:27:21 -0000 1.2
+++ Tasks.java 17 Aug 2002 20:29:18 -0000 1.3
@@ -2,7 +2,7 @@
public class Tasks {
// Open GUI, close
- // TODO Hardcoded testcase, one passing test, show green bar, show test counts
+ // Hardcoded testcase, one passing test, show green bar, show test counts
// TODO 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
Index: SwingRunner.java
===================================================================
RCS file: /cvsroot/mockobjects/no-stone-unturned/src/nostone/junitrunner/SwingRunner.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SwingRunner.java 17 Aug 2002 20:26:06 -0000 1.1
+++ SwingRunner.java 17 Aug 2002 20:29:18 -0000 1.2
@@ -1,11 +1,14 @@
package nostone.junitrunner;
+import junit.framework.Test;
+import junit.framework.TestResult;
+
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class SwingRunner extends JFrame {
- public SwingRunner() {
+ public SwingRunner( Test test ) {
super("Swing Runner");
JButton quitButton = new JButton("Quit");
@@ -16,12 +19,37 @@
}
});
+ JProgressBar progressBar = new JProgressBar();
+ progressBar.setName("progress bar");
+ progressBar.setForeground(Color.GREEN);
+ progressBar.setValue(1);
+ progressBar.setMaximum(1);
+
+ getContentPane().setLayout(new FlowLayout());
+ getContentPane().add(progressBar);
+ addLabel("1", "total count");
+ addLabel("1", "success count");
+ addLabel("0", "failure count");
+ addLabel("0", "error count");
getContentPane().add(quitButton);
pack();
}
+ private void addLabel(String initialValue, String name) {
+ JLabel label = new JLabel(initialValue);
+ label.setName(name);
+ getContentPane().add(label);
+ }
+
static public void main(String[] args) {
- SwingRunner runner = new SwingRunner();
+ SwingRunner runner = new SwingRunner( new Test() {
+ public int countTestCases() {
+ return 0;
+ }
+ public void run(TestResult result) {
+ }
+ } );
+
runner.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
Window w = e.getWindow();
Index: SwingRunnerTest.java
===================================================================
RCS file: /cvsroot/mockobjects/no-stone-unturned/src/nostone/junitrunner/SwingRunnerTest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SwingRunnerTest.java 17 Aug 2002 20:27:21 -0000 1.2
+++ SwingRunnerTest.java 17 Aug 2002 20:29:18 -0000 1.3
@@ -6,19 +6,27 @@
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
-import junit.framework.TestCase;
+import junit.framework.*;
import com.mockobjects.ExpectationCounter;
import javax.swing.*;
public class SwingRunnerTest extends TestCase {
- private SwingRunner runner = new SwingRunner();
+ private SwingRunner runner;
public SwingRunnerTest(String name) {
super(name);
}
public void testCreateGui() {
+ runner = new SwingRunner( new Test() {
+ public int countTestCases() {
+ return 0;
+ }
+ public void run(TestResult result) {
+ }
+ } );
+
final ExpectationCounter closingCalls = new ExpectationCounter("window closing");
runner.addWindowListener(new WindowAdapter() {
@@ -34,9 +42,32 @@
public void testOnePassingTest() {
+ runner = new SwingRunner( new Test() {
+ public int countTestCases() {
+ return 1;
+ }
+ public void run(TestResult result) {
+ result.endTest( this );
+ }
+ } );
+ JProgressBar progressBar = (JProgressBar)find("progress bar");
+ assertNotNull("should have progress bar", progressBar);
+ assertEquals("progress bar colour", Color.GREEN, progressBar.getForeground());
+ assertEquals("progress bar value", 1, progressBar.getValue());
+ assertEquals("progress bar max", 1, progressBar.getMaximum());
+
+ checkLabelText("total count", "1");
+ checkLabelText("success count", "1");
+ checkLabelText("failure count", "0");
+ checkLabelText("error count", "0");
+ }
+ private void checkLabelText(String name, String expectedText) {
+ JLabel label = (JLabel) find(name);
+ assertNotNull("Should have " + name, label);
+ assertEquals(name, expectedText, label.getText());
}
private Component find(String name) {
|