]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
41eae683221cecd6f740e8651231a6218377cd03
[tmp/jakarta-migration.git] /
1 /**
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:
5  *
6  * http://www.collectionspace.org
7  * http://wiki.collectionspace.org
8  *
9  * Copyright © 2009 Regents of the University of California
10  *
11  * Licensed under the Educational Community License (ECL), Version 2.0.
12  * You may not use this file except in compliance with this License.
13  *
14  * You may obtain a copy of the ECL 2.0 License at
15  * https://source.collectionspace.org/collection-space/LICENSE.txt
16  */
17
18 package org.collectionspace.services.id;
19
20 import static org.junit.Assert.fail;
21 import junit.framework.TestCase;
22
23 /**     
24  * StringIDGeneratorPartTest
25  *
26  * Test class for StringIDGeneratorPart.
27  *
28  * $LastChangedRevision$
29  * $LastChangedDate$
30  */
31 public class StringIDGeneratorPartTest extends TestCase {
32
33         IDGeneratorPart part;
34
35         public void testNextID() {
36
37                 part = new StringIDGeneratorPart("E");          
38                 assertEquals("E", part.nextID());       
39                 
40                 part = new StringIDGeneratorPart("XYZ");                
41                 assertEquals("XYZ", part.nextID());             
42                 
43         }
44
45         public void testresetID() {
46         
47                 part = new StringIDGeneratorPart(".");
48                 assertEquals(".", part.nextID());
49                 part.resetID();
50                 assertEquals(".", part.nextID());
51                         
52         }
53
54         public void testInitialID() {
55                 part = new StringIDGeneratorPart("-");
56                 assertEquals("-", part.getInitialID());
57         }
58
59         public void testCurrentID() {
60                 part = new StringIDGeneratorPart("- -");
61                 assertEquals("- -", part.getCurrentID());
62         }
63         
64         public void testNullInitialValue() {
65         
66                 try {
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.
71                 }
72                 
73         }
74
75         public void testEmptyInitialValue() {
76         
77                 try {
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.
82                 }
83
84         }
85
86         public void testIsValidID() {
87         
88                 part = new StringIDGeneratorPart("-");
89                 assertTrue(part.isValidID("-"));
90
91                 part = new StringIDGeneratorPart("-");
92                 assertFalse(part.isValidID("--"));
93
94                 // Test chars with special meaning in regexes.
95                 part = new StringIDGeneratorPart(".");
96                 assertTrue(part.isValidID("."));
97
98                 part = new StringIDGeneratorPart("TE");
99                 assertTrue(part.isValidID("TE"));
100
101                 part = new StringIDGeneratorPart("TE");
102                 assertFalse(part.isValidID("T"));
103
104                 part = new StringIDGeneratorPart("T");
105                 assertFalse(part.isValidID("TE"));
106
107         part = new StringIDGeneratorPart("-");
108         assertFalse(part.isValidID(null));
109         
110         part = new StringIDGeneratorPart("-");
111         assertFalse(part.isValidID(""));
112         
113         }       
114
115         // @TODO: Add more tests of boundary conditions, exceptions ...
116  
117 }