KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > tests > common > helper > ExceptionHelper


1 /**
2  * EasyBeans
3  * Copyright (C) 2006 Bull S.A.S.
4  * Contact: easybeans@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: ExceptionHelper.java 893 2006-07-19 14:19:23Z pinheirg $
23  * --------------------------------------------------------------------------
24  */

25 package org.objectweb.easybeans.tests.common.helper;
26
27
28
29 /**
30  * @author Eduardo Studzinski Estima de Castro
31  * @author Gisele Pinheiro Souza
32  *
33  */

34 public final class ExceptionHelper {
35
36     /**
37      * Creates a new instance of ExceptionHelper.
38      *
39      */

40     private ExceptionHelper(){
41     }
42
43     /**
44      * Verifies if the cause of an exception is another exception.
45      * @param e obtained exception
46      * @param expected expected exception as cause
47      */

48     public static void checkCause(final Exception JavaDoc e, final Class JavaDoc expected){
49         if (!(expected.equals(e.getCause().getClass()))){
50             throw new IllegalStateException JavaDoc(e.getCause());
51         }
52     }
53
54     /**
55      * Verifies if two exceptions has the same class.
56      * @param e the received exception.
57      * @param expectedException the expected exception.
58      * @return true if are the same exception, false otherwise.
59      */

60     public static boolean isEquals(final Exception JavaDoc e, final Class JavaDoc expectedException) {
61        return e.getClass().getName() == expectedException.getName();
62     }
63
64 }
65
Popular Tags