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: package org.apache.ivy.core.module.id;
019:
020: import junit.framework.TestCase;
021:
022: public class ModuleIdTest extends TestCase {
023:
024: public void testModuleId() {
025: String org = "apache";
026: String name = "some-new-module";
027: ModuleId moduleId = new ModuleId(org, name);
028:
029: assertEquals(org, moduleId.getOrganisation());
030: assertEquals(name, moduleId.getName());
031: }
032:
033: public void testModuleIdIllegalArgumentException() {
034: String org = "apache";
035: String name = "some-new-module";
036:
037: try {
038: new ModuleId(null, name);
039: } catch (IllegalArgumentException iae) {
040: fail("A null should be allowed for argument 'org'.");
041: }
042:
043: try {
044: new ModuleId(org, null);
045: fail("A IllegalArgumentException should have been thrown for the argument 'name'.");
046: } catch (IllegalArgumentException iae) {
047: // success
048: }
049: }
050:
051: public void testEqualsObjectTrue() {
052: String org = "apache";
053: String name = "some-new-module";
054: ModuleId moduleId = new ModuleId(org, name);
055: ModuleId moduleId2 = new ModuleId(org, name);
056:
057: assertTrue(moduleId.equals(moduleId));
058: assertTrue(moduleId.equals(moduleId2));
059: assertTrue(moduleId2.equals(moduleId));
060: }
061:
062: public void testEqualsObjectFalse() {
063: String org = "apache";
064: String name = "some-new-module";
065: ModuleId moduleId = new ModuleId(org, name);
066: ModuleId moduleId2 = new ModuleId(null, name);
067:
068: assertFalse(moduleId.equals(null));
069: assertFalse(moduleId.equals(moduleId2));
070: assertFalse(moduleId2.equals(moduleId));
071: }
072:
073: public void testEncodeToString() {
074: String org = "apache";
075: String name = "some-new-module";
076: ModuleId moduleId = new ModuleId(org, name);
077:
078: assertEquals(org + ModuleId.ENCODE_SEPARATOR + name, moduleId
079: .encodeToString());
080: }
081:
082: public void testDecode() {
083: String org = "apache";
084: String name = "some-new-module";
085: ModuleId moduleId = new ModuleId(org, name);
086:
087: ModuleId moduleId2 = ModuleId.decode(moduleId.encodeToString());
088: assertEquals(moduleId, moduleId2);
089: }
090:
091: public void testCompareToNullObject() {
092: String org = "apache";
093: String name = "some-new-module";
094: ModuleId moduleId = new ModuleId(org, name);
095:
096: try {
097: moduleId.compareTo(null);
098: fail("A NullPointerException was expected.");
099: } catch (NullPointerException npe) {
100: // success
101: }
102: }
103:
104: public void testCompareToOtherObject() {
105: String org = "apache";
106: String name = "some-new-module";
107: ModuleId moduleId = new ModuleId(org, name);
108:
109: try {
110: moduleId.compareTo(new String());
111: fail("A ClassCastException was expected.");
112: } catch (ClassCastException cce) {
113: // success
114: }
115: }
116:
117: public void testCompareToEqual() {
118: String org = "apache";
119: String name = "some-new-module";
120: ModuleId moduleId = new ModuleId(org, name);
121:
122: assertTrue(moduleId.compareTo(new ModuleId(org, name)) == 0);
123: }
124:
125: public void testCompareToLessThan() {
126: String org = "apache";
127: String name = "some-new-module";
128: ModuleId moduleId = new ModuleId(org, name);
129: String name2 = "the-new-module";
130: ModuleId moduleId2 = new ModuleId(org, name2);
131: System.out.println(moduleId + "\n" + moduleId2);
132:
133: assertTrue(moduleId.compareTo(moduleId2) < 0);
134: }
135:
136: public void testCompareToGreatherThan() {
137: String org = "apache";
138: String name = "some-new-module";
139: ModuleId moduleId = new ModuleId(org, name);
140: String name2 = "the-new-module";
141: ModuleId moduleId2 = new ModuleId(org, name2);
142: System.out.println(moduleId + "\n" + moduleId2);
143:
144: assertTrue(moduleId2.compareTo(moduleId) > 0);
145: }
146: }
|