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.function.*;
017
018import org.apache.juneau.internal.*;
019import org.apache.juneau.serializer.*;
020
021/**
022 * Used for assertion calls against throwable objects.
023 *
024 * <h5 class='section'>Example:</h5>
025 * <p class='bjava'>
026 *    <jc>// Validates the throwable message or one of the parent messages contain 'Foobar'.</jc>
027 *    <jsm>assertThrowable</jsm>(<jv>throwable</jv>).contains(<js>"Foobar"</js>);
028 * </p>
029 *
030 *
031 * <h5 class='section'>Test Methods:</h5>
032 * <p>
033 * <ul class='javatree'>
034 *    <li class='jc'>{@link FluentObjectAssertion}
035 *    <ul class='javatreec'>
036 *       <li class='jm'>{@link FluentObjectAssertion#isExists() isExists()}
037 *       <li class='jm'>{@link FluentObjectAssertion#is(Object) is(Object)}
038 *       <li class='jm'>{@link FluentObjectAssertion#is(Predicate) is(Predicate)}
039 *       <li class='jm'>{@link FluentObjectAssertion#isNot(Object) isNot(Object)}
040 *       <li class='jm'>{@link FluentObjectAssertion#isAny(Object...) isAny(Object...)}
041 *       <li class='jm'>{@link FluentObjectAssertion#isNotAny(Object...) isNotAny(Object...)}
042 *       <li class='jm'>{@link FluentObjectAssertion#isNull() isNull()}
043 *       <li class='jm'>{@link FluentObjectAssertion#isNotNull() isNotNull()}
044 *       <li class='jm'>{@link FluentObjectAssertion#isString(String) isString(String)}
045 *       <li class='jm'>{@link FluentObjectAssertion#isJson(String) isJson(String)}
046 *       <li class='jm'>{@link FluentObjectAssertion#isSame(Object) isSame(Object)}
047 *       <li class='jm'>{@link FluentObjectAssertion#isSameJsonAs(Object) isSameJsonAs(Object)}
048 *       <li class='jm'>{@link FluentObjectAssertion#isSameSortedJsonAs(Object) isSameSortedJsonAs(Object)}
049 *       <li class='jm'>{@link FluentObjectAssertion#isSameSerializedAs(Object, WriterSerializer) isSameSerializedAs(Object, WriterSerializer)}
050 *       <li class='jm'>{@link FluentObjectAssertion#isType(Class) isType(Class)}
051 *       <li class='jm'>{@link FluentObjectAssertion#isExactType(Class) isExactType(Class)}
052 *    </ul>
053 * </ul>
054 *
055 * <h5 class='section'>Transform Methods:</h5>
056 * <p>
057 * <ul class='javatree'>
058 *    <li class='jc'>{@link FluentThrowableAssertion}
059 *    <ul class='javatreec'>
060 *       <li class='jm'>{@link FluentThrowableAssertion#asMessage() asMessage()}
061 *       <li class='jm'>{@link FluentThrowableAssertion#asMessages() asMessages()}
062 *       <li class='jm'>{@link FluentThrowableAssertion#asLocalizedMessage() asLocalizedMessage()}
063 *       <li class='jm'>{@link FluentThrowableAssertion#asLocalizedMessages() asLocalizedMessages()}
064 *       <li class='jm'>{@link FluentThrowableAssertion#asStackTrace() asStackTrace()}
065 *       <li class='jm'>{@link FluentThrowableAssertion#asCausedBy() asCausedBy()}
066 *       <li class='jm'>{@link FluentThrowableAssertion#asCausedBy(Class) asCausedBy(Class)}
067 *       <li class='jm'>{@link FluentThrowableAssertion#asFind(Class) asFind(Class)}
068 *    </ul>
069 *    <li class='jc'>{@link FluentObjectAssertion}
070 *    <ul class='javatreec'>
071 *       <li class='jm'>{@link FluentObjectAssertion#asString() asString()}
072 *       <li class='jm'>{@link FluentObjectAssertion#asString(WriterSerializer) asString(WriterSerializer)}
073 *       <li class='jm'>{@link FluentObjectAssertion#asString(Function) asString(Function)}
074 *       <li class='jm'>{@link FluentObjectAssertion#asJson() asJson()}
075 *       <li class='jm'>{@link FluentObjectAssertion#asJsonSorted() asJsonSorted()}
076 *       <li class='jm'>{@link FluentObjectAssertion#asTransformed(Function) asApplied(Function)}
077 *       <li class='jm'>{@link FluentObjectAssertion#asAny() asAny()}
078 * </ul>
079 * </ul>
080 *
081 * <h5 class='section'>Configuration Methods:</h5>
082 * <p>
083 * <ul class='javatree'>
084 *    <li class='jc'>{@link Assertion}
085 *    <ul class='javatreec'>
086 *       <li class='jm'>{@link Assertion#setMsg(String, Object...) setMsg(String, Object...)}
087 *       <li class='jm'>{@link Assertion#setOut(PrintStream) setOut(PrintStream)}
088 *       <li class='jm'>{@link Assertion#setSilent() setSilent()}
089 *       <li class='jm'>{@link Assertion#setStdOut() setStdOut()}
090 *       <li class='jm'>{@link Assertion#setThrowable(Class) setThrowable(Class)}
091 *    </ul>
092 * </ul>
093 *
094 * <h5 class='section'>See Also:</h5><ul>
095 *    <li class='link'><a class="doclink" href="../../../../index.html#ja.Overview">Overview &gt; juneau-assertions &gt; Overview</a>
096 * </ul>
097 *
098 * @param <T> The throwable type.
099 */
100@FluentSetters(returns="ThrowableAssertion<T>")
101public class ThrowableAssertion<T extends Throwable> extends FluentThrowableAssertion<T,ThrowableAssertion<T>> {
102
103   //-----------------------------------------------------------------------------------------------------------------
104   // Static
105   //-----------------------------------------------------------------------------------------------------------------
106
107   /**
108    * Static creator.
109    *
110    * @param <X> The throwable type.
111    * @param value
112    *    The object being tested.
113    *    <br>Can be <jk>null</jk>.
114    * @return A new assertion object.
115    */
116   public static <X extends Throwable> ThrowableAssertion<X> create(X value) {
117      return new ThrowableAssertion<>(value);
118   }
119
120   //-----------------------------------------------------------------------------------------------------------------
121   // Instance
122   //-----------------------------------------------------------------------------------------------------------------
123
124   /**
125    * Constructor.
126    *
127    * @param value
128    *    The object being tested.
129    *    <br>Can be <jk>null</jk>.
130    */
131   public ThrowableAssertion(T value) {
132      super(value, null);
133   }
134
135   //-----------------------------------------------------------------------------------------------------------------
136   // Fluent setters
137   //-----------------------------------------------------------------------------------------------------------------
138
139   // <FluentSetters>
140
141   @Override /* GENERATED - org.apache.juneau.assertions.Assertion */
142   public ThrowableAssertion<T> setMsg(String msg, Object...args) {
143      super.setMsg(msg, args);
144      return this;
145   }
146
147   @Override /* GENERATED - org.apache.juneau.assertions.Assertion */
148   public ThrowableAssertion<T> setOut(PrintStream value) {
149      super.setOut(value);
150      return this;
151   }
152
153   @Override /* GENERATED - org.apache.juneau.assertions.Assertion */
154   public ThrowableAssertion<T> setSilent() {
155      super.setSilent();
156      return this;
157   }
158
159   @Override /* GENERATED - org.apache.juneau.assertions.Assertion */
160   public ThrowableAssertion<T> setStdOut() {
161      super.setStdOut();
162      return this;
163   }
164
165   @Override /* GENERATED - org.apache.juneau.assertions.Assertion */
166   public ThrowableAssertion<T> setThrowable(Class<? extends java.lang.RuntimeException> value) {
167      super.setThrowable(value);
168      return this;
169   }
170
171   // </FluentSetters>
172}