https://github.com/t28hub/auto-truth
Generate the Truth extensions for value objects for Java 8+.
https://github.com/t28hub/auto-truth
assertions java kotlin testing truth
Last synced: about 15 hours ago
JSON representation
Generate the Truth extensions for value objects for Java 8+.
- Host: GitHub
- URL: https://github.com/t28hub/auto-truth
- Owner: t28hub
- License: apache-2.0
- Created: 2019-12-13T14:35:32.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2025-06-07T11:01:15.000Z (about 1 year ago)
- Last Synced: 2025-06-07T12:17:54.528Z (about 1 year ago)
- Topics: assertions, java, kotlin, testing, truth
- Language: Kotlin
- Homepage:
- Size: 423 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# AutoTruth
[](https://github.com/t28hub/auto-truth/actions)
[](https://app.fossa.io/projects/custom%2B14538%2Fauto-truth?ref=badge_shield)
[](https://sonarcloud.io/dashboard?id=io.t28.auto.truth)
[](https://sonarcloud.io/dashboard?id=io.t28.auto.truth)
Generate the [Truth](https://truth.dev/) extensions for value objects for Java 8+.
## Usage
Add the `@AutoTruth` annotation to a custom subject class and specify a value object class.
This example uses [Employee.java](https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/extension/Employee.java).
```java
@AutoSubject(Employee.class)
class EmployeeSubject {
}
```
Then AutoTruth generates the `AutoEmployeeSubject` that is declared the following methods:
* `hasUsername(String)`
* `hasId(long)`
* `hasName(String)`
* `hasLocation(Location)`
* `isCeo()`
* `isNotCeo()`
You can extends the `AutoEmployeeSubject` as follows, if the generated methods are not enough.
```java
@AutoSubject(Employee.class)
public class EmployeeSubject extends AutoEmployeeSubject {
private final Employee actual;
EmployeeSubject(FailureMetadata failureMetadata, Employee actual) {
super(failureMetadata, actual);
this.actual = actual;
}
public static EmployeeSubject assertThat(Employee actual) {
return Truth.assertAbout(EmployeeSubject::new).that(actual);
}
public LocationSubject location() {
final Location actual = this.actual.location();
return check("location()").about(LocationSubject::new).that(actual);
}
@AutoSubject(Employee.Location.class)
public static class LocationSubject {}
}
```
### Supported types
AutoTruth supports the following types:
#### Primitive types
* `boolean`
* `byte`
* `char`
* `short`
* `int`
* `long`
* `float`
* `double`
#### Array types
* `boolean[]`
* `byte[]`
* `char[]`
* `short[]`
* `int[]`
* `long[]`
* `float[]`
* `double[]`
* `Object[]`
#### Java8 types
* `Optional`
* `OptionalInt`
* `OptionalLong`
* `OptionalDouble`
* `Stream`
* `IntStream`
* `LongStream`
#### Other JDK types
* `Enum`
* `Object`
* `Class`
* `String`
* `Iterable`
* `Map`
## Installing
The AutoTruth packages are available on the [GitHub Packages](https://github.com/t28hub/auto-truth/packages).
You need an access token to install packages in GitHub Packages.
Instructions for creating an access token is described in [GitHub Help](https://help.github.com/en/packages/publishing-and-managing-packages/about-github-packages#about-tokens).
### Gradle
```
repositories {
mavenCentral()
jcenter()
maven {
url 'https://maven.pkg.github.com/t28hub/auto-truth'
credentials {
username = 'YOUR_GITHUB_USERNAME'
password = 'YOUR_GITHUB_TOKEN'
}
}
}
dependencies {
testImplementation "com.google.truth:truth:$LATEST_TRUTH_VERSION"
testImplementation "com.google.truth.extensions:truth-java8-extension:$LATEST_TRUTH_VERSION"
testImplementation "io.t28.auto:auto-truth-annotations:$LATEST_VERSION"
testAnnotationProcessor "io.t28.auto:auto-truth-processor:$LATEST_VERSION"
}
```
### Maven
See [GitHub Help](https://help.github.com/en/packages/using-github-packages-with-your-projects-ecosystem/configuring-apache-maven-for-use-with-github-packages).
## License
[](https://app.fossa.io/projects/custom%2B14538%2Fauto-truth?ref=badge_large)