public void testProposal() {
long start = System.nanoTime();
QWickieProposalComputer proposal = new QWickieProposalComputer();
proposal.sessionStarted();
ContentAssistInvocationContext context = new ContentAssistInvocationContext(javaDocument, 0);
IProgressMonitor monitor = new NullProgressMonitor();
assertEquals(proposal.computeCompletionProposals(context, monitor).size(), 0);
final ICompilationUnit cu = JavaCore.createCompilationUnitFrom(javaFile);
ITextViewer viewer = new TextViewer(new Shell(), 0);
int offset = 420;
context = new JavaContentAssistInvocationContext(viewer, offset, new CompilationUnitEditor()) {
@SuppressWarnings("restriction")
@Override
public IType getExpectedType() {
JavaElement je = null;
return new ResolvedBinaryType(je, "String", "java.lang.String");
}
@Override
public IDocument getDocument() {
String content = javaDocument.get();
javaDocument.set(content.replace("message", "messag"));
return javaDocument;
}
@Override
public ICompilationUnit getCompilationUnit() {
return cu;
}
};
List<ICompletionProposal> proposals = proposal.computeCompletionProposals(context, monitor);
assertEquals(2, proposals.size());
assertEquals("<div wicket:id=\"<b>message</b>\"></div>", proposals.get(0).getAdditionalProposalInfo());
assertEquals("message", proposals.get(0).getDisplayString());
assertEquals(415, proposals.get(0).getSelection(javaDocument).x);
assertEquals("<div wicket:id=\"<b>message2</b>\"></div>", proposals.get(1).getAdditionalProposalInfo());
assertEquals("message2", proposals.get(1).getDisplayString());
assertEquals(415, proposals.get(1).getSelection(javaDocument).x);
offset = 421;
context = new ContentAssistInvocationContext(viewer, offset) {
@Override
public IDocument getDocument() {
return javaDocument;
}
};