assertj / assertj/doc

Add custom exception assertions

Aperta
#175 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
CSS
Stelle
26
Fork
32
Merge medio
2g 9h
PR unite (30g)
3

Descrizione

Currently, the documentation shows how to extend an assertion in [2.6.2 Custom Assertions](https://assertj.github.io/doc/#assertj-core-custom-assertions) but there is no documentation for custom exception asserts, which seems to use a slightly different mechanism with some other class hierarchy.

It would be nice to include this in the guide and in the [examples repository](https://github.com/assertj/assertj-examples)

The goal for this section in the guide will be to present, given a custom exception, a way to assert on the specific fields in that class. For instance, given a custom exception:
```
package com.example.exception;

public class DetailException extends RuntimeException {

private String detail;

public DetailException(String message, String detail) {
super(message);
this.detail = detail;
}

public String getDetail() {
return detail;
}
}
```

and a business logic throwing this exception
```
package com.example.thrower;

import com.example.exception.DetailException;

public class DetailExceptionThrower {

public void throwException() {
throw new DetailException("message", "a detailed exception explanation");
}
}
```

write an extension to write a test like:
```
package com.example.thrower;

import org.junit.jupiter.api.Test;

import static org.assertj.extension.DetailExceptionAssertions.assertThatDetailException;

class DetailExceptionThrowerCustomAssertionTest {

private final DetailExceptionThrower underTest = new DetailExceptionThrower();

@Test
void test_customAssertion() {
assertThatDetailException()
.isThrownBy(underTest::throwException)
.withMessage("message")
.withDetail("a detailed exception explanation");
}
}
```

is it even possible to write an extension like this?

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

Inizia con la sezione esistente «2.6.2 Custom Assertions» nella guida AssertJ collegata e ispeziona il repository assertj-examples collegato per verificarne gli esempi di assertions attuali. Verifica come le assertions personalizzate per le eccezioni si inseriscono nella gerarchia di classi esistente e documenta in entrambe le posizioni un esempio che copra il messaggio dell’eccezione e i campi di dettaglio.

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

Valutazione

Stack tecnologico
java
Ambito
documentation
Tipo di issue
Documentazione
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.