From fb0d04ff93229b649dade3ae231d86afb8e0f25e Mon Sep 17 00:00:00 2001 From: Stephen Kitt Date: Thu, 6 Oct 2016 10:13:58 +0200 Subject: [PATCH] Support testing null against null in equalsHelper() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit In its intended context, equalsHelper() should never be called with two null parameters, but it's easy to support the general case — and because this isn't SQL, null equals itself. Change-Id: I826435e81a4dd59aaac72ad9ab07a80069f7a17f Signed-off-by: Stephen Kitt --- .../opendaylight/yangtools/util/EvenMoreObjects.java | 6 +++--- .../yangtools/util/EvenMoreObjectsTest.java | 11 +++++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/EvenMoreObjects.java b/common/util/src/main/java/org/opendaylight/yangtools/util/EvenMoreObjects.java index c7988c1bf8..137ff43e78 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/EvenMoreObjects.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/EvenMoreObjects.java @@ -34,12 +34,12 @@ public final class EvenMoreObjects { @SuppressWarnings("unchecked") public static boolean equalsHelper(T self, Object other, BooleanEqualsFunction equals) { - if (other == null) { - return false; - } if (other == self) { return true; } + if (other == null) { + return false; + } if (self.getClass() != other.getClass()) { return false; } diff --git a/common/util/src/test/java/org/opendaylight/yangtools/util/EvenMoreObjectsTest.java b/common/util/src/test/java/org/opendaylight/yangtools/util/EvenMoreObjectsTest.java index 644f6e32df..59bcd85217 100644 --- a/common/util/src/test/java/org/opendaylight/yangtools/util/EvenMoreObjectsTest.java +++ b/common/util/src/test/java/org/opendaylight/yangtools/util/EvenMoreObjectsTest.java @@ -7,6 +7,8 @@ */ package org.opendaylight.yangtools.util; +import static org.junit.Assert.assertTrue; + import com.google.common.base.MoreObjects; import com.google.common.testing.EqualsTester; import java.util.Objects; @@ -15,7 +17,7 @@ import org.junit.Test; public class EvenMoreObjectsTest { @Test - public void test() { + public void thingPassesEqualsTester() { new EqualsTester() .addEqualityGroup(new Thing("hello", 123), new Thing("hello", 123)) .addEqualityGroup(new Thing("hoi", 123), new Thing("hoi", 123)) @@ -24,7 +26,12 @@ public class EvenMoreObjectsTest { .testEquals(); } - static class Thing { + @Test + public void nullEqualsNull() { + assertTrue(EvenMoreObjects.equalsHelper(null, null, (one, another) -> true)); + } + + private static class Thing { String name; Integer age; -- 2.36.6