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; 41 42 43 /*** 44 * JUnit Test for <code>DatePrecision</code>. 45 * 46 * @author <a href="mlipper@US-ABP.com">Matthew Lipper</a> 47 * 48 * @see <a href="http://junit.org">JUnit</a> 49 */ 50 public class DatePrecisionTest extends BaseTestCase { 51 public void testCompareTo() { 52 assertTrue(-1 == DatePrecision.YEAR.compareTo(DatePrecision.MONTH)); 53 assertTrue(-1 == DatePrecision.MONTH.compareTo(DatePrecision.DATE)); 54 assertTrue(-1 == DatePrecision.DATE.compareTo(DatePrecision.HOUR_OF_DAY)); 55 assertTrue(-1 == DatePrecision.HOUR_OF_DAY.compareTo( 56 DatePrecision.MINUTE)); 57 assertTrue(-1 == DatePrecision.MINUTE.compareTo(DatePrecision.SECOND)); 58 assertTrue(-1 == DatePrecision.SECOND.compareTo( 59 DatePrecision.MILLISECOND)); 60 61 assertTrue(0 == DatePrecision.YEAR.compareTo(DatePrecision.YEAR)); 62 assertTrue(0 == DatePrecision.MONTH.compareTo(DatePrecision.MONTH)); 63 assertTrue(0 == DatePrecision.DATE.compareTo(DatePrecision.DATE)); 64 assertTrue(0 == DatePrecision.HOUR_OF_DAY.compareTo( 65 DatePrecision.HOUR_OF_DAY)); 66 assertTrue(0 == DatePrecision.MINUTE.compareTo(DatePrecision.MINUTE)); 67 assertTrue(0 == DatePrecision.SECOND.compareTo(DatePrecision.SECOND)); 68 assertTrue(0 == DatePrecision.MILLISECOND.compareTo( 69 DatePrecision.MILLISECOND)); 70 71 assertTrue(1 == DatePrecision.MILLISECOND.compareTo( 72 DatePrecision.SECOND)); 73 assertTrue(1 == DatePrecision.SECOND.compareTo(DatePrecision.MINUTE)); 74 assertTrue(1 == DatePrecision.MINUTE.compareTo( 75 DatePrecision.HOUR_OF_DAY)); 76 assertTrue(1 == DatePrecision.HOUR_OF_DAY.compareTo(DatePrecision.DATE)); 77 assertTrue(1 == DatePrecision.DATE.compareTo(DatePrecision.MONTH)); 78 assertTrue(1 == DatePrecision.MONTH.compareTo(DatePrecision.YEAR)); 79 } 80 81 public void testIncrement() { 82 //DatePrecision.YEAR 83 TimePoint temp = new TimePoint(1900, 12, 31); 84 TimePoint yearPrecision = temp.toPrecison(DatePrecision.YEAR); 85 TimePoint yrResult = yearPrecision.increment(-5); 86 assertTrue(yrResult.getYear() == 1895); 87 88 //DatePrecision.MONTH 89 TimePoint monthPrecision = new TimePoint(2100, 1); 90 TimePoint monResult = monthPrecision.increment(-1); 91 92 //Flying cars, etc. 93 assertTrue(monResult.getYear() == 2099); 94 95 //DatePrecision.DATE 96 TimePoint datePrecision = new TimePoint(2003, 12, 31); 97 TimePoint dpResult = datePrecision.increment(2); 98 assertTrue(dpResult.getDayOfMonth() == 2); 99 100 //DatePrecision.HOUR_OF_DAY 101 TimePoint hourPrecision = new TimePoint(2004, 11, 13, 1); 102 TimePoint hResult = hourPrecision.increment(-3); 103 assertTrue(hResult.getHourOfDay() == 22); 104 105 //DatePrecision.MINUTE 106 TimePoint minutePrecision = new TimePoint(2003, 5, 8, 12, 56); 107 TimePoint minResult = minutePrecision.increment(120); 108 assertTrue(minResult.getMinute() == 56); 109 assertTrue(minResult.getHourOfDay() == 14); 110 111 //TODO DatePrecision.SECOND 112 //TODO DatePrecision.MILLISECOND 113 } 114 115 public void testEquals() { 116 assertTrue(DatePrecision.SECOND.equals(DatePrecision.SECOND)); 117 assertTrue(!DatePrecision.SECOND.equals(DatePrecision.MONTH)); 118 119 assertTrue(DatePrecision.YEAR.equals(DatePrecision.YEAR)); 120 assertTrue(!DatePrecision.YEAR.equals(DatePrecision.DATE)); 121 122 assertTrue(DatePrecision.MONTH.equals(DatePrecision.MONTH)); 123 assertTrue(!DatePrecision.MONTH.equals(DatePrecision.SECOND)); 124 125 assertTrue(DatePrecision.DATE.equals(DatePrecision.DATE)); 126 assertTrue(!DatePrecision.DATE.equals(DatePrecision.HOUR_OF_DAY)); 127 128 assertTrue(DatePrecision.HOUR_OF_DAY.equals(DatePrecision.HOUR_OF_DAY)); 129 assertTrue(!DatePrecision.HOUR_OF_DAY.equals(DatePrecision.MILLISECOND)); 130 131 assertTrue(DatePrecision.MINUTE.equals(DatePrecision.MINUTE)); 132 assertTrue(!DatePrecision.MINUTE.equals(DatePrecision.YEAR)); 133 134 assertTrue(DatePrecision.SECOND.equals(DatePrecision.SECOND)); 135 assertTrue(!DatePrecision.SECOND.equals(DatePrecision.MINUTE)); 136 137 assertTrue(DatePrecision.MILLISECOND.equals(DatePrecision.MILLISECOND)); 138 assertTrue(!DatePrecision.MILLISECOND.equals(DatePrecision.MONTH)); 139 } 140 }

This page was automatically generated by Maven