Skip to content

Commit

Permalink
Runs several OpenRewrite recipes
Browse files Browse the repository at this point in the history
  • Loading branch information
jqno committed Dec 23, 2024
1 parent 6c50c0a commit 38f1e28
Show file tree
Hide file tree
Showing 24 changed files with 34 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class RecordObjectAccessorCopyingTest {

private Objenesis objenesis = new ObjenesisStd();
private final Objenesis objenesis = new ObjenesisStd();

@Test
void copyHappyPath() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private List<Method> getEqualsMethods() {
List<Method> result = new ArrayList<>();

for (Method method : type.getDeclaredMethods()) {
if (method.getName().equals("equals") && !Modifier.isStatic(method.getModifiers())) {
if ("equals".equals(method.getName()) && !Modifier.isStatic(method.getModifiers())) {
result.add(method);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public final class AwtFactoryProvider implements FactoryProvider {
private static final int CS_RED = ColorSpace.CS_sRGB;
private static final int CS_BLUE = ColorSpace.CS_LINEAR_RGB;

@Override
public FactoryCache getFactoryCache() {
FactoryCache cache = new FactoryCache();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public final class GuavaFactoryProvider implements FactoryProvider {

private static final Comparator<Object> OBJECT_COMPARATOR = Comparator.comparingInt(Object::hashCode);

@Override
public FactoryCache getFactoryCache() {
FactoryCache cache = new FactoryCache();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public final class JavaFxFactoryProvider implements FactoryProvider {
* As long as there's no easy dependency for JavaFX to rely on in Maven, we can't refer to the actual types, and
* have to go around it with String representations of the type names.
*/
@Override
public FactoryCache getFactoryCache() {
FactoryCache cache = new FactoryCache();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

public final class JavaxFactoryProvider implements FactoryProvider {

@Override
public FactoryCache getFactoryCache() {
FactoryCache cache = new FactoryCache();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

public final class JodaFactoryProvider implements FactoryProvider {

@Override
public FactoryCache getFactoryCache() {
FactoryCache cache = new FactoryCache();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

public final class RmiFactoryProvider implements FactoryProvider {

@Override
public FactoryCache getFactoryCache() {
FactoryCache cache = new FactoryCache();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
public class AnnotationProperties {

private final String className;
private Map<String, String> enumValues = new HashMap<>();
private Map<String, Set<String>> arrayValues = new HashMap<>();
private final Map<String, String> enumValues = new HashMap<>();
private final Map<String, Set<String>> arrayValues = new HashMap<>();

/**
* Constructor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
public final class Formatter {

private final String message;
private Object[] objects;
private final Object[] objects;

/** Private constructor. Call {@link #of(String, Object...)} to instantiate. */
private Formatter(String message, Object... objects) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public EclipseGetClassPoint(int x, int y, Color color) {
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((color == null) ? 0 : color.hashCode());
result = prime * result + (color == null ? 0 : color.hashCode());
result = prime * result + x;
result = prime * result + y;
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public EclipseInstanceOfPoint(int x, int y, Color color) {
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((color == null) ? 0 : color.hashCode());
result = prime * result + (color == null ? 0 : color.hashCode());
result = prime * result + x;
result = prime * result + y;
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public boolean equals(final java.lang.Object o) {
return true;
}

@Override
@java.lang.SuppressWarnings("all")
public boolean canEqual(final java.lang.Object other) {
return other instanceof LombokCanEqual.ColorPoint;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public boolean equals(Object obj) {
return false;
}
ThreeFieldsUsingAndOr other = (ThreeFieldsUsingAndOr) obj;
return (Objects.equals(f, other.f) && Objects.equals(g, other.g) || Objects.equals(h, other.h));
return Objects.equals(f, other.f) && Objects.equals(g, other.g) || Objects.equals(h, other.h);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ public int hashCode() {
}

interface InterfaceWithEquals {
@Override
boolean equals(Object obj);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ static final class StaticEqualsMethod {
this.i = i;
}

@Override
public boolean equals(Object obj) {
if (!(obj instanceof StaticEqualsMethod)) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void reportReturnsTheSameInformationAsVerify() {
assertThat(reported.length).isEqualTo(verified.length + 1);

for (int i = 0; i < verified.length; i++) {
if (!verified[i].getMethodName().equals("verify")) {
if (!"verify".equals(verified[i].getMethodName())) {
// When the `verify` method is reached, the stacktraces start to diverge.
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ class SubjectCreatorTest {
private static final String S_RED = "abc";
private static final String S_BLUE = "xyz";

private Configuration<SomeClass> config = ConfigurationHelper.emptyConfiguration(SomeClass.class);
private ValueProvider valueProvider = new SubjectCreatorTestValueProvider();
private FieldCache fieldCache = new FieldCache();
private Objenesis objenesis = new ObjenesisStd();
private final Configuration<SomeClass> config = ConfigurationHelper.emptyConfiguration(SomeClass.class);
private final ValueProvider valueProvider = new SubjectCreatorTestValueProvider();
private final FieldCache fieldCache = new FieldCache();
private final Objenesis objenesis = new ObjenesisStd();
private SubjectCreator<SomeClass> sut = new SubjectCreator<>(config, valueProvider, fieldCache, objenesis);

private Field fieldX;
Expand Down Expand Up @@ -197,6 +197,7 @@ void noValueFound() {

static class SubjectCreatorTestValueProvider implements ValueProvider {

@Override
@SuppressWarnings("unchecked")
public <T> Optional<Tuple<T>> provide(TypeTag tag) {
if (int.class.equals(tag.getType())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class VintageValueProviderTest {
private static final TypeTag POINT_TAG = new TypeTag(Point.class);
private static final TypeTag INT_TAG = new TypeTag(int.class);

private Objenesis objenesis = new ObjenesisStd();
private FactoryCache factoryCache = new FactoryCache();
private final Objenesis objenesis = new ObjenesisStd();
private final FactoryCache factoryCache = new FactoryCache();
private VintageValueProvider vp;

@BeforeEach
Expand Down Expand Up @@ -170,6 +170,7 @@ public NpeThrowing(int i) {
this.i = i;
}

@Override
public boolean equals(Object obj) {
if (obj == null) {
throw new NullPointerException();
Expand All @@ -180,6 +181,7 @@ public boolean equals(Object obj) {
return i == ((NpeThrowing) obj).i;
}

@Override
public int hashCode() {
return i;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class SimpleFactoryTest {

private SimpleFactory<String> factory = new SimpleFactory<>("red", "blue", new String("red"));
private final SimpleFactory<String> factory = new SimpleFactory<>("red", "blue", new String("red"));

@Test
void createRed() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

class InPlaceObjectAccessorCopyingTest {

private Objenesis objenesis = new ObjenesisStd();
private final Objenesis objenesis = new ObjenesisStd();

@Test
void copyHappyPath() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

class FieldCacheTest {

private String stringField = "string";
private final String stringField = "string";
private final Tuple<String> stringValues = Tuple.of("red", "blue", "red");

private String intField = "int";
private final String intField = "int";
private final Tuple<Integer> intValues = Tuple.of(1, 2, 1);

private FieldCache cache = new FieldCache();
private final FieldCache cache = new FieldCache();

@Test
void putAndGetTuple() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

class InstantiatorTest {

private Objenesis objenesis = new ObjenesisStd();
private final Objenesis objenesis = new ObjenesisStd();

@Test
void instantiateClass() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class TupleTest {

private Tuple<String> tuple = Tuple.of("red", "blue", new String("red"));
private final Tuple<String> tuple = Tuple.of("red", "blue", new String("red"));

@Test
void equalsAndHashCode() {
Expand Down

0 comments on commit 38f1e28

Please sign in to comment.