001 /*
002 * Created on Mar 19, 2007
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
005 * in compliance with 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
010 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
011 * or implied. See the License for the specific language governing permissions and limitations under
012 * the License.
013 *
014 * Copyright @2007-2011 the original author or authors.
015 */
016 package org.fest.assertions;
017
018 import static java.lang.Boolean.valueOf;
019
020 /**
021 * Assertions for {@code Boolean}s and {@code boolean}s.
022 * <p>
023 * To create a new instance of this class invoke either <code>{@link Assertions#assertThat(Boolean)}</code> or
024 * <code>{@link Assertions#assertThat(boolean)}</code>.
025 * </p>
026 *
027 * @author Alex Ruiz
028 * @author Yvonne Wang
029 * @author David DIDIER
030 * @author Ansgar Konermann
031 */
032 public class BooleanAssert extends GenericAssert<BooleanAssert, Boolean> {
033
034 /**
035 * Creates a new <code>{@link BooleanAssert}</code>.
036 * @param actual the actual value to verify.
037 */
038 protected BooleanAssert(boolean actual) {
039 super(BooleanAssert.class, actual);
040 }
041
042 /**
043 * Creates a new <code>{@link BooleanAssert}</code>.
044 * @param actual the actual value to verify.
045 */
046 protected BooleanAssert(Boolean actual) {
047 super(BooleanAssert.class, actual);
048 }
049
050 /**
051 * Verifies that the actual {@code Boolean} value is {@code true}.
052 * @throws AssertionError if the actual {@code Boolean} value is {@code false}.
053 */
054 public void isTrue() {
055 isEqualTo(true);
056 }
057
058 /**
059 * Verifies that the actual {@code Boolean} value is {@code false}.
060 * @throws AssertionError if the actual {@code Boolean} value is {@code true}.
061 */
062 public void isFalse() {
063 isEqualTo(false);
064 }
065
066 /**
067 * Verifies that the actual {@code Boolean} is equal to the given one.
068 * @param expected the given {@code boolean} to compare the actual {@code Boolean} to.
069 * @return this assertion object.
070 * @throws AssertionError if the actual {@code Boolean} is not equal to the given one.
071 */
072 public BooleanAssert isEqualTo(boolean expected) {
073 return isEqualTo(valueOf(expected));
074 }
075
076 /**
077 * Verifies that the actual {@code Boolean} is not equal to the given one.
078 * @param other the given {@code boolean} to compare the actual {@code Boolean} to.
079 * @return this assertion object.
080 * @throws AssertionError if the actual {@code Boolean} is equal to the given one.
081 */
082 public BooleanAssert isNotEqualTo(boolean other) {
083 return isNotEqualTo(valueOf(other));
084 }
085 }