assertj / assertj/assertj-generator

Feature: Create "unwrapped" overload for `hasX` if X is a value type

Aperta
#159 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Java
Stelle
72
Fork
47
Merge medio
1g 16h
PR unite (30g)
2

Descrizione

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.

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Non è indicato alcun file sorgente né alcun test. Inizia dal percorso del plugin Maven del generatore e dal meccanismo esistente di personalizzazione dei template menzionato nell’issue, quindi esamina come vengono definiti i metodi hasX generati. Prima dell’implementazione, concorda sui pattern di costruzione dei tipi valore supportati, sui limiti dei parametri e sul fatto che gli alias basati su annotazioni rientrino o meno nell’ambito; il lavoro è considerato completato quando il comportamento scelto è specificato e coperto da test dell’output generato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
java
Ambito
tooling
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.