001: /*
002: * Copyright 2006 Google Inc.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License. You may obtain a copy of
006: * the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013: * License for the specific language governing permissions and limitations under
014: * the License.
015: */
016: package junit.framework;
017:
018: /**
019: * Translatable version of JUnit's <code>Assert</code>.
020: */
021: public class Assert {
022: public static void assertEquals(boolean obj1, boolean obj2) {
023: assertEquals("", obj1, obj2);
024: }
025:
026: public static void assertEquals(byte obj1, byte obj2) {
027: assertEquals("", obj1, obj2);
028: }
029:
030: public static void assertEquals(char obj1, char obj2) {
031: assertEquals("", obj1, obj2);
032: }
033:
034: public static void assertEquals(double obj1, double obj2,
035: double delta) {
036: assertEquals("", obj1, obj2, delta);
037: }
038:
039: public static void assertEquals(float obj1, float obj2, float delta) {
040: assertEquals("", obj1, obj2, delta);
041: }
042:
043: public static void assertEquals(int expected, int actual) {
044: assertEquals("", expected, actual);
045: }
046:
047: public static void assertEquals(long obj1, long obj2) {
048: assertEquals("", obj1, obj2);
049: }
050:
051: public static void assertEquals(Object obj1, Object obj2) {
052: assertEquals("", obj1, obj2);
053: }
054:
055: public static void assertEquals(String str, boolean obj1,
056: boolean obj2) {
057: assertEquals(str, Boolean.valueOf(obj1), Boolean.valueOf(obj2));
058: }
059:
060: public static void assertEquals(String str, byte obj1, byte obj2) {
061: assertEquals(str, new Byte(obj1), new Byte(obj2));
062: }
063:
064: public static void assertEquals(String str, char obj1, char obj2) {
065: assertEquals(str, new Character(obj1), new Character(obj2));
066: }
067:
068: public static void assertEquals(String str, double obj1,
069: double obj2, double delta) {
070: if (obj1 == obj2) {
071: return;
072: } else if (Math.abs(obj1 - obj2) <= delta) {
073: return;
074: } else {
075: fail(str + " expected=" + obj1 + " actual=" + obj2
076: + " delta=" + delta);
077: }
078: }
079:
080: public static void assertEquals(String str, float obj1, float obj2,
081: float delta) {
082: if (obj1 == obj2) {
083: return;
084: } else if (Math.abs(obj1 - obj2) <= delta) {
085: return;
086: } else {
087: fail(str + " expected=" + obj1 + " actual=" + obj2
088: + " delta=" + delta);
089: }
090: }
091:
092: public static void assertEquals(String msg, int expected, int actual) {
093: if (expected != actual) {
094: fail(msg + " expected=" + expected + " actual=" + actual);
095: }
096: }
097:
098: public static void assertEquals(String str, long obj1, long obj2) {
099: assertEquals(str, new Long(obj1), new Long(obj2));
100: }
101:
102: public static void assertEquals(String msg, Object obj1, Object obj2) {
103: if (obj1 == null && obj2 == null) {
104: return;
105: }
106:
107: if (obj1 != null && obj1.equals(obj2)) {
108: return;
109: }
110:
111: fail(msg + " expected=" + obj1 + " actual=" + obj2);
112: }
113:
114: public static void assertFalse(boolean condition) {
115: assertFalse(null, condition);
116: }
117:
118: public static void assertFalse(String message, boolean condition) {
119: assertTrue(message, !condition);
120: }
121:
122: public static void assertNotNull(Object obj) {
123: assertNotNull(null, obj);
124: }
125:
126: public static void assertNotNull(String msg, Object obj) {
127: assertTrue(msg, obj != null);
128: }
129:
130: public static void assertNotSame(Object obj1, Object obj2) {
131: assertNotSame(null, obj1, obj2);
132: }
133:
134: public static void assertNotSame(String msg, Object obj1,
135: Object obj2) {
136: if (obj1 != obj2) {
137: return;
138: }
139:
140: if (msg == null) {
141: msg = "";
142: }
143:
144: fail(msg + " expected and actual match");
145: }
146:
147: public static void assertNull(Object obj) {
148: assertNull(null, obj);
149: }
150:
151: public static void assertNull(String msg, Object obj) {
152: assertTrue(msg, obj == null);
153: }
154:
155: public static void assertSame(Object obj1, Object obj2) {
156: assertSame(null, obj1, obj2);
157: }
158:
159: public static void assertSame(String msg, Object obj1, Object obj2) {
160: if (obj1 == obj2) {
161: return;
162: }
163:
164: if (msg == null) {
165: msg = "";
166: }
167:
168: fail(msg + " expected and actual do not match");
169: }
170:
171: public static void assertTrue(boolean condition) {
172: assertTrue(null, condition);
173: }
174:
175: public static void assertTrue(String message, boolean condition) {
176: if (!condition) {
177: fail(message);
178: }
179: }
180:
181: public static void fail() {
182: fail(null);
183: }
184:
185: public static void fail(String message) {
186: throw new AssertionFailedError(message);
187: }
188:
189: /**
190: * Utility class, no public constructor needed.
191: */
192: protected Assert() {
193: }
194: }
|