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