KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > tests > common > asserts > Assert


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: Assert.java 704 2006-06-21 14:49:08Z studzine $
23  * --------------------------------------------------------------------------
24  */

25 package org.objectweb.easybeans.tests.common.asserts;
26
27 import static org.objectweb.easybeans.tests.common.helper.InterceptorHelper.getPrintOrderErrorMsg;
28
29 import java.util.List JavaDoc;
30
31 /**
32  * It's creates new assert functions.
33  * @author Eduardo Studzinski Estima de Castro
34  * @author Gisele Pinheiro Souza
35  */

36 public class Assert extends org.testng.Assert{
37
38     /**
39      * Asserts that two lists has the same elements.
40      * @param expected first list to compare
41      * @param result second list to compare
42      * @param message if assert fails, exception message
43      */

44     public static void assertEquals(final List JavaDoc expected, final List JavaDoc result, final String JavaDoc message) {
45
46         // if the arrays are null, they have the same elements
47
if (expected == null ^ result == null) {
48             throw new AssertionError JavaDoc(getPrintOrderErrorMsg(expected, result, message));
49         }
50         if (expected != null) {
51             // Checks if the arrays has the same size
52
if (expected.size() == result.size()) {
53                 // Compare each element
54
for (int i = 0; i < expected.size(); i++) {
55                     if (!(expected.get(i).equals(result.get(i)))) {
56                         throw new AssertionError JavaDoc(getPrintOrderErrorMsg(expected, result, message));
57                     }
58                 }
59             } else {
60                 throw new AssertionError JavaDoc(getPrintOrderErrorMsg(expected, result, message));
61             }
62         }
63     }
64
65     /**
66      * Asserts that an object is equal at least with a value in the args.
67      * @param result the value that will be compared.
68      * @param message the error message.
69      * @param expected the list of correct values for the parameter result.
70      */

71     public static void assertEquals(final Object JavaDoc result, final Object JavaDoc[] expected, final String JavaDoc message){
72         boolean bolIsEqual = false;
73         int i = 0;
74
75         if(expected == null){
76             throw new AssertionError JavaDoc("The args are null");
77         }
78
79         while(!bolIsEqual && i < expected.length){
80             if(expected[i].equals(result)){
81                 bolIsEqual = true;
82             }else{
83                 i++;
84             }
85         }
86         if(!bolIsEqual){
87             throw new AssertionError JavaDoc(message);
88         }
89     }
90 }
91
Popular Tags