KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > junit > launcher > TestKind


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  * IBM Corporation - initial API and implementation
10  * David Saff (saff@mit.edu) - initial API and implementation
11  * (bug 102632: [JUnit] Support for JUnit 4.)
12  *******************************************************************************/

13
14 package org.eclipse.jdt.internal.junit.launcher;
15
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.core.runtime.IConfigurationElement;
18
19 import org.eclipse.jdt.internal.junit.ui.JUnitPlugin;
20
21
22 public class TestKind implements ITestKind {
23
24     private final IConfigurationElement fElement;
25     private ITestFinder fFinder;
26
27     public TestKind(IConfigurationElement element) {
28         fElement = element;
29         fFinder= null;
30     }
31
32     /*
33      * @see org.eclipse.jdt.internal.junit.launcher.ITestKind#createFinder()
34      */

35     public ITestFinder getFinder() {
36         if (fFinder == null) {
37             try {
38                 fFinder= (ITestFinder) fElement.createExecutableExtension(FINDER_CLASS_NAME);
39             } catch (CoreException e1) {
40                 JUnitPlugin.log(e1);
41                 fFinder= ITestFinder.NULL;
42             }
43         }
44         return fFinder;
45     }
46
47     /*
48      * @see org.eclipse.jdt.internal.junit.launcher.ITestKind#getDisplayName()
49      */

50     public String JavaDoc getDisplayName() {
51         return getAttribute(DISPLAY_NAME);
52     }
53
54     /*
55      * @see org.eclipse.jdt.internal.junit.launcher.ITestKind#getFinderClassName()
56      */

57     public String JavaDoc getFinderClassName() {
58         return getAttribute(FINDER_CLASS_NAME);
59     }
60
61     /*
62      * @see org.eclipse.jdt.internal.junit.launcher.ITestKind#getId()
63      */

64     public String JavaDoc getId() {
65         return getAttribute(ID);
66     }
67
68     /*
69      * @see org.eclipse.jdt.internal.junit.launcher.ITestKind#getLoaderClassName()
70      */

71     public String JavaDoc getLoaderClassName() {
72         return getAttribute(LOADER_CLASS_NAME);
73     }
74
75     public String JavaDoc getLoaderPluginId() {
76         return getAttribute(LOADER_PLUGIN_ID);
77     }
78
79     /*
80      * @see org.eclipse.jdt.internal.junit.launcher.ITestKind#getPrecededKindId()
81      */

82     public String JavaDoc getPrecededKindId() {
83         String JavaDoc attribute= getAttribute(PRECEDES);
84         return attribute == null ? "" : attribute; //$NON-NLS-1$
85
}
86
87     /*
88      * @see org.eclipse.jdt.internal.junit.launcher.ITestKind#isNull()
89      */

90     public boolean isNull() {
91         return false;
92     }
93
94     protected String JavaDoc getAttribute(String JavaDoc attributeName) {
95         return fElement.getAttribute(attributeName);
96     }
97
98     boolean precedes(ITestKind otherKind) {
99         final String JavaDoc precededKindId = getPrecededKindId();
100         String JavaDoc[] ids = precededKindId.split(","); //$NON-NLS-1$
101
for (int i = 0; i < ids.length; i++) {
102             if (ids[i].equals(otherKind.getId()))
103                 return true;
104         }
105         return false;
106     }
107
108     /*
109      * @see org.eclipse.jdt.internal.junit.launcher.ITestKind#getClasspathEntries()
110      */

111     public JUnitRuntimeClasspathEntry[] getClasspathEntries() {
112         IConfigurationElement[] children= fElement.getChildren(ITestKind.RUNTIME_CLASSPATH_ENTRY);
113         JUnitRuntimeClasspathEntry[] returnThis= new JUnitRuntimeClasspathEntry[children.length];
114         for (int i= 0; i < children.length; i++) {
115             IConfigurationElement element= children[i];
116             String JavaDoc pluginID= element.getAttribute(ITestKind.CLASSPATH_PLUGIN_ID);
117             String JavaDoc pathToJar= element.getAttribute(ITestKind.CLASSPATH_PATH_TO_JAR);
118             returnThis[i]= new JUnitRuntimeClasspathEntry(pluginID, pathToJar);
119         }
120         return returnThis;
121     }
122     
123     /*
124      * @see java.lang.Object#toString()
125      */

126     public String JavaDoc toString() {
127         return getDisplayName() + " (id: " + getId() + ")"; //$NON-NLS-1$ //$NON-NLS-2$
128
}
129 }
130
Popular Tags