2 * This document is a part of the source code and related artifacts
3 * for CollectionSpace, an open source collections management system
4 * for museums and related institutions:
6 * http://www.collectionspace.org
7 * http://wiki.collectionspace.org
9 * Copyright © 2009 Regents of the University of California
11 * Licensed under the Educational Community License (ECL), Version 2.0.
12 * You may not use this file except in compliance with this License.
14 * You may obtain a copy of the ECL 2.0 License at
15 * https://source.collectionspace.org/collection-space/LICENSE.txt
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
24 package org.collectionspace.services.id.test;
26 import junit.framework.TestCase;
27 import org.collectionspace.services.id.StoredValueIDGeneratorPart;
28 import org.collectionspace.services.id.StringIDGeneratorPart;
31 * StringIDGeneratorPartTest
33 * Test class for StringIDGeneratorPart.
35 * $LastChangedRevision$
38 public class StringIDGeneratorPartTest extends TestCase {
40 StoredValueIDGeneratorPart part;
42 public void testNullInitialValue() {
44 part = new StringIDGeneratorPart(null);
45 fail("Should have thrown IllegalArgumentException here");
46 } catch (IllegalArgumentException expected) {
47 // This Exception should be thrown, and thus the test should pass.
51 public void testEmptyInitialValue() {
53 part = new StringIDGeneratorPart("");
54 fail("Should have thrown IllegalArgumentException here");
55 } catch (IllegalArgumentException expected) {
56 // This Exception should be thrown, and thus the test should pass.
60 public void testGetInitialID() {
61 part = new StringIDGeneratorPart("-");
62 assertEquals("-", part.getInitialID());
65 public void testGetCurrentID() {
66 part = new StringIDGeneratorPart("- -");
67 assertEquals("- -", part.getCurrentID());
70 public void testNewID() {
71 part = new StringIDGeneratorPart("E");
72 assertEquals("E", part.newID());
73 part = new StringIDGeneratorPart("XYZ");
74 assertEquals("XYZ", part.newID());
77 public void testIsValidID() {
78 part = new StringIDGeneratorPart("-");
79 assertTrue(part.isValidID("-"));
80 part = new StringIDGeneratorPart("TE");
81 assertTrue(part.isValidID("TE"));
83 part = new StringIDGeneratorPart("-");
84 assertFalse(part.isValidID(null));
85 part = new StringIDGeneratorPart("-");
86 assertFalse(part.isValidID(""));
87 part = new StringIDGeneratorPart("-");
88 assertFalse(part.isValidID("--"));
89 part = new StringIDGeneratorPart("TE");
90 assertFalse(part.isValidID("T"));
91 part = new StringIDGeneratorPart("T");
92 assertFalse(part.isValidID("TE"));
96 public void testIsValidIDWithRegexChars() {
97 // Test chars with special meaning in regexes.
98 // @TODO Will throw a PatternSyntaxException; we need to catch this.
99 part = new StringIDGeneratorPart("*");
100 assertTrue(part.isValidID("*"));
101 part = new StringIDGeneratorPart("T*E");
102 assertTrue(part.isValidID("T*E"));
106 // @TODO: Add more tests of boundary conditions, exceptions ...