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 static java.util.stream.Collectors.*; 016 017import java.io.*; 018import java.util.*; 019import java.util.function.*; 020 021import org.apache.juneau.common.internal.*; 022import org.apache.juneau.internal.*; 023import org.apache.juneau.serializer.*; 024 025/** 026 * Used for fluent assertion calls against lists of strings. 027 * 028 * <h5 class='section'>Test Methods:</h5> 029 * <p> 030 * <ul class='javatree'> 031 * <li class='jc'>{@link FluentListAssertion} 032 * <ul class='javatreec'> 033 * <li class='jm'>{@link FluentListAssertion#isHas(Object...) isHas(Object...)} 034 * <li class='jm'>{@link FluentListAssertion#isEach(Predicate...) isEach(Predicate...)} 035 * </ul> 036 * <li class='jc'>{@link FluentCollectionAssertion} 037 * <ul class='javatreec'> 038 * <li class='jm'>{@link FluentCollectionAssertion#isEmpty() isEmpty()} 039 * <li class='jm'>{@link FluentCollectionAssertion#isNotEmpty() isNotEmpty()} 040 * <li class='jm'>{@link FluentCollectionAssertion#isContains(Object) isContains(Object)} 041 * <li class='jm'>{@link FluentCollectionAssertion#isNotContains(Object) isNotContains(Object)} 042 * <li class='jm'>{@link FluentCollectionAssertion#isAny(Predicate) isAny(Predicate)} 043 * <li class='jm'>{@link FluentCollectionAssertion#isAll(Predicate) isAll(Predicate)} 044 * <li class='jm'>{@link FluentCollectionAssertion#isSize(int size) isSize(int size)} 045 * </ul> 046 * <li class='jc'>{@link FluentObjectAssertion} 047 * <ul class='javatreec'> 048 * <li class='jm'>{@link FluentObjectAssertion#isExists() isExists()} 049 * <li class='jm'>{@link FluentObjectAssertion#is(Object) is(Object)} 050 * <li class='jm'>{@link FluentObjectAssertion#is(Predicate) is(Predicate)} 051 * <li class='jm'>{@link FluentObjectAssertion#isNot(Object) isNot(Object)} 052 * <li class='jm'>{@link FluentObjectAssertion#isAny(Object...) isAny(Object...)} 053 * <li class='jm'>{@link FluentObjectAssertion#isNotAny(Object...) isNotAny(Object...)} 054 * <li class='jm'>{@link FluentObjectAssertion#isNull() isNull()} 055 * <li class='jm'>{@link FluentObjectAssertion#isNotNull() isNotNull()} 056 * <li class='jm'>{@link FluentObjectAssertion#isString(String) isString(String)} 057 * <li class='jm'>{@link FluentObjectAssertion#isJson(String) isJson(String)} 058 * <li class='jm'>{@link FluentObjectAssertion#isSame(Object) isSame(Object)} 059 * <li class='jm'>{@link FluentObjectAssertion#isSameJsonAs(Object) isSameJsonAs(Object)} 060 * <li class='jm'>{@link FluentObjectAssertion#isSameSortedJsonAs(Object) isSameSortedJsonAs(Object)} 061 * <li class='jm'>{@link FluentObjectAssertion#isSameSerializedAs(Object, WriterSerializer) isSameSerializedAs(Object, WriterSerializer)} 062 * <li class='jm'>{@link FluentObjectAssertion#isType(Class) isType(Class)} 063 * <li class='jm'>{@link FluentObjectAssertion#isExactType(Class) isExactType(Class)} 064 * </ul> 065 * </ul> 066 * 067 * <h5 class='section'>Transform Methods:</h5> 068 * <p> 069 * <ul class='javatree'> 070 * <li class='jc'>{@link FluentStringListAssertion} 071 * <ul class='javatreec'> 072 * <li class='jm'>{@link FluentStringListAssertion#asJoin() asJoin()} 073 * <li class='jm'>{@link FluentStringListAssertion#asJoin(String) asJoin(String)} 074 * <li class='jm'>{@link FluentStringListAssertion#asJoin(String,String,String) asJoin(String,String,String)} 075 * <li class='jm'>{@link FluentStringListAssertion#asTrimmed() asTrimmed()} 076 * </ul> 077 * <li class='jc'>{@link FluentListAssertion} 078 * <ul class='javatreec'> 079 * <li class='jm'>{@link FluentListAssertion#asStrings() asStrings()} 080 * <li class='jm'>{@link FluentListAssertion#asStrings(Function) asStrings(Function)} 081 * <li class='jm'>{@link FluentListAssertion#asCdl() asCdl()} 082 * <li class='jm'>{@link FluentListAssertion#asCdl(Function) asCdl(Function)} 083 * <li class='jm'>{@link FluentListAssertion#asItem(int) asItem(int)} 084 * <li class='jm'>{@link FluentListAssertion#asSorted() asSorted()} 085 * <li class='jm'>{@link FluentListAssertion#asSorted(Comparator) asSorted(Comparator)} 086 * </ul> 087 * <li class='jc'>{@link FluentCollectionAssertion} 088 * <ul class='javatreec'> 089 * <li class='jm'>{@link FluentCollectionAssertion#asStrings() asStrings()} 090 * <li class='jm'>{@link FluentCollectionAssertion#asSize() asSize()} 091 * </ul> 092 * <li class='jc'>{@link FluentObjectAssertion} 093 * <ul class='javatreec'> 094 * <li class='jm'>{@link FluentObjectAssertion#asString() asString()} 095 * <li class='jm'>{@link FluentObjectAssertion#asString(WriterSerializer) asString(WriterSerializer)} 096 * <li class='jm'>{@link FluentObjectAssertion#asString(Function) asString(Function)} 097 * <li class='jm'>{@link FluentObjectAssertion#asJson() asJson()} 098 * <li class='jm'>{@link FluentObjectAssertion#asJsonSorted() asJsonSorted()} 099 * <li class='jm'>{@link FluentObjectAssertion#asTransformed(Function) asApplied(Function)} 100 * <li class='jm'>{@link FluentObjectAssertion#asAny() asAny()} 101 * </ul> 102 * </ul> 103 * 104 * <h5 class='section'>Configuration Methods:</h5> 105 * <p> 106 * <ul class='javatree'> 107 * <li class='jc'>{@link Assertion} 108 * <ul class='javatreec'> 109 * <li class='jm'>{@link Assertion#setMsg(String, Object...) setMsg(String, Object...)} 110 * <li class='jm'>{@link Assertion#setOut(PrintStream) setOut(PrintStream)} 111 * <li class='jm'>{@link Assertion#setSilent() setSilent()} 112 * <li class='jm'>{@link Assertion#setStdOut() setStdOut()} 113 * <li class='jm'>{@link Assertion#setThrowable(Class) setThrowable(Class)} 114 * </ul> 115 * </ul> 116 * 117 * <h5 class='section'>See Also:</h5><ul> 118 * <li class='link'><a class="doclink" href="../../../../index.html#ja.Overview">Overview > juneau-assertions > Overview</a> 119 * </ul> 120 * 121 * @param <R> The return type. 122 */ 123@FluentSetters(returns="FluentStringListAssertion<R>") 124public class FluentStringListAssertion<R> extends FluentListAssertion<String,R> { 125 126 //----------------------------------------------------------------------------------------------------------------- 127 // Instance 128 //----------------------------------------------------------------------------------------------------------------- 129 130 /** 131 * Constructor. 132 * 133 * @param value 134 * The object being tested. 135 * <br>Can be <jk>null</jk>. 136 * @param returns 137 * The object to return after a test method is called. 138 * <br>If <jk>null</jk>, the test method returns this object allowing multiple test method calls to be 139 * used on the same assertion. 140 */ 141 public FluentStringListAssertion(List<String> value, R returns) { 142 this(null, value, returns); 143 } 144 145 /** 146 * Chained constructor. 147 * 148 * <p> 149 * Used when transforming one assertion into another so that the assertion config can be used by the new assertion. 150 * 151 * @param creator 152 * The assertion that created this assertion. 153 * <br>Should be <jk>null</jk> if this is the top-level assertion. 154 * @param value 155 * The object being tested. 156 * <br>Can be <jk>null</jk>. 157 * @param returns 158 * The object to return after a test method is called. 159 * <br>If <jk>null</jk>, the test method returns this object allowing multiple test method calls to be 160 * used on the same assertion. 161 */ 162 public FluentStringListAssertion(Assertion creator, List<String> value, R returns) { 163 super(creator, value, returns); 164 } 165 166 //----------------------------------------------------------------------------------------------------------------- 167 // Transform methods 168 //----------------------------------------------------------------------------------------------------------------- 169 170 /** 171 * Concatenates this list of strings into a {@link FluentStringAssertion}. 172 * 173 * @return A new assertion. 174 */ 175 public FluentStringAssertion<R> asJoin() { 176 return new FluentStringAssertion<>(this, valueIsNull() ? null : value().stream().collect(joining()), returns()); 177 } 178 179 /** 180 * Concatenates this list of strings into a {@link FluentStringAssertion}. 181 * 182 * @param delimiter The delimiter to be used between each element. 183 * @return A new assertion. 184 */ 185 public FluentStringAssertion<R> asJoin(String delimiter) { 186 return new FluentStringAssertion<>(this, valueIsNull() ? null : value().stream().collect(joining(delimiter)), returns()); 187 } 188 189 /** 190 * Concatenates this list of strings into a {@link FluentStringAssertion}. 191 * 192 * @param delimiter The delimiter to be used between each element. 193 * @param prefix The sequence of characters to be used at the beginning of the joined result. 194 * @param suffix The sequence of characters to be used at the end of the joined result. 195 * @return A new assertion. 196 */ 197 public FluentStringAssertion<R> asJoin(String delimiter, String prefix, String suffix) { 198 return new FluentStringAssertion<>(this, valueIsNull() ? null : value().stream().collect(joining(delimiter, prefix, suffix)), returns()); 199 } 200 201 /** 202 * Trims all strings in this list (ignoring null) and returns it as a new string-list assertion. 203 * 204 * @return A new assertion. 205 */ 206 public FluentStringListAssertion<R> asTrimmed() { 207 return new FluentStringListAssertion<>(this, valueIsNull() ? null : value().stream().map(x -> StringUtils.trim(x)).collect(toList()), returns()); 208 } 209 210 //----------------------------------------------------------------------------------------------------------------- 211 // Fluent setters 212 //----------------------------------------------------------------------------------------------------------------- 213 214 // <FluentSetters> 215 216 @Override /* GENERATED - org.apache.juneau.assertions.Assertion */ 217 public FluentStringListAssertion<R> setMsg(String msg, Object...args) { 218 super.setMsg(msg, args); 219 return this; 220 } 221 222 @Override /* GENERATED - org.apache.juneau.assertions.Assertion */ 223 public FluentStringListAssertion<R> setOut(PrintStream value) { 224 super.setOut(value); 225 return this; 226 } 227 228 @Override /* GENERATED - org.apache.juneau.assertions.Assertion */ 229 public FluentStringListAssertion<R> setSilent() { 230 super.setSilent(); 231 return this; 232 } 233 234 @Override /* GENERATED - org.apache.juneau.assertions.Assertion */ 235 public FluentStringListAssertion<R> setStdOut() { 236 super.setStdOut(); 237 return this; 238 } 239 240 @Override /* GENERATED - org.apache.juneau.assertions.Assertion */ 241 public FluentStringListAssertion<R> setThrowable(Class<? extends java.lang.RuntimeException> value) { 242 super.setThrowable(value); 243 return this; 244 } 245 246 // </FluentSetters> 247}