~ubuntu-branches/debian/stretch/protobuf/stretch

« back to all changes in this revision

Viewing changes to java/src/test/java/com/google/protobuf/UnmodifiableLazyStringListTest.java

  • Committer: Package Import Robot
  • Author(s): Robert S. Edmonds
  • Date: 2014-09-11 22:50:10 UTC
  • mfrom: (10.1.9 experimental)
  • Revision ID: package-import@ubuntu.com-20140911225010-wt4yo9dpc1fzuq5g
Tags: 2.6.0-3
Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
import junit.framework.TestCase;
34
34
 
35
35
import java.util.Iterator;
 
36
import java.util.List;
36
37
import java.util.ListIterator;
37
38
 
38
39
/**
60
61
    assertEquals(BYTE_STRING_A, list.getByteString(0));
61
62
    assertEquals(BYTE_STRING_B, list.getByteString(1));
62
63
    assertEquals(BYTE_STRING_C, list.getByteString(2));
 
64
 
 
65
    List<ByteString> byteStringList = list.asByteStringList();
 
66
    assertSame(list.getByteString(0), byteStringList.get(0));
 
67
    assertSame(list.getByteString(1), byteStringList.get(1));
 
68
    assertSame(list.getByteString(2), byteStringList.get(2));
63
69
  }
64
70
 
65
71
  public void testModifyMethods() {
88
94
    } catch (UnsupportedOperationException e) {
89
95
      // expected
90
96
    }
 
97
    assertEquals(3, list.size());
 
98
 
 
99
    List<ByteString> byteStringList = list.asByteStringList();
 
100
    try {
 
101
      byteStringList.remove(0);
 
102
      fail();
 
103
    } catch (UnsupportedOperationException e) {
 
104
      // expected
 
105
    }
 
106
    assertEquals(3, list.size());
 
107
    assertEquals(3, byteStringList.size());
 
108
 
 
109
    try {
 
110
      byteStringList.add(BYTE_STRING_B);
 
111
      fail();
 
112
    } catch (UnsupportedOperationException e) {
 
113
      // expected
 
114
    }
 
115
    assertEquals(3, list.size());
 
116
    assertEquals(3, byteStringList.size());
 
117
 
 
118
    try {
 
119
      byteStringList.set(1, BYTE_STRING_B);
 
120
      fail();
 
121
    } catch (UnsupportedOperationException e) {
 
122
      // expected
 
123
    }
 
124
    assertEquals(3, list.size());
 
125
    assertEquals(3, byteStringList.size());
91
126
  }
92
127
 
93
128
  public void testIterator() {
108
143
    }
109
144
    assertEquals(3, count);
110
145
 
 
146
    List<ByteString> byteStringList = list.asByteStringList();
 
147
    Iterator<ByteString> byteIter = byteStringList.iterator();
 
148
    count = 0;
 
149
    while (byteIter.hasNext()) {
 
150
      byteIter.next();
 
151
      count++;
 
152
      try {
 
153
        byteIter.remove();
 
154
        fail();
 
155
      } catch (UnsupportedOperationException e) {
 
156
        // expected
 
157
      }
 
158
    }
 
159
    assertEquals(3, count);
111
160
  }
112
161
 
113
162
  public void testListIterator() {
140
189
    }
141
190
    assertEquals(3, count);
142
191
 
 
192
    List<ByteString> byteStringList = list.asByteStringList();
 
193
    ListIterator<ByteString> byteIter = byteStringList.listIterator();
 
194
    count = 0;
 
195
    while (byteIter.hasNext()) {
 
196
      byteIter.next();
 
197
      count++;
 
198
      try {
 
199
        byteIter.remove();
 
200
        fail();
 
201
      } catch (UnsupportedOperationException e) {
 
202
        // expected
 
203
      }
 
204
      try {
 
205
        byteIter.set(BYTE_STRING_A);
 
206
        fail();
 
207
      } catch (UnsupportedOperationException e) {
 
208
        // expected
 
209
      }
 
210
      try {
 
211
        byteIter.add(BYTE_STRING_A);
 
212
        fail();
 
213
      } catch (UnsupportedOperationException e) {
 
214
        // expected
 
215
      }
 
216
    }
 
217
    assertEquals(3, count);
143
218
  }
144
219
 
145
220
  private LazyStringArrayList createSampleList() {