001: /*
002: * <copyright>
003: *
004: * Copyright 2001-2004 BBNT Solutions, LLC
005: * under sponsorship of the Defense Advanced Research Projects
006: * Agency (DARPA).
007: *
008: * You can redistribute this software and/or modify it under the
009: * terms of the Cougaar Open Source License as published on the
010: * Cougaar Open Source Website (www.cougaar.org).
011: *
012: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023: *
024: * </copyright>
025: */
026: package org.cougaar.tools.csmart.core.property.name;
027:
028: import junit.framework.*;
029:
030: /**
031: * Unit test for class SimpleName.
032: */
033: public class SimpleNameTest extends TestCase {
034:
035: private SimpleName tst = null;
036: private String name = "SimpleName";
037:
038: public SimpleNameTest(String name) {
039: super (name);
040: }
041:
042: protected void setUp() {
043: tst = new SimpleName(name);
044: }
045:
046: protected void tearDown() {
047: }
048:
049: public void testSize() {
050: assertEquals("Test size()", 1, tst.size());
051: }
052:
053: public void testGet() {
054: assertEquals("Test get()", new SimpleName(name), tst.get(0));
055:
056: // Test Exceptions
057: try {
058: tst.get(4);
059: fail("IllegalArgumentException Expected");
060: } catch (IllegalArgumentException e) {
061: }
062: }
063:
064: public void testGetPrefix() {
065: assertNull("Test getPrefix()", tst.getPrefix());
066: }
067:
068: public void testLast() {
069: assertEquals("Test last()", new SimpleName(name), tst.last());
070: }
071:
072: public void testEndsWith() {
073: assertTrue("Test endsWith()", tst
074: .endsWith(new SimpleName(name)));
075: assertTrue("Test endsWith()", !tst.endsWith(new SimpleMulti(
076: name)));
077: }
078:
079: public void testStartsWith() {
080: assertTrue("Test startsWith()", tst.startsWith(new SimpleName(
081: name)));
082: assertTrue("Test startsWith()", !tst
083: .startsWith(new SimpleMulti(name)));
084: }
085:
086: public void testEquals() {
087: assertTrue("Test equals()", tst.equals(new SimpleName(name)));
088: }
089:
090: public void testCompareTo() {
091: assertTrue("Test compareTo()", (tst.compareTo(new SimpleName(
092: name)) == 0));
093: assertTrue("Test compareTo()", (tst.compareTo(new SimpleMulti(
094: name)) > 0));
095: assertTrue("Test compareTo()", (tst.compareTo(new SimpleName(
096: "a")) < 0));
097: }
098:
099: public static Test suite() {
100: return new TestSuite(SimpleNameTest.class);
101: }
102:
103: public static void main(String[] args) {
104: junit.textui.TestRunner.run(suite());
105: }
106:
107: public class SimpleMulti extends MultiName {
108: public SimpleMulti(String name) {
109: super (new SimpleName(name));
110: }
111:
112: protected CompositeName getParentName() {
113: return new SimpleName("Parent");
114: }
115: }
116:
117: }
|