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 * <h2 class='section'>Example:</h2>
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 * <h2 class='section'>Test Methods:</h2>
045 * <ul class='javatree'>
046 *    <li class='jc'>{@link FluentObjectAssertion}
047 *       <ul class='javatreec'>
048 *          <li class='jm'>{@link FluentObjectAssertion#isExists() isExists()}</li>
049 *          <li class='jm'>{@link FluentObjectAssertion#is(Object) is(Object)}</li>
050 *          <li class='jm'>{@link FluentObjectAssertion#is(Predicate) is(Predicate)}</li>
051 *          <li class='jm'>{@link FluentObjectAssertion#isNot(Object) isNot(Object)}</li>
052 *          <li class='jm'>{@link FluentObjectAssertion#isAny(Object...) isAny(Object...)}</li>
053 *          <li class='jm'>{@link FluentObjectAssertion#isNotAny(Object...) isNotAny(Object...)}</li>
054 *          <li class='jm'>{@link FluentObjectAssertion#isNull() isNull()}</li>
055 *          <li class='jm'>{@link FluentObjectAssertion#isNotNull() isNotNull()}</li>
056 *          <li class='jm'>{@link FluentObjectAssertion#isString(String) isString(String)}</li>
057 *          <li class='jm'>{@link FluentObjectAssertion#isSame(Object) isSame(Object)}</li>
058 *          <li class='jm'>{@link FluentObjectAssertion#isType(Class) isType(Class)}</li>
059 *          <li class='jm'>{@link FluentObjectAssertion#isExactType(Class) isExactType(Class)}</li>
060 *       </ul>
061 *    </li>
062 * </ul>
063 *
064 * <h2 class='section'>Transform Methods:</h2>
065 * <ul class='javatree'>
066 *    <li class='jc'>{@link FluentAnyAssertion}
067 *    <ul class='javatreec'>
068 *       <li class='jm'>{@link FluentAnyAssertion#asArray(Class) asArray(Class)}
069 *       <li class='jm'>{@link FluentAnyAssertion#asIntArray() asIntArray()}
070 *       <li class='jm'>{@link FluentAnyAssertion#asLongArray() asLongArray()}
071 *       <li class='jm'>{@link FluentAnyAssertion#asShortArray() asShortArray()}
072 *       <li class='jm'>{@link FluentAnyAssertion#asFloatArray() asFloatArray()}
073 *       <li class='jm'>{@link FluentAnyAssertion#asDoubleArray() asDoubleArray()}
074 *       <li class='jm'>{@link FluentAnyAssertion#asCharArray() asCharArray()}
075 *       <li class='jm'>{@link FluentAnyAssertion#asByteArray() asByteArray()}
076 *       <li class='jm'>{@link FluentAnyAssertion#asBooleanArray() asBooleanArray()}
077 *       <li class='jm'>{@link FluentAnyAssertion#asBoolean() asBoolean()}
078 *       <li class='jm'>{@link FluentAnyAssertion#asBytes() asBytes()}
079 *       <li class='jm'>{@link FluentAnyAssertion#asCollection() asCollection()}
080 *       <li class='jm'>{@link FluentAnyAssertion#asCollection(Class) asCollection(Class)}
081 *       <li class='jm'>{@link FluentAnyAssertion#asStringList() asStringList()}
082 *       <li class='jm'>{@link FluentAnyAssertion#asComparable() asComparable()}
083 *       <li class='jm'>{@link FluentAnyAssertion#asDate() asDate()}
084 *       <li class='jm'>{@link FluentAnyAssertion#asInteger() asInteger()}
085 *       <li class='jm'>{@link FluentAnyAssertion#asLong() asLong()}
086 *       <li class='jm'>{@link FluentAnyAssertion#asList() asList()}
087 *       <li class='jm'>{@link FluentAnyAssertion#asList(Class) asList(Class)}
088 *       <li class='jm'>{@link FluentAnyAssertion#asMap() asMap()}
089 *       <li class='jm'>{@link FluentAnyAssertion#asMap(Class,Class) asMap(Class,Class)}
090 *       <li class='jm'>{@link FluentAnyAssertion#asBean() asBean()}
091 *       <li class='jm'>{@link FluentAnyAssertion#asBean(Class) asBean(Class)}
092 *       <li class='jm'>{@link FluentAnyAssertion#asBeanList(Class) asBeanList(Class)}
093 *       <li class='jm'>{@link FluentAnyAssertion#asZonedDateTime() asZonedDateTime()}
094 *    </ul>
095 *    <li class='jc'>{@link FluentObjectAssertion}
096 *    <ul class='javatreec'>
097 *       <li class='jm'>{@link FluentObjectAssertion#asString() asString()}
098 *       <li class='jm'>{@link FluentObjectAssertion#asString(ThrowingFunction) asString(ThrowingFunction)}
099 *       <li class='jm'>{@link FluentObjectAssertion#asTransformed(UnaryOperator) asTransformed(UnaryOperator)}
100 *       <li class='jm'>{@link FluentObjectAssertion#asAny() asAny()}
101 * </ul>
102 * </ul>
103 *
104 * <h2 class='section'>Configuration Methods:</h2>
105 * <ul class='javatree'>
106 *    <li class='jc'>{@link Assertion}
107 *    <ul class='javatreec'>
108 *       <li class='jm'>{@link Assertion#setMsg(String, Object...) setMsg(String, Object...)}
109 *       <li class='jm'>{@link Assertion#setOut(PrintStream) setOut(PrintStream)}
110 *       <li class='jm'>{@link Assertion#setSilent() setSilent()}
111 *       <li class='jm'>{@link Assertion#setStdOut() setStdOut()}
112 *       <li class='jm'>{@link Assertion#setThrowable(Class) setThrowable(Class)}
113 *    </ul>
114 * </ul>
115 *
116 * <h2 class='section'>See Also:</h2>
117 * <ul>
118 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauEcosystemOverview">Juneau Ecosystem</a>
119 * </ul>
120 *
121 * @param <T> The object type.
122 */
123public class AnyAssertion<T> extends FluentAnyAssertion<T,AnyAssertion<T>> {
124
125   // -----------------------------------------------------------------------------------------------------------------
126   // Static
127   // -----------------------------------------------------------------------------------------------------------------
128
129   /**
130    * Static creator.
131    *
132    * @param <T> The value type.
133    * @param value
134    *    The object being tested.
135    *    <br>Can be <jk>null</jk> (assertions such as {@code isNull()} then operate on the absence of a value).
136    * @return A new assertion object.
137    */
138   public static <T> AnyAssertion<T> create(T value) {
139      return new AnyAssertion<>(value);
140   }
141
142   // -----------------------------------------------------------------------------------------------------------------
143   // Instance
144   // -----------------------------------------------------------------------------------------------------------------
145
146   /**
147    * Constructor.
148    *
149    * @param value
150    *    The object being tested.
151    *    <br>Can be <jk>null</jk> (assertions such as {@code isNull()} then operate on the absence of a value).
152    */
153   public AnyAssertion(T value) {
154      super(value, null);
155   }
156
157   // -----------------------------------------------------------------------------------------------------------------
158   // Fluent setters
159   // -----------------------------------------------------------------------------------------------------------------
160   @Override /* Overridden from Assertion */
161   public AnyAssertion<T> setMsg(String msg, Object...args) {
162      super.setMsg(msg, args);
163      return this;
164   }
165
166   @Override /* Overridden from Assertion */
167   public AnyAssertion<T> setOut(PrintStream value) {
168      super.setOut(value);
169      return this;
170   }
171
172   @Override /* Overridden from Assertion */
173   public AnyAssertion<T> setSilent() {
174      super.setSilent();
175      return this;
176   }
177
178   @Override /* Overridden from Assertion */
179   public AnyAssertion<T> setStdOut() {
180      super.setStdOut();
181      return this;
182   }
183
184   @Override /* Overridden from Assertion */
185   public AnyAssertion<T> setThrowable(Class<? extends RuntimeException> value) {
186      super.setThrowable(value);
187      return this;
188   }
189}