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 org.apache.juneau.common.internal.StringUtils.*;
016
017import java.io.*;
018import java.util.function.*;
019import java.util.regex.*;
020
021import org.apache.juneau.internal.*;
022import org.apache.juneau.serializer.*;
023
024/**
025 * Used for assertion calls against string objects.
026 *
027 * <h5 class='section'>Example:</h5>
028 * <p class='bjava'>
029 *    <jc>// Validates the response body of an HTTP call is the text "OK".</jc>
030 *    <jsm>assertString</jsm>(<jv>httpBody</jv>).is(<js>"OK"</js>);
031 * </p>
032 *
033 * <h5 class='section'>Test Methods:</h5>
034 * <p>
035 * <ul class='javatree'>
036 *    <li class='jc'>{@link FluentStringAssertion}
037 *    <ul class='javatreec'>
038 *       <li class='jm'>{@link FluentStringAssertion#is(String) is(String)}
039 *       <li class='jm'>{@link FluentStringAssertion#isNot(String) isNot(String)}
040 *       <li class='jm'>{@link FluentStringAssertion#isLines(String...) isLines(String...)}
041 *       <li class='jm'>{@link FluentStringAssertion#isSortedLines(String...) isSortedLines(String...)}
042 *       <li class='jm'>{@link FluentStringAssertion#isIc(String) isIc(String)}
043 *       <li class='jm'>{@link FluentStringAssertion#isNotIc(String) isNotIc(String)}
044 *       <li class='jm'>{@link FluentStringAssertion#isContains(String...) isContains(String...)}
045 *       <li class='jm'>{@link FluentStringAssertion#isNotContains(String...) isNotContains(String...)}
046 *       <li class='jm'>{@link FluentStringAssertion#isEmpty() isEmpty()}
047 *       <li class='jm'>{@link FluentStringAssertion#isNotEmpty() isNotEmpty()}
048 *       <li class='jm'>{@link FluentStringAssertion#isString(Object) isString(Object)}
049 *       <li class='jm'>{@link FluentStringAssertion#isMatches(String) isMatches(String)}
050 *       <li class='jm'>{@link FluentStringAssertion#isPattern(String) isPattern(String)}
051 *       <li class='jm'>{@link FluentStringAssertion#isPattern(String,int) isPattern(String,int)}
052 *       <li class='jm'>{@link FluentStringAssertion#isPattern(Pattern) isPattern(Pattern)}
053 *       <li class='jm'>{@link FluentStringAssertion#isStartsWith(String) isStartsWith(String)}
054 *       <li class='jm'>{@link FluentStringAssertion#isEndsWith(String) isEndsWith(String)}
055 *    </ul>
056 *    <li class='jc'>{@link FluentObjectAssertion}
057 *    <ul class='javatreec'>
058 *       <li class='jm'>{@link FluentObjectAssertion#isExists() isExists()}
059 *       <li class='jm'>{@link FluentObjectAssertion#is(Object) is(Object)}
060 *       <li class='jm'>{@link FluentObjectAssertion#is(Predicate) is(Predicate)}
061 *       <li class='jm'>{@link FluentObjectAssertion#isNot(Object) isNot(Object)}
062 *       <li class='jm'>{@link FluentObjectAssertion#isAny(Object...) isAny(Object...)}
063 *       <li class='jm'>{@link FluentObjectAssertion#isNotAny(Object...) isNotAny(Object...)}
064 *       <li class='jm'>{@link FluentObjectAssertion#isNull() isNull()}
065 *       <li class='jm'>{@link FluentObjectAssertion#isNotNull() isNotNull()}
066 *       <li class='jm'>{@link FluentObjectAssertion#isString(String) isString(String)}
067 *       <li class='jm'>{@link FluentObjectAssertion#isJson(String) isJson(String)}
068 *       <li class='jm'>{@link FluentObjectAssertion#isSame(Object) isSame(Object)}
069 *       <li class='jm'>{@link FluentObjectAssertion#isSameJsonAs(Object) isSameJsonAs(Object)}
070 *       <li class='jm'>{@link FluentObjectAssertion#isSameSortedJsonAs(Object) isSameSortedJsonAs(Object)}
071 *       <li class='jm'>{@link FluentObjectAssertion#isSameSerializedAs(Object, WriterSerializer) isSameSerializedAs(Object, WriterSerializer)}
072 *       <li class='jm'>{@link FluentObjectAssertion#isType(Class) isType(Class)}
073 *       <li class='jm'>{@link FluentObjectAssertion#isExactType(Class) isExactType(Class)}
074 *    </ul>
075 * </ul>
076 *
077 * <h5 class='section'>Transform Methods:</h5>
078 * <p>
079 * <ul class='javatree'>
080 *    <li class='jc'>{@link FluentStringAssertion}
081 *    <ul class='javatreec'>
082 *       <li class='jm'>{@link FluentStringAssertion#asReplaceAll(String,String) asReplaceAll(String,String)}
083 *       <li class='jm'>{@link FluentStringAssertion#asReplace(String,String) asReplace(String,String)}
084 *       <li class='jm'>{@link FluentStringAssertion#asUrlDecode() asUrlDecode()}
085 *       <li class='jm'>{@link FluentStringAssertion#asLc() asLc()}
086 *       <li class='jm'>{@link FluentStringAssertion#asUc() asUc()}
087 *       <li class='jm'>{@link FluentStringAssertion#asLines() asLines()}
088 *       <li class='jm'>{@link FluentStringAssertion#asSplit(String) asSplit(String)}
089 *       <li class='jm'>{@link FluentStringAssertion#asLength() asLength()}
090 *       <li class='jm'>{@link FluentStringAssertion#asOneLine() asOneLine()}
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 &gt; juneau-assertions &gt; Overview</a>
119 * </ul>
120 */
121@FluentSetters(returns="StringAssertion")
122public class StringAssertion extends FluentStringAssertion<StringAssertion> {
123
124   //-----------------------------------------------------------------------------------------------------------------
125   // Static
126   //-----------------------------------------------------------------------------------------------------------------
127
128   /**
129    * Static creator.
130    *
131    * @param value
132    *    The object being tested.
133    *    <br>Can be <jk>null</jk>.
134    * @return A new assertion object.
135    */
136   public static StringAssertion create(Object value) {
137      return new StringAssertion(value);
138   }
139
140   //-----------------------------------------------------------------------------------------------------------------
141   // Instance
142   //-----------------------------------------------------------------------------------------------------------------
143
144   /**
145    * Constructor.
146    *
147    * @param value
148    *    The object being tested.
149    *    <br>Can be <jk>null</jk>.
150    */
151   public StringAssertion(Object value) {
152      super(stringify(value), null);
153   }
154
155   //-----------------------------------------------------------------------------------------------------------------
156   // Fluent setters
157   //-----------------------------------------------------------------------------------------------------------------
158
159   // <FluentSetters>
160
161   @Override /* GENERATED - org.apache.juneau.assertions.Assertion */
162   public StringAssertion setMsg(String msg, Object...args) {
163      super.setMsg(msg, args);
164      return this;
165   }
166
167   @Override /* GENERATED - org.apache.juneau.assertions.Assertion */
168   public StringAssertion setOut(PrintStream value) {
169      super.setOut(value);
170      return this;
171   }
172
173   @Override /* GENERATED - org.apache.juneau.assertions.Assertion */
174   public StringAssertion setSilent() {
175      super.setSilent();
176      return this;
177   }
178
179   @Override /* GENERATED - org.apache.juneau.assertions.Assertion */
180   public StringAssertion setStdOut() {
181      super.setStdOut();
182      return this;
183   }
184
185   @Override /* GENERATED - org.apache.juneau.assertions.Assertion */
186   public StringAssertion setThrowable(Class<? extends java.lang.RuntimeException> value) {
187      super.setThrowable(value);
188      return this;
189   }
190
191   @Override /* GENERATED - org.apache.juneau.assertions.FluentStringAssertion */
192   public StringAssertion asJavaStrings() {
193      super.asJavaStrings();
194      return this;
195   }
196
197   // </FluentSetters>
198}