Add custom exception assertions

Aperta
#175 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

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

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.

Descrizione

Currently, the documentation shows how to extend an assertion in 2.6.2 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

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?

Lingua principale
CSS
Stelle
26
Fork
32
Merge medio
1g 19h
PR unite (30g)
4

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di assertj/doc

Tutte le issue di assertj/doc

Issue simili

Altre issue su Documentation

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.