001    package org.hackystat.sensor.ant.jdepend;
002    
003    import static org.junit.Assert.assertEquals;
004    
005    import java.io.File;
006    import java.util.ArrayList;
007    import org.junit.Test;
008    
009    /**
010     * Tests the Package2Path processor.
011     * 
012     * @author Philip Johnson
013     */
014    public class TestPackage2Path {
015      private String sep = System.getProperty("file.separator");
016      private String foo = "foo";
017      private String bar = "bar";
018      private String path1 = "c:" + sep + foo + sep + bar + sep + "Baz.java";
019      private String path2 = "c:" + sep + foo + sep + bar + sep + "baz" + sep + "Baz.java";
020      private String path3 = "c:" + sep + foo + sep + bar + sep + "Qux.java";
021    
022        /**
023       * Tests Package2Path by setting up some sample data and running some queries on it.
024       * @throws Exception If a program error occurs.
025       */
026      @Test
027      public void testPackage2Path() throws Exception {
028        ArrayList<File> fileList = new ArrayList<File>();
029        fileList.add(new File(path1));
030        fileList.add(new File(path2));
031        fileList.add(new File(path3));
032        
033        Package2Path package2path = new Package2Path(fileList);
034        assertEquals("test1", "c:" + sep + foo + sep + bar, package2path.getPath("foo.bar"));
035        assertEquals("test2", "c:" + sep + foo + sep + bar + sep + "baz", 
036            package2path.getPath("foo.bar.baz"));
037        assertEquals("test3", null, package2path.getPath("foo.bar.baz.qux"));
038      }
039    
040    }