01: /*******************************************************************************
02: * Copyright (c) 2005 BEA Systems, Inc.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * jgarms@bea.com - initial API and implementation
10: *
11: *******************************************************************************/package org.eclipse.jdt.apt.tests.annotations;
12:
13: /**
14: * Utility class to hold results of processor-based tests.
15: * All methods are static.
16: */
17: public final class ProcessorTestStatus {
18:
19: /**
20: * Marker string to indicate that no errors were encountered.
21: */
22: public static final String NO_ERRORS = "NO ERRORS";
23:
24: /** Error status. Will be == NO_ERRORS if no errors were encountered **/
25: private static String s_errorStatus = NO_ERRORS;
26:
27: /** An expected condition failed. Record the error **/
28: public static void failWithoutException(final String error) {
29: s_errorStatus = error;
30: }
31:
32: /** Returns true if any errors were encountered **/
33: public static boolean hasErrors() {
34: return s_errorStatus == NO_ERRORS;
35: }
36:
37: /** Get the error string. Will be NO_ERRORS if none were encountered **/
38: public static String getErrors() {
39: return s_errorStatus;
40: }
41:
42: /** Reset the status. Needs to be called before each set of tests that could fail **/
43: public static void reset() {
44: s_errorStatus = NO_ERRORS;
45: }
46:
47: // Private c-tor to prevent construction
48: private ProcessorTestStatus() {
49: }
50:
51: public static void assertEquals(String reason, Object expected,
52: Object actual) {
53: if (expected == actual)
54: return;
55: if (expected != null && expected.equals(actual))
56: return;
57: ProcessorTestStatus.fail("Expected " + expected + ", but saw "
58: + actual + ". Reason: " + reason);
59: }
60:
61: public static void assertEquals(String reason, String expected,
62: String actual) {
63: if (expected == actual)
64: return;
65: if (expected != null && expected.equals(actual))
66: return;
67: ProcessorTestStatus.fail("Expected " + expected + ", but saw "
68: + actual + ". Reason: " + reason);
69: }
70:
71: public static void assertEquals(String reason, int expected,
72: int actual) {
73: if (expected == actual)
74: return;
75: ProcessorTestStatus.fail("Expected " + expected + ", but saw "
76: + actual + ". Reason: " + reason);
77: }
78:
79: public static void assertTrue(String reason, boolean expected) {
80: if (!expected)
81: ProcessorTestStatus.fail(reason);
82: }
83:
84: public static void fail(final String reason) {
85: failWithoutException(reason);
86: throw new IllegalStateException("Failed during test: " + reason);
87: }
88:
89: }
|