001: /*BEGIN_COPYRIGHT_BLOCK
002: *
003: * Copyright (c) 2001-2007, JavaPLT group at Rice University (javaplt@rice.edu)
004: * All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions are met:
008: * * Redistributions of source code must retain the above copyright
009: * notice, this list of conditions and the following disclaimer.
010: * * Redistributions in binary form must reproduce the above copyright
011: * notice, this list of conditions and the following disclaimer in the
012: * documentation and/or other materials provided with the distribution.
013: * * Neither the names of DrJava, the JavaPLT group, Rice University, nor the
014: * names of its contributors may be used to endorse or promote products
015: * derived from this software without specific prior written permission.
016: *
017: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
018: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
019: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
020: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
021: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
022: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
023: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
024: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
025: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
026: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
027: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
028: *
029: * This software is Open Source Initiative approved Open Source Software.
030: * Open Source Initative Approved is a trademark of the Open Source Initiative.
031: *
032: * This file is part of DrJava. Download the current version of this project
033: * from http://www.drjava.org/ or http://sourceforge.net/projects/drjava/
034: *
035: * END_COPYRIGHT_BLOCK*/
036:
037: package edu.rice.cs.util.docnavigation;
038:
039: import junit.framework.TestCase;
040:
041: import edu.rice.cs.util.swing.Utilities;
042: import edu.rice.cs.drjava.DrJavaTestCase;
043:
044: import java.io.*;
045: import java.util.*;
046:
047: public class JListSortNavigatorTest extends DrJavaTestCase {
048:
049: protected JListSortNavigator<DummyINavigatorItem> list;
050: protected DummyINavigatorItem i1, i2, i3, i4;
051:
052: public void setUp() throws Exception {
053: super .setUp();
054:
055: list = new JListSortNavigator<DummyINavigatorItem>();
056:
057: i1 = new DummyINavigatorItem("item1");
058: i2 = new DummyINavigatorItem("item2");
059: i3 = new DummyINavigatorItem("item3");
060: i4 = new DummyINavigatorItem("item4");
061: list.addDocument(i1);
062: list.addDocument(i2);
063: list.addDocument(i3);
064: list.addDocument(i4);
065: }
066:
067: public void testTraversalOps() {
068: assertEquals("doc count test", 4, list.getDocumentCount());
069: assertSame("getFirst test", i1, list.getFirst());
070: assertSame("getLast test", i4, list.getLast());
071:
072: list.setNextChangeModelInitiated(true);
073: list.setActiveDoc(i1);
074:
075: Utilities.clearEventQueue();
076: assertSame("getCurrent test", i1, list.getCurrent());
077: assertSame("getNext test 1", i2, list.getNext(i1));
078: assertSame("getNext test 2", i3, list.getNext(i2));
079: assertSame("getNext test 3", i4, list.getNext(i3));
080:
081: assertSame("getPrevious test 1", i3, list.getPrevious(i4));
082: assertSame("getPrevious test 2", i2, list.getPrevious(i3));
083: assertSame("getPrevious test 3", i1, list.getPrevious(i2));
084:
085: assertTrue("contains test 1", list.contains(i1));
086: assertTrue("contains test 2", list.contains(i2));
087: assertTrue("contains test 3", list.contains(i3));
088: assertTrue("contains test 4", list.contains(i4));
089:
090: assertFalse("contains test 5", list
091: .contains(new DummyINavigatorItem("item1")));
092:
093: Enumeration<DummyINavigatorItem> docs = list.getDocuments();
094: DummyINavigatorItem[] docsArray = new DummyINavigatorItem[4];
095: for (int i = 0; i < 4; i++)
096: docsArray[i] = docs.nextElement();
097: assertTrue("getDocuments test", Arrays.equals(docsArray,
098: new DummyINavigatorItem[] { i1, i2, i3, i4 }));
099: }
100:
101: /**
102: * Test of getting the list of selected items.
103: * Commented out when changes from revision 4171 were reverted.
104: */
105: // public void testGetSelectedDocuments() {
106: // list.clearSelection();
107: // list.addSelectionInterval(0, 1);
108: // assertEquals("Two items should be selected", 2, list.getSelectionCount());
109: // assertEquals("Two items should be selected", 2, list.getDocumentSelectedCount());
110: // assertEquals("Zero groups should be selected", 0, list.getGroupSelectedCount());
111: // java.util.List<DummyINavigatorItem> l = list.getSelectedDocuments();
112: // assertEquals("Two items should be selected", 2, l.size());
113: // assertEquals("Wrong item 1", i1, l.get(0));
114: // assertEquals("Wrong item 2", i2, l.get(1));
115: //
116: // list.clearSelection();
117: // list.addSelectionInterval(0, 3);
118: // assertEquals("Four items should be selected", 4, list.getSelectionCount());
119: // assertEquals("Four items should be selected", 4, list.getDocumentSelectedCount());
120: // assertEquals("Zero groups should be selected", 0, list.getGroupSelectedCount());
121: // l = list.getSelectedDocuments();
122: // assertEquals("Four items should be selected", 4, l.size());
123: // assertEquals("Wrong item 1", i1, l.get(0));
124: // assertEquals("Wrong item 2", i2, l.get(1));
125: // assertEquals("Wrong item 3", i3, l.get(2));
126: // assertEquals("Wrong item 4", i4, l.get(3));
127: //
128: // list.clearSelection();
129: // list.addSelectionInterval(0, 1);
130: // list.addSelectionInterval(2, 3);
131: // assertEquals("Four items should be selected", 4, list.getSelectionCount());
132: // assertEquals("Four items should be selected", 4, list.getDocumentSelectedCount());
133: // assertEquals("Zero groups should be selected", 0, list.getGroupSelectedCount());
134: // l = list.getSelectedDocuments();
135: // assertEquals("Four items should be selected", 4, l.size());
136: // assertEquals("Wrong item 1", i1, l.get(0));
137: // assertEquals("Wrong item 2", i2, l.get(1));
138: // assertEquals("Wrong item 3", i3, l.get(2));
139: // assertEquals("Wrong item 4", i4, l.get(3));
140: //
141: // list.clearSelection();
142: // assertEquals("Zero items should be selected", 0, list.getSelectionCount());
143: // assertEquals("Zero items should be selected", 0, list.getDocumentSelectedCount());
144: // assertEquals("Zero groups should be selected", 0, list.getGroupSelectedCount());
145: // l = list.getSelectedDocuments();
146: // assertEquals("Zero items should be selected", 0, l.size());
147: // }
148: }
|