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
015import java.io.*;
016import java.util.function.*;
017
018import org.apache.juneau.internal.*;
019import org.apache.juneau.serializer.*;
020
021/**
022 * Used for assertion calls against generic POJOs.
023 *
024 * <p>
025 * Extends from {@link ObjectAssertion} allowing you to perform basic assertions, but adds several transform
026 * methods to convert to more-specific assertion types.
027 *
028 * <h5 class='section'>Example:</h5>
029 * <p class='bjava'>
030 *    <jk>import static</jk> org.apache.juneau.assertions.Assertions.*;
031 *
032 *    List&lt;MyBean&gt; <jv>listOfBeans</jv> = ...;
033 *    <jsm>assertList</jsm>(<jv>listOfBeans</jv>)
034 *       .asItem(1)  <jc>// Returns an AnyAssertion.</jc>
035 *       .asBean()  <jc>// Transforms to BeanAssertion.</jc>
036 *          .asProperty(<js>"foo"</js>)  <jc>// Returns an AnyAssertion.</jc>
037 *          .asString()  <jc>// Transforms to StringAssertion.</jc>
038 *             .is(<js>"bar"</js>);  <jc>// Performs test.</jc>
039 * </p>
040 *
041 *
042 * <h5 class='section'>Test Methods:</h5>
043 * <p>
044 * <ul class='javatree'>
045 *    <li class='jc'>{@link FluentObjectAssertion}
046 *       <ul class='javatreec'>
047 *          <li class='jm'>{@link FluentObjectAssertion#isExists() isExists()}</li>
048 *          <li class='jm'>{@link FluentObjectAssertion#is(Object) is(Object)}</li>
049 *          <li class='jm'>{@link FluentObjectAssertion#is(Predicate) is(Predicate)}</li>
050 *          <li class='jm'>{@link FluentObjectAssertion#isNot(Object) isNot(Object)}</li>
051 *          <li class='jm'>{@link FluentObjectAssertion#isAny(Object...) isAny(Object...)}</li>
052 *          <li class='jm'>{@link FluentObjectAssertion#isNotAny(Object...) isNotAny(Object...)}</li>
053 *          <li class='jm'>{@link FluentObjectAssertion#isNull() isNull()}</li>
054 *          <li class='jm'>{@link FluentObjectAssertion#isNotNull() isNotNull()}</li>
055 *          <li class='jm'>{@link FluentObjectAssertion#isString(String) isString(String)}</li>
056 *          <li class='jm'>{@link FluentObjectAssertion#isJson(String) isJson(String)}</li>
057 *          <li class='jm'>{@link FluentObjectAssertion#isSame(Object) isSame(Object)}</li>
058 *          <li class='jm'>{@link FluentObjectAssertion#isSameJsonAs(Object) isSameJsonAs(Object)}</li>
059 *          <li class='jm'>{@link FluentObjectAssertion#isSameSortedJsonAs(Object) isSameSortedJsonAs(Object)}</li>
060 *          <li class='jm'>{@link FluentObjectAssertion#isSameSerializedAs(Object, WriterSerializer) isSameSerializedAs(Object, WriterSerializer)}</li>
061 *          <li class='jm'>{@link FluentObjectAssertion#isType(Class) isType(Class)}</li>
062 *          <li class='jm'>{@link FluentObjectAssertion#isExactType(Class) isExactType(Class)}</li>
063 *       </ul>
064 *    </li>
065 * </ul>
066 *
067 * <h5 class='section'>Transform Methods:</h5>
068 * <p>
069 * <ul class='javatree'>
070 *    <li class='jc'>{@link FluentAnyAssertion}
071 *    <ul class='javatreec'>
072 *       <li class='jm'>{@link FluentAnyAssertion#asArray(Class) asArray(Class)}
073 *       <li class='jm'>{@link FluentAnyAssertion#asIntArray() asIntArray()}
074 *       <li class='jm'>{@link FluentAnyAssertion#asLongArray() asLongArray()}
075 *       <li class='jm'>{@link FluentAnyAssertion#asShortArray() asShortArray()}
076 *       <li class='jm'>{@link FluentAnyAssertion#asFloatArray() asFloatArray()}
077 *       <li class='jm'>{@link FluentAnyAssertion#asDoubleArray() asDoubleArray()}
078 *       <li class='jm'>{@link FluentAnyAssertion#asCharArray() asCharArray()}
079 *       <li class='jm'>{@link FluentAnyAssertion#asByteArray() asByteArray()}
080 *       <li class='jm'>{@link FluentAnyAssertion#asBooleanArray() asBooleanArray()}
081 *       <li class='jm'>{@link FluentAnyAssertion#asBoolean() asBoolean()}
082 *       <li class='jm'>{@link FluentAnyAssertion#asBytes() asBytes()}
083 *       <li class='jm'>{@link FluentAnyAssertion#asCollection() asCollection()}
084 *       <li class='jm'>{@link FluentAnyAssertion#asCollection(Class) asCollection(Class)}
085 *       <li class='jm'>{@link FluentAnyAssertion#asStringList() asStringList()}
086 *       <li class='jm'>{@link FluentAnyAssertion#asComparable() asComparable()}
087 *       <li class='jm'>{@link FluentAnyAssertion#asDate() asDate()}
088 *       <li class='jm'>{@link FluentAnyAssertion#asInteger() asInteger()}
089 *       <li class='jm'>{@link FluentAnyAssertion#asLong() asLong()}
090 *       <li class='jm'>{@link FluentAnyAssertion#asList() asList()}
091 *       <li class='jm'>{@link FluentAnyAssertion#asList(Class) asList(Class)}
092 *       <li class='jm'>{@link FluentAnyAssertion#asMap() asMap()}
093 *       <li class='jm'>{@link FluentAnyAssertion#asMap(Class,Class) asMap(Class,Class)}
094 *       <li class='jm'>{@link FluentAnyAssertion#asBean() asBean()}
095 *       <li class='jm'>{@link FluentAnyAssertion#asBean(Class) asBean(Class)}
096 *       <li class='jm'>{@link FluentAnyAssertion#asBeanList(Class) asBeanList(Class)}
097 *       <li class='jm'>{@link FluentAnyAssertion#asZonedDateTime() asZonedDateTime()}
098 *    </ul>
099 *    <li class='jc'>{@link FluentObjectAssertion}
100 *    <ul class='javatreec'>
101 *       <li class='jm'>{@link FluentObjectAssertion#asString() asString()}
102 *       <li class='jm'>{@link FluentObjectAssertion#asString(WriterSerializer) asString(WriterSerializer)}
103 *       <li class='jm'>{@link FluentObjectAssertion#asString(Function) asString(Function)}
104 *       <li class='jm'>{@link FluentObjectAssertion#asJson() asJson()}
105 *       <li class='jm'>{@link FluentObjectAssertion#asJsonSorted() asJsonSorted()}
106 *       <li class='jm'>{@link FluentObjectAssertion#asTransformed(Function) asApplied(Function)}
107 *       <li class='jm'>{@link FluentObjectAssertion#asAny() asAny()}
108 * </ul>
109 * </ul>
110 *
111 * <h5 class='section'>Configuration Methods:</h5>
112 * <p>
113 * <ul class='javatree'>
114 *    <li class='jc'>{@link Assertion}
115 *    <ul class='javatreec'>
116 *       <li class='jm'>{@link Assertion#setMsg(String, Object...) setMsg(String, Object...)}
117 *       <li class='jm'>{@link Assertion#setOut(PrintStream) setOut(PrintStream)}
118 *       <li class='jm'>{@link Assertion#setSilent() setSilent()}
119 *       <li class='jm'>{@link Assertion#setStdOut() setStdOut()}
120 *       <li class='jm'>{@link Assertion#setThrowable(Class) setThrowable(Class)}
121 *    </ul>
122 * </ul>
123 *
124 * <h5 class='section'>See Also:</h5>
125 * <ul>
126 *    <li class='link'><a class="doclink" href="../../../../index.html#ja.Overview">Overview &gt; juneau-assertions &gt; Overview</a>
127 * </ul>
128 *
129 * @param <T> The object type.
130 */
131@FluentSetters(returns="AnyAssertion<T>")
132public class AnyAssertion<T> extends FluentAnyAssertion<T,AnyAssertion<T>> {
133
134   //-----------------------------------------------------------------------------------------------------------------
135   // Static
136   //-----------------------------------------------------------------------------------------------------------------
137
138   /**
139    * Static creator.
140    *
141    * @param <T> The value type.
142    * @param value
143    *    The object being tested.
144    *    <br>Can be <jk>null</jk>.
145    * @return A new assertion object.
146    */
147   public static <T> AnyAssertion<T> create(T value) {
148      return new AnyAssertion<>(value);
149   }
150
151   //-----------------------------------------------------------------------------------------------------------------
152   // Instance
153   //-----------------------------------------------------------------------------------------------------------------
154
155   /**
156    * Constructor.
157    *
158    * @param value
159    *    The object being tested.
160    *    <br>Can be <jk>null</jk>.
161    */
162   public AnyAssertion(T value) {
163      super(value, null);
164   }
165
166   //-----------------------------------------------------------------------------------------------------------------
167   // Fluent setters
168   //-----------------------------------------------------------------------------------------------------------------
169
170   // <FluentSetters>
171
172   @Override /* GENERATED - org.apache.juneau.assertions.Assertion */
173   public AnyAssertion<T> setMsg(String msg, Object...args) {
174      super.setMsg(msg, args);
175      return this;
176   }
177
178   @Override /* GENERATED - org.apache.juneau.assertions.Assertion */
179   public AnyAssertion<T> setOut(PrintStream value) {
180      super.setOut(value);
181      return this;
182   }
183
184   @Override /* GENERATED - org.apache.juneau.assertions.Assertion */
185   public AnyAssertion<T> setSilent() {
186      super.setSilent();
187      return this;
188   }
189
190   @Override /* GENERATED - org.apache.juneau.assertions.Assertion */
191   public AnyAssertion<T> setStdOut() {
192      super.setStdOut();
193      return this;
194   }
195
196   @Override /* GENERATED - org.apache.juneau.assertions.Assertion */
197   public AnyAssertion<T> setThrowable(Class<? extends java.lang.RuntimeException> value) {
198      super.setThrowable(value);
199      return this;
200   }
201
202   // </FluentSetters>
203}