001// *************************************************************************************************************************** 002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * 003// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * 004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * 005// * 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 is distributed on an * 010// * "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// *************************************************************************************************************************** 013package org.apache.juneau.assertions; 014 015 016import org.apache.juneau.internal.*; 017 018/** 019 * Used for fluent assertion calls against booleans. 020 * 021 * @param <R> The return type. 022 */ 023@FluentSetters(returns="FluentBooleanAssertion<R>") 024public class FluentBooleanAssertion<R> extends FluentComparableAssertion<R> { 025 026 private final Boolean value; 027 028 /** 029 * Constructor. 030 * 031 * @param value The value being tested. 032 * @param returns The object to return after the test. 033 */ 034 public FluentBooleanAssertion(Boolean value, R returns) { 035 this(null, value, returns); 036 } 037 038 /** 039 * Constructor. 040 * 041 * @param creator The assertion that created this assertion. 042 * @param value The value being tested. 043 * @param returns The object to return after the test. 044 */ 045 public FluentBooleanAssertion(Assertion creator, Boolean value, R returns) { 046 super(creator, value, returns); 047 this.value = value; 048 } 049 050 /** 051 * Asserts that the value is true. 052 * 053 * @return The response object (for method chaining). 054 * @throws AssertionError If assertion failed. 055 */ 056 public R isTrue() throws AssertionError { 057 exists(); 058 if (value == false) 059 throw error("Value was false."); 060 return returns(); 061 } 062 063 /** 064 * Asserts that the value is false. 065 * 066 * @return The response object (for method chaining). 067 * @throws AssertionError If assertion failed. 068 */ 069 public R isFalse() throws AssertionError { 070 exists(); 071 if (value == true) 072 throw error("Value was true."); 073 return returns(); 074 } 075 076 // <FluentSetters> 077 078 @Override /* GENERATED - Assertion */ 079 public FluentBooleanAssertion<R> msg(String msg, Object...args) { 080 super.msg(msg, args); 081 return this; 082 } 083 084 @Override /* GENERATED - Assertion */ 085 public FluentBooleanAssertion<R> stderr() { 086 super.stderr(); 087 return this; 088 } 089 090 @Override /* GENERATED - Assertion */ 091 public FluentBooleanAssertion<R> stdout() { 092 super.stdout(); 093 return this; 094 } 095 096 // </FluentSetters> 097}