diff options
author | Chris Povirk <cpovirk@google.com> | 2011-11-21 14:14:12 -0500 |
---|---|---|
committer | Michael Bolin <bolinfest@google.com> | 2011-11-21 14:17:41 -0500 |
commit | c28f287b996c0cedc5516a0426fbd49f6c9611ec (patch) | |
tree | 2fdd94eea5d6adbf23e5faa1b8de06ef9f7b4bb6 | |
parent | de2dc0d76651c52ab3f44a78d242eff0a6b37a0d (diff) | |
download | s2-geometry-library-java-c28f287b996c0cedc5516a0426fbd49f6c9611ec.tar.gz |
Inline checkEqualsAndHashCodeMethods calls in preparation for deprecating the method.
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=25471702
-rw-r--r-- | tests/com/google/common/geometry/S2PolylineTest.java | 51 | ||||
-rw-r--r-- | tests/com/google/testing/util/MoreAsserts.java | 56 |
2 files changed, 46 insertions, 61 deletions
diff --git a/tests/com/google/common/geometry/S2PolylineTest.java b/tests/com/google/common/geometry/S2PolylineTest.java index abce80e..9da9bcb 100644 --- a/tests/com/google/common/geometry/S2PolylineTest.java +++ b/tests/com/google/common/geometry/S2PolylineTest.java @@ -17,7 +17,8 @@ package com.google.common.geometry; import com.google.common.collect.Lists; -import com.google.testing.util.MoreAsserts; + +import junit.framework.Assert; import java.util.List; @@ -105,16 +106,16 @@ public strictfp class S2PolylineTest extends GeometryTestCase { S2Polyline line1 = new S2Polyline(vertices); S2Polyline line2 = new S2Polyline(vertices); - MoreAsserts.checkEqualsAndHashCodeMethods(line1, line2, true); + checkEqualsAndHashCodeMethods(line1, line2, true); List<S2Point> moreVertices = Lists.newLinkedList(vertices); moreVertices.remove(0); S2Polyline line3 = new S2Polyline(moreVertices); - MoreAsserts.checkEqualsAndHashCodeMethods(line1, line3, false); - MoreAsserts.checkEqualsAndHashCodeMethods(line1, null, false); - MoreAsserts.checkEqualsAndHashCodeMethods(line1, "", false); + checkEqualsAndHashCodeMethods(line1, line3, false); + checkEqualsAndHashCodeMethods(line1, null, false); + checkEqualsAndHashCodeMethods(line1, "", false); } public void testProject() { @@ -159,4 +160,44 @@ public strictfp class S2PolylineTest extends GeometryTestCase { assertEquals(2, edgeIndex); } + /** + * Utility for testing equals() and hashCode() results at once. + * Tests that lhs.equals(rhs) matches expectedResult, as well as + * rhs.equals(lhs). Also tests that hashCode() return values are + * equal if expectedResult is true. (hashCode() is not tested if + * expectedResult is false, as unequal objects can have equal hashCodes.) + * + * @param lhs An Object for which equals() and hashCode() are to be tested. + * @param rhs As lhs. + * @param expectedResult True if the objects should compare equal, + * false if not. + */ + private static void checkEqualsAndHashCodeMethods(Object lhs, Object rhs, + boolean expectedResult) { + if ((lhs == null) && (rhs == null)) { + Assert.assertTrue( + "Your check is dubious...why would you expect null != null?", + expectedResult); + return; + } + + if ((lhs == null) || (rhs == null)) { + Assert.assertFalse( + "Your check is dubious...why would you expect an object " + + "to be equal to null?", expectedResult); + } + + if (lhs != null) { + assertEquals(expectedResult, lhs.equals(rhs)); + } + if (rhs != null) { + assertEquals(expectedResult, rhs.equals(lhs)); + } + + if (expectedResult) { + String hashMessage = + "hashCode() values for equal objects should be the same"; + Assert.assertTrue(hashMessage, lhs.hashCode() == rhs.hashCode()); + } + } } diff --git a/tests/com/google/testing/util/MoreAsserts.java b/tests/com/google/testing/util/MoreAsserts.java index e4a8d37..7d1f142 100644 --- a/tests/com/google/testing/util/MoreAsserts.java +++ b/tests/com/google/testing/util/MoreAsserts.java @@ -118,62 +118,6 @@ public final class MoreAsserts { assertContentsAnyOrder((String) null, expected, actual, comparator); } - - /** - * Utility for testing equals() and hashCode() results at once. - * Tests that lhs.equals(rhs) matches expectedResult, as well as - * rhs.equals(lhs). Also tests that hashCode() return values are - * equal if expectedResult is true. (hashCode() is not tested if - * expectedResult is false, as unequal objects can have equal hashCodes.) - * - * @param lhs An Object for which equals() and hashCode() are to be tested. - * @param rhs As lhs. - * @param expectedResult True if the objects should compare equal, - * false if not. - */ - public static void checkEqualsAndHashCodeMethods( - String message, Object lhs, Object rhs, boolean expectedResult) { - - if ((lhs == null) && (rhs == null)) { - Assert.assertTrue( - "Your check is dubious...why would you expect null != null?", - expectedResult); - return; - } - - if ((lhs == null) || (rhs == null)) { - Assert.assertFalse( - "Your check is dubious...why would you expect an object " - + "to be equal to null?", expectedResult); - } - - if (lhs != null) { - assertEqualsImpl(message, expectedResult, lhs.equals(rhs)); - } - if (rhs != null) { - assertEqualsImpl(message, expectedResult, rhs.equals(lhs)); - } - - if (expectedResult) { - String hashMessage = - "hashCode() values for equal objects should be the same"; - if (message != null) { - hashMessage += ": " + message; - } - Assert.assertTrue(hashMessage, lhs.hashCode() == rhs.hashCode()); - } - } - - /** - * Variant of - * {@link #checkEqualsAndHashCodeMethods(String, Object, Object, boolean)} - * using a generic message. - */ - public static void checkEqualsAndHashCodeMethods(Object lhs, Object rhs, - boolean expectedResult) { - checkEqualsAndHashCodeMethods((String) null, lhs, rhs, expectedResult); - } - private static void failNotEqual(String message, Object expected, Object actual) { if ((expected != null) && (actual != null) |