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 * <h5 class='section'>Example:</h5> 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 * <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#isSame(Object) isSame(Object)} 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 FluentBeanAssertion} 059 * <ul class='javatreec'> 060 * <li class='jm'>{@link FluentBeanAssertion#asPropertyMap(String...) asPropertyMap(String...)} 061 * <li class='jm'>{@link FluentBeanAssertion#asProperty(String) asProperty(String)} 062 * <li class='jm'>{@link FluentBeanAssertion#asProperties(String...) asProperties(String...)} 063 * </ul> 064 * <li class='jc'>{@link FluentObjectAssertion} 065 * <ul class='javatreec'> 066 * <li class='jm'>{@link FluentObjectAssertion#asString() asString()} 067 * <li class='jm'>{@link FluentObjectAssertion#asString(ThrowingFunction) asString(ThrowingFunction)} 068 * <li class='jm'>{@link FluentObjectAssertion#asTransformed(UnaryOperator) asTransformed(UnaryOperator)} 069 * <li class='jm'>{@link FluentObjectAssertion#asAny() asAny()} 070 * </ul> 071 * </ul> 072 * 073 * <h5 class='section'>Configuration Methods:</h5> 074 * <p> 075 * <ul class='javatree'> 076 * <li class='jc'>{@link Assertion} 077 * <ul class='javatreec'> 078 * <li class='jm'>{@link Assertion#setMsg(String, Object...) setMsg(String, Object...)} 079 * <li class='jm'>{@link Assertion#setOut(PrintStream) setOut(PrintStream)} 080 * <li class='jm'>{@link Assertion#setSilent() setSilent()} 081 * <li class='jm'>{@link Assertion#setStdOut() setStdOut()} 082 * <li class='jm'>{@link Assertion#setThrowable(Class) setThrowable(Class)} 083 * </ul> 084 * </ul> 085 * 086 * <h5 class='section'>See Also:</h5><ul> 087 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauEcosystemOverview">Juneau Ecosystem</a> 088 * </ul> 089 * 090 * @param <T> The bean type. 091 */ 092public class BeanAssertion<T> extends FluentBeanAssertion<T,BeanAssertion<T>> { 093 094 /** 095 * Static creator. 096 * 097 * @param <T> The value type. 098 * @param value 099 * The object being tested. 100 * <br>Can be <jk>null</jk> (assertions such as {@code isNull()} then operate on the absence of a value). 101 * @return A new assertion object. 102 */ 103 public static <T> BeanAssertion<T> create(T value) { 104 return new BeanAssertion<>(value); 105 } 106 107 /** 108 * Constructor. 109 * 110 * @param value 111 * The object being tested. 112 * <br>Can be <jk>null</jk> (assertions such as {@code isNull()} then operate on the absence of a value). 113 */ 114 public BeanAssertion(T value) { 115 super(value, null); 116 } 117 118 @Override /* Overridden from Assertion */ 119 public BeanAssertion<T> setMsg(String msg, Object...args) { 120 super.setMsg(msg, args); 121 return this; 122 } 123 124 @Override /* Overridden from Assertion */ 125 public BeanAssertion<T> setOut(PrintStream value) { 126 super.setOut(value); 127 return this; 128 } 129 130 @Override /* Overridden from Assertion */ 131 public BeanAssertion<T> setSilent() { 132 super.setSilent(); 133 return this; 134 } 135 136 @Override /* Overridden from Assertion */ 137 public BeanAssertion<T> setStdOut() { 138 super.setStdOut(); 139 return this; 140 } 141 142 @Override /* Overridden from Assertion */ 143 public BeanAssertion<T> setThrowable(Class<? extends RuntimeException> value) { 144 super.setThrowable(value); 145 return this; 146 } 147}