From cef8036123a4f0a1dbad49f98e5e163d84eeff22 Mon Sep 17 00:00:00 2001 From: KingOfSquares <19822231+KingOfSquares@users.noreply.github.com> Date: Mon, 23 Oct 2023 17:41:06 +0200 Subject: [PATCH] Use EqualsTester instead of weird equality assertion --- .../kyori/adventure/text/title/TitleTest.java | 9 +++- .../adventure/text/title/TitleTimesTest.java | 9 +++- .../net/kyori/test/EqualityAssertions.java | 50 ------------------- 3 files changed, 14 insertions(+), 54 deletions(-) delete mode 100644 api/src/test/java/net/kyori/test/EqualityAssertions.java diff --git a/api/src/test/java/net/kyori/adventure/text/title/TitleTest.java b/api/src/test/java/net/kyori/adventure/text/title/TitleTest.java index 8295033bf..1e4bd57dd 100644 --- a/api/src/test/java/net/kyori/adventure/text/title/TitleTest.java +++ b/api/src/test/java/net/kyori/adventure/text/title/TitleTest.java @@ -23,11 +23,11 @@ */ package net.kyori.adventure.text.title; +import com.google.common.testing.EqualsTester; import java.time.Duration; import net.kyori.adventure.text.Component; import net.kyori.adventure.title.Title; import net.kyori.adventure.title.TitlePart; -import net.kyori.test.EqualityAssertions; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -85,6 +85,11 @@ void testEquality() { final Title notEqualTitle = Title.title(Component.text("cat"), Component.text("bar"), Title.Times.times(Duration.ofMillis(500), Duration.ofMillis(1000), Duration.ofMillis(1500))); final Title notEqualTimes = Title.title(Component.text("foo"), Component.text("bar"), Title.Times.times(Duration.ofMillis(499), Duration.ofMillis(1000), Duration.ofMillis(1500))); - EqualityAssertions.assertEqualityAndNonEquality(title, equalTitle, notEqualSubtitle, notEqualTitle, notEqualTimes); + new EqualsTester() + .addEqualityGroup(title, equalTitle) + .addEqualityGroup(notEqualSubtitle) + .addEqualityGroup(notEqualTitle) + .addEqualityGroup(notEqualTimes) + .testEquals(); } } diff --git a/api/src/test/java/net/kyori/adventure/text/title/TitleTimesTest.java b/api/src/test/java/net/kyori/adventure/text/title/TitleTimesTest.java index 82ea95e51..c133d5e61 100644 --- a/api/src/test/java/net/kyori/adventure/text/title/TitleTimesTest.java +++ b/api/src/test/java/net/kyori/adventure/text/title/TitleTimesTest.java @@ -23,11 +23,11 @@ */ package net.kyori.adventure.text.title; +import com.google.common.testing.EqualsTester; import java.time.Duration; import net.kyori.adventure.title.Title; import org.junit.jupiter.api.Test; -import static net.kyori.test.EqualityAssertions.assertEqualityAndNonEquality; import static org.junit.jupiter.api.Assertions.assertEquals; public class TitleTimesTest { @@ -52,6 +52,11 @@ void testEquality() { final Title.Times notEqualStay = Title.Times.times(Duration.ofMillis(1000), Duration.ofMillis(2001), Duration.ofMillis(1234)); final Title.Times notEqualFadeOut = Title.Times.times(Duration.ofMillis(1000), Duration.ofMillis(2000), Duration.ofMillis(1235)); - assertEqualityAndNonEquality(times, equalTimes, notEqualFadeIn, notEqualStay, notEqualFadeOut); + new EqualsTester() + .addEqualityGroup(times, equalTimes) + .addEqualityGroup(notEqualFadeIn) + .addEqualityGroup(notEqualStay) + .addEqualityGroup(notEqualFadeOut) + .testEquals(); } } diff --git a/api/src/test/java/net/kyori/test/EqualityAssertions.java b/api/src/test/java/net/kyori/test/EqualityAssertions.java deleted file mode 100644 index e9978a1f7..000000000 --- a/api/src/test/java/net/kyori/test/EqualityAssertions.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * This file is part of adventure, licensed under the MIT License. - * - * Copyright (c) 2017-2023 KyoriPowered - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package net.kyori.test; - -import org.jetbrains.annotations.NotNull; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; - -public final class EqualityAssertions { - - private EqualityAssertions() { - } - - //Covers all branches in the standard #equals and #hashcode used in this project - @SafeVarargs - public static void assertEqualityAndNonEquality(final @NotNull T value, final @NotNull T equalToValue, final @NotNull T@NotNull... notEqualToValue) { - assertEquals(value, value); - assertEquals(value, equalToValue); - assertNotEquals(value, null); - assertNotEquals(value, value instanceof String ? new boolean[0] : ""); - assertEquals(value.hashCode(), equalToValue.hashCode()); - - for (final T t : notEqualToValue) { - assertNotEquals(value, t); - assertNotEquals(value.hashCode(), t.hashCode()); - } - } -}