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 arbitrary POJOs.
025 *
026 * <h2 class='section'>Example:</h2>
027 * <p class='bjava'>
028 *    <jc>// Validates the specified POJO is the specified type.</jc>
029 *    <jsm>assertObject</jsm>(<jv>myPojo</jv>).isType(MyBean.<jk>class</jk>);
030 * </p>
031 *
032 *
033 * <h2 class='section'>Test Methods:</h2>
034 * <ul class='javatree'>
035 *    <li class='jc'>{@link FluentObjectAssertion}
036 *    <ul class='javatreec'>
037 *       <li class='jm'>{@link FluentObjectAssertion#isExists() isExists()}
038 *       <li class='jm'>{@link FluentObjectAssertion#is(Object) is(Object)}
039 *       <li class='jm'>{@link FluentObjectAssertion#is(Predicate) is(Predicate)}
040 *       <li class='jm'>{@link FluentObjectAssertion#isNot(Object) isNot(Object)}
041 *       <li class='jm'>{@link FluentObjectAssertion#isAny(Object...) isAny(Object...)}
042 *       <li class='jm'>{@link FluentObjectAssertion#isNotAny(Object...) isNotAny(Object...)}
043 *       <li class='jm'>{@link FluentObjectAssertion#isNull() isNull()}
044 *       <li class='jm'>{@link FluentObjectAssertion#isNotNull() isNotNull()}
045 *       <li class='jm'>{@link FluentObjectAssertion#isString(String) isString(String)}
046 *       <li class='jm'>{@link FluentObjectAssertion#isSame(Object) isSame(Object)}
047 *       <li class='jm'>{@link FluentObjectAssertion#isType(Class) isType(Class)}
048 *       <li class='jm'>{@link FluentObjectAssertion#isExactType(Class) isExactType(Class)}
049 *    </ul>
050 * </ul>
051 *
052 * <h2 class='section'>Transform Methods:</h2>
053 * <ul class='javatree'>
054 *    <li class='jc'>{@link FluentObjectAssertion}
055 *    <ul class='javatreec'>
056 *       <li class='jm'>{@link FluentObjectAssertion#asString() asString()}
057 *       <li class='jm'>{@link FluentObjectAssertion#asString(ThrowingFunction) asString(ThrowingFunction)}
058 *       <li class='jm'>{@link FluentObjectAssertion#asTransformed(UnaryOperator) asTransformed(UnaryOperator)}
059 *       <li class='jm'>{@link FluentObjectAssertion#asAny() asAny()}
060 * </ul>
061 * </ul>
062 *
063 * <h2 class='section'>Configuration Methods:</h2>
064 * <ul class='javatree'>
065 *    <li class='jc'>{@link Assertion}
066 *    <ul class='javatreec'>
067 *       <li class='jm'>{@link Assertion#setMsg(String, Object...) setMsg(String, Object...)}
068 *       <li class='jm'>{@link Assertion#setOut(PrintStream) setOut(PrintStream)}
069 *       <li class='jm'>{@link Assertion#setSilent() setSilent()}
070 *       <li class='jm'>{@link Assertion#setStdOut() setStdOut()}
071 *       <li class='jm'>{@link Assertion#setThrowable(Class) setThrowable(Class)}
072 *    </ul>
073 * </ul>
074 *
075 * <h2 class='section'>See Also:</h2><ul>
076 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauEcosystemOverview">Juneau Ecosystem</a>
077 * </ul>
078 *
079 * @param <T> The object type.
080 */
081public class ObjectAssertion<T> extends FluentObjectAssertion<T,ObjectAssertion<T>> {
082
083   /**
084    * Static creator.
085    *
086    * @param <T> The value type.
087    * @param value
088    *    The object being tested.
089    *    <br>Can be <jk>null</jk> (assertions such as {@code isNull()} then operate on the absence of a value).
090    * @return A new assertion object.
091    */
092   public static <T> ObjectAssertion<T> create(T value) {
093      return new ObjectAssertion<>(value);
094   }
095
096   /**
097    * Constructor.
098    *
099    * @param value
100    *    The object being tested.
101    *    <br>Can be <jk>null</jk> (assertions such as {@code isNull()} then operate on the absence of a value).
102    */
103   public ObjectAssertion(T value) {
104      super(value, null);
105   }
106
107   @Override /* Overridden from Assertion */
108   public ObjectAssertion<T> setMsg(String msg, Object...args) {
109      super.setMsg(msg, args);
110      return this;
111   }
112
113   @Override /* Overridden from Assertion */
114   public ObjectAssertion<T> setOut(PrintStream value) {
115      super.setOut(value);
116      return this;
117   }
118
119   @Override /* Overridden from Assertion */
120   public ObjectAssertion<T> setSilent() {
121      super.setSilent();
122      return this;
123   }
124
125   @Override /* Overridden from Assertion */
126   public ObjectAssertion<T> setStdOut() {
127      super.setStdOut();
128      return this;
129   }
130
131   @Override /* Overridden from Assertion */
132   public ObjectAssertion<T> setThrowable(Class<? extends RuntimeException> value) {
133      super.setThrowable(value);
134      return this;
135   }
136}