froehlich 02/01/20 05:59:37
Added: simplestore/src/test/org/apache/commons/simplestore
TestObject.java TestMRUMemoryStore.java
TestMap.java TestAll.java
Log:
added junit test cases
Revision Changes Path
1.1
jakarta-commons-sandbox/simplestore/src/test/org/apache/commons/simplestore/TestObject.java
Index: TestObject.java
===================================================================
/*****************************************************************************
* Copyright (C) The Apache Software Foundation. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Apache Software License *
* version 1.1, a copy of which has been included with this distribution in *
* the LICENSE file. *
*****************************************************************************/
package org.apache.commons.simplestore;
import junit.framework.*;
import java.util.Collection;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.NoSuchElementException;
/**
* @author Gerhard Froehlich <a href="mailto:[EMAIL PROTECTED]">
* [EMAIL PROTECTED]</a>
*
* @version $Id: TestObject.java,v 1.1 2002/01/20 13:59:36 froehlich Exp $
*/
public abstract class TestObject extends TestCase {
public TestObject(String testName) {
super(testName);
}
/**
* Return a new, empty {@link Object} to used for testing.
*/
public abstract Object makeObject();
public void testObjectEqualsSelf() {
Object obj = makeObject();
assertEquals("A Object should equal itself",obj,obj);
}
public void testObjectHashCodeEqualsSelfHashCode() {
Object obj = makeObject();
assertEquals("hashCode should be repeatable",obj.hashCode(),obj.hashCode());
}
public void testObjectHashCodeEqualsContract() {
Object obj1 = makeObject();
if(obj1.equals(obj1)) {
assertEquals("[1] When two objects are equal, their hashCodes should be
also.",obj1.hashCode(),obj1.hashCode());
}
Object obj2 = makeObject();
if(obj1.equals(obj2)) {
assertEquals("[2] When two objects are equal, their hashCodes should be
also.",obj1.hashCode(),obj2.hashCode());
}
}
}
1.1
jakarta-commons-sandbox/simplestore/src/test/org/apache/commons/simplestore/TestMRUMemoryStore.java
Index: TestMRUMemoryStore.java
===================================================================
/*****************************************************************************
* Copyright (C) The Apache Software Foundation. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Apache Software License *
* version 1.1, a copy of which has been included with this distribution in *
* the LICENSE file. *
*****************************************************************************/
package org.apache.commons.simplestore;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import java.util.Map;
import java.util.HashMap;
/**
* @author Gerhard Froehlich <a href="mailto:[EMAIL PROTECTED]">
* [EMAIL PROTECTED]</a>
* @version $Id: TestMRUMemoryStore.java,v 1.1 2002/01/20 13:59:36 froehlich Exp $
*/
public class TestMRUMemoryStore extends TestMap
{
public TestMRUMemoryStore(String testName) {
super(testName);
}
public static Test suite() {
return new TestSuite(TestMRUMemoryStore.class);
}
public static void main(String args[]) {
String[] testCaseName = { TestMRUMemoryStore.class.getName() };
junit.textui.TestRunner.main(testCaseName);
}
public Map makeMap() {
MRUMemoryStore store = new MRUMemoryStore(10);
return store;
}
public void setUp() {
map = makeMap();
}
public void testNewMap() {
assertTrue("New map is empty", map.isEmpty());
assertEquals("New map has size zero", map.size(), 0);
}
public void testSearch() {
map.put("first", "First Item");
map.put("second", "Second Item");
assertEquals("Top item is 'Second Item'", map.get("first"), "First Item");
assertEquals("Next Item is 'First Item'", map.get("second"), "Second Item");
}
}
1.1
jakarta-commons-sandbox/simplestore/src/test/org/apache/commons/simplestore/TestMap.java
Index: TestMap.java
===================================================================
/*****************************************************************************
* Copyright (C) The Apache Software Foundation. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Apache Software License *
* version 1.1, a copy of which has been included with this distribution in *
* the LICENSE file. *
*****************************************************************************/
package org.apache.commons.simplestore;
import junit.framework.*;
import java.util.Map;
import java.util.Collection;
/**
* @author Gerhard Froehlich <a href="mailto:[EMAIL PROTECTED]">
* [EMAIL PROTECTED]</a>
*
* @version $Id: TestMap.java,v 1.1 2002/01/20 13:59:36 froehlich Exp $
*/
public abstract class TestMap extends TestObject {
public TestMap(String testName) {
super(testName);
}
protected Map map = null;
/**
* Return a new, empty {@link Map} to used for testing.
*/
public abstract Map makeMap();
public Object makeObject() {
return makeMap();
}
/**
* Try to put the given pair into the given Collection.
*
* Fails any Throwable except UnsupportedOperationException,
* ClassCastException, or IllegalArgumentException
* or NullPointerException is thrown.
*/
protected Object tryToPut(Map map, Object key, Object val) {
try {
return map.put(key,val);
} catch(UnsupportedOperationException e) {
return null;
} catch(ClassCastException e) {
return null;
} catch(IllegalArgumentException e) {
return null;
} catch(NullPointerException e) {
return null;
} catch(Throwable t) {
t.printStackTrace();
fail("Map.put should only throw UnsupportedOperationException,
ClassCastException, IllegalArgumentException or NullPointerException. Found " +
t.toString());
return null; // never get here, since fail throws exception
}
}
}
1.1
jakarta-commons-sandbox/simplestore/src/test/org/apache/commons/simplestore/TestAll.java
Index: TestAll.java
===================================================================
/*****************************************************************************
* Copyright (C) The Apache Software Foundation. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Apache Software License *
* version 1.1, a copy of which has been included with this distribution in *
* the LICENSE file. *
*****************************************************************************/
package org.apache.commons.simplestore;
import junit.framework.*;
/**
* @author Gerhard Froehlich <a href="mailto:[EMAIL PROTECTED]">
* [EMAIL PROTECTED]</a>
* @version $Id: TestAll.java,v 1.1 2002/01/20 13:59:36 froehlich Exp $
*/
public class TestAll extends TestCase {
public TestAll(String testName) {
super(testName);
}
public static Test suite() {
TestSuite suite = new TestSuite();
//suite.addTest(TestSoftRefMemoryStore.suite());
suite.addTest(TestMRUMemoryStore.suite());
//suite.addTest(JispFilesystemStore.suite());
return suite;
}
public static void main(String args[]) {
String[] testCaseName = { TestAll.class.getName() };
junit.textui.TestRunner.main(testCaseName);
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>