Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 146098 Details for
Bug 286343
[JUnit] JUnit3TestFinder does doesn't quite behave correctly
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
Test case that describes the conditions of this bug
JUnit3TestFinderTest.java (text/plain), 5.25 KB, created by
Robert Konigsberg
on 2009-08-31 14:53:01 EDT
(
hide
)
Description:
Test case that describes the conditions of this bug
Filename:
MIME Type:
Creator:
Robert Konigsberg
Created:
2009-08-31 14:53:01 EDT
Size:
5.25 KB
patch
obsolete
>package org.brainkandy.testfindertest; > >import java.io.ByteArrayInputStream; >import java.util.ArrayList; >import java.util.Collections; >import java.util.HashSet; >import java.util.Iterator; >import java.util.List; >import java.util.Set; > >import org.eclipse.core.resources.IContainer; >import org.eclipse.core.resources.IFile; >import org.eclipse.core.resources.IFolder; >import org.eclipse.core.resources.IProject; >import org.eclipse.core.resources.IProjectDescription; >import org.eclipse.core.resources.IResource; >import org.eclipse.core.resources.ResourcesPlugin; >import org.eclipse.core.runtime.CoreException; >import org.eclipse.core.runtime.NullProgressMonitor; >import org.eclipse.jdt.core.IJavaProject; >import org.eclipse.jdt.core.IType; >import org.eclipse.jdt.core.JavaCore; >import org.eclipse.jdt.internal.junit.launcher.JUnit3TestFinder; > >import junit.framework.TestCase; > >public class JUnit3TestFinderTest extends TestCase { > private IProject project; > > public void testSanity() throws CoreException { > project = createProject(); > setText(".classpath", > new String[] { > "<?xml version=\"1.0\" encoding=\"UTF-8\"?>", > "<classpath>", > "<classpathentry kind=\"src\" path=\"\"/>", > "<classpathentry kind=\"con\" path=\"org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5\"/>", > "<classpathentry kind=\"con\" path=\"org.eclipse.jdt.junit.JUNIT_CONTAINER/3\"/>", > "<classpathentry kind=\"output\" path=\"\"/>", > "</classpath>" > }); > > // Standard case -- Should work, and does. > setText("src/com/example/Foo.java", > new String[] { > "package com.example;", > "import junit.framework.Test;", > "class Foo {", > " public static Test suite() { return null; }", > "}" > }); > > // Test suite case -- the one I really want to work. > // Should return, but does not. > setText("src/com/example/Bar.java", > new String[] { > "package com.example;", > "import junit.framework.TestSuite;", > "class Bar {", > " public static TestSuite suite() { return null; }", > "}" > }); > > // Case where "test" is a false positive. > // Should not return, but does. > setText("src/com/example/Baz.java", > new String[] { > "package com.example;", > "import com.example.framework.Test;", > "class Baz {", > " public static Test suite() { return null; }", > "}" > }); > > // Support class for code above. > setText("src/com/example/framework/Test.java", > new String[] { > "package com.example.framework;", > "class Test { }" > }); > > // Case where Test is explicitly imported in code. > // Should work. but does. > setText("src/com/example/Quux.java", > new String[] { > "package com.example;", > "class Quux {", > " public static junit.framework.Test suite() { return null; }", > "}" > }); > > // Plain old class, has a void suite method > setText("src/com/example/Corge.java", > new String[] { > "package com.example;", > "class Corge {", > " public static void suite() { return null; }", > "}" > }); > > project.refreshLocal(IResource.DEPTH_INFINITE, null); > IJavaProject jp = JavaCore.create(project); > JUnit3TestFinder finder = new JUnit3TestFinder(); > Set set = new HashSet(); > finder.findTestsInContainer(jp, set, new NullProgressMonitor()); > List<String> list = new ArrayList<String>(); > for (Iterator iter = set.iterator(); iter.hasNext();) { > list.add(((IType) iter.next()).getElementName()); > } > Collections.sort(list); > String actual = list.toString(); > > // This is the test that should fail, but passes, because > // Baz isn't a real test suite. > assertEquals("This is the test that should fail", > "[Baz, Foo, Quux]", actual); > > // This is the test that should pass, but doesn't, because > // the test suite finder doesn't look at the type heirarchy. > assertEquals("This is the test that should pass", > "[Bar, Foo, Quux]", actual); > } > > private IProject createProject() throws CoreException { > IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("adsf"); > project.create(null); > project.open(null); > IProjectDescription description = project.getDescription(); > String[] natureIds = description.getNatureIds(); > description.setNatureIds(new String[] { JavaCore.NATURE_ID }); > project.setDescription(description, null); > return project; > } > > private void setText(String path, String[] lines) throws CoreException { > StringBuilder sb = new StringBuilder(); > for (int i = 0; i < lines.length; i++) { > sb.append(lines[i]); > sb.append("\n"); > } > String text = sb.toString(); > IFile file = project.getFile(path); > mkdirs(file.getParent()); > > if (file.exists()) { > file.setContents(new ByteArrayInputStream(text.getBytes()), 0, null); > } else { > file.create(new ByteArrayInputStream(text.getBytes()), 0, null); > } > } > > private void mkdirs(IContainer container) throws CoreException { > if (container instanceof IFolder) { > IFolder folder = (IFolder) container; > if (!folder.exists()) { > mkdirs(folder.getParent()); > folder.create(false, true, null); > } > } > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 286343
: 146098