Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix equals/hashcode on class with inner class #244

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public T increaseValue(final T value) {
return (T) next.increaseValue(value);
}
LOGGER.debug("Could not change value '{}' ot type {} by any field value changer", value, value.getClass());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shall we add more info to this log? to create custom value changers in that case?
shall it be in WARN level?

return value;
return null;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void Should_Register_First_Value_Changer() {
}

@Test
void Should_Not_Change_If_No_Matching_Changer() {
void Should_Be_Null_If_No_Matching_Changer() {
// given
final AbstractFieldValueChanger abstractFieldValueChanger = new ImplementationForTest();
final String expectedValue = "string";
Expand All @@ -39,7 +39,7 @@ void Should_Not_Change_If_No_Matching_Changer() {
final Object result = abstractFieldValueChanger.increaseValue(expectedValue);

// then
assertThat(result).isEqualTo(expectedValue);
assertThat(result).isNull();
}

@Test
Expand Down
13 changes: 13 additions & 0 deletions src/test/java/pl/pojo/tester/internal/tester/EqualsTesterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ void Should_Pass_All_Equals_Tests() {
assertThat(result).isNull();
}

@Test
void Should_Pass_All_Equals_Tests_On_Embedded_Classes() {
// given
final Class[] classesToTest = {GoodPojo_Equals_HashCode_Inner_Class.class};
final EqualsTester equalsTester = new EqualsTester(DefaultFieldValueChanger.INSTANCE);

// when
final Throwable result = catchThrowable(() -> equalsTester.testAll(classesToTest));

// then
assertThat(result).isNull();
}

@Test
void Should_Pass_All_Equals_Tests_Excluding_Fields() {
// given
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package pl.pojo.tester.internal.tester;

import lombok.Builder;
import lombok.Data;

@Data
@Builder
public class GoodPojo_Equals_HashCode_Inner_Class {
private InternalClass internalClass;

@Data
public static class InternalClass {
String id;
}
}