diff --git a/src/main/java/org/assertj/core/api/AbstractDoubleAssert.java b/src/main/java/org/assertj/core/api/AbstractDoubleAssert.java index fac2908a24..d298abfea4 100644 --- a/src/main/java/org/assertj/core/api/AbstractDoubleAssert.java +++ b/src/main/java/org/assertj/core/api/AbstractDoubleAssert.java @@ -46,12 +46,12 @@ public abstract class AbstractDoubleAssert> extends AbstractComparableAssert implements FloatingPointNumberAssert { - private static final Double NEGATIVE_ZERO = Double.valueOf(-0.0); + private static final Double NEGATIVE_ZERO = -0.0; @VisibleForTesting Doubles doubles = Doubles.instance(); - private boolean isPrimitive; + private final boolean isPrimitive; public AbstractDoubleAssert(Double actual, Class selfType) { super(actual, selfType); diff --git a/src/main/java/org/assertj/core/api/AbstractFloatAssert.java b/src/main/java/org/assertj/core/api/AbstractFloatAssert.java index f9c3c1e1b7..b13a2d6152 100644 --- a/src/main/java/org/assertj/core/api/AbstractFloatAssert.java +++ b/src/main/java/org/assertj/core/api/AbstractFloatAssert.java @@ -44,12 +44,12 @@ public abstract class AbstractFloatAssert> extends AbstractComparableAssert implements FloatingPointNumberAssert { - private static final Float NEGATIVE_ZERO = Float.valueOf(-0.0f); + private static final Float NEGATIVE_ZERO = -0.0f; @VisibleForTesting Floats floats = Floats.instance(); - private boolean isPrimitive; + private final boolean isPrimitive; public AbstractFloatAssert(Float actual, Class selfType) { super(actual, selfType); diff --git a/src/main/java/org/assertj/core/api/AbstractIterableAssert.java b/src/main/java/org/assertj/core/api/AbstractIterableAssert.java index 6a6e313b90..aa865175e4 100644 --- a/src/main/java/org/assertj/core/api/AbstractIterableAssert.java +++ b/src/main/java/org/assertj/core/api/AbstractIterableAssert.java @@ -2826,7 +2826,7 @@ private ELEMENT_ASSERT internalElement(int index) { isNotEmpty(); assertThat(index).describedAs(navigationDescription("check index validity")) .isBetween(0, IterableUtil.sizeOf(actual) - 1); - ELEMENT elementAtIndex = null; + ELEMENT elementAtIndex; if (actual instanceof List) { @SuppressWarnings("unchecked") List list = (List) actual; diff --git a/src/main/java/org/assertj/core/error/BasicErrorMessageFactory.java b/src/main/java/org/assertj/core/error/BasicErrorMessageFactory.java index a2292c8bab..748c27144d 100644 --- a/src/main/java/org/assertj/core/error/BasicErrorMessageFactory.java +++ b/src/main/java/org/assertj/core/error/BasicErrorMessageFactory.java @@ -22,6 +22,7 @@ import static org.assertj.core.util.Strings.quote; import java.util.Arrays; +import java.util.Objects; import org.assertj.core.description.Description; import org.assertj.core.presentation.Representation; @@ -85,7 +86,7 @@ public boolean equals(Object obj) { if (obj == null) return false; if (getClass() != obj.getClass()) return false; UnquotedString other = (UnquotedString) obj; - return string == null ? other.string == null : string.equals(other.string); + return Objects.equals(string, other.string); } } diff --git a/src/main/java/org/assertj/core/internal/Comparables.java b/src/main/java/org/assertj/core/internal/Comparables.java index 63aee6ac66..432525313e 100644 --- a/src/main/java/org/assertj/core/internal/Comparables.java +++ b/src/main/java/org/assertj/core/internal/Comparables.java @@ -92,7 +92,7 @@ public boolean equals(Object obj) { if (comparisonStrategy == null) { if (other.comparisonStrategy != null) return false; } else if (!comparisonStrategy.equals(other.comparisonStrategy)) return false; - return failures == null ? other.failures == null : failures.equals(other.failures); + return java.util.Objects.equals(failures, other.failures); } @Override diff --git a/src/main/java/org/assertj/core/internal/FieldByFieldComparator.java b/src/main/java/org/assertj/core/internal/FieldByFieldComparator.java index 549f670d1c..3ef8ebd72d 100644 --- a/src/main/java/org/assertj/core/internal/FieldByFieldComparator.java +++ b/src/main/java/org/assertj/core/internal/FieldByFieldComparator.java @@ -45,7 +45,7 @@ public FieldByFieldComparator(Map> comparatorsByPropertyOr } public FieldByFieldComparator() { - this(new TreeMap>(), defaultTypeComparators()); + this(new TreeMap<>(), defaultTypeComparators()); } @Override diff --git a/src/main/java/org/assertj/core/internal/IgnoringFieldsComparator.java b/src/main/java/org/assertj/core/internal/IgnoringFieldsComparator.java index a673d4bad3..0601d1ed7f 100644 --- a/src/main/java/org/assertj/core/internal/IgnoringFieldsComparator.java +++ b/src/main/java/org/assertj/core/internal/IgnoringFieldsComparator.java @@ -24,7 +24,7 @@ public class IgnoringFieldsComparator extends FieldByFieldComparator { - private String[] fields; + private final String[] fields; public IgnoringFieldsComparator(Map> comparatorByPropertyOrField, TypeComparators comparatorByType, String... fields) { @@ -33,7 +33,7 @@ public IgnoringFieldsComparator(Map> comparatorByPropertyO } public IgnoringFieldsComparator(String... fields) { - this(new HashMap>(), defaultTypeComparators(), fields); + this(new HashMap<>(), defaultTypeComparators(), fields); } @VisibleForTesting diff --git a/src/main/java/org/assertj/core/internal/OnFieldsComparator.java b/src/main/java/org/assertj/core/internal/OnFieldsComparator.java index bef5e831a1..dbb552c50b 100644 --- a/src/main/java/org/assertj/core/internal/OnFieldsComparator.java +++ b/src/main/java/org/assertj/core/internal/OnFieldsComparator.java @@ -27,7 +27,7 @@ public class OnFieldsComparator extends FieldByFieldComparator { - private String[] fields; + private final String[] fields; public OnFieldsComparator(Map> comparatorByPropertyOrField, TypeComparators comparatorByType, String... fields) { @@ -42,7 +42,7 @@ public OnFieldsComparator(Map> comparatorByPropertyOrField } public OnFieldsComparator(String... fields) { - this(new HashMap>(), defaultTypeComparators(), fields); + this(new HashMap<>(), defaultTypeComparators(), fields); } @VisibleForTesting diff --git a/src/main/java/org/assertj/core/util/Throwables.java b/src/main/java/org/assertj/core/util/Throwables.java index 2f6adb2b64..e29f14b1f8 100644 --- a/src/main/java/org/assertj/core/util/Throwables.java +++ b/src/main/java/org/assertj/core/util/Throwables.java @@ -64,7 +64,7 @@ public static List describeErrors(List errors) { public static void appendStackTraceInCurrentThreadToThrowable(Throwable t, String methodToStartFrom) { List stackTrace = newArrayList(t.getStackTrace()); stackTrace.addAll(stackTraceInCurrentThread(methodToStartFrom)); - t.setStackTrace(stackTrace.toArray(new StackTraceElement[stackTrace.size()])); + t.setStackTrace(stackTrace.toArray(new StackTraceElement[0])); } private static List stackTraceInCurrentThread(String methodToStartFrom) { @@ -130,7 +130,7 @@ public static void removeAssertJRelatedElementsFromStackTrace(Throwable throwabl } previous = element; } - StackTraceElement[] newStackTrace = filtered.toArray(new StackTraceElement[filtered.size()]); + StackTraceElement[] newStackTrace = filtered.toArray(new StackTraceElement[0]); throwable.setStackTrace(newStackTrace); } diff --git a/src/main/java/org/assertj/core/util/diff/DiffUtils.java b/src/main/java/org/assertj/core/util/diff/DiffUtils.java index 35c032d307..5285c1fcc9 100644 --- a/src/main/java/org/assertj/core/util/diff/DiffUtils.java +++ b/src/main/java/org/assertj/core/util/diff/DiffUtils.java @@ -46,7 +46,7 @@ public class DiffUtils { * revised sequences. Never {@code null}. */ public static Patch diff(List original, List revised) { - return DiffUtils.diff(original, revised, new MyersDiff()); + return DiffUtils.diff(original, revised, new MyersDiff<>()); } /**