001 /*
002 * $Id: DetailedAssertionError.java,v 1.1 2014/01/02 21:06:00 oboehm Exp $
003 *
004 * Copyright (c) 2013 by Oliver Boehm
005 *
006 * Licensed under the Apache License, Version 2.0 (the "License");
007 * you may not use this file except in compliance with the License.
008 * You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express orimplied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 *
018 * (c)reated 02.01.2014 by oliver (ob@oasd.de)
019 */
020
021 package patterntesting.runtime.exception;
022
023 import java.lang.reflect.InvocationTargetException;
024
025
026 /**
027 * This is a kind of better {@link AssertionError} which gives you some more
028 * details of the given cause.
029 *
030 * @author oliver
031 * @since 1.4 (02.01.2014)
032 */
033 public class DetailedAssertionError extends AssertionError {
034
035 private static final long serialVersionUID = 20140102L;
036 private final Throwable cause;
037
038 /**
039 * Instantiates a new detailed assertion error.
040 *
041 * @param detailMessage the detail message
042 * @param cause the cause
043 */
044 public DetailedAssertionError(final Object detailMessage, final Throwable cause) {
045 super(detailMessage);
046 this.cause = cause;
047 }
048
049 /**
050 * Gets the cause.
051 *
052 * @return the cause
053 * @see java.lang.Throwable#getCause()
054 */
055 @Override
056 public Throwable getCause() {
057 if (this.cause instanceof InvocationTargetException) {
058 Throwable origCause = this.cause.getCause();
059 if (origCause != null) {
060 return origCause;
061 }
062 }
063 return this.cause;
064 }
065
066 }
067