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; 014 015import static org.apache.juneau.common.internal.StringUtils.*; 016 017import java.text.*; 018 019/** 020 * An extension of {@link AssertionError} with helper constructors for messages with message-style arguments. 021 * 022 * <h5 class='section'>See Also:</h5><ul> 023 * </ul> 024 * 025 * @serial exclude 026 */ 027public class BasicAssertionError extends AssertionError { 028 029 private static final long serialVersionUID = 1L; 030 031 /** 032 * Constructor. 033 * 034 * @param message The {@link MessageFormat}-style message. 035 * @param args Optional {@link MessageFormat}-style arguments. 036 */ 037 public BasicAssertionError(String message, Object...args) { 038 super(format(message, args)); 039 } 040 041 /** 042 * Constructor. 043 * 044 * @param cause The cause of this exception. 045 * @param message The {@link MessageFormat}-style message. 046 * @param args Optional {@link MessageFormat}-style arguments. 047 */ 048 public BasicAssertionError(Throwable cause, String message, Object...args) { 049 this(getMessage(cause, message, null), args); 050 initCause(cause); 051 } 052 053 /** 054 * Finds the message. 055 * 056 * @param cause The cause. 057 * @param msg The message. 058 * @param def The default value if both above are <jk>null</jk>. 059 * @return The resolved message. 060 */ 061 protected static final String getMessage(Throwable cause, String msg, String def) { 062 if (msg != null) 063 return msg; 064 if (cause != null) 065 return cause.getMessage(); 066 return def; 067 } 068}