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.test;
32 import com.google.protobuf.*;
34 import junit.framework.TestCase;
36 import java.util.Iterator;
37 import java.util.ListIterator;
40 * Tests for {@link UnmodifiableLazyStringList}.
42 * @author jonp@google.com (Jon Perlow)
44 public class UnmodifiableLazyStringListTest extends TestCase {
46 private static String STRING_A = "A";
47 private static String STRING_B = "B";
48 private static String STRING_C = "C";
50 private static ByteString BYTE_STRING_A = ByteString.copyFromUtf8("A");
51 private static ByteString BYTE_STRING_B = ByteString.copyFromUtf8("B");
52 private static ByteString BYTE_STRING_C = ByteString.copyFromUtf8("C");
54 public void testReadOnlyMethods() {
55 LazyStringArrayList rawList = createSampleList();
56 UnmodifiableLazyStringList list = new UnmodifiableLazyStringList(rawList);
57 assertEquals(3, list.size());
58 assertSame(STRING_A, list.get(0));
59 assertSame(STRING_B, list.get(1));
60 assertSame(STRING_C, list.get(2));
61 assertEquals(BYTE_STRING_A, list.getByteString(0));
62 assertEquals(BYTE_STRING_B, list.getByteString(1));
63 assertEquals(BYTE_STRING_C, list.getByteString(2));
66 public void testModifyMethods() {
67 LazyStringArrayList rawList = createSampleList();
68 UnmodifiableLazyStringList list = new UnmodifiableLazyStringList(rawList);
73 } catch (UnsupportedOperationException e) {
76 assertEquals(3, list.size());
81 } catch (UnsupportedOperationException e) {
84 assertEquals(3, list.size());
87 list.set(1, STRING_B);
89 } catch (UnsupportedOperationException e) {
94 public void testIterator() {
95 LazyStringArrayList rawList = createSampleList();
96 UnmodifiableLazyStringList list = new UnmodifiableLazyStringList(rawList);
98 Iterator<String> iter = list.iterator();
100 while (iter.hasNext()) {
106 } catch (UnsupportedOperationException e) {
110 assertEquals(3, count);
114 public void testListIterator() {
115 LazyStringArrayList rawList = createSampleList();
116 UnmodifiableLazyStringList list = new UnmodifiableLazyStringList(rawList);
118 ListIterator<String> iter = list.listIterator();
120 while (iter.hasNext()) {
126 } catch (UnsupportedOperationException e) {
132 } catch (UnsupportedOperationException e) {
138 } catch (UnsupportedOperationException e) {
142 assertEquals(3, count);
146 private LazyStringArrayList createSampleList() {
147 LazyStringArrayList rawList = new LazyStringArrayList();
148 rawList.add(STRING_A);
149 rawList.add(STRING_B);
150 rawList.add(STRING_C);