1 19 20 package org.netbeans.modules.java.j2seplatform.platformdefinition; 21 22 import java.io.IOException ; 23 import java.io.OutputStreamWriter ; 24 import java.io.PrintWriter ; 25 import org.netbeans.api.java.queries.SourceLevelQuery; 26 import org.netbeans.junit.MockServices; 27 import org.netbeans.junit.NbTestCase; 28 import org.openide.filesystems.FileLock; 29 import org.openide.filesystems.FileObject; 30 import org.openide.filesystems.FileUtil; 31 32 35 public class DefaultSourceLevelQueryImplTest extends NbTestCase { 36 37 public DefaultSourceLevelQueryImplTest(String testName) { 38 super(testName); 39 } 40 41 protected void setUp() throws Exception { 42 clearWorkDir(); 43 MockServices.setServices(new Class [] {JavaPlatformProviderImpl.class}); 44 } 45 46 public void testGetSourceLevel() throws Exception { 47 FileObject root = FileUtil.toFileObject(this.getWorkDir()); 48 assertNotNull ("Cannot convert File to FileObject, missing master-fs?",root); FileObject javaFile = createTestFile (root,"test","Test.java","package test;\n class Test {}"); assertEquals("1.5", SourceLevelQuery.getSourceLevel(javaFile)); 51 } 52 53 private FileObject createTestFile (FileObject root, String path, String fileName, String content) throws IOException { 54 FileObject pkg = FileUtil.createFolder(root, path); 55 assertNotNull (pkg); 56 FileObject data = pkg.createData(fileName); 57 FileLock lock = data.lock(); 58 try { 59 PrintWriter out = new PrintWriter (new OutputStreamWriter (data.getOutputStream(lock))); 60 try { 61 out.println (content); 62 } finally { 63 out.close(); 64 } 65 } finally { 66 lock.releaseLock(); 67 } 68 return data; 69 } 70 71 } 72 | Popular Tags |