1 19 package org.netbeans.modules.xml.schema.completion; 20 21 import java.util.List ; 22 import junit.framework.*; 23 import javax.swing.text.Document ; 24 import org.openide.filesystems.FileObject; 25 26 30 public abstract class AbstractTestCase extends TestCase { 31 32 protected String instanceResourcePath; 33 protected FileObject instanceFileObject; 34 protected Document instanceDocument; 35 36 public AbstractTestCase(String testName) { 37 super(testName); 38 } 39 40 protected void setUp() throws Exception { 41 } 42 43 protected void tearDown() throws Exception { 44 } 45 46 protected void setupCompletion(String path, StringBuffer buffer) throws Exception { 47 this.instanceResourcePath = path; 48 this.instanceFileObject = Util.getResourceAsFileObject(path); 49 this.instanceDocument = Util.getResourceAsDocument(path); 50 instanceDocument.remove(0, instanceDocument.getLength()); 51 instanceDocument.insertString(0, buffer.toString(), null); 52 } 53 54 58 protected List <CompletionResultItem> query(int caretOffset) throws Exception { 59 assert(instanceFileObject != null && instanceDocument != null); 60 CompletionQuery instance = new CompletionQuery(instanceFileObject); 61 return instance.getCompletionItems(instanceDocument, caretOffset); 62 } 63 64 protected void assertResult(List <CompletionResultItem> result, 65 String [] expectedResult) { 66 assert(result.size() == expectedResult.length); 67 for(int i=0; i<expectedResult.length; i++) { 68 boolean found = false; 69 for(CompletionResultItem item : result) { 70 String resultItem = item.getReplacementText(); 71 if(item instanceof AttributeResultItem) 72 resultItem = resultItem.substring(0, resultItem.indexOf("=")); 73 if(resultItem.equals(expectedResult[i])) 74 found = true; 75 } 76 assert(found); 77 } 78 } 79 80 } 81 | Popular Tags |