01: /*******************************************************************************
02: * Copyright (c) 2005, 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.core.tests.internal.databinding;
11:
12: import java.util.LinkedList;
13: import java.util.List;
14:
15: import junit.framework.TestCase;
16:
17: import org.eclipse.core.internal.databinding.RandomAccessListIterator;
18:
19: public class RandomAccessListIteratorTest extends TestCase {
20:
21: private List emptyList = new LinkedList();
22: private RandomAccessListIterator rali0 = new RandomAccessListIterator(
23: emptyList);
24: private List listWithOne;
25: private RandomAccessListIterator rali1;
26: private List list;
27: private RandomAccessListIterator raliN;
28:
29: protected void setUp() throws Exception {
30: listWithOne = new LinkedList();
31: listWithOne.add("Uno");
32: rali1 = new RandomAccessListIterator(listWithOne);
33: list = new LinkedList();
34: list.add("One");
35: list.add("Two");
36: list.add("three");
37: list.add("four");
38: raliN = new RandomAccessListIterator(list);
39: }
40:
41: public void testGet_emptyList() {
42: try {
43: rali0.get(0);
44: fail("Should have thrown exception");
45: } catch (IndexOutOfBoundsException e) {
46: // success
47: }
48: }
49:
50: public void testGet_withOne() {
51: try {
52: assertEquals("Uno", "Uno", rali1.get(0));
53:
54: rali1.get(1);
55: fail("Should have thrown IndexOutOfBoundsException");
56: } catch (Exception e) {
57: // success
58: }
59: }
60:
61: public void testGet_alreadyAtItem() {
62: assertEquals("one", "One", raliN.get(0));
63: }
64:
65: public void testGet_moveForward() throws Exception {
66: assertEquals("three", "three", raliN.get(2));
67: }
68:
69: public void testGet_moveBackward() throws Exception {
70: raliN.next();
71: raliN.next();
72: assertEquals("one", "One", raliN.get(0));
73: }
74:
75: public void testGet_getLast() throws Exception {
76: assertEquals("four", "four", raliN.get(3));
77: }
78:
79: public void testGet_indexTooHigh() throws Exception {
80: try {
81: raliN.get(4);
82: fail("Should have thrown exception");
83: } catch (IndexOutOfBoundsException e) {
84: // success
85: }
86: }
87:
88: public void testGet_indexTooLow() throws Exception {
89: try {
90: raliN.get(-100);
91: fail("Should have thrown exception");
92: } catch (IndexOutOfBoundsException e) {
93: // success
94: }
95: }
96:
97: }
|