Skip to content

Commit

Permalink
Propagates fieldnameToGetter via ConfiguredEqualsVerifier
Browse files Browse the repository at this point in the history
  • Loading branch information
jqno committed Jul 6, 2023
1 parent 2fad0ea commit 80b0360
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ public <T> SingleTypeEqualsVerifierApi<T> forClass(Class<T> type) {
type,
EnumSet.copyOf(warningsToSuppress),
factoryCache,
usingGetClass
usingGetClass,
fieldnameToGetter
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,20 @@ public SingleTypeEqualsVerifierApi(Class<T> type) {
* @param factoryCache Factories that can be used to create values.
* @param usingGetClass Whether {@code getClass} is used in the implementation of the {@code
* equals} method, instead of an {@code instanceof} check.
* @param converter A function that converts from field name to getter name.
*/
public SingleTypeEqualsVerifierApi(
Class<T> type,
EnumSet<Warning> warningsToSuppress,
FactoryCache factoryCache,
boolean usingGetClass
boolean usingGetClass,
Function<String, String> converter
) {
this(type);
this.warningsToSuppress = EnumSet.copyOf(warningsToSuppress);
this.factoryCache = this.factoryCache.merge(factoryCache);
this.usingGetClass = usingGetClass;
this.fieldnameToGetter = converter;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package nl.jqno.equalsverifier.integration.extra_features;

import java.util.Arrays;
import java.util.Objects;
import nl.jqno.equalsverifier.EqualsVerifier;
import nl.jqno.equalsverifier.Warning;
Expand Down Expand Up @@ -90,7 +91,7 @@ public void lazyGettersPickedUpInSuper() {
}

@Test
public void differentCodingStyle() {
public void differentCodingStyle_single() {
EqualsVerifier
.forClass(DifferentCodingStyleContainer.class)
.suppress(Warning.NONFINAL_FIELDS)
Expand All @@ -100,6 +101,29 @@ public void differentCodingStyle() {
.verify();
}

@Test
public void differentCodingStyle_configured() {
EqualsVerifier
.configure()
.suppress(Warning.NONFINAL_FIELDS)
.withFieldnameToGetterConverter(fn ->
"get" + Character.toUpperCase(fn.charAt(2)) + fn.substring(3)
)
.forClass(DifferentCodingStyleContainer.class)
.verify();
}

@Test
public void differentCodingStyle_multiple() {
EqualsVerifier
.forClasses(Arrays.asList(DifferentCodingStyleContainer.class))
.suppress(Warning.NONFINAL_FIELDS)
.withFieldnameToGetterConverter(fn ->
"get" + Character.toUpperCase(fn.charAt(2)) + fn.substring(3)
)
.verify();
}

private void getterNotUsed(Class<?> type, String method) {
ExpectedException
.when(() -> EqualsVerifier.forClass(type).suppress(Warning.NONFINAL_FIELDS).verify())
Expand Down

0 comments on commit 80b0360

Please sign in to comment.