https://github.com/testmonkeys/jentitytest
A Java library which provides hamcrest matchers for matching objects, based on annotations and strategies
https://github.com/testmonkeys/jentitytest
Last synced: about 1 year ago
JSON representation
A Java library which provides hamcrest matchers for matching objects, based on annotations and strategies
- Host: GitHub
- URL: https://github.com/testmonkeys/jentitytest
- Owner: TestMonkeys
- License: apache-2.0
- Created: 2016-06-07T19:35:14.000Z (almost 10 years ago)
- Default Branch: develop
- Last Pushed: 2024-01-10T13:46:44.000Z (about 2 years ago)
- Last Synced: 2025-01-13T04:43:02.639Z (about 1 year ago)
- Language: Java
- Homepage:
- Size: 421 KB
- Stars: 2
- Watchers: 4
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# jEntityTest
[](https://circleci.com/gh/TestMonkeys/jEntityTest)
[](https://codecov.io/gh/TestMonkeys/jEntityTest)
[](https://search.maven.org/artifact/org.testmonkeys/jentitytest)
[](https://codeclimate.com/github/TestMonkeys/jEntityTest/maintainability)
[](https://codeclimate.com/github/TestMonkeys/jEntityTest/test_coverage)
jEntityTest is a library that can compare two instances of a class based on their declared fields. Making it easier to check if they are equal. It also contains a hamcrest matcher so that you can use the comparison in assertions. The comparison can further be customized via annotations for each field.
# Usage Example
A simple use case would be creating a user via API, then retrieving it and checking it was created correctly:
```java
User createdUser = api.createUser(newUser);
assertThat(createdUser, Entity.isEqualTo(newUser));
```
In the above case, `Entity.isEqualTo`, which is part of jEntityTest, will do the comparison between the two objects.
Now let's look at the actual fields that the User object has
User fields | newUser values | createdUser values
------------ | -------------- | ------------------
id | | 1
firstName | John | John
lastName | Doe | Doe
The id was generated on while creating the user, so we can't know it beforehand. For the comparison to not fail in this case - fields can be decorated with annotations specifying the comparison strategy to be applied, so the user model would be:
```java
public class User{
@IgnoreComparison
private String id;
private String firstName;
private String lastName;
...
```
There are a few more comparison strategies that can be applied for any field, that will impact how the comparison is done.
# Comparison Strategies available
For a more detailed explanation of each comparison strategy please visit the [wiki](https://github.com/TestMonkeys/jEntityTest/wiki/JEntityTest-comparison-strategies)
## ChildEntityComparison
`@ChildEntityComparison` can be applied to a field if it is an object that you want to also compare by it's fields.
## ChildEntityListComparison
`@ChildEntityListComparison` can be applied to lists, this will compare each item in the list between the expected and actual objects.
## DateTimeComparison
`@DateTimeComparison` can be applied to LocalDateTime fields - and is parameterized to allow for a delta.
## StringComparison
`@StringComparison` can be applied to String fields and can be parameterized to trim, ignore specific characters, or ignore the case.