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