husted 2003/01/14 14:14:18
Added: resources/src/test/org/apache/commons/resources/impl
BasicMessageTestCase.java
BasicMessageListTestCase.java
Log:
Test cases for BasicMessage and BasicMessageList.
Revision Changes Path
1.1
jakarta-commons-sandbox/resources/src/test/org/apache/commons/resources/impl/BasicMessageTestCase.java
Index: BasicMessageTestCase.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Struts", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.commons.resources.impl;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.apache.commons.resources.impl.BasicMessage;
/**
* Unit tests for the <code>org.apache.commons.resources.Message</code> class.
* <p>
* Orginally based on org.apache.http.action.TestActionMessage, Revision 1.2.
*
* @author Dominique Plante
* @version $Revision: 1.1 $ $Date: 2003/01/14 22:14:18 $
*/
public class BasicMessageTestCase extends TestCase
{
protected BasicMessage amWithNoValue = null;
protected BasicMessage amWithOneValue = null;
/**
* Defines the testcase name for JUnit.
*
* @param theName the testcase's name.
*/
public BasicMessageTestCase(String theName)
{
super(theName);
}
/**
* Start the tests.
*
* @param theArgs the arguments. Not used
*/
public static void main(String[] theArgs)
{
junit.awtui.TestRunner.main(new String[]
{BasicMessageTestCase.class.getName()});
}
/**
* @return a test suite (<code>TestSuite</code>) that includes all methods
* starting with "test"
*/
public static Test suite()
{
// All methods starting with "test" will be executed in the test suite.
return new TestSuite(BasicMessageTestCase.class);
}
public void setUp()
{
amWithNoValue = new BasicMessage("amWithNoValue");
amWithOneValue = new BasicMessage("amWithOneValue", new
String("stringValue"));
}
public void tearDown()
{
amWithNoValue = null;
}
public void testBasicMessageWithNoValue()
{
assertTrue("testBasicMessageWithNoValue value is not null",
amWithNoValue.getValues() == null);
assertTrue("testBasicMessageWithNoValue key is not amWithNoValue",
amWithNoValue.getKey() == "amWithNoValue");
}
public void testBasicMessageWithAStringValue()
{
Object [] values = amWithOneValue.getValues();
assertTrue("testBasicMessageWithAStringValue value is not null",
values != null);
assertTrue("testBasicMessageWithAStringValue value[0] is not the
string stringValue",
values[0].equals("stringValue"));
assertTrue("testBasicMessageWithAStringValue key is not
amWithOneValue",
amWithOneValue.getKey() == "amWithOneValue");
}
}
1.1
jakarta-commons-sandbox/resources/src/test/org/apache/commons/resources/impl/BasicMessageListTestCase.java
Index: BasicMessageListTestCase.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project" and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.commons.resources.impl;
import java.util.Iterator;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.apache.commons.resources.impl.BasicMessage;
import org.apache.commons.resources.impl.BasicMessageList;
import org.apache.commons.resources.Message;
import org.apache.commons.resources.MessageList;
/**
* Unit tests for the <code>org.apache.commons.resources.MessageList</code> class.
* <p>
* Originally based on org.apache.http.action.TestMessages, Revision 1.4.
*
* @author Dominique Plante
* @author David Graham
* @version $Revision: 1.1 $ $Date: 2003/01/14 22:14:18 $
*/
public class BasicMessageListTestCase extends TestCase {
protected MessageList aMsgs = null;
protected MessageList anMsgs = null;
protected Message msg1 = null;
protected Message msg2 = null;
protected Message msg3 = null;
protected Message msg4 = null;
protected Message msg5 = null;
/**
* Defines the testcase name for JUnit.
*
* @param theName the testcase's name.
*/
public BasicMessageListTestCase(String theName) {
super(theName);
}
/**
* Start the tests.
*
* @param theArgs the arguments. Not used
*/
public static void main(String[] theArgs) {
junit.awtui.TestRunner.main(new String[] {
BasicMessageListTestCase.class.getName()});
}
/**
* @return a test suite (<code>TestSuite</code>) that includes all methods
* starting with "test"
*/
public static Test suite() {
// All methods starting with "test" will be executed in the test suite.
return new TestSuite(BasicMessageListTestCase.class);
}
public void setUp() {
aMsgs = new BasicMessageList();
anMsgs = new BasicMessageList();
Object[] objs1 = new Object[] { "a", "b", "c", "d", "e" };
Object[] objs2 = new Object[] { "f", "g", "h", "i", "j" };
msg1 = new BasicMessage("aMessage", objs1);
msg2 = new BasicMessage("anMessage", objs2);
msg3 = new BasicMessage("msg3", "value1");
msg4 = new BasicMessage("msg4", "value2");
msg5 = new BasicMessage("msg5", "value3", "value4");
}
public void tearDown() {
aMsgs = null;
}
public void testEmpty() {
assertTrue("aMsgs is not empty!", aMsgs.isEmpty());
}
public void testNotEmpty() {
aMsgs.add("myProp", msg1);
assertTrue("aMsgs is empty!", aMsgs.isEmpty() == false);
}
public void testSizeWithOneProperty() {
aMsgs.add("myProp", msg1);
aMsgs.add("myProp", msg2);
assertTrue("number of mesages is not 2", aMsgs.size("myProp") == 2);
}
public void testSizeWithManyProperties() {
aMsgs.add("myProp1", msg1);
aMsgs.add("myProp2", msg2);
aMsgs.add("myProp3", msg3);
aMsgs.add("myProp3", msg4);
aMsgs.add("myProp4", msg5);
assertTrue("number of messages for myProp1 is not 1",
aMsgs.size("myProp1") == 1);
assertTrue("number of messages", aMsgs.size() == 5);
}
public void testSizeAndEmptyAfterClear() {
testSizeWithOneProperty();
aMsgs.clear();
testEmpty();
assertTrue("number of meesages is not 0", aMsgs.size("myProp") == 0);
}
public void testGetWithNoProperty() {
Iterator it = aMsgs.get("myProp");
assertTrue("iterator is not empty!", it.hasNext() == false);
}
public void testGetForAProperty() {
testSizeWithOneProperty();
Iterator it = aMsgs.get("myProp");
assertTrue("iterator is empty!", it.hasNext() == true);
}
/**
* Tests adding an MessageList object to an MessageList object.
*/
public void testAddMessages() {
Message msg1 = new BasicMessage("key");
Message msg2 = new BasicMessage("key2");
Message msg3 = new BasicMessage("key3");
MessageList msgs = new BasicMessageList();
MessageList add = new BasicMessageList();
msgs.add("prop1", msg1);
add.add("prop1", msg2);
add.add("prop3", msg3);
msgs.add(add);
assertTrue(msgs.size() == 3);
assertTrue(msgs.size("prop1") == 2);
// test message order
Iterator props = msgs.get();
int count = 1;
while (props.hasNext()) {
Message msg = (Message) props.next();
if (count == 1) {
assertTrue(msg.getKey().equals("key"));
} else if (count == 2) {
assertTrue(msg.getKey().equals("key2"));
} else {
assertTrue(msg.getKey().equals("key3"));
}
count++;
}
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>