assertj / assertj/assertj-generator
Feature: Create "unwrapped" overload for `hasX` if X is a value type
- Dominant language
- Java
- Stars
- 72
- Forks
- 47
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 2
Description
This is potentially a little vague in its broadness, but here goes.
Say we have a value class like e.g.
```java
@Value
class AccountNumber {
String rawValue;
}
```
If another class (for which we generate assertions) has a property of this type, we can assert:
```java
assertThat(someObject).hasAccountNumber(new AccountNumber("abc"))
```
Nicer would be:
```java
assertThat(someObject).hasAccountNumber("abc")
```
The generator could look for constructors, static `_.of` methods, and other popular patterns. It's not clear to me if there should be a limit on the length of the parameter list. Anyway, the desired implementation seems straight-forward:
```java
public S hasAccountNumber(String accountNumberRawValue) {
return hasAccountNumber(new AccountNumber(fooRawValue));
}
```
As an alternative, there could be an annotation like e.g.
```java
@AssertionAlias
static Foo of(String rawValue) { ... }
```
On a property `Foo bar`, this would cause additional generation of something like
```java
public S hasBar(String fooRawValue) {
return hasBar(Foo.of(fooRawValue));
}
```
PS: This is probably easily done for specific use cases in any given project using templates, but I don't see documentation for a way to inject custom templates when using the generator through the Maven plugin.
Contributor guide
Assessment
This issue has not been assessed yet.