001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.commons.collections.primitives; 018 019import junit.framework.Test; 020import junit.framework.TestCase; 021import junit.framework.TestSuite; 022 023/** 024 * @version $Revision: 480451 $ $Date: 2006-11-29 02:45:08 -0500 (Wed, 29 Nov 2006) $ 025 * @author Rodney Waldhoff 026 */ 027public class TestCharCollections extends TestCase { 028 029 //------------------------------------------------------------ Conventional 030 031 public TestCharCollections(String testName) { 032 super(testName); 033 } 034 035 public static Test suite() { 036 return new TestSuite(TestCharCollections.class); 037 } 038 039 //---------------------------------------------------------------- Tests 040 041 public void testSingletonCharListIterator() { 042 CharListIterator iter = CharCollections.singletonCharListIterator((char)17); 043 assertTrue(!iter.hasPrevious()); 044 assertTrue(iter.hasNext()); 045 assertEquals(17,iter.next()); 046 assertTrue(iter.hasPrevious()); 047 assertTrue(!iter.hasNext()); 048 assertEquals(17,iter.previous()); 049 try { 050 iter.set((char)18); 051 fail("Expected UnsupportedOperationException"); 052 } catch(UnsupportedOperationException e) { 053 // expected 054 } 055 } 056 057 public void testSingletonCharIterator() { 058 CharIterator iter = CharCollections.singletonCharIterator((char)17); 059 assertTrue(iter.hasNext()); 060 assertEquals(17,iter.next()); 061 assertTrue(!iter.hasNext()); 062 try { 063 iter.remove(); 064 fail("Expected UnsupportedOperationException"); 065 } catch(UnsupportedOperationException e) { 066 // expected 067 } 068 } 069 070 public void testSingletonCharList() { 071 CharList list = CharCollections.singletonCharList((char)17); 072 assertEquals(1,list.size()); 073 assertEquals(17,list.get(0)); 074 try { 075 list.add((char)18); 076 fail("Expected UnsupportedOperationException"); 077 } catch(UnsupportedOperationException e) { 078 // expected 079 } 080 } 081 082 public void testUnmodifiableCharListNull() { 083 try { 084 CharCollections.unmodifiableCharList(null); 085 fail("Expected NullPointerException"); 086 } catch(NullPointerException e) { 087 // expected 088 } 089 } 090 091 public void testEmptyCharList() { 092 assertSame(CharCollections.EMPTY_CHAR_LIST,CharCollections.getEmptyCharList()); 093 assertTrue(CharCollections.EMPTY_CHAR_LIST.isEmpty()); 094 try { 095 CharCollections.EMPTY_CHAR_LIST.add((char)1); 096 fail("Expected UnsupportedOperationExcpetion"); 097 } catch(UnsupportedOperationException e) { 098 // expected 099 } 100 } 101 102 public void testUnmodifiableCharIteratorNull() { 103 try { 104 CharCollections.unmodifiableCharIterator(null); 105 fail("Expected NullPointerException"); 106 } catch(NullPointerException e) { 107 // expected 108 } 109 } 110 111 public void testEmptyCharIterator() { 112 assertSame(CharCollections.EMPTY_CHAR_ITERATOR,CharCollections.getEmptyCharIterator()); 113 assertTrue(! CharCollections.EMPTY_CHAR_ITERATOR.hasNext()); 114 try { 115 CharCollections.EMPTY_CHAR_ITERATOR.remove(); 116 fail("Expected UnsupportedOperationExcpetion"); 117 } catch(UnsupportedOperationException e) { 118 // expected 119 } 120 } 121 122 public void testUnmodifiableCharListIteratorNull() { 123 try { 124 CharCollections.unmodifiableCharListIterator(null); 125 fail("Expected NullPointerException"); 126 } catch(NullPointerException e) { 127 // expected 128 } 129 } 130 131 public void testEmptyCharListIterator() { 132 assertSame(CharCollections.EMPTY_CHAR_LIST_ITERATOR,CharCollections.getEmptyCharListIterator()); 133 assertTrue(! CharCollections.EMPTY_CHAR_LIST_ITERATOR.hasNext()); 134 assertTrue(! CharCollections.EMPTY_CHAR_LIST_ITERATOR.hasPrevious()); 135 try { 136 CharCollections.EMPTY_CHAR_LIST_ITERATOR.add((char)1); 137 fail("Expected UnsupportedOperationExcpetion"); 138 } catch(UnsupportedOperationException e) { 139 // expected 140 } 141 } 142} 143