1 19 20 package org.netbeans.api.java.queries; 21 22 import org.netbeans.junit.MockServices; 23 import org.netbeans.junit.NbTestCase; 24 import org.netbeans.spi.java.queries.SourceLevelQueryImplementation; 25 import org.openide.filesystems.FileObject; 26 import org.openide.filesystems.FileUtil; 27 28 31 public class SourceLevelQueryTest extends NbTestCase { 32 33 public SourceLevelQueryTest(String n) { 34 super(n); 35 } 36 37 private static String LEVEL; 38 private FileObject f; 39 40 protected void setUp() throws Exception { 41 super.setUp(); 42 MockServices.setServices(SLQ.class); 43 LEVEL = null; 44 f = FileUtil.createMemoryFileSystem().getRoot(); 45 } 46 47 public void testBasicUsage() throws Exception { 48 assertNull(SourceLevelQuery.getSourceLevel(f)); 49 LEVEL = "1.3"; 50 assertEquals("1.3", SourceLevelQuery.getSourceLevel(f)); 51 LEVEL = "1.5"; 52 assertEquals("1.5", SourceLevelQuery.getSourceLevel(f)); 53 MockServices.setServices(); 54 assertNull(SourceLevelQuery.getSourceLevel(f)); 55 } 56 57 public void testRobustness() throws Exception { 58 LEVEL = "${default.javac.source}"; 60 assertNull(SourceLevelQuery.getSourceLevel(f)); 61 } 62 63 public static final class SLQ implements SourceLevelQueryImplementation { 64 65 public SLQ() {} 66 67 public String getSourceLevel(FileObject javaFile) { 68 return LEVEL; 69 } 70 71 } 72 73 } 74 | Popular Tags |