org.unitils.reflectionassert.comparator.Comparator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of unitils Show documentation
Show all versions of unitils Show documentation
Unitils provides utilities to further simplify unit-testing with JUnit, DBUnit, EasyMock
Hibernate and Spring. The goal is to make unit-testing easy and maintainable by offering
utilities such as automatic DB-schema maintainance and equality assertion through reflection.
/*
* Copyright 2008, Unitils.org
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.unitils.reflectionassert.comparator;
import org.unitils.reflectionassert.ReflectionComparator;
import org.unitils.reflectionassert.difference.Difference;
/**
* Interface for comparing 2 given objects.
*
* One should always first call canCompare before calling compare to perform the actual comparison.
* If canCompare returns false, the comparator implementation is not suited to compare the given objects and compare
* should not be called.
*
* @author Tim Ducheyne
* @author Filip Neven
*/
public interface Comparator {
/**
* Checks whether this comparator can compare the given objects.
*
* This method should always be called before calling the compare method. If false is returned compare
* should not be invoked.
*
* @param left The left object
* @param right The right object
* @return True if compare can be called, false otherwise
*/
boolean canCompare(Object left, Object right);
/**
* Compares the given objects and returns the difference (if any).
*
* The reflection comparator is passed as an argument and can be used to perform inner comparisons.
* E.g. during the comparison of an object the given comparator can be used to compare the instance
* fields of the object.
*
* @param left The left object
* @param right The right object
* @param onlyFirstDifference True if only the first difference should be returned
* @param reflectionComparator The root comparator for inner comparisons, not null
* @return The difference, null if a match is found
*/
Difference compare(Object left, Object right, boolean onlyFirstDifference, ReflectionComparator reflectionComparator);
}