assertj / assertj/doc

Add custom exception assertions

Ouverte
#175 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
CSS
Étoiles
26
Forks
32
Merge moyen
2 j 9 h
PR mergées (30 j)
3

Description

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?

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Piste de recherche

Commencez par la section existante « 2.6.2 Custom Assertions » du guide AssertJ lié et examinez le dépôt assertj-examples lié pour voir ses exemples d’assertions actuels. Confirmez comment les assertions personnalisées d’exception s’intègrent dans la hiérarchie de classes existante, puis documentez aux deux endroits un exemple couvrant le message de l’exception et les champs de détail.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
java
Domaine
documentation
Type d'issue
Documentation
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
35/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.