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