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 arbitrary POJOs.
023 *
024 * <h5 class='section'>Example:</h5>
025 * <p class='bjava'>
026 *    <jc>// Validates the specified POJO is the specified type.</jc>
027 *    <jsm>assertObject</jsm>(<jv>myPojo</jv>).isType(MyBean.<jk>class</jk>);
028 * </p>
029 *
030 *
031 * <h5 class='section'>Test Methods:</h5>
032 * <p>
033 * <ul class='javatree'>
034 *    <li class='jc'>{@link FluentObjectAssertion}
035 *    <ul class='javatreec'>
036 *       <li class='jm'>{@link FluentObjectAssertion#isExists() isExists()}
037 *       <li class='jm'>{@link FluentObjectAssertion#is(Object) is(Object)}
038 *       <li class='jm'>{@link FluentObjectAssertion#is(Predicate) is(Predicate)}
039 *       <li class='jm'>{@link FluentObjectAssertion#isNot(Object) isNot(Object)}
040 *       <li class='jm'>{@link FluentObjectAssertion#isAny(Object...) isAny(Object...)}
041 *       <li class='jm'>{@link FluentObjectAssertion#isNotAny(Object...) isNotAny(Object...)}
042 *       <li class='jm'>{@link FluentObjectAssertion#isNull() isNull()}
043 *       <li class='jm'>{@link FluentObjectAssertion#isNotNull() isNotNull()}
044 *       <li class='jm'>{@link FluentObjectAssertion#isString(String) isString(String)}
045 *       <li class='jm'>{@link FluentObjectAssertion#isJson(String) isJson(String)}
046 *       <li class='jm'>{@link FluentObjectAssertion#isSame(Object) isSame(Object)}
047 *       <li class='jm'>{@link FluentObjectAssertion#isSameJsonAs(Object) isSameJsonAs(Object)}
048 *       <li class='jm'>{@link FluentObjectAssertion#isSameSortedJsonAs(Object) isSameSortedJsonAs(Object)}
049 *       <li class='jm'>{@link FluentObjectAssertion#isSameSerializedAs(Object, WriterSerializer) isSameSerializedAs(Object, WriterSerializer)}
050 *       <li class='jm'>{@link FluentObjectAssertion#isType(Class) isType(Class)}
051 *       <li class='jm'>{@link FluentObjectAssertion#isExactType(Class) isExactType(Class)}
052 *    </ul>
053 * </ul>
054 *
055 * <h5 class='section'>Transform Methods:</h5>
056 * <p>
057 * <ul class='javatree'>
058 *    <li class='jc'>{@link FluentObjectAssertion}
059 *    <ul class='javatreec'>
060 *       <li class='jm'>{@link FluentObjectAssertion#asString() asString()}
061 *       <li class='jm'>{@link FluentObjectAssertion#asString(WriterSerializer) asString(WriterSerializer)}
062 *       <li class='jm'>{@link FluentObjectAssertion#asString(Function) asString(Function)}
063 *       <li class='jm'>{@link FluentObjectAssertion#asJson() asJson()}
064 *       <li class='jm'>{@link FluentObjectAssertion#asJsonSorted() asJsonSorted()}
065 *       <li class='jm'>{@link FluentObjectAssertion#asTransformed(Function) asApplied(Function)}
066 *       <li class='jm'>{@link FluentObjectAssertion#asAny() asAny()}
067 * </ul>
068 * </ul>
069 *
070 * <h5 class='section'>Configuration Methods:</h5>
071 * <p>
072 * <ul class='javatree'>
073 *    <li class='jc'>{@link Assertion}
074 *    <ul class='javatreec'>
075 *       <li class='jm'>{@link Assertion#setMsg(String, Object...) setMsg(String, Object...)}
076 *       <li class='jm'>{@link Assertion#setOut(PrintStream) setOut(PrintStream)}
077 *       <li class='jm'>{@link Assertion#setSilent() setSilent()}
078 *       <li class='jm'>{@link Assertion#setStdOut() setStdOut()}
079 *       <li class='jm'>{@link Assertion#setThrowable(Class) setThrowable(Class)}
080 *    </ul>
081 * </ul>
082 *
083 * <h5 class='section'>See Also:</h5><ul>
084 *    <li class='link'><a class="doclink" href="../../../../index.html#ja.Overview">Overview &gt; juneau-assertions &gt; Overview</a>
085 * </ul>
086 *
087 * @param <T> The object type.
088 */
089@FluentSetters(returns="ObjectAssertion<T>")
090public class ObjectAssertion<T> extends FluentObjectAssertion<T,ObjectAssertion<T>> {
091
092   //-----------------------------------------------------------------------------------------------------------------
093   // Static
094   //-----------------------------------------------------------------------------------------------------------------
095
096   /**
097    * Static creator.
098    *
099    * @param <T> The value type.
100    * @param value
101    *    The object being tested.
102    *    <br>Can be <jk>null</jk>.
103    * @return A new assertion object.
104    */
105   public static <T> ObjectAssertion<T> create(T value) {
106      return new ObjectAssertion<>(value);
107   }
108
109   //-----------------------------------------------------------------------------------------------------------------
110   // Instance
111   //-----------------------------------------------------------------------------------------------------------------
112
113   /**
114    * Constructor.
115    *
116    * @param value
117    *    The object being tested.
118    *    <br>Can be <jk>null</jk>.
119    */
120   public ObjectAssertion(T value) {
121      super(value, null);
122   }
123
124   //-----------------------------------------------------------------------------------------------------------------
125   // Fluent setters
126   //-----------------------------------------------------------------------------------------------------------------
127
128   // <FluentSetters>
129
130   @Override /* GENERATED - org.apache.juneau.assertions.Assertion */
131   public ObjectAssertion<T> setMsg(String msg, Object...args) {
132      super.setMsg(msg, args);
133      return this;
134   }
135
136   @Override /* GENERATED - org.apache.juneau.assertions.Assertion */
137   public ObjectAssertion<T> setOut(PrintStream value) {
138      super.setOut(value);
139      return this;
140   }
141
142   @Override /* GENERATED - org.apache.juneau.assertions.Assertion */
143   public ObjectAssertion<T> setSilent() {
144      super.setSilent();
145      return this;
146   }
147
148   @Override /* GENERATED - org.apache.juneau.assertions.Assertion */
149   public ObjectAssertion<T> setStdOut() {
150      super.setStdOut();
151      return this;
152   }
153
154   @Override /* GENERATED - org.apache.juneau.assertions.Assertion */
155   public ObjectAssertion<T> setThrowable(Class<? extends java.lang.RuntimeException> value) {
156      super.setThrowable(value);
157      return this;
158   }
159
160   // </FluentSetters>
161}