001    /*
002     * Created on Jul 25, 2010
003     * 
004     * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
005     * the License. You may obtain a copy of the License at
006     * 
007     * http://www.apache.org/licenses/LICENSE-2.0
008     * 
009     * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
010     * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
011     * specific language governing permissions and limitations under the License.
012     * 
013     * Copyright @2010-2011 the original author or authors.
014     */
015    package org.fest.assertions.core;
016    
017    import java.util.Comparator;
018    
019    /**
020     * Assertions applicable to groups of values that can be enumerated (e.g. arrays, collections or strings.)
021     * @param <S> the "self" type of this assertion class. Please read &quot;<a href="http://bit.ly/anMa4g"
022     *          target="_blank">Emulating 'self types' using Java Generics to simplify fluent API implementation</a>&quot;
023     *          for more details.
024     * @param <T> the type of elements of the "actual" value.
025     * 
026     * @author Yvonne Wang
027     * @author Alex Ruiz
028     */
029    public interface EnumerableAssert<S, T> {
030    
031      /**
032       * Verifies that the actual group of values is {@code null} or empty.
033       * @throws AssertionError if the actual group of values is not {@code null} or not empty.
034       */
035      void isNullOrEmpty();
036    
037      /**
038       * Verifies that the actual group of values is empty.
039       * @throws AssertionError if the actual group of values is not empty.
040       */
041      void isEmpty();
042    
043      /**
044       * Verifies that the actual group of values is not empty.
045       * @return {@code this} assertion object.
046       * @throws AssertionError if the actual group of values is empty.
047       */
048      S isNotEmpty();
049    
050      /**
051       * Verifies that the number of values in the actual group is equal to the given one.
052       * @param expected the expected number of values in the actual group.
053       * @return {@code this} assertion object.
054       * @throws AssertionError if the number of values of the actual group is not equal to the given one.
055       */
056      S hasSize(int expected);
057    
058      /**
059       * Use given custom comparator instead of relying on actual type A <code>equals</code> method to compare group
060       * elements for incoming assertion checks.
061       * <p>
062       * Custom comparator is bound to assertion instance, meaning that if a new assertion is created, it will use default
063       * comparison strategy.
064       * <p>
065       * Examples :
066       * 
067       * <pre>
068       * // compares invoices by payee 
069       * assertThat(invoiceList).usingComparator(invoicePayeeComparator).isEqualTo(expectedInvoiceList).
070       * 
071       * // compares invoices by date, doesNotHaveDuplicates and contains both use the given invoice date comparator
072       * assertThat(invoiceList).usingComparator(invoiceDateComparator).doesNotHaveDuplicates().contains(may2010Invoice)
073       * 
074       * // as assertThat(invoiceList) creates a new assertion, it falls back to standard comparison strategy 
075       * // based on Invoice's equal method to compare invoiceList elements to lowestInvoice.                                                      
076       * assertThat(invoiceList).contains(lowestInvoice).
077       * 
078       * // standard comparison : the fellowshipOfTheRing includes Gandalf but not Sauron (believe me) ...
079       * assertThat(fellowshipOfTheRing).contains(gandalf)
080       *                                .doesNotContain(sauron);
081       * 
082       * // ... but if we compare only races, Sauron is in fellowshipOfTheRing because he's a Maia like Gandalf.
083       * assertThat(fellowshipOfTheRing).usingElementComparator(raceComparator)
084       *                                .contains(sauron);
085       * </pre>
086       * 
087       * @param customComparator the comparator to use for incoming assertion checks.
088       * @throws NullPointerException if the given comparator is {@code null}.
089       * @return {@code this} assertion object.
090       */
091      S usingElementComparator(Comparator<? super T> customComparator);
092    
093      /**
094       * Revert to standard comparison for incoming assertion group element checks.
095       * <p>
096       * This method should be used to disable a custom comparison strategy set by calling
097       * {@link #usingElementComparator(Comparator)}.
098       * @return {@code this} assertion object.
099       */
100      S usingDefaultElementComparator();
101    }