craigmcc 2004/10/17 15:39:00
Modified: chain/src/java/org/apache/commons/chain/impl
CatalogFactoryBase.java
Added: chain/src/test/org/apache/commons/chain/impl
CatalogFactoryBaseTestCase.java
Log:
Add a unit test for CatalogFactoryBase.
Hmm ... having to explictly reference CatalogFactoryBase to call getInstance()
seems a little odd ... maybe we should make CatalogFactory itself a concrete
class instead of an interface (analogous to LogFactory in [logging]).
Revision Changes Path
1.2 +3 -3 jakarta-commons/chain/src/java/org/apache/commons/chain/impl/CatalogFactoryBase.java
Index: CatalogFactoryBase.java
===================================================================
RCS file: /home/cvs/jakarta-commons/chain/src/java/org/apache/commons/chain/impl/CatalogFactoryBase.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- CatalogFactoryBase.java 17 Oct 2004 01:53:53 -0000 1.1
+++ CatalogFactoryBase.java 17 Oct 2004 22:39:00 -0000 1.2
@@ -20,8 +20,8 @@
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
-import org.apache.commons.chain.CatalogFactory;
import org.apache.commons.chain.Catalog;
+import org.apache.commons.chain.CatalogFactory;
/**
* <p>A simple implementation of {@link CatalogFactory}.</p>
@@ -79,7 +79,7 @@
*
* @return the singleton instance of CatalogFactoryBase.
*/
- public CatalogFactory getInstance() {
+ public static CatalogFactory getInstance() {
return instance;
1.1 jakarta-commons/chain/src/test/org/apache/commons/chain/impl/CatalogFactoryBaseTestCase.java
Index: CatalogFactoryBaseTestCase.java
===================================================================
/*
* Copyright 1999-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.chain.impl;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.apache.commons.chain.Catalog;
import org.apache.commons.chain.CatalogFactory;
import org.apache.commons.chain.Command;
import org.apache.commons.chain.impl.CatalogBase;
import org.apache.commons.chain.impl.CatalogFactoryBase;
import java.util.Iterator;
/**
* <p>Test case for the <code>CatalogFactoryBase</code> class.</p>
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2004/10/17 22:39:00 $
*/
public class CatalogFactoryBaseTestCase extends TestCase {
// ---------------------------------------------------- Instance Variables
/**
* <p>The {@link CatalogFactory} instance under test.</p>
*/
protected CatalogFactory factory = null;
// ---------------------------------------------------------- Constructors
/**
* Construct a new instance of this test case.
*
* @param name Name of the test case
*/
public CatalogFactoryBaseTestCase(String name) {
super(name);
}
// -------------------------------------------------- Overall Test Methods
/**
* <p>Set up instance variables required by this test case.</p>
*/
public void setUp() {
factory = CatalogFactoryBase.getInstance();
}
/**
* <p>Return the tests included in this test suite.</p>
*/
public static Test suite() {
return (new TestSuite(CatalogFactoryBaseTestCase.class));
}
/**
* <p>Tear down instance variables required by this test case.</p>
*/
public void tearDown() {
factory = null;
}
// ------------------------------------------------ Individual Test Methods
/**
* <p>Test the default {@link Catalog} instance.</p>
*/
public void testDefaultCatalog() {
Catalog catalog = new CatalogBase();
factory.setCatalog(catalog);
assertEquals(catalog, factory.getCatalog());
assertEquals(catalog,
factory.getCatalog("org.apache.commons.chain.DEFAULT_CATALOG"));
assertEquals(1, getCatalogCount());
factory.clear();
assertEquals(0, getCatalogCount());
}
/**
* <p>Test a pristine instance of {@link CatalogFactory}.</p>
*/
public void testPristine() {
assertNotNull(factory);
assertNull(factory.getCatalog());
assertNull(factory.getCatalog("foo"));
assertEquals(0, getCatalogCount());
}
/**
* <p>Test adding a specifically named {@link Catalog} instance.</p>
*/
public void testSpecificCatalog() {
Catalog catalog = new CatalogBase();
factory.setCatalog(catalog);
catalog = new CatalogBase();
factory.addCatalog("foo", catalog);
assertTrue(catalog == factory.getCatalog("foo"));
assertEquals(2, getCatalogCount());
factory.addCatalog("foo", new CatalogBase());
assertEquals(2, getCatalogCount());
assertTrue(!(catalog == factory.getCatalog("foo")));
factory.clear();
assertEquals(0, getCatalogCount());
}
// ------------------------------------------------------- Support Methods
/**
* <p>Return the number of {@link Catalog}s defined in our
* {@link CatalogFactory}.</p>
*/
private int getCatalogCount() {
Iterator names = factory.getNames();
assertNotNull(names);
int n = 0;
while (names.hasNext()) {
names.next();
n++;
}
return n;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
|