001    /*
002     * Created on Oct 21, 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.api;
016    
017    import java.util.Comparator;
018    
019    import org.fest.assertions.internal.Booleans;
020    import org.fest.util.VisibleForTesting;
021    
022    /**
023     * Assertion methods for bytes.
024     * <p>
025     * To create an instance of this class, invoke <code>{@link Assertions#assertThat(Boolean)}</code> or
026     * <code>{@link Assertions#assertThat(boolean)}</code>.
027     * </p>
028     * 
029     * @author Alex Ruiz
030     * @author Yvonne Wang
031     * @author David DIDIER
032     * @author Ansgar Konermann
033     * @author Mikhail Mazursky
034     */
035    public class BooleanAssert extends AbstractAssert<BooleanAssert, Boolean> {
036    
037      @VisibleForTesting
038      Booleans booleans = Booleans.instance();
039    
040      protected BooleanAssert(Boolean actual) {
041        super(actual, BooleanAssert.class);
042      }
043    
044      /**
045       * Verifies that the actual value is {@code true}.
046       * @return {@code this} assertion object.
047       * @throws AssertionError if the actual value is {@code null}.
048       * @throws AssertionError if the actual value is not {@code true}.
049       */
050      public BooleanAssert isTrue() {
051        return isEqualTo(true);
052      }
053    
054      /**
055       * Verifies that the actual value is {@code false}.
056       * @return {@code this} assertion object.
057       * @throws AssertionError if the actual value is {@code null}.
058       * @throws AssertionError if the actual value is not {@code false}.
059       */
060      public BooleanAssert isFalse() {
061        return isEqualTo(false);
062      }
063    
064      /**
065       * Verifies that the actual value is equal to the given one.
066       * @param expected the given value to compare the actual value to.
067       * @return {@code this} assertion object.
068       * @throws AssertionError if the actual value is {@code null}.
069       * @throws AssertionError if the actual value is not equal to the given one.
070       */
071      public BooleanAssert isEqualTo(boolean expected) {
072        booleans.assertEqual(info, actual, expected);
073        return this;
074      }
075    
076      /**
077       * Verifies that the actual value is not equal to the given one.
078       * @param other the given value to compare the actual value to.
079       * @return {@code this} assertion object.
080       * @throws AssertionError if the actual value is {@code null}.
081       * @throws AssertionError if the actual value is equal to the given one.
082       */
083      public BooleanAssert isNotEqualTo(boolean other) {
084        booleans.assertNotEqual(info, actual, other);
085        return this;
086      }
087    
088      @Override
089      public BooleanAssert usingComparator(Comparator<? super Boolean> customComparator) {
090        throw new UnsupportedOperationException("custom Comparator is not supported for Boolean comparison");
091      }
092    }