151617181920212223
public class UnmodifiableVectorTest { public static void testCreation() { Vector v=new Vector(Arrays.asList("one", "two")); UnmodifiableVector uv=new UnmodifiableVector(v); Assert.assertEquals(v.size(), uv.size()); assert uv.contains("two"); }
2324252627282930
} @Test(expectedExceptions=UnsupportedOperationException.class) public static void testAddition() { Vector v=new Vector(Arrays.asList("one", "two")); UnmodifiableVector uv=new UnmodifiableVector(v); uv.add("three"); }
3031323334353637
} @Test(expectedExceptions=UnsupportedOperationException.class) public static void testRemoval() { Vector v=new Vector(Arrays.asList("one", "two")); UnmodifiableVector uv=new UnmodifiableVector(v); uv.add("two"); }
3738394041424344454647484950515253
} @Test(expectedExceptions=UnsupportedOperationException.class) public static void testIteration() { Vector v=new Vector(Arrays.asList("one", "two")); UnmodifiableVector uv=new UnmodifiableVector(v); Object el; for(Iterator it=uv.iterator(); it.hasNext();) { el=it.next(); System.out.println(el); } for(Iterator it=uv.iterator(); it.hasNext();) { el=it.next(); it.remove(); } }
5354555657585960616263646566676869
} @Test(expectedExceptions=UnsupportedOperationException.class) public static void testListIteration() { Vector v=new Vector(Arrays.asList("one", "two")); UnmodifiableVector uv=new UnmodifiableVector(v); Object el; for(ListIterator it=uv.listIterator(); it.hasNext();) { el=it.next(); System.out.println(el); } for(ListIterator it=uv.listIterator(); it.hasNext();) { el=it.next(); it.remove(); } }
17181920212223
public void setUp() throws Exception { super.setUp(); v=new Vector(); v.add("one"); v.add("two"); uv=new UnmodifiableVector(v); }