/tst/org/diffkit/diff/diffor/tst/TestDateDiffor.groovy

http://diffkit.googlecode.com/ · 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. */
  16. package org.diffkit.diff.diffor.tst
  17. import org.apache.commons.lang.time.DateUtils;
  18. import org.diffkit.common.DKCalendarSpan;
  19. import org.diffkit.diff.diffor.DKDateDiffor
  20. import groovy.util.GroovyTestCase;
  21. /**
  22. * @author jpanico
  23. */
  24. public class TestDateDiffor extends GroovyTestCase {
  25. public void testDiff(){
  26. def now = new Date()
  27. assert ! new DKDateDiffor().isDiff( null, null, null)
  28. assert new DKDateDiffor().isDiff( now, null, null)
  29. assert new DKDateDiffor().isDiff( null, now, null)
  30. assert ! new DKDateDiffor().isDiff( now, now, null)
  31. def threeDaysFromNow = DateUtils.addDays( now , 3)
  32. // in case of daylight savings time
  33. threeDaysFromNow = DateUtils.addHours( threeDaysFromNow , -1)
  34. assert new DKDateDiffor().isDiff( now, threeDaysFromNow, null)
  35. assert new DKDateDiffor().isDiff( threeDaysFromNow, now, null)
  36. def tolerance = new DKCalendarSpan(3, DKCalendarSpan.Unit.DAY);
  37. assert ! new DKDateDiffor(tolerance).isDiff( null, null, null)
  38. assert new DKDateDiffor(tolerance).isDiff( now, null, null)
  39. assert new DKDateDiffor(tolerance).isDiff( null, now, null)
  40. assert ! new DKDateDiffor(tolerance).isDiff( now, now, null)
  41. assert ! new DKDateDiffor(tolerance).isDiff( now, threeDaysFromNow, null)
  42. assert ! new DKDateDiffor(tolerance).isDiff( threeDaysFromNow, now, null)
  43. tolerance = new DKCalendarSpan(2, DKCalendarSpan.Unit.DAY);
  44. assert ! new DKDateDiffor(tolerance).isDiff( now, now, null)
  45. assert new DKDateDiffor(tolerance).isDiff( now, threeDaysFromNow, null)
  46. assert new DKDateDiffor(tolerance).isDiff( threeDaysFromNow, now, null)
  47. tolerance = new DKCalendarSpan(4, DKCalendarSpan.Unit.DAY);
  48. assert ! new DKDateDiffor(tolerance).isDiff( now, now, null)
  49. assert ! new DKDateDiffor(tolerance).isDiff( now, threeDaysFromNow, null)
  50. assert ! new DKDateDiffor(tolerance).isDiff( threeDaysFromNow, now, null)
  51. }
  52. }