-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…equals-and-hashcode-have-unwanted-fields #121 make pojo test fails when equals and hashcode have unwanted fields
- Loading branch information
Showing
13 changed files
with
205 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/java/pl/pojo/tester/internal/assertion/equals/EqualEqualsAssertionError.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package pl.pojo.tester.internal.assertion.equals; | ||
|
||
|
||
class EqualEqualsAssertionError extends EqualsAssertionError { | ||
|
||
private static final String CONSTRAINT_NOT_EQUAL = | ||
"The equals method should return true if objects should be equal.\n" | ||
+ "Current implementation returns false.\n" | ||
+ "Object:\n" | ||
+ "%s\n" | ||
+ "should be equal to:\n" | ||
+ "%s"; | ||
private final Object testedObject; | ||
private final Object otherObject; | ||
|
||
EqualEqualsAssertionError(final Class<?> testedCass, final Object testedObject, final Object otherObject) { | ||
super(testedCass); | ||
this.testedObject = testedObject; | ||
this.otherObject = otherObject; | ||
} | ||
|
||
@Override | ||
protected String getDetailedMessage() { | ||
return String.format(CONSTRAINT_NOT_EQUAL, testedObject, otherObject); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/test/java/pl/pojo/tester/internal/assertion/equals/EqualEqualsAssertionErrorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package pl.pojo.tester.internal.assertion.equals; | ||
|
||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.platform.runner.JUnitPlatform; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@RunWith(JUnitPlatform.class) | ||
public class EqualEqualsAssertionErrorTest { | ||
|
||
@Test | ||
public void Should_Return_Expected_Detailed_Message() { | ||
// given | ||
final String expectedMessage = "The equals method should return true if objects should be equal.\n" | ||
+ "Current implementation returns false.\n" | ||
+ "Object:\n" | ||
+ "testedObject\n" | ||
+ "should be equal to:\n" | ||
+ "otherObject"; | ||
final Class<String> testedCass = String.class; | ||
final String testedObject = "testedObject"; | ||
final String otherObject = "otherObject"; | ||
final EqualEqualsAssertionError error = new EqualEqualsAssertionError(testedCass, testedObject, otherObject); | ||
|
||
// when | ||
final String result = error.getDetailedMessage(); | ||
|
||
// then | ||
assertThat(result).isEqualTo(expectedMessage); | ||
} | ||
} |
Oops, something went wrong.