| 1 | /* |
| 2 | * JTiger Unit Testing Framework for J2SE 1.5 |
| 3 | * Copyright (C) 2005 Tony Morris |
| 4 | * |
| 5 | * This software is licenced under the |
| 6 | * Common Public Licence version 1.0 |
| 7 | * http://www.opensource.org/licenses/cpl1.0.php |
| 8 | * |
| 9 | * You received a copy of this licence with this software. |
| 10 | */ |
| 11 | package org.jtiger.report.xml; |
| 12 | |
| 13 | import java.util.Arrays; |
| 14 | import org.jtiger.framework.ReadOnlyArray; |
| 15 | import org.jtiger.framework.TestResult; |
| 16 | |
| 17 | /** |
| 18 | * A bean that is used by {@link XmlFixtureResultsHandler the XML result handler} to produce a report. |
| 19 | * |
| 20 | * @author %javadoc.author.tag% |
| 21 | * @version %version%<br/> |
| 22 | * <i>Build Number %build.number%</i><br/> |
| 23 | * <i>Build Time %build.time% CET (GMT + 1)</i> |
| 24 | */ |
| 25 | public final class TestResultBeanImpl |
| 26 | implements TestResultBean |
| 27 | { |
| 28 | private static final long serialVersionUID = 2L; |
| 29 | |
| 30 | private String testResult; |
| 31 | private String message; |
| 32 | private Throwable exception; |
| 33 | private Long elapsedTime; |
| 34 | private String[] categories; |
| 35 | private String testName; |
| 36 | private String testDescription; |
| 37 | private String testMethodName; |
| 38 | private String fixtureName; |
| 39 | private String fixtureDescription; |
| 40 | private Class<?> fixtureClass; |
| 41 | |
| 42 | /** |
| 43 | * Create a default <tt>TestResultBeanImpl</tt>. |
| 44 | */ |
| 45 | public TestResultBeanImpl() |
| 46 | { |
| 47 | |
| 48 | } |
| 49 | |
| 50 | TestResultBeanImpl(final TestResult tr) |
| 51 | { |
| 52 | setTestResult(tr.getTestResultType().toString()); |
| 53 | setMessage(tr.getMessage()); |
| 54 | setException(tr.getException()); |
| 55 | setElapsedTime(tr.getElapsedTime()); |
| 56 | |
| 57 | final ReadOnlyArray<String> categories = tr.getCategories(); |
| 58 | final String[] aCategories = new String[categories.length()]; |
| 59 | for(int i = 0; i < aCategories.length; i++) |
| 60 | { |
| 61 | aCategories[i] = categories.get(i); |
| 62 | } |
| 63 | setCategories(aCategories); |
| 64 | |
| 65 | setTestName(tr.getTestName()); |
| 66 | setTestDescription(tr.getTestDescription()); |
| 67 | setTestMethodName(tr.getTestMethodName()); |
| 68 | setFixtureName(tr.getFixtureName()); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Returns the testResult property of the bean. |
| 73 | * |
| 74 | * @return The testResult property of the bean. |
| 75 | */ |
| 76 | public String getTestResult() |
| 77 | { |
| 78 | return testResult; |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Sets the testResult property of the bean. |
| 83 | * |
| 84 | * @param testResult The testResult property of the bean. |
| 85 | */ |
| 86 | public void setTestResult(final String testResult) |
| 87 | { |
| 88 | this.testResult = testResult; |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Returns the message property of the bean. |
| 93 | * |
| 94 | * @return The message property of the bean. |
| 95 | */ |
| 96 | public String getMessage() |
| 97 | { |
| 98 | return message; |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Sets the message property of the bean. |
| 103 | * |
| 104 | * @param message The message property of the bean. |
| 105 | */ |
| 106 | public void setMessage(final String message) |
| 107 | { |
| 108 | this.message = message; |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Returns the exception property of the bean. |
| 113 | * |
| 114 | * @return The exception property of the bean. |
| 115 | */ |
| 116 | public Throwable getException() |
| 117 | { |
| 118 | return exception; |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * Sets the exception property of the bean. |
| 123 | * |
| 124 | * @param exception The exception property of the bean. |
| 125 | */ |
| 126 | public void setException(final Throwable exception) |
| 127 | { |
| 128 | this.exception = exception; |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * Returns the elapsedTime property of the bean. |
| 133 | * |
| 134 | * @return The elapsedTime property of the bean. |
| 135 | */ |
| 136 | public Long getElapsedTime() |
| 137 | { |
| 138 | return elapsedTime; |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Sets the elapsedTime property of the bean. |
| 143 | * |
| 144 | * @param elapsedTime The elapsedTime property of the bean. |
| 145 | */ |
| 146 | public void setElapsedTime(final Long elapsedTime) |
| 147 | { |
| 148 | this.elapsedTime = elapsedTime; |
| 149 | } |
| 150 | |
| 151 | /** |
| 152 | * Returns the categories property of the bean. |
| 153 | * |
| 154 | * @return The categories property of the bean. |
| 155 | */ |
| 156 | public String[] getCategories() |
| 157 | { |
| 158 | return categories; |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * Sets the categories property of the bean. |
| 163 | * |
| 164 | * @param categories The categories property of the bean. |
| 165 | */ |
| 166 | public void setCategories(final String[] categories) |
| 167 | { |
| 168 | this.categories = categories; |
| 169 | } |
| 170 | |
| 171 | /** |
| 172 | * Returns the testName property of the bean. |
| 173 | * |
| 174 | * @return The testName property of the bean. |
| 175 | */ |
| 176 | public String getTestName() |
| 177 | { |
| 178 | return testName; |
| 179 | } |
| 180 | |
| 181 | /** |
| 182 | * Sets the testName property of the bean. |
| 183 | * |
| 184 | * @param testName The testName property of the bean. |
| 185 | */ |
| 186 | public void setTestName(final String testName) |
| 187 | { |
| 188 | this.testName = testName; |
| 189 | } |
| 190 | |
| 191 | /** |
| 192 | * Returns the testDescription property of the bean. |
| 193 | * |
| 194 | * @return The testDescription property of the bean. |
| 195 | */ |
| 196 | public String getTestDescription() |
| 197 | { |
| 198 | return testDescription; |
| 199 | } |
| 200 | |
| 201 | /** |
| 202 | * Sets the testDescription property of the bean. |
| 203 | * |
| 204 | * @param testDescription The testDescription property of the bean. |
| 205 | */ |
| 206 | public void setTestDescription(final String testDescription) |
| 207 | { |
| 208 | this.testDescription = testDescription; |
| 209 | } |
| 210 | |
| 211 | /** |
| 212 | * Returns the testMethodName property of the bean. |
| 213 | * |
| 214 | * @return The testMethodName property of the bean. |
| 215 | */ |
| 216 | public String getTestMethodName() |
| 217 | { |
| 218 | return testMethodName; |
| 219 | } |
| 220 | |
| 221 | /** |
| 222 | * Sets the testMethodName property of the bean. |
| 223 | * |
| 224 | * @param testMethodName The testMethodName property of the bean. |
| 225 | */ |
| 226 | public void setTestMethodName(final String testMethodName) |
| 227 | { |
| 228 | this.testMethodName = testMethodName; |
| 229 | } |
| 230 | |
| 231 | /** |
| 232 | * Returns the fixtureName property of the bean. |
| 233 | * |
| 234 | * @return The fixtureName property of the bean. |
| 235 | */ |
| 236 | public String getFixtureName() |
| 237 | { |
| 238 | return fixtureName; |
| 239 | } |
| 240 | |
| 241 | /** |
| 242 | * Sets the fixtureName property of the bean. |
| 243 | * |
| 244 | * @param fixtureName The fixtureName property of the bean. |
| 245 | */ |
| 246 | public void setFixtureName(final String fixtureName) |
| 247 | { |
| 248 | this.fixtureName = fixtureName; |
| 249 | } |
| 250 | |
| 251 | /** |
| 252 | * Returns the fixtureDescription property of the bean. |
| 253 | * |
| 254 | * @return The fixtureDescription property of the bean. |
| 255 | */ |
| 256 | public String getFixtureDescription() |
| 257 | { |
| 258 | return fixtureDescription; |
| 259 | } |
| 260 | |
| 261 | /** |
| 262 | * Sets the fixtureDescription property of the bean. |
| 263 | * |
| 264 | * @param fixtureDescription The fixtureDescription property of the bean. |
| 265 | */ |
| 266 | public void setFixtureDescription(final String fixtureDescription) |
| 267 | { |
| 268 | this.fixtureDescription = fixtureDescription; |
| 269 | } |
| 270 | |
| 271 | /** |
| 272 | * Returns the fixtureClass property of the bean. |
| 273 | * |
| 274 | * @return The fixtureClass property of the bean. |
| 275 | */ |
| 276 | public Class<?> getFixtureClass() |
| 277 | { |
| 278 | return fixtureClass; |
| 279 | } |
| 280 | |
| 281 | /** |
| 282 | * Sets the fixtureClass property of the bean. |
| 283 | * |
| 284 | * @param fixtureClass The fixtureClass property of the bean. |
| 285 | */ |
| 286 | public void setFixtureClass(final Class<?> fixtureClass) |
| 287 | { |
| 288 | this.fixtureClass = fixtureClass; |
| 289 | } |
| 290 | |
| 291 | /** |
| 292 | * Returns a <a href="%j2se.api.spec%/java/lang/String.html">java.lang.String</a> representation of the bean, which |
| 293 | * consists of the testResult property, the message property, the exception property, the elapsedTime property, the |
| 294 | * categories property, the testName property, the testDescription property, the testMethodName property, the |
| 295 | * testMethodParameterTypes property, the fixtureName property, the fixtureDescription property, and the |
| 296 | * fixtureClass property. |
| 297 | * |
| 298 | * @return A <a href="%j2se.api.spec%/java/lang/String.html">java.lang.String</a> representation of the bean, which |
| 299 | * consists of the testResult property, the message property, the exception property, the elapsedTime property, the |
| 300 | * categories property, the testName property, the testDescription property, the testMethodName property, the |
| 301 | * testMethodParameterTypes property, the fixtureName property, the fixtureDescription property, and the |
| 302 | * fixtureClass property. |
| 303 | */ |
| 304 | @Override |
| 305 | public String toString() |
| 306 | { |
| 307 | final StringBuilder sb = new StringBuilder(); |
| 308 | |
| 309 | sb.append('['); |
| 310 | sb.append(testResult); |
| 311 | sb.append("]["); |
| 312 | sb.append(message); |
| 313 | sb.append("]["); |
| 314 | sb.append(exception); |
| 315 | sb.append("]["); |
| 316 | sb.append(elapsedTime); |
| 317 | sb.append("]["); |
| 318 | sb.append(Arrays.toString(categories)); |
| 319 | sb.append("]["); |
| 320 | sb.append(testName); |
| 321 | sb.append("]["); |
| 322 | sb.append(testDescription); |
| 323 | sb.append("]["); |
| 324 | sb.append(testMethodName); |
| 325 | sb.append("]["); |
| 326 | sb.append(fixtureName); |
| 327 | sb.append("]["); |
| 328 | sb.append(fixtureDescription); |
| 329 | sb.append("]["); |
| 330 | sb.append(fixtureClass); |
| 331 | sb.append(']'); |
| 332 | |
| 333 | return sb.toString(); |
| 334 | } |
| 335 | |
| 336 | /** |
| 337 | * Compares two instance of <tt>TestResultBeanImpl</tt> returning <code>true</code> iff the testResult, message, |
| 338 | * exception, elapsedTime, categories, testName, testDescription, testMethodName, testMethodParameterTypes, |
| 339 | * fixtureName, fixtureDescription, and fixtureClass properties are equal, <code>false</code> otherwise. |
| 340 | * |
| 341 | * @param o An instance of <tt>TestResultBeanImpl</tt> to compare for equality. |
| 342 | * @return <code>true</code> iff the testResult, message, exception, elapsedTime, categories, testName, |
| 343 | * testDescription, testMethodName, testMethodParameterTypes, fixtureName, fixtureDescription, and fixtureClass |
| 344 | * properties are equal, <code>false</code> otherwise. |
| 345 | */ |
| 346 | @Override |
| 347 | public boolean equals(final Object o) |
| 348 | { |
| 349 | if(this == o) |
| 350 | { |
| 351 | return true; |
| 352 | } |
| 353 | |
| 354 | if(o == null || o.getClass() != TestResultBeanImpl.class) |
| 355 | { |
| 356 | return false; |
| 357 | } |
| 358 | |
| 359 | final TestResultBeanImpl r = (TestResultBeanImpl)o; |
| 360 | |
| 361 | return (testResult == null ? r.testResult == null : testResult.equals(r.testResult)) && |
| 362 | (message == null ? r.message == null : message.equals(r.message)) && |
| 363 | (exception == null ? r.exception == null : exception.equals(r.exception)) && |
| 364 | (elapsedTime == null ? r.elapsedTime == null : elapsedTime.equals(r.elapsedTime)) && |
| 365 | (categories == null ? r.categories == null : Arrays.equals(categories, r.categories)) && |
| 366 | (testName == null ? r.testName == null : testName.equals(r.testName)) && |
| 367 | (testDescription == null ? r.testDescription == null : testDescription.equals(r.testDescription)) && |
| 368 | (testMethodName == null ? r.testMethodName == null : testMethodName.equals(r.testMethodName)) && |
| 369 | (fixtureName == null ? r.fixtureName == null : fixtureName.equals(r.fixtureName)) && |
| 370 | (fixtureDescription == null ? r.fixtureDescription == null : fixtureDescription.equals(r.fixtureDescription)) && |
| 371 | (fixtureClass == r.fixtureClass); |
| 372 | } |
| 373 | |
| 374 | /** |
| 375 | * Returns a hash code for this <tt>TestResultBeanImpl</tt> based on the testResult, message, exception, elapsedTime, |
| 376 | * categories, testName, testDescription, testMethodName, testMethodParameterTypes, fixtureName, fixtureDescription, |
| 377 | * and fixtureClass properties. |
| 378 | * |
| 379 | * @return A hash code for this <tt>TestResultBeanImpl</tt> based on the testResult, message, exception, elapsedTime, |
| 380 | * categories, testName, testDescription, testMethodName, testMethodParameterTypes, fixtureName, fixtureDescription, |
| 381 | * and fixtureClass properties. |
| 382 | */ |
| 383 | @Override |
| 384 | public int hashCode() |
| 385 | { |
| 386 | final int oddPrime = 461; |
| 387 | int result = 73; |
| 388 | |
| 389 | if(testResult != null) |
| 390 | { |
| 391 | result = result * oddPrime + testResult.hashCode(); |
| 392 | } |
| 393 | |
| 394 | if(message != null) |
| 395 | { |
| 396 | result = result * oddPrime + message.hashCode(); |
| 397 | } |
| 398 | |
| 399 | if(exception != null) |
| 400 | { |
| 401 | result = result * oddPrime + exception.hashCode(); |
| 402 | } |
| 403 | |
| 404 | if(elapsedTime != null) |
| 405 | { |
| 406 | result = result * oddPrime + elapsedTime.hashCode(); |
| 407 | } |
| 408 | |
| 409 | if(categories != null) |
| 410 | { |
| 411 | result = result * oddPrime + Arrays.hashCode(categories); |
| 412 | } |
| 413 | |
| 414 | if(testName != null) |
| 415 | { |
| 416 | result = result * oddPrime + testName.hashCode(); |
| 417 | } |
| 418 | |
| 419 | if(testDescription != null) |
| 420 | { |
| 421 | result = result * oddPrime + testDescription.hashCode(); |
| 422 | } |
| 423 | |
| 424 | if(testMethodName != null) |
| 425 | { |
| 426 | result = result * oddPrime + testMethodName.hashCode(); |
| 427 | } |
| 428 | |
| 429 | if(fixtureName != null) |
| 430 | { |
| 431 | result = result * oddPrime + fixtureName.hashCode(); |
| 432 | } |
| 433 | |
| 434 | if(fixtureDescription != null) |
| 435 | { |
| 436 | result = result * oddPrime + fixtureDescription.hashCode(); |
| 437 | } |
| 438 | |
| 439 | if(fixtureClass != null) |
| 440 | { |
| 441 | result = result * oddPrime + fixtureClass.hashCode(); |
| 442 | } |
| 443 | |
| 444 | return result; |
| 445 | } |
| 446 | } |