01: /**
02: * EasyBeans
03: * Copyright (C) 2006 Bull S.A.S.
04: * Contact: easybeans@ow2.org
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * 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 1970 2007-10-16 11:49:25Z benoitf $
23: * --------------------------------------------------------------------------
24: */package org.ow2.easybeans.tests.common.asserts;
25:
26: import static org.ow2.easybeans.tests.common.helper.InterceptorHelper.getPrintOrderErrorMsg;
27:
28: import java.util.List;
29:
30: /**
31: * It's creates new assert functions.
32: * @author Eduardo Studzinski Estima de Castro
33: * @author Gisele Pinheiro Souza
34: */
35: public class Assert extends org.testng.Assert {
36:
37: /**
38: * Asserts that two lists has the same elements.
39: * @param expected first list to compare
40: * @param result second list to compare
41: * @param message if assert fails, exception message
42: */
43: public static void assertEquals(final List expected,
44: final List result, final String message) {
45:
46: // if the arrays are null, they have the same elements
47: if (expected == null ^ result == null) {
48: throw new AssertionError(getPrintOrderErrorMsg(expected,
49: result, message));
50: }
51: if (expected != null) {
52: // Checks if the arrays has the same size
53: if (expected.size() == result.size()) {
54: // Compare each element
55: for (int i = 0; i < expected.size(); i++) {
56: if (!(expected.get(i).equals(result.get(i)))) {
57: throw new AssertionError(getPrintOrderErrorMsg(
58: expected, result, message));
59: }
60: }
61: } else {
62: throw new AssertionError(getPrintOrderErrorMsg(
63: expected, result, message));
64: }
65: }
66: }
67:
68: /**
69: * Asserts that an object is equal at least with a value in the args.
70: * @param result the value that will be compared.
71: * @param message the error message.
72: * @param expected the list of correct values for the parameter result.
73: */
74: public static void assertEquals(final Object result,
75: final Object[] expected, final String message) {
76: boolean bolIsEqual = false;
77: int i = 0;
78:
79: if (expected == null) {
80: throw new AssertionError("The args are null");
81: }
82:
83: while (!bolIsEqual && i < expected.length) {
84: if (expected[i].equals(result)) {
85: bolIsEqual = true;
86: } else {
87: i++;
88: }
89: }
90: if (!bolIsEqual) {
91: throw new AssertionError(message);
92: }
93: }
94: }
|