01: /*
02: * Copyright 2002 Felix Pahl. All rights reserved.
03: * Use is subject to license terms.
04: */
05:
06: package uk.org.ponder.util;
07:
08: public class Assertions {
09: private Assertions() {
10: }
11:
12: final private static boolean debugging = true;
13:
14: public static void expect(boolean condition, String message)
15: throws AssertionException {
16: if (debugging)
17: if (!condition)
18: throw new AssertionException(message);
19: }
20:
21: public static void expect(boolean found, boolean expected)
22: throws AssertionException {
23: if (debugging)
24: if (found != expected)
25: throw new AssertionException("expected " + expected
26: + ", found " + found);
27: }
28:
29: public static void expect(int found, int expected)
30: throws AssertionException {
31: if (debugging)
32: if (found != expected)
33: throw new AssertionException("expected " + expected
34: + ", found " + found);
35: }
36:
37: public static void expect(double found, double expected)
38: throws AssertionException {
39: if (debugging)
40: if (found != expected)
41: throw new AssertionException("expected " + expected
42: + ", found " + found);
43: }
44:
45: public static void expect(Object found, Object expected)
46: throws AssertionException {
47: if (debugging)
48: if ((found == null && expected != null)
49: || (found != null && !found.equals(expected)))
50: throw new AssertionException("expected " + expected
51: + ", found " + found);
52: }
53:
54: public static void unexpect(boolean found, boolean unexpected)
55: throws AssertionException {
56: if (debugging)
57: if (found == unexpected)
58: throw new AssertionException("unexpected " + found);
59: }
60:
61: public static void unexpect(int found, int unexpected)
62: throws AssertionException {
63: if (debugging)
64: if (found == unexpected)
65: throw new AssertionException("unexpected " + found);
66: }
67:
68: public static void unexpect(double found, double unexpected)
69: throws AssertionException {
70: if (debugging)
71: if (found == unexpected)
72: throw new AssertionException("unexpected " + found);
73: }
74:
75: public static void unexpect(Object found, Object unexpected)
76: throws AssertionException {
77: if (debugging)
78: if ((found == null && unexpected == null)
79: || (found != null && found.equals(unexpected)))
80: throw new AssertionException("unexpected " + found);
81: }
82:
83: public static void limit(int found, int min, int max)
84: throws AssertionException {
85: if (debugging)
86: if (!(min <= found && found <= max))
87: throw new AssertionException(found + " out of range ["
88: + min + "," + max + "]");
89: }
90:
91: public static void limit(double found, double min, double max)
92: throws AssertionException {
93: if (debugging)
94: if (!(min <= found && found <= max))
95: throw new AssertionException(found + " out of range ["
96: + min + "," + max + "]");
97: }
98: }
|