001 /*
002 * Created on Apr 12, 2009
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
005 * the License. You may obtain a copy of the License at
006 *
007 * http://www.apache.org/licenses/LICENSE-2.0
008 *
009 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
010 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
011 * specific language governing permissions and limitations under the License.
012 *
013 * Copyright @2009 the original author or authors.
014 */
015 package org.fest.test;
016
017 /**
018 * Understands verification of the equals/hashCode contract.
019 *
020 * @author Alex Ruiz
021 */
022 public interface EqualsHashCodeContractTestCase {
023
024 void should_not_be_equal_to_Object_not_being_of_same_type();
025
026 /**
027 * If two objects are equal, they must remain equal as long as they are not modified.
028 */
029 void should_have_consistent_equals();
030
031 /**
032 * The object must be equal to itself, which it would be at any given instance; unless you intentionally override the
033 * equals method to behave otherwise.
034 */
035 void should_have_reflexive_equals();
036
037 /**
038 * If object of one class is equal to another class object, the other class object must be equal to this class object.
039 * In other words, one object can not unilaterally decide whether it is equal to another object; two objects, and
040 * consequently the classes to which they belong, must bilaterally decide if they are equal or not. They BOTH must
041 * agree.
042 */
043 void should_have_symmetric_equals();
044
045 /**
046 * If the first object is equal to the second object and the second object is equal to the third object; then the
047 * first object is equal to the third object. In other words, if two objects agree that they are equal, and follow the
048 * symmetry principle, one of them can not decide to have a similar contract with another object of different class.
049 * All three must agree and follow symmetry principle for various permutations of these three classes.
050 */
051 void should_have_transitive_equals();
052
053 /**
054 * If two objects are equal, then they must have the same hash code, however the opposite is NOT true.
055 */
056 void should_maintain_equals_and_hashCode_contract();
057
058 /**
059 * Verifies that the implementation of the method <code>equals</code> returns <code>false</code> if a
060 * <code>null</code> is passed as argument.
061 */
062 void should_not_be_equal_to_null();
063 }