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