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