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 TestByteCollections extends TestCase { 028 029 //------------------------------------------------------------ Conventional 030 031 public TestByteCollections(String testName) { 032 super(testName); 033 } 034 035 public static Test suite() { 036 return new TestSuite(TestByteCollections.class); 037 } 038 039 //---------------------------------------------------------------- Tests 040 041 public void testSingletonByteListIterator() { 042 ByteListIterator iter = ByteCollections.singletonByteListIterator((byte)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((byte)18); 051 fail("Expected UnsupportedOperationException"); 052 } catch(UnsupportedOperationException e) { 053 // expected 054 } 055 } 056 057 public void testSingletonByteIterator() { 058 ByteIterator iter = ByteCollections.singletonByteIterator((byte)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 testSingletonByteList() { 071 ByteList list = ByteCollections.singletonByteList((byte)17); 072 assertEquals(1,list.size()); 073 assertEquals(17,list.get(0)); 074 try { 075 list.add((byte)18); 076 fail("Expected UnsupportedOperationException"); 077 } catch(UnsupportedOperationException e) { 078 // expected 079 } 080 } 081 082 public void testUnmodifiableByteListNull() { 083 try { 084 ByteCollections.unmodifiableByteList(null); 085 fail("Expected NullPointerException"); 086 } catch(NullPointerException e) { 087 // expected 088 } 089 } 090 091 public void testEmptyByteList() { 092 assertSame(ByteCollections.EMPTY_BYTE_LIST,ByteCollections.getEmptyByteList()); 093 assertTrue(ByteCollections.EMPTY_BYTE_LIST.isEmpty()); 094 try { 095 ByteCollections.EMPTY_BYTE_LIST.add((byte)1); 096 fail("Expected UnsupportedOperationExcpetion"); 097 } catch(UnsupportedOperationException e) { 098 // expected 099 } 100 } 101 102 public void testUnmodifiableByteIteratorNull() { 103 try { 104 ByteCollections.unmodifiableByteIterator(null); 105 fail("Expected NullPointerException"); 106 } catch(NullPointerException e) { 107 // expected 108 } 109 } 110 111 public void testEmptyByteIterator() { 112 assertSame(ByteCollections.EMPTY_BYTE_ITERATOR,ByteCollections.getEmptyByteIterator()); 113 assertTrue(! ByteCollections.EMPTY_BYTE_ITERATOR.hasNext()); 114 try { 115 ByteCollections.EMPTY_BYTE_ITERATOR.remove(); 116 fail("Expected UnsupportedOperationExcpetion"); 117 } catch(UnsupportedOperationException e) { 118 // expected 119 } 120 } 121 122 public void testUnmodifiableByteListIteratorNull() { 123 try { 124 ByteCollections.unmodifiableByteListIterator(null); 125 fail("Expected NullPointerException"); 126 } catch(NullPointerException e) { 127 // expected 128 } 129 } 130 131 public void testEmptyByteListIterator() { 132 assertSame(ByteCollections.EMPTY_BYTE_LIST_ITERATOR,ByteCollections.getEmptyByteListIterator()); 133 assertTrue(! ByteCollections.EMPTY_BYTE_LIST_ITERATOR.hasNext()); 134 assertTrue(! ByteCollections.EMPTY_BYTE_LIST_ITERATOR.hasPrevious()); 135 try { 136 ByteCollections.EMPTY_BYTE_LIST_ITERATOR.add((byte)1); 137 fail("Expected UnsupportedOperationExcpetion"); 138 } catch(UnsupportedOperationException e) { 139 // expected 140 } 141 } 142} 143