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