1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved.
3 // http://code.google.com/p/protobuf/
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above
12 // copyright notice, this list of conditions and the following disclaimer
13 // in the documentation and/or other materials provided with the
15 // * Neither the name of Google Inc. nor the names of its
16 // contributors may be used to endorse or promote products derived from
17 // this software without specific prior written permission.
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 package com.google.protobuf;
33 import junit.framework.TestCase;
35 import java.util.Iterator;
36 import java.util.ListIterator;
39 * Tests for {@link UnmodifiableLazyStringList}.
41 * @author jonp@google.com (Jon Perlow)
43 public class UnmodifiableLazyStringListTest extends TestCase {
45 private static String STRING_A = "A";
46 private static String STRING_B = "B";
47 private static String STRING_C = "C";
49 private static ByteString BYTE_STRING_A = ByteString.copyFromUtf8("A");
50 private static ByteString BYTE_STRING_B = ByteString.copyFromUtf8("B");
51 private static ByteString BYTE_STRING_C = ByteString.copyFromUtf8("C");
53 public void testReadOnlyMethods() {
54 LazyStringArrayList rawList = createSampleList();
55 UnmodifiableLazyStringList list = new UnmodifiableLazyStringList(rawList);
56 assertEquals(3, list.size());
57 assertSame(STRING_A, list.get(0));
58 assertSame(STRING_B, list.get(1));
59 assertSame(STRING_C, list.get(2));
60 assertEquals(BYTE_STRING_A, list.getByteString(0));
61 assertEquals(BYTE_STRING_B, list.getByteString(1));
62 assertEquals(BYTE_STRING_C, list.getByteString(2));
65 public void testModifyMethods() {
66 LazyStringArrayList rawList = createSampleList();
67 UnmodifiableLazyStringList list = new UnmodifiableLazyStringList(rawList);
72 } catch (UnsupportedOperationException e) {
75 assertEquals(3, list.size());
80 } catch (UnsupportedOperationException e) {
83 assertEquals(3, list.size());
86 list.set(1, STRING_B);
88 } catch (UnsupportedOperationException e) {
93 public void testIterator() {
94 LazyStringArrayList rawList = createSampleList();
95 UnmodifiableLazyStringList list = new UnmodifiableLazyStringList(rawList);
97 Iterator<String> iter = list.iterator();
99 while (iter.hasNext()) {
105 } catch (UnsupportedOperationException e) {
109 assertEquals(3, count);
113 public void testListIterator() {
114 LazyStringArrayList rawList = createSampleList();
115 UnmodifiableLazyStringList list = new UnmodifiableLazyStringList(rawList);
117 ListIterator<String> iter = list.listIterator();
119 while (iter.hasNext()) {
125 } catch (UnsupportedOperationException e) {
131 } catch (UnsupportedOperationException e) {
137 } catch (UnsupportedOperationException e) {
141 assertEquals(3, count);
145 private LazyStringArrayList createSampleList() {
146 LazyStringArrayList rawList = new LazyStringArrayList();
147 rawList.add(STRING_A);
148 rawList.add(STRING_B);
149 rawList.add(STRING_C);