001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.juneau.bct.assertions;
018
019import java.io.*;
020import java.util.function.*;
021
022
023/**
024 * Used for assertion calls against generic POJOs.
025 *
026 * <p>
027 * Extends from {@link ObjectAssertion} allowing you to perform basic assertions, but adds several transform
028 * methods to convert to more-specific assertion types.
029 *
030 * <h5 class='section'>Example:</h5>
031 * <p class='bjava'>
032 *    <jk>import static</jk> org.apache.juneau.bct.assertions.Assertions.*;
033 *
034 *    List&lt;MyBean&gt; <jv>listOfBeans</jv> = ...;
035 *    <jsm>assertList</jsm>(<jv>listOfBeans</jv>)
036 *       .asItem(1)  <jc>// Returns an AnyAssertion.</jc>
037 *       .asBean()  <jc>// Transforms to BeanAssertion.</jc>
038 *          .asProperty(<js>"foo"</js>)  <jc>// Returns an AnyAssertion.</jc>
039 *          .asString()  <jc>// Transforms to StringAssertion.</jc>
040 *             .is(<js>"bar"</js>);  <jc>// Performs test.</jc>
041 * </p>
042 *
043 *
044 * <h5 class='section'>Test Methods:</h5>
045 * <p>
046 * <ul class='javatree'>
047 *    <li class='jc'>{@link FluentObjectAssertion}
048 *       <ul class='javatreec'>
049 *          <li class='jm'>{@link FluentObjectAssertion#isExists() isExists()}</li>
050 *          <li class='jm'>{@link FluentObjectAssertion#is(Object) is(Object)}</li>
051 *          <li class='jm'>{@link FluentObjectAssertion#is(Predicate) is(Predicate)}</li>
052 *          <li class='jm'>{@link FluentObjectAssertion#isNot(Object) isNot(Object)}</li>
053 *          <li class='jm'>{@link FluentObjectAssertion#isAny(Object...) isAny(Object...)}</li>
054 *          <li class='jm'>{@link FluentObjectAssertion#isNotAny(Object...) isNotAny(Object...)}</li>
055 *          <li class='jm'>{@link FluentObjectAssertion#isNull() isNull()}</li>
056 *          <li class='jm'>{@link FluentObjectAssertion#isNotNull() isNotNull()}</li>
057 *          <li class='jm'>{@link FluentObjectAssertion#isString(String) isString(String)}</li>
058 *          <li class='jm'>{@link FluentObjectAssertion#isSame(Object) isSame(Object)}</li>
059 *          <li class='jm'>{@link FluentObjectAssertion#isType(Class) isType(Class)}</li>
060 *          <li class='jm'>{@link FluentObjectAssertion#isExactType(Class) isExactType(Class)}</li>
061 *       </ul>
062 *    </li>
063 * </ul>
064 *
065 * <h5 class='section'>Transform Methods:</h5>
066 * <p>
067 * <ul class='javatree'>
068 *    <li class='jc'>{@link FluentAnyAssertion}
069 *    <ul class='javatreec'>
070 *       <li class='jm'>{@link FluentAnyAssertion#asArray(Class) asArray(Class)}
071 *       <li class='jm'>{@link FluentAnyAssertion#asIntArray() asIntArray()}
072 *       <li class='jm'>{@link FluentAnyAssertion#asLongArray() asLongArray()}
073 *       <li class='jm'>{@link FluentAnyAssertion#asShortArray() asShortArray()}
074 *       <li class='jm'>{@link FluentAnyAssertion#asFloatArray() asFloatArray()}
075 *       <li class='jm'>{@link FluentAnyAssertion#asDoubleArray() asDoubleArray()}
076 *       <li class='jm'>{@link FluentAnyAssertion#asCharArray() asCharArray()}
077 *       <li class='jm'>{@link FluentAnyAssertion#asByteArray() asByteArray()}
078 *       <li class='jm'>{@link FluentAnyAssertion#asBooleanArray() asBooleanArray()}
079 *       <li class='jm'>{@link FluentAnyAssertion#asBoolean() asBoolean()}
080 *       <li class='jm'>{@link FluentAnyAssertion#asBytes() asBytes()}
081 *       <li class='jm'>{@link FluentAnyAssertion#asCollection() asCollection()}
082 *       <li class='jm'>{@link FluentAnyAssertion#asCollection(Class) asCollection(Class)}
083 *       <li class='jm'>{@link FluentAnyAssertion#asStringList() asStringList()}
084 *       <li class='jm'>{@link FluentAnyAssertion#asComparable() asComparable()}
085 *       <li class='jm'>{@link FluentAnyAssertion#asDate() asDate()}
086 *       <li class='jm'>{@link FluentAnyAssertion#asInteger() asInteger()}
087 *       <li class='jm'>{@link FluentAnyAssertion#asLong() asLong()}
088 *       <li class='jm'>{@link FluentAnyAssertion#asList() asList()}
089 *       <li class='jm'>{@link FluentAnyAssertion#asList(Class) asList(Class)}
090 *       <li class='jm'>{@link FluentAnyAssertion#asMap() asMap()}
091 *       <li class='jm'>{@link FluentAnyAssertion#asMap(Class,Class) asMap(Class,Class)}
092 *       <li class='jm'>{@link FluentAnyAssertion#asBean() asBean()}
093 *       <li class='jm'>{@link FluentAnyAssertion#asBean(Class) asBean(Class)}
094 *       <li class='jm'>{@link FluentAnyAssertion#asBeanList(Class) asBeanList(Class)}
095 *       <li class='jm'>{@link FluentAnyAssertion#asZonedDateTime() asZonedDateTime()}
096 *    </ul>
097 *    <li class='jc'>{@link FluentObjectAssertion}
098 *    <ul class='javatreec'>
099 *       <li class='jm'>{@link FluentObjectAssertion#asString() asString()}
100 *       <li class='jm'>{@link FluentObjectAssertion#asString(ThrowingFunction) asString(ThrowingFunction)}
101 *       <li class='jm'>{@link FluentObjectAssertion#asTransformed(UnaryOperator) asTransformed(UnaryOperator)}
102 *       <li class='jm'>{@link FluentObjectAssertion#asAny() asAny()}
103 * </ul>
104 * </ul>
105 *
106 * <h5 class='section'>Configuration Methods:</h5>
107 * <p>
108 * <ul class='javatree'>
109 *    <li class='jc'>{@link Assertion}
110 *    <ul class='javatreec'>
111 *       <li class='jm'>{@link Assertion#setMsg(String, Object...) setMsg(String, Object...)}
112 *       <li class='jm'>{@link Assertion#setOut(PrintStream) setOut(PrintStream)}
113 *       <li class='jm'>{@link Assertion#setSilent() setSilent()}
114 *       <li class='jm'>{@link Assertion#setStdOut() setStdOut()}
115 *       <li class='jm'>{@link Assertion#setThrowable(Class) setThrowable(Class)}
116 *    </ul>
117 * </ul>
118 *
119 * <h5 class='section'>See Also:</h5>
120 * <ul>
121 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauEcosystemOverview">Juneau Ecosystem</a>
122 * </ul>
123 *
124 * @param <T> The object type.
125 */
126public class AnyAssertion<T> extends FluentAnyAssertion<T,AnyAssertion<T>> {
127
128   // -----------------------------------------------------------------------------------------------------------------
129   // Static
130   // -----------------------------------------------------------------------------------------------------------------
131
132   /**
133    * Static creator.
134    *
135    * @param <T> The value type.
136    * @param value
137    *    The object being tested.
138    *    <br>Can be <jk>null</jk> (assertions such as {@code isNull()} then operate on the absence of a value).
139    * @return A new assertion object.
140    */
141   public static <T> AnyAssertion<T> create(T value) {
142      return new AnyAssertion<>(value);
143   }
144
145   // -----------------------------------------------------------------------------------------------------------------
146   // Instance
147   // -----------------------------------------------------------------------------------------------------------------
148
149   /**
150    * Constructor.
151    *
152    * @param value
153    *    The object being tested.
154    *    <br>Can be <jk>null</jk> (assertions such as {@code isNull()} then operate on the absence of a value).
155    */
156   public AnyAssertion(T value) {
157      super(value, null);
158   }
159
160   // -----------------------------------------------------------------------------------------------------------------
161   // Fluent setters
162   // -----------------------------------------------------------------------------------------------------------------
163   @Override /* Overridden from Assertion */
164   public AnyAssertion<T> setMsg(String msg, Object...args) {
165      super.setMsg(msg, args);
166      return this;
167   }
168
169   @Override /* Overridden from Assertion */
170   public AnyAssertion<T> setOut(PrintStream value) {
171      super.setOut(value);
172      return this;
173   }
174
175   @Override /* Overridden from Assertion */
176   public AnyAssertion<T> setSilent() {
177      super.setSilent();
178      return this;
179   }
180
181   @Override /* Overridden from Assertion */
182   public AnyAssertion<T> setStdOut() {
183      super.setStdOut();
184      return this;
185   }
186
187   @Override /* Overridden from Assertion */
188   public AnyAssertion<T> setThrowable(Class<? extends RuntimeException> value) {
189      super.setThrowable(value);
190      return this;
191   }
192}