01: /********************************************************************************
02: * CruiseControl, a Continuous Integration Toolkit
03: * Copyright (c) 2001, ThoughtWorks, Inc.
04: * 200 E. Randolph, 25th Floor
05: * Chicago, IL 60601 USA
06: * All rights reserved.
07: *
08: * Redistribution and use in source and binary forms, with or without
09: * modification, are permitted provided that the following conditions
10: * are met:
11: *
12: * + Redistributions of source code must retain the above copyright
13: * notice, this list of conditions and the following disclaimer.
14: *
15: * + Redistributions in binary form must reproduce the above
16: * copyright notice, this list of conditions and the following
17: * disclaimer in the documentation and/or other materials provided
18: * with the distribution.
19: *
20: * + Neither the name of ThoughtWorks, Inc., CruiseControl, nor the
21: * names of its contributors may be used to endorse or promote
22: * products derived from this software without specific prior
23: * written permission.
24: *
25: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
29: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36: ********************************************************************************/package net.sourceforge.cruisecontrol.labelincrementers;
37:
38: import junit.framework.TestCase;
39:
40: public class FormattedLabelIncrementerTest extends TestCase {
41:
42: private FormattedLabelIncrementer incrementer;
43: private FormattedLabelIncrementer noPrefixIncrementer;
44:
45: public FormattedLabelIncrementerTest(String name) {
46: super (name);
47: }
48:
49: public void setUp() {
50: incrementer = new FormattedLabelIncrementer();
51: noPrefixIncrementer = new FormattedLabelIncrementer();
52: noPrefixIncrementer.setPrefix(false);
53: }
54:
55: public void testIsValidLabel() {
56: assertTrue(incrementer.isValidLabel("X_88_INT"));
57: assertTrue(noPrefixIncrementer.isValidLabel("88_INT"));
58:
59: }
60:
61: public void testInvalidLabel() {
62: assertFalse(incrementer.isValidLabel("x_y"));
63: assertFalse(incrementer.isValidLabel("x88"));
64: assertFalse(incrementer.isValidLabel("Y_88_FOO"));
65: assertFalse(noPrefixIncrementer.isValidLabel("X_88_INT"));
66: assertFalse(noPrefixIncrementer.isValidLabel("x88"));
67: assertFalse(noPrefixIncrementer.isValidLabel("88_FOO"));
68: }
69:
70: public void testIncrementLabel() {
71: assertEquals("X_89_REL", incrementer.incrementLabel("X_88_REL",
72: null));
73: assertEquals("89_REL", noPrefixIncrementer.incrementLabel(
74: "88_REL", null));
75: }
76:
77: public void testGetDefaultLabel() {
78: assertEquals("CC_1_INT", incrementer.getDefaultLabel());
79: assertTrue(incrementer.isValidLabel(incrementer
80: .getDefaultLabel()));
81: assertEquals("1_INT", noPrefixIncrementer.getDefaultLabel());
82: assertTrue(incrementer.isValidLabel(noPrefixIncrementer
83: .getDefaultLabel()));
84: }
85:
86: public void testDefaultLabel() {
87: incrementer.setDefaultLabel("FOO_69_REL");
88: assertEquals("FOO_69_REL", incrementer.getDefaultLabel());
89: incrementer.setDefaultLabel("bar_69_REL");
90: assertEquals("BAR_69_REL", incrementer.getDefaultLabel());
91: noPrefixIncrementer.setDefaultLabel("69_REL");
92: assertEquals("69_REL", noPrefixIncrementer.getDefaultLabel());
93: }
94:
95: }
|