Skip to content

Commit

Permalink
Replaces assertNotSame with equivalent AssertJ
Browse files Browse the repository at this point in the history
  • Loading branch information
jqno committed Dec 19, 2024
1 parent a9cf82f commit b34c09b
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 t) {}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
}

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -165,7 +164,7 @@ void copy() {
actual = sut.copy(original);

assertThat(actual).isEqualTo(expected);
assertNotSame(expected, actual);
assertThat(actual).isNotSameAs(expected);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;

Expand Down Expand Up @@ -74,15 +73,13 @@ void giveBlueFromCache() {

@Test
void giveRedCopyFromFactory() {
assertThat(vp.<String>giveRedCopy(STRING_TAG)).isEqualTo("r");
assertNotSame(vp.giveRed(STRING_TAG), vp.giveRedCopy(STRING_TAG));
assertThat(vp.<String>giveRedCopy(STRING_TAG)).isEqualTo("r").isNotSameAs(vp.giveRed(STRING_TAG));
}

@Test
void giveRedCopyFromCache() {
vp.giveRedCopy(STRING_TAG);
assertThat(vp.<String>giveRedCopy(STRING_TAG)).isEqualTo("r");
assertNotSame(vp.giveRed(STRING_TAG), vp.giveRedCopy(STRING_TAG));
assertThat(vp.<String>giveRedCopy(STRING_TAG)).isEqualTo("r").isNotSameAs(vp.giveRed(STRING_TAG));
}

@Test
Expand All @@ -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.<Point>giveRedCopy(POINT_TAG)).isEqualTo(new Point(42, 42)).isNotSameAs(vp.giveRed(POINT_TAG));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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");
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -73,7 +72,7 @@ private <T> T copyOf(T from, Class<T> type) {
}

private static <T> void assertAllFieldsEqual(T original, T copy, Class<? extends T> type) {
assertNotSame(original, copy);
assertThat(original).isNotSameAs(copy);
for (FieldProbe probe : FieldIterable.of(type)) {
try {
assertThat(probe.getValue(copy)).isEqualTo(probe.getValue(original));
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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());
}
}

0 comments on commit b34c09b

Please sign in to comment.