1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.jdiagnose;
17
18 import java.util.Collections;
19 import java.util.List;
20
21 /***
22 * A Diagnostic Unit. This behaves in a similar way to JUnit *Test classes.
23 * Subclass this method and when this diagnostic is run, any void methods that
24 * start with "diagnose" will be run. e.g.
25 *
26 * <code>
27 * public class FailingDiagnostic extends DiagnosticUnit {
28 * public void diagnoseFailure() {
29 * assertTrue("False isn't True!", false);
30 * }
31 * }
32 * </code>
33 *
34 * User: jamie Date: May 29, 2004 Time: 11:10:21 PM
35 */
36 public class DiagnosticUnit implements DiagnosticUnitLifeCycle, DiagnosticContainer, Diagnostic {
37
38 private DelegatingDiagnosticUnit delegatingDiagnosticUnit = null;
39
40 private String name;
41
42 /***
43 * Create a new DiagnosticUnit with a Fully Qualified Name
44 *
45 * @param name
46 * the name of this diagnostic.
47 */
48 public DiagnosticUnit(String name) {
49 this.name = name;
50 this.delegatingDiagnosticUnit = new DelegatingDiagnosticUnit(
51 this);
52 }
53
54 /***
55 * Creates a new DiagnosticUnit. It's name defaults to the FQ class name.
56 */
57 public DiagnosticUnit() {
58 this.delegatingDiagnosticUnit = new DelegatingDiagnosticUnit(
59 this);
60 }
61
62 /***
63 * Set Up method. Called before every "diagnose" method.
64 */
65 public void setUp() throws Exception {
66 }
67
68 /***
69 * Tear Down method. Called after every "diagnose" method.
70 */
71 public void tearDown() throws Exception {
72
73 }
74
75 /***
76 * Returns the name of this diagnostic. Defaults to the FQ Class name.
77 */
78 public String getName() {
79 return name == null ? delegatingDiagnosticUnit.getName() : name;
80 }
81
82 /***
83 * Get the children Diagnostics of this diagnostic. Should be
84 * Diagnostics that run the "diagnose" methods on subclasses
85 * of this class.
86 */
87 public List getDiagnostics() {
88 return delegatingDiagnosticUnit.getDiagnostics();
89 }
90
91 /***
92 * Assert that a test is true
93 * @param msg a message if the assertion if false
94 * @param test the test to test
95 */
96 public void assertTrue(String msg, boolean test) {
97 Assert.assertTrue(msg, test);
98 }
99
100 /***
101 * Assert that a test is true
102 * @param test the test to test
103 */
104 public void assertTrue(boolean test) {
105 Assert.assertTrue(test);
106 }
107
108 /***
109 * Assert that two objects are equal
110 * @param msg a message if the assertion if false
111 * @param toTestAgainst the object to test against
112 * @param test the test object
113 */
114 public void assertEquals(String msg, Object toTestAgainst, Object test) {
115 Assert.assertEquals(msg, toTestAgainst, test);
116 }
117
118 /***
119 * Assert that two objects are equal
120 * @param toTestAgainst the object to test against
121 * @param test the test object
122 */
123 public void assertEquals(Object toTestAgainst, Object test) {
124 Assert.assertEquals(toTestAgainst, test);
125 }
126
127 /***
128 * Assert that an object is null
129 * @param msg a message if the assertion if false
130 * @param test the test object
131 */
132 public void assertNull(String msg, Object test) {
133 Assert.assertNull(msg, test);
134 }
135
136 /***
137 * Assert that an object is null
138 * @param test the test object
139 */
140 public void assertNull(Object test) {
141 Assert.assertNull(test);
142 }
143
144 /***
145 * Assert that an object is not null
146 * @param msg a message if the assertion if false
147 * @param test the test object
148 */
149 public void assertNotNull(String msg, Object test) {
150 Assert.assertNotNull(msg, test);
151 }
152
153 /***
154 * Assert that an object is not null
155 * @param test the test object
156 */
157 public void assertNotNull(Object test) {
158 Assert.assertNotNull(test);
159 }
160
161 /***
162 * @see org.jdiagnose.DiagnosticContainer#getDiagnosticContainers()
163 */
164 public List getDiagnosticContainers() {
165 return Collections.EMPTY_LIST;
166 }
167
168 /***
169 * @see org.jdiagnose.Diagnostic#diagnose()
170 */
171 public void diagnose() throws DiagnosticException {
172 delegatingDiagnosticUnit.diagnose();
173 }
174
175 }