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 */ 034 public class BooleanAssert extends AbstractAssert<BooleanAssert, Boolean> { 035 036 @VisibleForTesting 037 Booleans booleans = Booleans.instance(); 038 039 protected BooleanAssert(Boolean actual) { 040 super(actual, BooleanAssert.class); 041 } 042 043 /** 044 * Verifies that the actual value is {@code true}. 045 * @return {@code this} assertion object. 046 * @throws AssertionError if the actual value is {@code null}. 047 * @throws AssertionError if the actual value is not {@code true}. 048 */ 049 public BooleanAssert isTrue() { 050 return isEqualTo(true); 051 } 052 053 /** 054 * Verifies that the actual value is {@code false}. 055 * @return {@code this} assertion object. 056 * @throws AssertionError if the actual value is {@code null}. 057 * @throws AssertionError if the actual value is not {@code false}. 058 */ 059 public BooleanAssert isFalse() { 060 return isEqualTo(false); 061 } 062 063 /** 064 * Verifies that the actual value is equal to the given one. 065 * @param expected the given value to compare the actual value to. 066 * @return {@code this} assertion object. 067 * @throws AssertionError if the actual value is {@code null}. 068 * @throws AssertionError if the actual value is not equal to the given one. 069 */ 070 public BooleanAssert isEqualTo(boolean expected) { 071 booleans.assertEqual(info, actual, expected); 072 return this; 073 } 074 075 /** 076 * Verifies that the actual value is not equal to the given one. 077 * @param other the given value to compare the actual value to. 078 * @return {@code this} assertion object. 079 * @throws AssertionError if the actual value is {@code null}. 080 * @throws AssertionError if the actual value is equal to the given one. 081 */ 082 public BooleanAssert isNotEqualTo(boolean other) { 083 booleans.assertNotEqual(info, actual, other); 084 return this; 085 } 086 087 @Override 088 public BooleanAssert usingComparator(Comparator<?> customComparator) { 089 throw new UnsupportedOperationException("custom Comparator is not supported for Boolean comparison"); 090 } 091 }