Update of /cvsroot/csseditor/net.sourceforge.csseditor.tests/src/net/sourceforge/csseditor/tests/internal/text
In directory sc8-pr-cvs1:/tmp/cvs-serv30092/src/net/sourceforge/csseditor/tests/internal/text
Added Files:
CssContentAssistProcessorTest.java
Log Message:
Fix für bug #875410, and a test case (albeit a rather bad one)
--- NEW FILE: CssContentAssistProcessorTest.java ---
/*
* Copyright (c) 2003 Christopher Lenz and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* Christopher Lenz - initial API and implementation
*
* $Id: CssContentAssistProcessorTest.java,v 1.1 2004/01/12 17:37:09 cell Exp $
*/
package net.sourceforge.csseditor.tests.internal.text;
import java.util.Arrays;
import net.sourceforge.csseditor.IProfile;
import net.sourceforge.csseditor.internal.model.PropertyInfo;
import net.sourceforge.csseditor.internal.text.CssContentAssistProcessor;
import net.sourceforge.csseditor.tests.TextEditorTestCase;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
import org.eclipse.ui.texteditor.ITextEditor;
import com.mockobjects.dynamic.C;
import com.mockobjects.dynamic.Mock;
/**
* Tests for the <code>CssContentAssistProcessor</code> class, which implements
* the computation of content assist proposals.
*/
public class CssContentAssistProcessorTest extends TextEditorTestCase {
// Instance Variables ------------------------------------------------------
/**
* A mock {@link IProfile}.
*/
private Mock mockProfile;
/**
* A mock {@link ITextViewer}.
*/
private Mock mockTextViewer;
// Constructors ------------------------------------------------------------
/**
* Default contructor.
*/
public CssContentAssistProcessorTest() {
super("test.css");
}
// TestCase Implementation -------------------------------------------------
/*
* @see junit.framework.TestCase#setUp()
*/
protected void setUp() throws CoreException {
super.setUp();
mockProfile = new Mock(IProfile.class);
mockTextViewer = new Mock(ITextViewer.class);
}
/*
* @see junit.framework.TestCase#tearDown()
*/
protected void tearDown() throws CoreException {
super.tearDown();
mockProfile.verify();
mockTextViewer.verify();
}
// Test Methods ------------------------------------------------------------
/**
* Verifies that the content assist processor proposes the complete property
* when triggered over a property where the last latter is missing, and when
* there is only one matching property in the profile.
*/
public void testProposeSingleProperty() throws CoreException {
ITextEditor editor = setUpEditor("sel { pro: val }");
mockTextViewer.matchAndReturn("getDocument", getDocument());
mockProfile.expectAndReturn("getProperties", Arrays.asList(
new Object[] { "prop" }));
mockProfile.expectAndReturn("getPropertyInfo", C.args(C.eq("prop")),
new PropertyInfo("prop", ""));
// TODO: This shouldn't be necessary, the content assist processor
// should actually block until the model is synced with the source (aka
// reconciled), but currently it'll return an empty list of proposals
// (at best)
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
IContentAssistProcessor processor = new CssContentAssistProcessor(
null, (IProfile) mockProfile.proxy(), editor);
ICompletionProposal[] proposals = processor.computeCompletionProposals(
(ITextViewer) mockTextViewer.proxy(), 9);
assertNotNull(proposals);
assertEquals(1, proposals.length);
assertEquals("prop", proposals[0].getDisplayString());
}
}
|