001/*
002 * $Id: Failures.java,v 1.7 2016/12/18 20:19:38 oboehm Exp $
003 *
004 * Copyright (c) 2010 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 13.09.2010 by oliver (ob@oasd.de)
019 */
020
021package patterntesting.runtime.junit;
022
023import java.util.HashMap;
024import java.util.Map;
025
026import patterntesting.runtime.util.Converter;
027
028/**
029 * For the ObjectTester and other tester classes we need a chance to collect the
030 * thrown Assertions and throw it at the end of a combined or complex check.
031 *
032 * @author oliver
033 * @since 1.0.3 (13.09.2010)
034 */
035public final class Failures extends AssertionError {
036
037        private static final long serialVersionUID = 20100913L;
038        private final Map<Class<?>, AssertionError> errors = new HashMap<>();
039
040        /**
041         * Adds the given class and error to the internal error colllection.
042         *
043         * @param clazz
044         *            the clazz
045         * @param error
046         *            the error
047         */
048        public void add(final Class<?> clazz, final AssertionError error) {
049                errors.put(clazz, error);
050        }
051
052        /**
053         * Gets the errors.
054         *
055         * @return the errors
056         */
057        public Map<Class<?>, AssertionError> getErrors() {
058                return errors;
059        }
060
061        /**
062         * Checks for errors.
063         *
064         * @return true, if successful
065         */
066        public boolean hasErrors() {
067                return !this.errors.isEmpty();
068        }
069
070        /**
071         * Gets the message.
072         *
073         * @return the message
074         * @see java.lang.Throwable#getMessage()
075         */
076        @Override
077        public String getMessage() {
078                return Converter.toString(this.errors.keySet()) + " failed";
079        }
080
081}