01: /*
02: * Copyright 2006-2007, Unitils.org
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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.unitils.reflectionassert;
17:
18: import java.util.Date;
19: import java.util.Map;
20: import java.util.Stack;
21:
22: /**
23: * @author Tim Ducheyne
24: * @author Filip Neven
25: */
26: public class LenientDatesComparator extends ReflectionComparator {
27:
28: // todo javadoc
29: public LenientDatesComparator(ReflectionComparator chainedComparator) {
30: super (chainedComparator);
31: }
32:
33: // todo javadoc
34: public boolean canHandle(Object left, Object right) {
35: return (left == null || left instanceof Date)
36: && (right == null || right instanceof Date);
37: }
38:
39: // todo javadoc
40: @Override
41: protected Difference doGetDifference(Object left, Object right,
42: Stack<String> fieldStack,
43: Map<TraversedInstancePair, Boolean> traversedInstancePairs) {
44: if ((right == null && left != null)
45: || (right != null && left == null)) {
46: return new Difference(
47: "Lenient dates, but not both instantiated or both null.",
48: left, right, fieldStack);
49: }
50: return null;
51: }
52: }
|