1 33 34 package edu.rice.cs.util; 35 36 import edu.rice.cs.drjava.DrJavaTestCase; 37 38 import java.io.File ; 39 import java.io.IOException ; 40 import java.net.MalformedURLException ; 41 import java.net.URL ; 42 import java.util.ArrayList ; 43 44 45 public class ClassPathVectorTest extends DrJavaTestCase { 46 47 48 public void test_toString() { 49 ClassPathVector v = new ClassPathVector(); 50 assertEquals("Empty classpath", "", v.toString()); 51 addElement(v, "file:///jsr14.jar"); 52 assertEquals("One element classpath", File.separator+"jsr14.jar"+File.pathSeparator,v.toString()); 53 addElement(v, "file:///wherever/supercool.jar"); 54 String fileName = File.separator + "wherever" + File.separator + "supercool.jar"; 55 assertEquals("Multiple element classpath", File.separator+"jsr14.jar" + File.pathSeparator + fileName + File.pathSeparator, v.toString()); 56 addElement(v, "http://www.drjava.org/hosted.jar"); 57 assertEquals("Multiple element classpath", File.separator+"jsr14.jar" + File.pathSeparator + fileName + File.pathSeparator + File.separator + "hosted.jar" + File.pathSeparator, v.toString()); 58 } 59 60 61 public void test_OverloadedAdds() { 62 ClassPathVector v = new ClassPathVector(); 63 v.add("asdf"); assertEquals("Nothing should be added", "", v.toString()); 65 } 66 67 68 public void test_asFileVector() throws IOException { 69 ClassPathVector vu = new ClassPathVector(); 70 File [] files = new File []{ 71 new File ("folder1/folder2/file1.ext"), 72 new File ("folder1/folder2/file2.ext"), 73 new File ("folder1/folder2/file3.ext") 74 }; 75 for (File f : files) vu.add(f); 76 77 ArrayList <File > vf = vu.asFileVector(); 78 assertEquals("Size of vectors should agree", vu.size(), vf.size()); 79 for(int i=0; i<files.length; i++) assertEquals(files[i].getCanonicalFile(), vf.get(i)); 80 } 81 82 private void addElement(ClassPathVector v, String element) { 83 try { 84 v.add(new URL (element)); 85 } catch(MalformedURLException e) { 86 fail("Mysterious MalformedURLException. Probably not our fault."); 87 } 88 } 89 90 } 91 | Popular Tags |