001: /********************************************************************************
002: * CruiseControl, a Continuous Integration Toolkit
003: * Copyright (c) 2001, ThoughtWorks, Inc.
004: * 200 E. Randolph, 25th Floor
005: * Chicago, IL 60601 USA
006: * All rights reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: *
012: * + Redistributions of source code must retain the above copyright
013: * notice, this list of conditions and the following disclaimer.
014: *
015: * + Redistributions in binary form must reproduce the above
016: * copyright notice, this list of conditions and the following
017: * disclaimer in the documentation and/or other materials provided
018: * with the distribution.
019: *
020: * + Neither the name of ThoughtWorks, Inc., CruiseControl, nor the
021: * names of its contributors may be used to endorse or promote
022: * products derived from this software without specific prior
023: * written permission.
024: *
025: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
026: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
027: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
028: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
029: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
030: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
031: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
032: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
033: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
034: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
035: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
036: ********************************************************************************/package net.sourceforge.cruisecontrol;
037:
038: import java.util.Calendar;
039: import java.util.Date;
040: import java.util.Map;
041:
042: import org.jdom.Element;
043:
044: import junit.framework.TestCase;
045:
046: /**
047: * @author jfredrick
048: */
049: public class BuilderTest extends TestCase {
050:
051: private Builder builder;
052: private final Calendar nov22nd2001;
053:
054: public BuilderTest(String name) {
055: super (name);
056: nov22nd2001 = Calendar.getInstance();
057: nov22nd2001.set(2001, Calendar.NOVEMBER, 22, 10, 1, 1);
058: }
059:
060: protected void setUp() throws Exception {
061: builder = new TestBuilder();
062: }
063:
064: public void testValidate() throws CruiseControlException {
065: try {
066: builder.validate();
067: } catch (CruiseControlException e) {
068: fail("no required attributes");
069: }
070:
071: builder.setTime("0000");
072: builder.validate();
073:
074: builder.setMultiple(1);
075: try {
076: builder.validate();
077: fail("can't set both time and multiple");
078: } catch (CruiseControlException e) {
079: // should throw exception
080: }
081:
082: builder.setTime("-1");
083: builder.validate();
084: }
085:
086: public void testIsValidDay() {
087: Date thursday = nov22nd2001.getTime();
088:
089: assertTrue(builder.isValidDay(thursday));
090:
091: builder.setDay("wednesday");
092: assertTrue(!builder.isValidDay(thursday));
093:
094: builder.setDay("thursday");
095: assertTrue(builder.isValidDay(thursday));
096: }
097:
098: public void testGetMultiple() {
099: assertEquals(1, builder.getMultiple());
100: builder.setTime("0100");
101: assertEquals(-1, builder.getMultiple());
102: }
103:
104: class TestBuilder extends Builder {
105: public Element build(Map properties, Progress progress)
106: throws CruiseControlException {
107: return null;
108: }
109:
110: public Element buildWithTarget(Map properties, String target,
111: Progress progress) throws CruiseControlException {
112: return null;
113: }
114: }
115: }
|