2014-05-15 14 views

risposta

8

Ho appena avendo uno sfogliare il codice sorgente per il ramo versione 1 e trovato questo:

/** 
* Verifies that the actual group of objects does not contain the given objects. 
* 
* @param objects the objects that the group of objects should exclude. 
* @return this assertion object. 
* @throws AssertionError  if the actual group of objects is {@code null}. 
* @throws NullPointerException if the given array is {@code null}. 
* @throws AssertionError  if the actual group of objects contains any of the given objects. 
*/ 
public final @Nonnull S excludes(@Nonnull Object... objects) { 
    assertExcludes(objects); 
    return myself(); 
} 

forse è meglio non fare ipotesi selvatici come questo, ma è nella stessa classe del metodo contains (ObjectGroupAssert) e Javadoc sembra descrivere la funzionalità che stai cercando.

Quindi penso, si avrebbe solo bisogno:

assertThat(list).excludes(5,7); 
+0

Funziona! Il nome del metodo 'excludes' è una piccola sorpresa per me – Freewind

+0

Huzzah! :) Sì, 'excludes' è nuovo anche per me, mi sarei aspettato una variante' doesNotContain'. Ma a pensarci, mi piacciono le esclude, ma potrebbe stare meglio con include come contropartita invece che contiene. –

Problemi correlati