001    /*
002     * Created on Jul 15, 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     * Base contract of all assertion objects: the minimum functionality that any assertion object should provide.
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 <A> the type of the "actual" value.
025     * 
026     * @author Yvonne Wang
027     * @author Alex Ruiz
028     * @author Nicolas François
029     * @author Mikhail Mazursky
030     */
031    public interface Assert<S, A> extends Descriptable<S>, ExtensionPoints<S, A> {
032    
033      /**
034       * Verifies that the actual value is equal to the given one.
035       * @param expected the given value to compare the actual value to.
036       * @return {@code this} assertion object.
037       * @throws AssertionError if the actual value is not equal to the given one.
038       */
039      S isEqualTo(A expected);
040    
041      /**
042       * Verifies that the actual value is not equal to the given one.
043       * @param other the given value to compare the actual value to.
044       * @return {@code this} assertion object.
045       * @throws AssertionError if the actual value is equal to the given one.
046       */
047      S isNotEqualTo(A other);
048    
049      /**
050       * Verifies that the actual value is {@code null}.
051       * @throws AssertionError if the actual value is not {@code null}.
052       */
053      void isNull();
054    
055      /**
056       * Verifies that the actual value is not {@code null}.
057       * @return {@code this} assertion object.
058       * @throws AssertionError if the actual value is {@code null}.
059       */
060      S isNotNull();
061    
062      /**
063       * Verifies that the actual value is the same as the given one.
064       * @param expected the given value to compare the actual value to.
065       * @return {@code this} assertion object.
066       * @throws AssertionError if the actual value is not the same as the given one.
067       */
068      S isSameAs(A expected);
069    
070      /**
071       * Verifies that the actual value is not the same as the given one.
072       * @param other the given value to compare the actual value to.
073       * @return {@code this} assertion object.
074       * @throws AssertionError if the actual value is the same as the given one.
075       */
076      S isNotSameAs(A other);
077    
078      /**
079       * Verifies that the actual value is present in the given array of values.
080       * @param values the given array to search the actual value in.
081       * @return {@code this} assertion object.
082       * @throws NullPointerException if the given array is {@code null}.
083       * @throws IllegalArgumentException if the given array is empty.
084       * @throws AssertionError if the actual value is not present in the given array.
085       */
086      S isIn(A... values);
087    
088      /**
089       * Verifies that the actual value is not present in the given array of values.
090       * @param values the given array to search the actual value in.
091       * @return {@code this} assertion object.
092       * @throws NullPointerException if the given array is {@code null}.
093       * @throws IllegalArgumentException if the given array is empty.
094       * @throws AssertionError if the actual value is present in the given array.
095       */
096      S isNotIn(A... values);
097    
098      /**
099       * Verifies that the actual value is present in the given values.
100       * @param values the given iterable to search the actual value in.
101       * @return {@code this} assertion object.
102       * @throws NullPointerException if the given collection is {@code null}.
103       * @throws IllegalArgumentException if the given collection is empty.
104       * @throws AssertionError if the actual value is not present in the given collection.
105       */
106      S isIn(Iterable<? extends A> values);
107    
108      /**
109       * Verifies that the actual value is not present in the given values.
110       * @param values the given iterable to search the actual value in.
111       * @return {@code this} assertion object.
112       * @throws NullPointerException if the given collection is {@code null}.
113       * @throws IllegalArgumentException if the given collection is empty.
114       * @throws AssertionError if the actual value is present in the given collection.
115       */
116      S isNotIn(Iterable<? extends A> values);
117    
118      /**
119       * Use given custom comparator instead of relying on actual type A equals method for incoming assertion checks.
120       * <p>
121       * Custom comparator is bound to assertion instance, meaning that if a new assertion is created, it will use default
122       * comparison strategy.
123       * <p>
124       * Examples :
125       * 
126       * <pre>
127       * // frodo and sam are instances of Character with Hobbit race (obviously :).
128       * // raceComparator implements Comparator&lt;Character&gt; 
129       * assertThat(frodo).usingComparator(raceComparator).isEqualTo(sam); 
130       * </pre>
131       * 
132       * @param customComparator the comparator to use for incoming assertion checks.
133       * @throws NullPointerException if the given comparator is {@code null}.
134       * @return {@code this} assertion object.
135       */
136      S usingComparator(Comparator<? super A> customComparator);
137    
138      /**
139       * Revert to standard comparison for incoming assertion checks.<p>
140       * This method should be used to disable a custom comparison strategy set by calling
141       * {@link #usingComparator(Comparator)}.
142       * @return {@code this} assertion object.
143       */
144      S usingDefaultComparator();
145    
146      /**
147       * Throws <code>{@link UnsupportedOperationException}</code> if called. It is easy to accidentally call
148       * <code>{@link #equals(Object)}</code> instead of <code>isEqualTo</code>.
149       * @throws UnsupportedOperationException if this method is called.
150       */
151      @Override
152      boolean equals(Object obj);
153    }