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 collections objects.
024 *
025 * <h5 class='section'>Example:</h5>
026 * <p class='bjava'>
027 *    <jc>// Validates the specified list is not empty.</jc>
028 *    <jsm>assertCollection</jsm>(<jv>myList</jv>).isNotEmpty();
029 * </p>
030 *
031 * <h5 class='section'>Test Methods:</h5>
032 * <p>
033 * <ul class='javatree'>
034 *    <li class='jc'>{@link FluentCollectionAssertion}
035 *    <ul class='javatreec'>
036 *       <li class='jm'>{@link FluentCollectionAssertion#isEmpty() isEmpty()}
037 *       <li class='jm'>{@link FluentCollectionAssertion#isNotEmpty() isNotEmpty()}
038 *       <li class='jm'>{@link FluentCollectionAssertion#isContains(Object) isContains(Object)}
039 *       <li class='jm'>{@link FluentCollectionAssertion#isNotContains(Object) isNotContains(Object)}
040 *       <li class='jm'>{@link FluentCollectionAssertion#isAny(Predicate) isAny(Predicate)}
041 *       <li class='jm'>{@link FluentCollectionAssertion#isAll(Predicate) isAll(Predicate)}
042 *       <li class='jm'>{@link FluentCollectionAssertion#isSize(int size) isSize(int size)}
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#isJson(String) isJson(String)}
056 *       <li class='jm'>{@link FluentObjectAssertion#isSame(Object) isSame(Object)}
057 *       <li class='jm'>{@link FluentObjectAssertion#isSameJsonAs(Object) isSameJsonAs(Object)}
058 *       <li class='jm'>{@link FluentObjectAssertion#isSameSortedJsonAs(Object) isSameSortedJsonAs(Object)}
059 *       <li class='jm'>{@link FluentObjectAssertion#isSameSerializedAs(Object, WriterSerializer) isSameSerializedAs(Object, WriterSerializer)}
060 *       <li class='jm'>{@link FluentObjectAssertion#isType(Class) isType(Class)}
061 *       <li class='jm'>{@link FluentObjectAssertion#isExactType(Class) isExactType(Class)}
062 *    </ul>
063 * </ul>
064 *
065 * <h5 class='section'>Transform Methods:</h5>
066 * <p>
067 * <ul class='javatree'>
068 *    <li class='jc'>{@link FluentCollectionAssertion}
069 *    <ul class='javatreec'>
070 *       <li class='jm'>{@link FluentCollectionAssertion#asStrings() asStrings()}
071 *       <li class='jm'>{@link FluentCollectionAssertion#asSize() asSize()}
072 *    </ul>
073 *    <li class='jc'>{@link FluentObjectAssertion}
074 *    <ul class='javatreec'>
075 *       <li class='jm'>{@link FluentObjectAssertion#asString() asString()}
076 *       <li class='jm'>{@link FluentObjectAssertion#asString(WriterSerializer) asString(WriterSerializer)}
077 *       <li class='jm'>{@link FluentObjectAssertion#asString(Function) asString(Function)}
078 *       <li class='jm'>{@link FluentObjectAssertion#asJson() asJson()}
079 *       <li class='jm'>{@link FluentObjectAssertion#asJsonSorted() asJsonSorted()}
080 *       <li class='jm'>{@link FluentObjectAssertion#asTransformed(Function) asApplied(Function)}
081 *       <li class='jm'>{@link FluentObjectAssertion#asAny() asAny()}
082 * </ul>
083 * </ul>
084 *
085 * <h5 class='section'>Configuration Methods:</h5>
086 * <p>
087 * <ul class='javatree'>
088 *    <li class='jc'>{@link Assertion}
089 *    <ul class='javatreec'>
090 *       <li class='jm'>{@link Assertion#setMsg(String, Object...) setMsg(String, Object...)}
091 *       <li class='jm'>{@link Assertion#setOut(PrintStream) setOut(PrintStream)}
092 *       <li class='jm'>{@link Assertion#setSilent() setSilent()}
093 *       <li class='jm'>{@link Assertion#setStdOut() setStdOut()}
094 *       <li class='jm'>{@link Assertion#setThrowable(Class) setThrowable(Class)}
095 *    </ul>
096 * </ul>
097 *
098 * <h5 class='section'>See Also:</h5><ul>
099 *    <li class='link'><a class="doclink" href="../../../../index.html#ja.Overview">Overview &gt; juneau-assertions &gt; Overview</a>
100 * </ul>
101 *
102 * @param <E> The element type.
103 */
104@FluentSetters(returns="CollectionAssertion<E>")
105public class CollectionAssertion<E> extends FluentCollectionAssertion<E,CollectionAssertion<E>> {
106
107   //-----------------------------------------------------------------------------------------------------------------
108   // Static
109   //-----------------------------------------------------------------------------------------------------------------
110
111   /**
112    * Static creator.
113    *
114    * @param <E> The element type.
115    * @param value
116    *    The object being tested.
117    *    <br>Can be <jk>null</jk>.
118    * @return A new assertion object.
119    */
120   public static <E> CollectionAssertion<E> create(Collection<E> value) {
121      return new CollectionAssertion<>(value);
122   }
123
124   //-----------------------------------------------------------------------------------------------------------------
125   // Instance
126   //-----------------------------------------------------------------------------------------------------------------
127
128   /**
129    * Constructor.
130    *
131    * @param value
132    *    The object being tested.
133    *    <br>Can be <jk>null</jk>.
134    */
135   public CollectionAssertion(Collection<E> value) {
136      super(value, null);
137   }
138
139   //-----------------------------------------------------------------------------------------------------------------
140   // Fluent setters
141   //-----------------------------------------------------------------------------------------------------------------
142
143   // <FluentSetters>
144
145   @Override /* GENERATED - org.apache.juneau.assertions.Assertion */
146   public CollectionAssertion<E> setMsg(String msg, Object...args) {
147      super.setMsg(msg, args);
148      return this;
149   }
150
151   @Override /* GENERATED - org.apache.juneau.assertions.Assertion */
152   public CollectionAssertion<E> setOut(PrintStream value) {
153      super.setOut(value);
154      return this;
155   }
156
157   @Override /* GENERATED - org.apache.juneau.assertions.Assertion */
158   public CollectionAssertion<E> setSilent() {
159      super.setSilent();
160      return this;
161   }
162
163   @Override /* GENERATED - org.apache.juneau.assertions.Assertion */
164   public CollectionAssertion<E> setStdOut() {
165      super.setStdOut();
166      return this;
167   }
168
169   @Override /* GENERATED - org.apache.juneau.assertions.Assertion */
170   public CollectionAssertion<E> setThrowable(Class<? extends java.lang.RuntimeException> value) {
171      super.setThrowable(value);
172      return this;
173   }
174
175   // </FluentSetters>
176}