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: 1. 9 * Redistributions of source code must retain the above copyright notice, this 10 * list of conditions and the following disclaimer. 2. Redistributions in 11 * binary form must reproduce the above copyright notice, this list of 12 * conditions and the following disclaimer in the documentation and/or other 13 * materials provided with the distribution. 3. The end-user documentation 14 * included with the redistribution, if any, must include the following 15 * acknowledgment: "This product includes software developed by the ChronicJ 16 * team (http://www.chronicj.org/)." Alternately, this acknowledgment may 17 * appear in the software itself, if and wherever such third-party 18 * acknowledgments normally appear. 4. The names "ChronicJ" and "Digital Clash" 19 * not be used to endorse or promote products derived from this software 20 * without prior written permission. For written permission, please contact 21 * info@digitalclash.com. 5. Products derived from this software may not be 22 * called "ChronicJ", "Digital Clash", nor may "ChronicJ" or "Digital Clash" 23 * appear in their name, without prior written permission of Digital Clash LLC. 24 * 25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 26 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 27 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 28 * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 29 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 30 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 31 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 32 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 34 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 * ==================================================================== This 36 * product includes software developed by the by the Apache Software Foundation 37 * (http://www.apache.org/). 38 * ==================================================================== 39 */ 40 package org.chronicj.impl; 41 42 import org.chronicj.DatePrecision; 43 import org.chronicj.TemporalExpression; 44 import org.chronicj.TemporalExpressionTest; 45 import org.chronicj.TimePoint; 46 47 import java.util.Date; 48 import java.util.GregorianCalendar; 49 50 51 /*** 52 * JUnit Test for ArbitraryDateRangeTE <i>and</i> ArbitraryTimePointTE. 53 * 54 * @author <a href="mlipper@US-ABP.com">Matthew Lipper</a> 55 * 56 * @see <a href="http://junit.org">JUnit</a> 57 */ 58 public class ArbitraryTETest extends TemporalExpressionTest { 59 /* 60 * (non-Javadoc) 61 * 62 * @see org.chronicj.TemporalExpressionTest#initExpressionsAndResults(org.chronicj.DatePrecision) 63 */ 64 protected void initExpressionsAndResults(DatePrecision precision) 65 throws Exception { 66 testExpression = new TemporalExpression[2]; 67 expectedTimePoint = new TimePoint[2][2]; 68 notExpectedTimePoint = new TimePoint[2][2]; 69 70 if (DatePrecision.YEAR.equals(precision)) { 71 /* ### 1908 (January 1st)### */ 72 testExpression[0] = new ArbitraryTimePointTE(new TimePoint( 73 new GregorianCalendar(1908, 0, 1), precision)); 74 75 //1908 (December 31st) 76 expectedTimePoint[0][0] = new TimePoint(new GregorianCalendar( 77 1908, 11, 31), precision); 78 79 //1908 (January 1st) 80 expectedTimePoint[0][1] = new TimePoint(new GregorianCalendar( 81 1907, 11, 32), precision); 82 ; 83 84 //Now 85 notExpectedTimePoint[0][0] = new TimePoint(new Date()); 86 87 //1988 (March 31st) 88 notExpectedTimePoint[0][1] = new TimePoint(new GregorianCalendar( 89 1988, 2, 31), precision); 90 } else if (DatePrecision.MONTH.equals(precision)) { 91 /* ### August, 2002 ### */ 92 testExpression[0] = new ArbitraryTimePointTE(new TimePoint(2002, 8)); 93 94 //August, 2002 95 expectedTimePoint[0][0] = new TimePoint(2002, 8); 96 97 //August 28th, 2002 98 expectedTimePoint[0][1] = new TimePoint(2002, 8, 28); 99 100 //August 28th, 2001 101 notExpectedTimePoint[0][0] = new TimePoint(2001, 8, 28); 102 103 //September, 2002 104 notExpectedTimePoint[0][1] = new TimePoint(2002, 9); 105 } else if (DatePrecision.DATE.equals(precision)) { 106 /* ### February 29th, 2004### */ 107 testExpression[0] = new ArbitraryTimePointTE(new TimePoint(2004, 2, 108 29)); 109 110 //February 29th, 2004 (12am - midnight) 111 expectedTimePoint[0][0] = new TimePoint(2004, 2, 29, 00, 00); 112 113 //February 29th, 2004 (12pm - noon) 114 expectedTimePoint[0][1] = new TimePoint(2004, 2, 29, 12, 00); 115 116 //February 28th, 2004 (12am - midnight) 117 notExpectedTimePoint[0][0] = new TimePoint(2004, 2, 28, 00, 00); 118 119 //February 29th, 2000 (12pm - noon) 120 notExpectedTimePoint[0][1] = new TimePoint(2000, 2, 29, 12, 00); 121 } else if (DatePrecision.HOUR_OF_DAY.equals(precision)) { 122 /* ### 12(:00)pm April 8th, 2000 ### */ 123 testExpression[0] = new ArbitraryTimePointTE(new TimePoint( 124 new GregorianCalendar(2000, 4, 8, 12, 0), 125 DatePrecision.HOUR_OF_DAY)); 126 127 //12(:20)pm April 8th, 2000 128 expectedTimePoint[0][0] = new TimePoint(new GregorianCalendar( 129 2000, 4, 8, 12, 20), DatePrecision.HOUR_OF_DAY); 130 131 //12(:00)pm April 8th, 2000 132 expectedTimePoint[0][1] = new TimePoint(new GregorianCalendar( 133 2000, 4, 8, 12, 0), DatePrecision.HOUR_OF_DAY); 134 135 //1(:00)pm April 8th, 2000 136 notExpectedTimePoint[0][0] = new TimePoint(2000, 4, 8, 1, 00); 137 138 //12(:20)pm April 9th, 2000 139 notExpectedTimePoint[0][1] = new TimePoint(2000, 4, 9, 12, 20); 140 } else if (DatePrecision.MINUTE.equals(precision)) { 141 /* ### 12:20pm April 8th, 2000 ### */ 142 testExpression[0] = new ArbitraryTimePointTE(new TimePoint(2000, 4, 143 8, 12, 20)); 144 145 //12:20pm April 8th, 2000 146 expectedTimePoint[0][0] = new TimePoint(2000, 4, 8, 12, 20); 147 148 //12:20pm April 8th, 2000 149 expectedTimePoint[0][1] = new TimePoint(new GregorianCalendar( 150 2000, 3, 8, 12, 20)); 151 152 //12:21pm April 8th, 2000 153 notExpectedTimePoint[0][0] = new TimePoint(2000, 4, 8, 12, 21); 154 155 //12:20pm April 9th, 2000 156 notExpectedTimePoint[0][1] = new TimePoint(2000, 4, 9, 12, 20); 157 } 158 } 159 160 /* 161 * (non-Javadoc) 162 * 163 * @see org.chronicj.TemporalExpressionTest#supports(org.chronicj.DatePrecision) 164 */ 165 protected boolean supports(DatePrecision precision) 166 throws Exception { 167 if (DatePrecision.SECOND.equals(precision) || 168 DatePrecision.MILLISECOND.equals(precision)) { 169 return false; 170 } 171 172 return true; 173 } 174 }

This page was automatically generated by Maven