You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sc...@apache.org on 2003/01/25 13:55:43 UTC
cvs commit: jakarta-commons/collections/src/test/org/apache/commons/collections TestList.java
scolebourne 2003/01/25 04:55:43
Modified: collections/src/test/org/apache/commons/collections
TestList.java
Log:
Add isSetSupported test to allow for immutable Lists
from Rich Dougherty, bug fix 15128
Revision Changes Path
1.15 +48 -13 jakarta-commons/collections/src/test/org/apache/commons/collections/TestList.java
Index: TestList.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestList.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- TestList.java 7 Nov 2002 21:32:36 -0000 1.14
+++ TestList.java 25 Jan 2003 12:55:43 -0000 1.15
@@ -1,13 +1,10 @@
/*
* $Header$
- * $Revision$
- * $Date$
- *
* ====================================================================
*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 1999-2001 The Apache Software Foundation. All rights
+ * Copyright (c) 1999-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -23,11 +20,11 @@
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
- * any, must include the following acknowlegement:
+ * any, must include the following acknowledgment:
* "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.
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
@@ -36,7 +33,7 @@
*
* 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.
+ * permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
@@ -58,7 +55,6 @@
* <http://www.apache.org/>.
*
*/
-
package org.apache.commons.collections;
import java.io.IOException;
@@ -76,7 +72,6 @@
import java.util.ListIterator;
import java.util.NoSuchElementException;
-
/**
* Tests base {@link java.util.List} methods and contracts.
* <p>
@@ -87,9 +82,11 @@
* you may still use this base set of cases. Simply override the
* test case (method) your {@link List} fails.
*
+ * @version $Revision$ $Date$
+ *
* @author Rodney Waldhoff
* @author Paul Jack
- * @version $Id$
+ * @author Stephen Colebourne
*/
public abstract class TestList extends TestCollection {
@@ -141,6 +138,18 @@
/**
+ * Returns true if the collections produced by
+ * {@link #makeCollection()} and {@link #makeFullCollection()}
+ * support the <code>set</code> operation.<p>
+ * Default implementation returns true. Override if your collection
+ * class does not support set.
+ */
+ protected boolean isSetSupported() {
+ return true;
+ }
+
+
+ /**
* Returns the {@link collection} field cast to a {@link List}.
*
* @return the collection field as a List
@@ -496,6 +505,8 @@
* empty list.
*/
public void testListSetByIndexBoundsChecking() {
+ if (!isSetSupported()) return;
+
List list = makeEmptyList();
Object element = getOtherElements()[0];
@@ -543,6 +554,8 @@
* full list.
*/
public void testListSetByIndexBoundsChecking2() {
+ if (!isSetSupported()) return;
+
List list = makeFullList();
Object element = getOtherElements()[0];
@@ -582,6 +595,8 @@
* Test {@link List#set(int,Object)}.
*/
public void testListSetByIndex() {
+ if (!isSetSupported()) return;
+
resetFull();
Object[] elements = getFullElements();
Object[] other = getOtherElements();
@@ -597,6 +612,26 @@
/**
+ * If {@link #isSetSupported()} returns false, tests that set operation
+ * raises <Code>UnsupportedOperationException.
+ */
+ public void testUnsupportedSet() {
+ if (isSetSupported()) return;
+
+ resetFull();
+ try {
+ ((List) collection).set(0, new Object());
+ fail("Emtpy collection should not support set.");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ // make sure things didn't change even if the expected exception was
+ // thrown.
+ verify();
+ }
+
+
+ /**
* Tests bounds checking for {@link List#remove(int)} on an
* empty list.
*/
@@ -834,7 +869,7 @@
* iterator.
*/
public void testListIteratorSet() {
- if (!isAddSupported()) return;
+ if (!isSetSupported()) return;
Object[] elements = getFullElements();
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>