1 22 package org.objectweb.petals.classloader.locator; 23 24 import java.io.File ; 25 import java.io.IOException ; 26 import java.net.MalformedURLException ; 27 import java.net.URL ; 28 29 import junit.framework.TestCase; 30 31 36 public class DirLocatorTest extends TestCase { 37 38 private String baseDir; 39 40 public void setUp() { 41 baseDir = this.getClass().getResource(".").toString(); 42 baseDir = baseDir.substring(0, baseDir.indexOf("target")); 43 baseDir = baseDir.substring(baseDir.indexOf(":") + 1); 44 } 45 46 public void testHasFile() throws MalformedURLException , IOException { 47 DirLocator dirLocator = new DirLocator(new URL ("file:" 48 + baseDir.replace(File.separator, "/") + "src/test-data/")); 49 assertTrue(dirLocator.hasFile("resourceCore.txt")); 50 } 51 52 public void testListContent() throws MalformedURLException , IOException { 53 DirLocator dirLocator = new DirLocator(new URL ("file:" 54 + baseDir.replace(File.separator, "/") + "src/test-data/")); 55 assertTrue((dirLocator.listContent(".").size() > 0)); 56 } 57 58 public void testExceptionNotExist() { 59 try { 60 new DirLocator(new URL ("file:\\test%20bad_file")); 61 fail(); 62 } catch (IOException e) { 63 } 65 } 66 67 public void testExceptionNotDirectory() { 68 try { 69 new DirLocator(new URL ("file:" 70 + baseDir.replace(File.separator, "/") + "src/test-data/test.zip")); 71 fail(); 72 } catch (IOException e) { 73 } 75 } 76 77 } 78 | Popular Tags |