From b34c09b4fc47011146f2c0ab5e8579e1f01fe4bd Mon Sep 17 00:00:00 2001 From: Jan Ouwens Date: Thu, 19 Dec 2024 19:38:00 +0100 Subject: [PATCH] Replaces assertNotSame with equivalent AssertJ --- .../factories/RecordFallbackFactoryTest.java | 3 +-- .../reflection/RecordObjectAccessorCopyingTest.java | 5 ++--- .../RecordObjectAccessorScramblingTest.java | 3 +-- .../factories/SealedTypesFallbackFactoryTest.java | 3 +-- .../internal/instantiation/SubjectCreatorTest.java | 3 +-- .../vintage/VintageValueProviderTest.java | 11 +++-------- .../prefabvalues/factories/FallbackFactoryTest.java | 4 +--- .../prefabvalues/factories/SimpleFactoryTest.java | 4 +--- .../reflection/InPlaceObjectAccessorCopyingTest.java | 5 ++--- .../equalsverifier/internal/reflection/TupleTest.java | 4 +--- 10 files changed, 14 insertions(+), 31 deletions(-) diff --git a/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/RecordFallbackFactoryTest.java b/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/RecordFallbackFactoryTest.java index 6c4a2f2d6..6f8661478 100644 --- a/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/RecordFallbackFactoryTest.java +++ b/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/RecordFallbackFactoryTest.java @@ -2,7 +2,6 @@ import static nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories.Factories.values; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertNotSame; import java.util.LinkedHashSet; @@ -36,7 +35,7 @@ void redCopyHasTheSameValuesAsRed_whenSutContainsGenericValueThatNeedsToBeIdenti Tuple tuple = factory.createValues(new TypeTag(GenericRecordContainer.class), valueProvider, typeStack); assertThat(tuple.getRedCopy()).isEqualTo(tuple.getRed()); - assertNotSame(tuple.getRed(), tuple.getRedCopy()); + assertThat(tuple.getRedCopy()).isNotSameAs(tuple.getRed()); } record GenericRecord(T t) {} diff --git a/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/reflection/RecordObjectAccessorCopyingTest.java b/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/reflection/RecordObjectAccessorCopyingTest.java index b378fd2ce..3c9d68cdf 100644 --- a/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/reflection/RecordObjectAccessorCopyingTest.java +++ b/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/reflection/RecordObjectAccessorCopyingTest.java @@ -1,7 +1,6 @@ package nl.jqno.equalsverifier.internal.instantiation.vintage.reflection; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertNotSame; import nl.jqno.equalsverifier.internal.reflection.FieldIterable; import nl.jqno.equalsverifier.internal.reflection.FieldProbe; @@ -19,7 +18,7 @@ void copyHappyPath() { Object original = instantiate(SimpleRecord.class); Object copy = copyOf(original); - assertNotSame(original, copy); + assertThat(copy).isNotSameAs(original); assertThat(copy).isEqualTo(original); } @@ -30,7 +29,7 @@ void shallowCopy() { RecordObjectAccessor originalAccessor = create(original); RecordObjectAccessor copyAccessor = create(copy); - assertNotSame(original, copy); + assertThat(copy).isNotSameAs(original); for (FieldProbe p : FieldIterable.of(original.getClass())) { Object a = originalAccessor.getField(p); Object b = copyAccessor.getField(p); diff --git a/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/reflection/RecordObjectAccessorScramblingTest.java b/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/reflection/RecordObjectAccessorScramblingTest.java index c8a88c2a7..2e41ea883 100644 --- a/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/reflection/RecordObjectAccessorScramblingTest.java +++ b/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/reflection/RecordObjectAccessorScramblingTest.java @@ -2,7 +2,6 @@ import static nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories.Factories.values; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertNotSame; import java.lang.reflect.Constructor; import java.util.LinkedHashSet; @@ -32,7 +31,7 @@ void scrambleLeavesOriginalUnaffected() throws Exception { Constructor c = Point.class.getDeclaredConstructor(int.class, int.class); Object original = c.newInstance(2, 3); Object copy = doScramble(original).get(); - assertNotSame(original, copy); + assertThat(original).isNotSameAs(copy); } @Test diff --git a/equalsverifier-17/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/SealedTypesFallbackFactoryTest.java b/equalsverifier-17/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/SealedTypesFallbackFactoryTest.java index 1bbcaa332..3607eed6d 100644 --- a/equalsverifier-17/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/SealedTypesFallbackFactoryTest.java +++ b/equalsverifier-17/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/SealedTypesFallbackFactoryTest.java @@ -2,7 +2,6 @@ import static nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories.Factories.values; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertNotSame; import java.util.LinkedHashSet; import java.util.Objects; @@ -37,7 +36,7 @@ void redCopyHasTheSameValuesAsRed_whenSutIsAbstractSealedAndPermittedTypeAddsFie Tuple tuple = factory.createValues(new TypeTag(SealedParentWithFinalChild.class), valueProvider, typeStack); assertThat(tuple.getRedCopy()).isEqualTo(tuple.getRed()); - assertNotSame(tuple.getRed(), tuple.getRedCopy()); + assertThat(tuple.getRedCopy()).isNotSameAs(tuple.getRed()); } public abstract static sealed class SealedParentWithFinalChild permits FinalSealedChild { diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/SubjectCreatorTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/SubjectCreatorTest.java index ad6cf259b..e9e838d7a 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/SubjectCreatorTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/SubjectCreatorTest.java @@ -1,7 +1,6 @@ package nl.jqno.equalsverifier.internal.instantiation; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertNotSame; import java.lang.reflect.Field; import java.util.Objects; @@ -165,7 +164,7 @@ void copy() { actual = sut.copy(original); assertThat(actual).isEqualTo(expected); - assertNotSame(expected, actual); + assertThat(actual).isNotSameAs(expected); } @Test diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/VintageValueProviderTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/VintageValueProviderTest.java index 0d793db43..e32d26286 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/VintageValueProviderTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/VintageValueProviderTest.java @@ -5,7 +5,6 @@ import static nl.jqno.equalsverifier.internal.testhelpers.Util.defaultHashCode; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; -import static org.junit.jupiter.api.Assertions.assertNotSame; import java.util.*; @@ -74,15 +73,13 @@ void giveBlueFromCache() { @Test void giveRedCopyFromFactory() { - assertThat(vp.giveRedCopy(STRING_TAG)).isEqualTo("r"); - assertNotSame(vp.giveRed(STRING_TAG), vp.giveRedCopy(STRING_TAG)); + assertThat(vp.giveRedCopy(STRING_TAG)).isEqualTo("r").isNotSameAs(vp.giveRed(STRING_TAG)); } @Test void giveRedCopyFromCache() { vp.giveRedCopy(STRING_TAG); - assertThat(vp.giveRedCopy(STRING_TAG)).isEqualTo("r"); - assertNotSame(vp.giveRed(STRING_TAG), vp.giveRedCopy(STRING_TAG)); + assertThat(vp.giveRedCopy(STRING_TAG)).isEqualTo("r").isNotSameAs(vp.giveRed(STRING_TAG)); } @Test @@ -99,9 +96,7 @@ void giveBlueFromFallbackFactory() { @Test void giveRedCopyFromFallbackFactory() { - Point actual = vp.giveRedCopy(POINT_TAG); - assertThat(actual).isEqualTo(new Point(42, 42)); - assertNotSame(vp.giveRed(POINT_TAG), actual); + assertThat(vp.giveRedCopy(POINT_TAG)).isEqualTo(new Point(42, 42)).isNotSameAs(vp.giveRed(POINT_TAG)); } @Test diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/FallbackFactoryTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/FallbackFactoryTest.java index cdcf084e9..2100adada 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/FallbackFactoryTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/FallbackFactoryTest.java @@ -4,7 +4,6 @@ import static nl.jqno.equalsverifier.internal.testhelpers.Util.defaultEquals; import static nl.jqno.equalsverifier.internal.testhelpers.Util.defaultHashCode; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertNotSame; import java.util.LinkedHashSet; @@ -75,8 +74,7 @@ void giveClassWithFields() { void redCopyIsNotSameAsRed() { Tuple tuple = factory.createValues(new TypeTag(IntContainer.class), valueProvider, typeStack); - assertThat(tuple.getRedCopy()).isEqualTo(tuple.getRed()); - assertNotSame(tuple.getRed(), tuple.getRedCopy()); + assertThat(tuple.getRedCopy()).isEqualTo(tuple.getRed()).isNotSameAs(tuple.getRed()); } @Test diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/SimpleFactoryTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/SimpleFactoryTest.java index 5de418613..c30ab531d 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/SimpleFactoryTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/SimpleFactoryTest.java @@ -1,7 +1,6 @@ package nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertNotSame; import org.junit.jupiter.api.Test; @@ -22,7 +21,6 @@ void createBlue() { @Test void redCopy() { String redCopy = factory.createValues(null, null, null).getRedCopy(); - assertThat(redCopy).isEqualTo("red"); - assertNotSame("red", redCopy); + assertThat(redCopy).isEqualTo("red").isNotSameAs("red"); } } diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/reflection/InPlaceObjectAccessorCopyingTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/reflection/InPlaceObjectAccessorCopyingTest.java index ae93e6d00..98a77cf6c 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/reflection/InPlaceObjectAccessorCopyingTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/reflection/InPlaceObjectAccessorCopyingTest.java @@ -1,7 +1,6 @@ package nl.jqno.equalsverifier.internal.instantiation.vintage.reflection; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertNotSame; import nl.jqno.equalsverifier.internal.exceptions.ReflectionException; import nl.jqno.equalsverifier.internal.reflection.FieldIterable; @@ -31,7 +30,7 @@ void shallowCopy() { PointContainer original = new PointContainer(new Point(1, 2)); PointContainer copy = copyOf(original); - assertNotSame(original, copy); + assertThat(original).isNotSameAs(copy); assertThat(original.getPoint() == copy.getPoint()).isTrue(); } @@ -73,7 +72,7 @@ private T copyOf(T from, Class type) { } private static void assertAllFieldsEqual(T original, T copy, Class type) { - assertNotSame(original, copy); + assertThat(original).isNotSameAs(copy); for (FieldProbe probe : FieldIterable.of(type)) { try { assertThat(probe.getValue(copy)).isEqualTo(probe.getValue(original)); diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/TupleTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/TupleTest.java index 07961c783..de46a6040 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/TupleTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/TupleTest.java @@ -1,7 +1,6 @@ package nl.jqno.equalsverifier.internal.reflection; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertNotSame; import nl.jqno.equalsverifier.EqualsVerifier; import nl.jqno.equalsverifier.Warning; @@ -33,7 +32,6 @@ void getRedCopy() { @Test void redAndRedCopyInvariant() { - assertThat(tuple.getRedCopy()).isEqualTo(tuple.getRed()); - assertNotSame(tuple.getRed(), tuple.getRedCopy()); + assertThat(tuple.getRedCopy()).isEqualTo(tuple.getRed()).isNotSameAs(tuple.getRed()); } }