001// *************************************************************************************************************************** 002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * 003// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * 004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * 005// * with the License. You may obtain a copy of the License at * 006// * * 007// * http://www.apache.org/licenses/LICENSE-2.0 * 008// * * 009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * 010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * 011// * specific language governing permissions and limitations under the License. * 012// *************************************************************************************************************************** 013package org.apache.juneau.assertions; 014 015import java.io.*; 016import java.util.*; 017import java.util.function.*; 018 019import org.apache.juneau.internal.*; 020import org.apache.juneau.serializer.*; 021 022/** 023 * Used for assertion calls against lists. 024 * 025 * <h5 class='section'>Example:</h5> 026 * <p class='bjava'> 027 * <jc>// Validates the specified POJO is the specified type.</jc> 028 * <jsm>assertMap</jsm>(<jv>myMap</jv>).isNotEmpty(); 029 * </p> 030 * 031 * 032 * <h5 class='section'>Test Methods:</h5> 033 * <p> 034 * <ul class='javatree'> 035 * <li class='jc'>{@link FluentMapAssertion} 036 * <ul class='javatreec'> 037 * <li class='jm'>{@link FluentMapAssertion#isEmpty() isEmpty()} 038 * <li class='jm'>{@link FluentMapAssertion#isNotEmpty() isNotEmpty()} 039 * <li class='jm'>{@link FluentMapAssertion#isContainsKey(String) isContainsKey(String)} 040 * <li class='jm'>{@link FluentMapAssertion#isNotContainsKey(String) isNotContainsKey(String)} 041 * <li class='jm'>{@link FluentMapAssertion#isSize(int) isSize(int)} 042 * </ul> 043 * <li class='jc'>{@link FluentObjectAssertion} 044 * <ul class='javatreec'> 045 * <li class='jm'>{@link FluentObjectAssertion#isExists() isExists()} 046 * <li class='jm'>{@link FluentObjectAssertion#is(Object) is(Object)} 047 * <li class='jm'>{@link FluentObjectAssertion#is(Predicate) is(Predicate)} 048 * <li class='jm'>{@link FluentObjectAssertion#isNot(Object) isNot(Object)} 049 * <li class='jm'>{@link FluentObjectAssertion#isAny(Object...) isAny(Object...)} 050 * <li class='jm'>{@link FluentObjectAssertion#isNotAny(Object...) isNotAny(Object...)} 051 * <li class='jm'>{@link FluentObjectAssertion#isNull() isNull()} 052 * <li class='jm'>{@link FluentObjectAssertion#isNotNull() isNotNull()} 053 * <li class='jm'>{@link FluentObjectAssertion#isString(String) isString(String)} 054 * <li class='jm'>{@link FluentObjectAssertion#isJson(String) isJson(String)} 055 * <li class='jm'>{@link FluentObjectAssertion#isSame(Object) isSame(Object)} 056 * <li class='jm'>{@link FluentObjectAssertion#isSameJsonAs(Object) isSameJsonAs(Object)} 057 * <li class='jm'>{@link FluentObjectAssertion#isSameSortedJsonAs(Object) isSameSortedJsonAs(Object)} 058 * <li class='jm'>{@link FluentObjectAssertion#isSameSerializedAs(Object, WriterSerializer) isSameSerializedAs(Object, WriterSerializer)} 059 * <li class='jm'>{@link FluentObjectAssertion#isType(Class) isType(Class)} 060 * <li class='jm'>{@link FluentObjectAssertion#isExactType(Class) isExactType(Class)} 061 * </ul> 062 * </ul> 063 * 064 * <h5 class='section'>Transform Methods:</h5> 065 * <p> 066 * <ul class='javatree'> 067 * <li class='jc'>{@link FluentMapAssertion} 068 * <ul class='javatreec'> 069 * <li class='jm'>{@link FluentMapAssertion#asValue(Object) asValue(Object)} 070 * <li class='jm'>{@link FluentMapAssertion#asValues(Object...) asValues(Object...)} 071 * <li class='jm'>{@link FluentMapAssertion#asValueMap(Object...) asValueMap(Object...)} 072 * <li class='jm'>{@link FluentMapAssertion#asSize() asSize()} 073 * </ul> 074 * <li class='jc'>{@link FluentObjectAssertion} 075 * <ul class='javatreec'> 076 * <li class='jm'>{@link FluentObjectAssertion#asString() asString()} 077 * <li class='jm'>{@link FluentObjectAssertion#asString(WriterSerializer) asString(WriterSerializer)} 078 * <li class='jm'>{@link FluentObjectAssertion#asString(Function) asString(Function)} 079 * <li class='jm'>{@link FluentObjectAssertion#asJson() asJson()} 080 * <li class='jm'>{@link FluentObjectAssertion#asJsonSorted() asJsonSorted()} 081 * <li class='jm'>{@link FluentObjectAssertion#asTransformed(Function) asApplied(Function)} 082 * <li class='jm'>{@link FluentObjectAssertion#asAny() asAny()} 083 * </ul> 084 * </ul> 085 * 086 * <h5 class='section'>Configuration Methods:</h5> 087 * <p> 088 * <ul class='javatree'> 089 * <li class='jc'>{@link Assertion} 090 * <ul class='javatreec'> 091 * <li class='jm'>{@link Assertion#setMsg(String, Object...) setMsg(String, Object...)} 092 * <li class='jm'>{@link Assertion#setOut(PrintStream) setOut(PrintStream)} 093 * <li class='jm'>{@link Assertion#setSilent() setSilent()} 094 * <li class='jm'>{@link Assertion#setStdOut() setStdOut()} 095 * <li class='jm'>{@link Assertion#setThrowable(Class) setThrowable(Class)} 096 * </ul> 097 * </ul> 098 * 099 * <h5 class='section'>See Also:</h5><ul> 100 * <li class='link'><a class="doclink" href="../../../../index.html#ja.Overview">Overview > juneau-assertions > Overview</a> 101 * </ul> 102 * 103 * @param <K> The map key type. 104 * @param <V> The map value type. 105 */ 106@FluentSetters(returns="MapAssertion<K,V>") 107public class MapAssertion<K,V> extends FluentMapAssertion<K,V,MapAssertion<K,V>> { 108 109 //----------------------------------------------------------------------------------------------------------------- 110 // Static 111 //----------------------------------------------------------------------------------------------------------------- 112 113 /** 114 * Static creator. 115 * 116 * @param <K> The key type. 117 * @param <V> The value type. 118 * @param value 119 * The object being tested. 120 * <br>Can be <jk>null</jk>. 121 * @return A new assertion object. 122 */ 123 public static <K,V> MapAssertion<K,V> create(Map<K,V> value) { 124 return new MapAssertion<>(value); 125 } 126 127 //----------------------------------------------------------------------------------------------------------------- 128 // Instance 129 //----------------------------------------------------------------------------------------------------------------- 130 131 /** 132 * Constructor. 133 * 134 * @param value 135 * The object being tested. 136 * <br>Can be <jk>null</jk>. 137 */ 138 public MapAssertion(Map<K,V> value) { 139 super(value, null); 140 } 141 142 //----------------------------------------------------------------------------------------------------------------- 143 // Fluent setters 144 //----------------------------------------------------------------------------------------------------------------- 145 146 // <FluentSetters> 147 148 @Override /* GENERATED - org.apache.juneau.assertions.Assertion */ 149 public MapAssertion<K,V> setMsg(String msg, Object...args) { 150 super.setMsg(msg, args); 151 return this; 152 } 153 154 @Override /* GENERATED - org.apache.juneau.assertions.Assertion */ 155 public MapAssertion<K,V> setOut(PrintStream value) { 156 super.setOut(value); 157 return this; 158 } 159 160 @Override /* GENERATED - org.apache.juneau.assertions.Assertion */ 161 public MapAssertion<K,V> setSilent() { 162 super.setSilent(); 163 return this; 164 } 165 166 @Override /* GENERATED - org.apache.juneau.assertions.Assertion */ 167 public MapAssertion<K,V> setStdOut() { 168 super.setStdOut(); 169 return this; 170 } 171 172 @Override /* GENERATED - org.apache.juneau.assertions.Assertion */ 173 public MapAssertion<K,V> setThrowable(Class<? extends java.lang.RuntimeException> value) { 174 super.setThrowable(value); 175 return this; 176 } 177 178 // </FluentSetters> 179}