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
18 package org.collectionspace.services.id;
20 import static org.junit.Assert.fail;
21 import junit.framework.TestCase;
24 * StringIDGeneratorPartTest
26 * Test class for StringIDGeneratorPart.
28 * $LastChangedRevision$
31 public class StringIDGeneratorPartTest extends TestCase {
35 public void testNextID() {
37 part = new StringIDGeneratorPart("E");
38 assertEquals("E", part.nextID());
40 part = new StringIDGeneratorPart("XYZ");
41 assertEquals("XYZ", part.nextID());
45 public void testresetID() {
47 part = new StringIDGeneratorPart(".");
48 assertEquals(".", part.nextID());
50 assertEquals(".", part.nextID());
54 public void testInitialID() {
55 part = new StringIDGeneratorPart("-");
56 assertEquals("-", part.getInitialID());
59 public void testCurrentID() {
60 part = new StringIDGeneratorPart("- -");
61 assertEquals("- -", part.getCurrentID());
64 public void testNullInitialValue() {
67 part = new StringIDGeneratorPart(null);
68 fail("Should have thrown IllegalArgumentException here");
69 } catch (IllegalArgumentException expected) {
70 // This Exception should be thrown, and thus the test should pass.
75 public void testEmptyInitialValue() {
78 part = new StringIDGeneratorPart("");
79 fail("Should have thrown IllegalArgumentException here");
80 } catch (IllegalArgumentException expected) {
81 // This Exception should be thrown, and thus the test should pass.
86 public void testIsValidID() {
88 part = new StringIDGeneratorPart("-");
89 assertTrue(part.isValidID("-"));
91 part = new StringIDGeneratorPart("-");
92 assertFalse(part.isValidID("--"));
94 // Test chars with special meaning in regexes.
95 part = new StringIDGeneratorPart(".");
96 assertTrue(part.isValidID("."));
98 part = new StringIDGeneratorPart("TE");
99 assertTrue(part.isValidID("TE"));
101 part = new StringIDGeneratorPart("TE");
102 assertFalse(part.isValidID("T"));
104 part = new StringIDGeneratorPart("T");
105 assertFalse(part.isValidID("TE"));
107 part = new StringIDGeneratorPart("-");
108 assertFalse(part.isValidID(null));
110 part = new StringIDGeneratorPart("-");
111 assertFalse(part.isValidID(""));
115 // @TODO: Add more tests of boundary conditions, exceptions ...