1 /* 2 * ==================================================================== The 3 * Apache Software License, Version 1.1 4 * 5 * Copyright (c) 2003 Digital Clash LLC. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions are met: 9 * 1. Redistributions of source code must retain the above copyright notice, 10 * this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. The end-user documentation included with the redistribution, if any, 15 * must include the following acknowledgment: "This product includes software 16 * developed by the ChronicJ team (http://www.chronicj.org/)." Alternately, 17 * this acknowledgment may appear in the software itself, if and wherever such 18 * third-party acknowledgments normally appear. 19 * 4. The names "ChronicJ" and "Digital Clash" not be used to endorse or 20 * promote products derived from this software without prior written 21 * permission. For written permission, please contact info@digitalclash.com. 22 * 5. Products derived from this software may not be called "ChronicJ", 23 * "Digital Clash", nor may "ChronicJ" or "Digital Clash" appear in their name, 24 * without prior written permission of Digital Clash LLC. 25 * 26 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 27 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 28 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 29 * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 30 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 31 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 32 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 33 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 35 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 * ==================================================================== This 37 * product includes software developed by the by the Apache Software Foundation 38 * (http://www.apache.org/). 39 * ==================================================================== 40 */ 41 package org.chronicj; 42 43 import junit.framework.TestCase; 44 45 import java.text.SimpleDateFormat; 46 47 import java.util.Calendar; 48 import java.util.Date; 49 50 51 /*** 52 * Base test case which should be extended by tests for this package. 53 * 54 * @author <a href="mlipper@US-ABP.com">Matthew Lipper</a> 55 */ 56 public abstract class BaseTestCase extends TestCase { 57 protected static final SimpleDateFormat sdf = new SimpleDateFormat( 58 "EEE, d MMM yyyy h:mm:ss.S a Z"); 59 60 public BaseTestCase() { 61 super(); 62 } 63 64 public BaseTestCase(String arg0) { 65 super(arg0); 66 } 67 68 protected void print(String msg, Calendar aCalendar) { 69 System.out.println(msg + sdf.format(aCalendar.getTime())); 70 } 71 72 protected void print(Calendar aCalendar) { 73 print(aCalendar.getTime()); 74 } 75 76 protected void print(DateRange aDateRange) { 77 System.out.println(aDateRange.toString()); 78 } 79 80 protected void print(String msg, DateRange aDateRange) { 81 System.out.println(msg + aDateRange.toString()); 82 } 83 84 protected void print(TimePoint aTimePoint) { 85 print(aTimePoint.getTime()); 86 } 87 88 protected void print(Date aDate) { 89 System.out.println(sdf.format(aDate)); 90 } 91 92 protected void clearToPrecision(Calendar aCalendar, int calendarConstant) { 93 print(getName() + " before: ", aCalendar); 94 95 //Normalize with fall-through 96 switch (calendarConstant) { 97 case Calendar.YEAR: 98 99 //Do nothing as this is the base precision for dates. 100 //e.g. calling: 101 //aCalendar.set(Calendar.YEAR,aCalendar.getActualMinimum(Calendar.YEAR)); 102 //would truncate, say 4:30pm, September 14th, 1934 to 103 //12:00:00am January (Feb actually?) 1st, 0001 AD after 104 //falling through the case statements below. 105 case Calendar.MONTH: 106 aCalendar.set(Calendar.MONTH, 107 aCalendar.getActualMinimum(Calendar.MONTH)); 108 109 case Calendar.DAY_OF_MONTH: 110 aCalendar.set(Calendar.DAY_OF_MONTH, 111 aCalendar.getActualMinimum(Calendar.DAY_OF_MONTH)); 112 113 case Calendar.HOUR: 114 aCalendar.set(Calendar.HOUR, 115 aCalendar.getActualMinimum(Calendar.HOUR)); 116 117 case Calendar.MINUTE: 118 aCalendar.set(Calendar.MINUTE, 119 aCalendar.getActualMinimum(Calendar.MINUTE)); 120 121 case Calendar.SECOND: 122 aCalendar.set(Calendar.SECOND, 123 aCalendar.getActualMinimum(Calendar.SECOND)); 124 125 case Calendar.MILLISECOND: 126 aCalendar.set(Calendar.MILLISECOND, 127 aCalendar.getActualMinimum(Calendar.MILLISECOND)); 128 129 default: 130 break; 131 } 132 133 print(getName() + " after: ", aCalendar); 134 } 135 }

This page was automatically generated by Maven