Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Add assertions for database structure

Aperta
#12 6 commenti 0 reazioni 1 assegnatario Vedi su GitHub

@regis1512 ci sta già lavorando.

Dal 9/7/2015.

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

enhancement

I need assertions for checking database structure.
E.g. I want to check if specific table exists in database.

Proposed assertions:
assertThat(table).exists();
or
assertThat(source).tableExists("name");

Additionally it would be nice to have convinience method isEmpty() for
assertThat(table).hasNumberOfRows(0);

JDBC code to check if table exists ()

public static boolean hasTable(DataSource ds, String name) {
        boolean exists = false;

        try(Connection c = ds.getConnection();
            //table names usually stored in database uppercased
            ResultSet rs = c.getMetaData().getTables(null, null, name.toUpperCase(), null)) {

            if (rs.next()) {
                exists = true; // table exists
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return exists;
    }

Or just do some operation and catch jdbc exception: table not exists. Below assertion partially does the trick, but is not elegant.
assertThat(table).hasNumberOfRows(0);

Lingua principale
Java
Stelle
130
Fork
21
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Guida per i contributori

Apri la guida per i contributori

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/assertj-db

Tutte le issue di assertj/assertj-db

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.