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.function.*;
021
022
023/**
024 * Used for assertion calls against throwable objects.
025 *
026 * <h2 class='section'>Example:</h2>
027 * <p class='bjava'>
028 *    <jc>// Validates the throwable message or one of the parent messages contain 'Foobar'.</jc>
029 *    <jsm>assertThrowable</jsm>(<jv>throwable</jv>).contains(<js>"Foobar"</js>);
030 * </p>
031 *
032 *
033 * <h2 class='section'>Test Methods:</h2>
034 * <ul class='javatree'>
035 *    <li class='jc'>{@link FluentObjectAssertion}
036 *    <ul class='javatreec'>
037 *       <li class='jm'>{@link FluentObjectAssertion#isExists() isExists()}
038 *       <li class='jm'>{@link FluentObjectAssertion#is(Object) is(Object)}
039 *       <li class='jm'>{@link FluentObjectAssertion#is(Predicate) is(Predicate)}
040 *       <li class='jm'>{@link FluentObjectAssertion#isNot(Object) isNot(Object)}
041 *       <li class='jm'>{@link FluentObjectAssertion#isAny(Object...) isAny(Object...)}
042 *       <li class='jm'>{@link FluentObjectAssertion#isNotAny(Object...) isNotAny(Object...)}
043 *       <li class='jm'>{@link FluentObjectAssertion#isNull() isNull()}
044 *       <li class='jm'>{@link FluentObjectAssertion#isNotNull() isNotNull()}
045 *       <li class='jm'>{@link FluentObjectAssertion#isString(String) isString(String)}
046 *       <li class='jm'>{@link FluentObjectAssertion#isSame(Object) isSame(Object)}
047 *       <li class='jm'>{@link FluentObjectAssertion#isType(Class) isType(Class)}
048 *       <li class='jm'>{@link FluentObjectAssertion#isExactType(Class) isExactType(Class)}
049 *    </ul>
050 * </ul>
051 *
052 * <h2 class='section'>Transform Methods:</h2>
053 * <ul class='javatree'>
054 *    <li class='jc'>{@link FluentThrowableAssertion}
055 *    <ul class='javatreec'>
056 *       <li class='jm'>{@link FluentThrowableAssertion#asMessage() asMessage()}
057 *       <li class='jm'>{@link FluentThrowableAssertion#asMessages() asMessages()}
058 *       <li class='jm'>{@link FluentThrowableAssertion#asLocalizedMessage() asLocalizedMessage()}
059 *       <li class='jm'>{@link FluentThrowableAssertion#asLocalizedMessages() asLocalizedMessages()}
060 *       <li class='jm'>{@link FluentThrowableAssertion#asStackTrace() asStackTrace()}
061 *       <li class='jm'>{@link FluentThrowableAssertion#asCausedBy() asCausedBy()}
062 *       <li class='jm'>{@link FluentThrowableAssertion#asCausedBy(Class) asCausedBy(Class)}
063 *       <li class='jm'>{@link FluentThrowableAssertion#asFind(Class) asFind(Class)}
064 *    </ul>
065 *    <li class='jc'>{@link FluentObjectAssertion}
066 *    <ul class='javatreec'>
067 *       <li class='jm'>{@link FluentObjectAssertion#asString() asString()}
068 *       <li class='jm'>{@link FluentObjectAssertion#asString(ThrowingFunction) asString(ThrowingFunction)}
069 *       <li class='jm'>{@link FluentObjectAssertion#asTransformed(UnaryOperator) asTransformed(UnaryOperator)}
070 *       <li class='jm'>{@link FluentObjectAssertion#asAny() asAny()}
071 * </ul>
072 * </ul>
073 *
074 * <h2 class='section'>Configuration Methods:</h2>
075 * <ul class='javatree'>
076 *    <li class='jc'>{@link Assertion}
077 *    <ul class='javatreec'>
078 *       <li class='jm'>{@link Assertion#setMsg(String, Object...) setMsg(String, Object...)}
079 *       <li class='jm'>{@link Assertion#setOut(PrintStream) setOut(PrintStream)}
080 *       <li class='jm'>{@link Assertion#setSilent() setSilent()}
081 *       <li class='jm'>{@link Assertion#setStdOut() setStdOut()}
082 *       <li class='jm'>{@link Assertion#setThrowable(Class) setThrowable(Class)}
083 *    </ul>
084 * </ul>
085 *
086 * <h2 class='section'>See Also:</h2><ul>
087 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauEcosystemOverview">Juneau Ecosystem</a>
088 * </ul>
089 *
090 * @param <T> The throwable type.
091 */
092public class ThrowableAssertion<T extends Throwable> extends FluentThrowableAssertion<T,ThrowableAssertion<T>> {
093
094   /**
095    * Static creator.
096    *
097    * @param <X> The throwable type.
098    * @param value
099    *    The object being tested.
100    *    <br>Can be <jk>null</jk> (assertions such as {@code isNull()} then operate on the absence of a value).
101    * @return A new assertion object.
102    */
103   public static <X extends Throwable> ThrowableAssertion<X> create(X value) {
104      return new ThrowableAssertion<>(value);
105   }
106
107   /**
108    * Constructor.
109    *
110    * @param value
111    *    The object being tested.
112    *    <br>Can be <jk>null</jk> (assertions such as {@code isNull()} then operate on the absence of a value).
113    */
114   public ThrowableAssertion(T value) {
115      super(value, null);
116   }
117
118   @Override /* Overridden from Assertion */
119   public ThrowableAssertion<T> setMsg(String msg, Object...args) {
120      super.setMsg(msg, args);
121      return this;
122   }
123
124   @Override /* Overridden from Assertion */
125   public ThrowableAssertion<T> setOut(PrintStream value) {
126      super.setOut(value);
127      return this;
128   }
129
130   @Override /* Overridden from Assertion */
131   public ThrowableAssertion<T> setSilent() {
132      super.setSilent();
133      return this;
134   }
135
136   @Override /* Overridden from Assertion */
137   public ThrowableAssertion<T> setStdOut() {
138      super.setStdOut();
139      return this;
140   }
141
142   @Override /* Overridden from Assertion */
143   public ThrowableAssertion<T> setThrowable(Class<? extends RuntimeException> value) {
144      super.setThrowable(value);
145      return this;
146   }
147}