View Javadoc
1   /*
2    * Copyright 2018 SPF4J.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.spf4j.test.log;
17  
18  import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
19  import org.hamcrest.Matcher;
20  import org.hamcrest.Matchers;
21  
22  /**
23   * @author Zoltan Farkas
24   */
25  public final class UncaughtExceptionDetail {
26  
27    private final Thread thread;
28    private final Throwable throwable;
29  
30    @SuppressFBWarnings("EI_EXPOSE_REP2")
31    public UncaughtExceptionDetail(final Thread thread, final Throwable throwable) {
32      this.thread = thread;
33      this.throwable = throwable;
34    }
35  
36    @SuppressFBWarnings("EI_EXPOSE_REP")
37    public Thread getThread() {
38      return thread;
39    }
40  
41    @SuppressFBWarnings("EI_EXPOSE_REP")
42    public Throwable getThrowable() {
43      return throwable;
44    }
45  
46    @Override
47    public String toString() {
48      return "UncaughtException{" + "thread=" + thread + ", throwable=" + throwable + '}';
49    }
50  
51    public static Matcher<UncaughtExceptionDetail> hasThrowable(final Matcher<Throwable> tMatcher) {
52      return Matchers.hasProperty("throwable", tMatcher);
53    }
54  
55    public static Matcher<UncaughtExceptionDetail> hasThread(final Matcher<Thread> tMatcher) {
56      return Matchers.hasProperty("thread", tMatcher);
57    }
58  
59  }