KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > junit4 > runner > JUnit4TestClassReference


1 /*******************************************************************************
2  * Copyright (c) 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * David Saff (saff@mit.edu) - initial API and implementation
10  * (bug 102632: [JUnit] Support for JUnit 4.)
11  *******************************************************************************/

12
13 package org.eclipse.jdt.internal.junit4.runner;
14
15 import org.eclipse.jdt.internal.junit.runner.ITestIdentifier;
16 import org.eclipse.jdt.internal.junit.runner.IVisitsTestTrees;
17 import org.junit.runner.Description;
18 import org.junit.runner.Request;
19
20 public class JUnit4TestClassReference extends JUnit4TestReference {
21     protected final Class JavaDoc<?> fClass;
22
23     public JUnit4TestClassReference(Class JavaDoc<?> clazz) {
24         super(Request.aClass(clazz));
25         fClass= clazz;
26     }
27
28     public int countTestCases() {
29         return fRunner.testCount();
30     }
31
32     public String JavaDoc getName() {
33         return fClass.getName();
34     }
35
36     public void sendTree(final IVisitsTestTrees notified) {
37         sendDescriptionTree(notified, fRunner.getDescription());
38     }
39
40     private void sendDescriptionTree(final IVisitsTestTrees notified, org.junit.runner.Description description) {
41         if (description.isTest()) {
42             notified.visitTreeEntry(new JUnit4Identifier(description), false, 1);
43         } else {
44             notified.visitTreeEntry(new JUnit4Identifier(description), true, description.getChildren().size());
45             for (Description child : description.getChildren()) {
46                 sendDescriptionTree(notified, child);
47             }
48         }
49     }
50
51     @Override JavaDoc
52     public boolean equals(Object JavaDoc obj) {
53         if (! (obj instanceof JUnit4TestReference))
54             return false;
55         
56         JUnit4TestReference ref= (JUnit4TestReference) obj;
57         return (ref.getIdentifier().equals(getIdentifier()));
58     }
59
60     @Override JavaDoc
61     public int hashCode() {
62         return fClass.hashCode();
63     }
64
65     public ITestIdentifier getIdentifier() {
66         return new JUnit4Identifier(fRunner.getDescription());
67     }
68 }
69
Popular Tags