Bug 94287 [JUnit] Some issues with "Add JUnit Libraries"
Version: 3.1.0 Build id: I20050509-2010 Steps to reproduce: 1.) Create a new Class Test 2.) Open Quick Fix on the class Name: Only Rename in File is shown 3.) add "implements MouseListener" to the class 4.) Open Quick Fix on the class Name: Now you got "Add JUnit Libraries" as an entry of the Quick Fix list Actual Results: "Add JUnit Libraries" is not listed on the Quick Fix List at first. Expected Results: "Add JUnit Libraries" is listed on the Quick Fix List at first. Another issue I noticed is that once you have selected "Add JUnit Libraries" the editor gets dirty although nothing has changed. This is ok to support an "Undo" Operation. But performing "Undo" after "Add JUnit Libraries" does not remove junit from the build path. Regards, Ben
org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/JUnitQuickFixProcessor.java
public boolean hasCorrections(ICompilationUnit unit, int problemId) {
		return IProblem.SuperclassNotFound == problemId || IProblem.ImportNotFound == problemId;
	}
	/* (non-Javadoc)
	 * @see org.eclipse.jdt.ui.text.java.IQuickFixProcessor#getCorrections(org.eclipse.jdt.ui.text.java.IInvocationContext, org.eclipse.jdt.ui.text.java.IProblemLocation[])
	 */
	public IJavaCompletionProposal[] getCorrections(final IInvocationContext context, IProblemLocation[] locations)  {
		if (isJUnitProblem(context, locations))
			return new IJavaCompletionProposal[] { new JUnitAddLibraryProposal(context) };
		return new IJavaCompletionProposal[] {};
	}
	private boolean isJUnitProblem(IInvocationContext context, IProblemLocation[] locations) {
		ICompilationUnit unit= context.getCompilationUnit();
		for (int i= 0; i < locations.length; i++) {
			IProblemLocation location= locations[i];
			try {
				String s= unit.getBuffer().getText(location.getOffset(), location.getLength());
				if (s.equals("TestCase") 
						|| s.equals("junit") 
						|| s.equals("TestSuite") 
						|| s.equals("Test")) 
					return true; 
			} catch (JavaModelException e) {
			    JUnitPlugin.log(e.getStatus());
			}
		}
		return false;
	}
}