|
From: <fb...@us...> - 2003-06-27 20:51:05
|
Update of /cvsroot/jgb/jgb/src/java/tests/jgb
In directory sc8-pr-cvs1:/tmp/cvs-serv22120/src/java/tests/jgb
Modified Files:
TestBuildWindowFromXmlFile.java
Log Message:
* src/java/core/jgb/InvalidParameterException.java,
src/java/core/jgb/RequiredArgumentMissingException.java,
src/java/core/jgb/TooManyArgumentsException.java,
src/java/core/jgb/UnknownArgumentException.java:
Created new Exception classes to handler Exception while
BuildWindowFromXmlFile starts up.
* src/java/tests/jgb/TestBuildWindowFromXmlFile.java:
Created tests to start having some coverage.
* src/java/core/jgb/BuildWindowFromXmlFile.java:
Implemented tests.
* src/java/core/jgb/builder/Builder.java:
Added a new build(InputSource) method to allow using an InputSource
instead of having an InputStream.
* src/java/core/jgb/builder/DefaultBuilder.java:
Implemented interface specifications.
Index: TestBuildWindowFromXmlFile.java
===================================================================
RCS file: /cvsroot/jgb/jgb/src/java/tests/jgb/TestBuildWindowFromXmlFile.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** TestBuildWindowFromXmlFile.java 27 Jun 2003 16:45:49 -0000 1.2
--- TestBuildWindowFromXmlFile.java 27 Jun 2003 20:49:50 -0000 1.3
***************
*** 20,30 ****
--- 20,40 ----
package jgb;
+ import com.mockobjects.dynamic.C;
import com.mockobjects.dynamic.Mock;
import jgb.builder.Builder;
import junit.framework.TestCase;
+ import javax.swing.*;
+ import java.util.ArrayList;
+ import java.util.Arrays;
+ import java.util.Collections;
+ import java.io.*;
+
+ import org.xml.sax.*;
+
public class TestBuildWindowFromXmlFile extends TestCase {
private final BuildWindowFromXmlFile windowBuilder = new BuildWindowFromXmlFile();
private final Mock mockBuilder = new Mock(Builder.class);
+ private String[] args;
protected void setUp() throws Exception {
***************
*** 32,37 ****
}
! public void testNotImplemented() {
! fail("Need to implement some tests here, real soon...");
}
}
--- 42,250 ----
}
! public void testUnderstandsVerboseOption() throws InvalidParameterException, FileNotFoundException {
! args = new String[]{
! "--verbose",
! "src/examples/simplewindow.xml",
! };
!
! mockBuilder.expect("setVerbose", C.eq(new Boolean(true)));
! windowBuilder.processArguments(
! (Builder) mockBuilder.proxy(),
! new ArrayList(Arrays.asList(args)));
!
! mockBuilder.verify();
! }
!
! public void testUnderstandsVerboseShortOption() throws InvalidParameterException, FileNotFoundException {
! args = new String[]{
! "-v",
! "src/examples/simplewindow.xml",
! };
!
! mockBuilder.expect("setVerbose", C.eq(new Boolean(true)));
! windowBuilder.processArguments(
! (Builder) mockBuilder.proxy(),
! new ArrayList(Arrays.asList(args)));
!
! mockBuilder.verify();
! }
!
! public void testUnderstandsQuietOption() throws InvalidParameterException, FileNotFoundException {
! args = new String[]{
! "--quiet",
! "src/examples/simplewindow.xml",
! };
!
! mockBuilder.expect("setQuiet", C.eq(new Boolean(true)));
! windowBuilder.processArguments(
! (Builder) mockBuilder.proxy(),
! new ArrayList(Arrays.asList(args)));
!
! mockBuilder.verify();
! }
!
! public void testUnderstandsQuietShortOption() throws InvalidParameterException, FileNotFoundException {
! args = new String[]{
! "-q",
! "src/examples/simplewindow.xml",
! };
!
! mockBuilder.expect("setQuiet", C.eq(new Boolean(true)));
! windowBuilder.processArguments(
! (Builder) mockBuilder.proxy(),
! new ArrayList(Arrays.asList(args)));
!
! mockBuilder.verify();
! }
!
! public void testComplainsAboutMissingArgumentWhenNoFilename() throws InvalidParameterException, FileNotFoundException {
! try {
! windowBuilder.processArguments(
! (Builder) mockBuilder.proxy(),
! Collections.EMPTY_LIST);
! fail("Failed to complain about missing argument");
! } catch (RequiredArgumentMissingException success) {
! assertTrue(true);
! }
! }
!
! public void testComplainsAboutUnknownOption() throws InvalidParameterException, FileNotFoundException {
! args = new String[]{
! "--unknown-option",
! };
!
! try {
! windowBuilder.processArguments(
! (Builder) mockBuilder.proxy(),
! Arrays.asList(args));
! fail("Failed to complain about unknown argument");
! } catch (UnknownArgumentException success) {
! assertTrue(true);
! }
! }
!
! public void testComplainsIfFileNotFound() throws InvalidParameterException, FileNotFoundException {
! args = new String[]{
! "some/non/possible/file/name/argument/that/should/not/really/exist.xml",
! };
!
! try {
! windowBuilder.processArguments(
! (Builder) mockBuilder.proxy(),
! Arrays.asList(args));
! fail("Failed to complain that file does not exist");
! } catch (FileNotFoundException success) {
! assertTrue(true);
! }
! }
!
! public void testComplainsIfTooManyArguments() throws InvalidParameterException, FileNotFoundException {
! args = new String[]{
! "src/examples/simplewindow.xml",
! "src/examples/simplewindow2.xml",
! };
!
! try {
! windowBuilder.processArguments(
! (Builder) mockBuilder.proxy(),
! Arrays.asList(args));
! fail("Failed to complain that there are too many arguments");
! } catch (TooManyArgumentsException success) {
! assertTrue(true);
! }
! }
!
! public void testReturnsFilenameArgument() throws InvalidParameterException, FileNotFoundException {
! args = new String[]{
! "src/examples/simplewindow.xml",
! };
!
! final String absolutePath = windowBuilder.processArguments(
! (Builder) mockBuilder.proxy(),
! Arrays.asList(args));
!
! assertEquals("Returned the absolute path to the file",
! new File(args[0]).getAbsolutePath(), absolutePath);
! }
!
! public void testTransfersControlToBuilder() throws IOException, SAXException {
! final JFrame window = new JFrame();
! final InputSource source = new InputSource();
! mockBuilder.expectAndReturn("build", C.same(source), window);
! final JWindow builtWindow = windowBuilder.start(
! new Builder() {
! public void setQuiet(boolean quiet) {
! }
!
! public void setVerbose(boolean verbose) {
! }
!
! public JWindow build(InputStream in) throws IOException, SAXException {
! return null;
! }
!
! public JWindow build(InputSource in) throws IOException, SAXException {
! assertSame(source,in);
! return window;
! }
!
! public void setLoggingStream(PrintWriter logStream) {
! }
!
! public void addResolver(EntityResolver resolver) {
! }
!
! public void setDocumentLocator(Locator locator) {
! }
!
! public void startDocument()
! throws SAXException {
! }
!
! public void endDocument()
! throws SAXException {
! }
!
! public void startPrefixMapping(String prefix, String uri)
! throws SAXException {
! }
!
! public void endPrefixMapping(String prefix)
! throws SAXException {
! }
!
! public void startElement(String namespaceURI, String localName,
! String qName, Attributes atts)
! throws SAXException {
! }
!
! public void endElement(String namespaceURI, String localName,
! String qName)
! throws SAXException {
! }
!
! public void characters(char ch[], int start, int length)
! throws SAXException {
! }
!
! public void ignorableWhitespace(char ch[], int start, int length)
! throws SAXException {
! }
!
! public void processingInstruction(String target, String data)
! throws SAXException {
! }
!
! public void skippedEntity(String name)
! throws SAXException {
! }
!
! public Object getObject(String name) {
! return null;
! }
! } , source);
! mockBuilder.verify();
! assertSame("Returns the window that was returned from the builder",
! window, builtWindow);
}
}
|