001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Alexey A. Ivanov
019: * @version $Revision$
020: */package javax.swing.text;
021:
022: import junit.framework.TestCase;
023:
024: public class TabSetTest extends TestCase {
025: private TabSet tabSet;
026:
027: private final TabStop[] tabStops = { new TabStop(44f),
028: new TabStop(56f, TabStop.ALIGN_CENTER, TabStop.LEAD_NONE),
029: new TabStop(72f, TabStop.ALIGN_RIGHT, TabStop.LEAD_DOTS),
030: new TabStop(100f) };
031:
032: public void testEquals() {
033: assertTrue(tabSet.equals(tabSet));
034: assertFalse(tabSet.equals(null));
035: assertTrue(tabSet.equals(new TabSet(tabStops)));
036: assertFalse(tabSet.equals(new TabSet(
037: new TabStop[] { tabStops[1] })));
038: }
039:
040: public void testGetTab() {
041: for (int i = 0; i < tabStops.length; i++) {
042: assertSame(tabStops[i], tabSet.getTab(i));
043: }
044: try {
045: tabSet.getTab(-1);
046: fail("IllegalArgumentException must be thrown");
047: } catch (IllegalArgumentException e) {
048: }
049: try {
050: tabSet.getTab(tabStops.length);
051: fail("IllegalArgumentException must be thrown");
052: } catch (IllegalArgumentException e) {
053: }
054: }
055:
056: public void testGetTabAfter() {
057: assertSame(tabStops[0], tabSet.getTabAfter(0f));
058: assertSame(tabStops[2], tabSet.getTabAfter(60f));
059: assertNull(tabSet
060: .getTabAfter(tabStops[3].getPosition() + 0.01f));
061: }
062:
063: public void testGetTabCount() {
064: assertEquals(tabStops.length, tabSet.getTabCount());
065: }
066:
067: public void testGetTabIndex() {
068: assertEquals(1, tabSet.getTabIndex(tabStops[1]));
069: assertEquals(3, tabSet.getTabIndex(tabStops[3]));
070: assertEquals(-1, tabSet.getTabIndex(null));
071: assertEquals(-1, tabSet.getTabIndex(new TabStop(56f)));
072: }
073:
074: public void testGetTabIndexAfter() {
075: assertEquals(0, tabSet.getTabIndexAfter(0f));
076: assertEquals(2, tabSet.getTabIndexAfter(60f));
077: assertEquals(-1, tabSet.getTabIndexAfter(tabStops[3]
078: .getPosition() + 0.01f));
079: }
080:
081: public void testHashcode() {
082: assertEquals(tabSet.hashCode(), new TabSet(tabStops).hashCode());
083: }
084:
085: public void testTabSet() {
086: assertEquals(tabStops.length, tabSet.getTabCount());
087: for (int i = 0; i < tabStops.length; i++) {
088: assertSame(tabStops[i], tabSet.getTab(i));
089: }
090: TabStop prev = tabStops[1];
091: tabStops[1] = new TabStop(60f);
092: assertNotSame(tabStops[1], tabSet.getTab(1));
093: assertSame(prev, tabSet.getTab(1));
094: }
095:
096: public void testToString() {
097: assertEquals("[ tab @44.0 - center tab @56.0 - "
098: + "right tab @72.0 (w/leaders) - tab @100.0 ]", tabSet
099: .toString());
100: }
101:
102: @Override
103: protected void setUp() throws Exception {
104: super .setUp();
105: tabSet = new TabSet(tabStops);
106: }
107: }
|