This source file includes following definitions.
- testReadOnlyMethods
- testModifyMethods
- testIterator
- testListIterator
- createSampleList
package com.google.protobuf;
import junit.framework.TestCase;
import java.util.Iterator;
import java.util.ListIterator;
public class UnmodifiableLazyStringListTest extends TestCase {
private static String STRING_A = "A";
private static String STRING_B = "B";
private static String STRING_C = "C";
private static ByteString BYTE_STRING_A = ByteString.copyFromUtf8("A");
private static ByteString BYTE_STRING_B = ByteString.copyFromUtf8("B");
private static ByteString BYTE_STRING_C = ByteString.copyFromUtf8("C");
public void testReadOnlyMethods() {
LazyStringArrayList rawList = createSampleList();
UnmodifiableLazyStringList list = new UnmodifiableLazyStringList(rawList);
assertEquals(3, list.size());
assertSame(STRING_A, list.get(0));
assertSame(STRING_B, list.get(1));
assertSame(STRING_C, list.get(2));
assertEquals(BYTE_STRING_A, list.getByteString(0));
assertEquals(BYTE_STRING_B, list.getByteString(1));
assertEquals(BYTE_STRING_C, list.getByteString(2));
}
public void testModifyMethods() {
LazyStringArrayList rawList = createSampleList();
UnmodifiableLazyStringList list = new UnmodifiableLazyStringList(rawList);
try {
list.remove(0);
fail();
} catch (UnsupportedOperationException e) {
}
assertEquals(3, list.size());
try {
list.add(STRING_B);
fail();
} catch (UnsupportedOperationException e) {
}
assertEquals(3, list.size());
try {
list.set(1, STRING_B);
fail();
} catch (UnsupportedOperationException e) {
}
}
public void testIterator() {
LazyStringArrayList rawList = createSampleList();
UnmodifiableLazyStringList list = new UnmodifiableLazyStringList(rawList);
Iterator<String> iter = list.iterator();
int count = 0;
while (iter.hasNext()) {
iter.next();
count++;
try {
iter.remove();
fail();
} catch (UnsupportedOperationException e) {
}
}
assertEquals(3, count);
}
public void testListIterator() {
LazyStringArrayList rawList = createSampleList();
UnmodifiableLazyStringList list = new UnmodifiableLazyStringList(rawList);
ListIterator<String> iter = list.listIterator();
int count = 0;
while (iter.hasNext()) {
iter.next();
count++;
try {
iter.remove();
fail();
} catch (UnsupportedOperationException e) {
}
try {
iter.set("bar");
fail();
} catch (UnsupportedOperationException e) {
}
try {
iter.add("bar");
fail();
} catch (UnsupportedOperationException e) {
}
}
assertEquals(3, count);
}
private LazyStringArrayList createSampleList() {
LazyStringArrayList rawList = new LazyStringArrayList();
rawList.add(STRING_A);
rawList.add(STRING_B);
rawList.add(STRING_C);
return rawList;
}
}