KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > maven > tools > plugin > util > TestUtils


1 package org.apache.maven.tools.plugin.util;
2
3 import java.net.URL JavaDoc;
4
5 import junit.framework.TestCase;
6
7 /**
8  * @author jdcasey
9  */

10 public class TestUtils
11     extends TestCase
12 {
13
14     public void testDirnameFunction_METATEST()
15     {
16         String JavaDoc classname = getClass().getName().replace( '.', '/' ) + ".class";
17         String JavaDoc basedir = TestUtils.dirname( classname );
18
19         ClassLoader JavaDoc cl = Thread.currentThread().getContextClassLoader();
20         URL JavaDoc resource = cl.getResource( classname );
21
22         assertEquals( resource.getPath(), basedir + classname );
23     }
24
25     public static String JavaDoc dirname( String JavaDoc file )
26     {
27         ClassLoader JavaDoc cl = Thread.currentThread().getContextClassLoader();
28         URL JavaDoc fileResource = cl.getResource( file );
29
30         String JavaDoc fullPath = fileResource.getPath();
31
32         return fullPath.substring( 0, fullPath.length() - file.length() );
33     }
34
35 }
Popular Tags