001: /*******************************************************************************
002: * Copyright (c) 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: ******************************************************************************/package org.eclipse.jface.conformance.databinding;
011:
012: import org.eclipse.core.databinding.observable.list.IObservableList;
013: import org.eclipse.jface.tests.databinding.RealmTester.CurrentRealm;
014:
015: /**
016: * Tests for IObservableList that don't require mutating the collection.
017: * <p>
018: * This class is experimental and can change at any time. It is recommended to
019: * not subclass or assume the test names will not change. The only API that is
020: * guaranteed to not change are the constructors. The tests will remain public
021: * and not final in order to allow for consumers to turn off a test if needed by
022: * subclassing.
023: * </p>
024: *
025: * @since 3.2
026: */
027: public class ObservableListContractTest extends
028: ObservableCollectionContractTest {
029: private IObservableList list;
030:
031: private IObservableCollectionContractDelegate delegate;
032:
033: /**
034: * @param delegate
035: */
036: public ObservableListContractTest(
037: IObservableCollectionContractDelegate delegate) {
038: super (delegate);
039: this .delegate = delegate;
040: }
041:
042: public ObservableListContractTest(String testName,
043: IObservableCollectionContractDelegate delegate) {
044: super (testName, delegate);
045: this .delegate = delegate;
046: }
047:
048: protected void setUp() throws Exception {
049: super .setUp();
050:
051: list = (IObservableList) getObservable();
052: }
053:
054: public void testListIterator_GetterCalled() throws Exception {
055: assertGetterCalled(new Runnable() {
056: public void run() {
057: list.listIterator();
058: }
059: }, "List.listIterator()", list);
060: }
061:
062: public void testGet_GetterCalled() throws Exception {
063: list = (IObservableList) delegate.createObservableCollection(
064: new CurrentRealm(true), 1);
065: assertGetterCalled(new Runnable() {
066: public void run() {
067: list.get(0);
068: }
069: }, "List.get(int)", list);
070: }
071:
072: public void testIndexOf_GetterCalled() throws Exception {
073: assertGetterCalled(new Runnable() {
074: public void run() {
075: list.indexOf(delegate.createElement(list));
076: }
077: }, "List.indexOf(int)", list);
078: }
079:
080: public void testLastIndexOf_GetterCalled() throws Exception {
081: assertGetterCalled(new Runnable() {
082: public void run() {
083: list.lastIndexOf(delegate.createElement(list));
084: }
085: }, "List.lastIndexOf(Object)", list);
086: }
087:
088: public void testListIteratorAtIndex_GetterCalled() throws Exception {
089: // Create a new list instead of adding an item because the list might
090: // not be mutable
091: list = (IObservableList) delegate.createObservableCollection(
092: new CurrentRealm(true), 1);
093: assertGetterCalled(new Runnable() {
094: public void run() {
095: list.listIterator(0);
096: }
097: }, "List.listIterator(int)", list);
098: }
099:
100: public void testSubList_GetterCalled() throws Exception {
101: list = (IObservableList) delegate.createObservableCollection(
102: new CurrentRealm(true), 1);
103: assertGetterCalled(new Runnable() {
104: public void run() {
105: list.subList(0, 1);
106: }
107: }, "List.subList(int, int)", list);
108: }
109: }
|