/tst/org/diffkit/diff/diffor/tst/TestDateDiffor.groovy
Groovy | 67 lines | 33 code | 15 blank | 19 comment | 0 complexity | bd0576da1aadca1001cb9fa86498e771 MD5 | raw file
1/** 2 * Copyright 2010-2011 Joseph Panico 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16package org.diffkit.diff.diffor.tst 17 18 19 20import org.apache.commons.lang.time.DateUtils; 21 22import org.diffkit.common.DKCalendarSpan; 23import org.diffkit.diff.diffor.DKDateDiffor 24 25import groovy.util.GroovyTestCase; 26 27 28/** 29 * @author jpanico 30 */ 31public class TestDateDiffor extends GroovyTestCase { 32 33 public void testDiff(){ 34 35 def now = new Date() 36 assert ! new DKDateDiffor().isDiff( null, null, null) 37 assert new DKDateDiffor().isDiff( now, null, null) 38 assert new DKDateDiffor().isDiff( null, now, null) 39 assert ! new DKDateDiffor().isDiff( now, now, null) 40 def threeDaysFromNow = DateUtils.addDays( now , 3) 41 // in case of daylight savings time 42 threeDaysFromNow = DateUtils.addHours( threeDaysFromNow , -1) 43 assert new DKDateDiffor().isDiff( now, threeDaysFromNow, null) 44 assert new DKDateDiffor().isDiff( threeDaysFromNow, now, null) 45 46 def tolerance = new DKCalendarSpan(3, DKCalendarSpan.Unit.DAY); 47 48 assert ! new DKDateDiffor(tolerance).isDiff( null, null, null) 49 assert new DKDateDiffor(tolerance).isDiff( now, null, null) 50 assert new DKDateDiffor(tolerance).isDiff( null, now, null) 51 assert ! new DKDateDiffor(tolerance).isDiff( now, now, null) 52 assert ! new DKDateDiffor(tolerance).isDiff( now, threeDaysFromNow, null) 53 assert ! new DKDateDiffor(tolerance).isDiff( threeDaysFromNow, now, null) 54 55 tolerance = new DKCalendarSpan(2, DKCalendarSpan.Unit.DAY); 56 assert ! new DKDateDiffor(tolerance).isDiff( now, now, null) 57 assert new DKDateDiffor(tolerance).isDiff( now, threeDaysFromNow, null) 58 assert new DKDateDiffor(tolerance).isDiff( threeDaysFromNow, now, null) 59 60 tolerance = new DKCalendarSpan(4, DKCalendarSpan.Unit.DAY); 61 assert ! new DKDateDiffor(tolerance).isDiff( now, now, null) 62 assert ! new DKDateDiffor(tolerance).isDiff( now, threeDaysFromNow, null) 63 assert ! new DKDateDiffor(tolerance).isDiff( threeDaysFromNow, now, null) 64 65 } 66 67}