001    package org.hackystat.sensor.ant.javancss;
002    
003    import static org.junit.Assert.assertEquals;
004    import static org.junit.Assert.assertNull;
005    
006    import java.math.BigInteger;
007    import java.util.ArrayList;
008    import java.util.List;
009    import java.io.File;
010    
011    import org.hackystat.sensor.ant.javancss.jaxb.Function;
012    import org.hackystat.sensor.ant.javancss.jaxb.Functions;
013    import org.junit.Test;
014    
015    /**
016     * Tests the CcnData abstraction.
017     * @author Philip Johnson
018     */
019    public class TestCcnData {
020    
021      /** The path to our hypothetical files. */
022      private File dir = new File("proj" + System.getProperty("file.separator") + 
023          "foo" + System.getProperty("file.separator") + 
024          "bar" + System.getProperty("file.separator"));
025      
026      /** The files we will have in our testing data structure. */
027      private File file1 = new File(dir, "Baz.java"); 
028      private File file2 = new File(dir, "Zob.java"); 
029      private File file3 = new File(dir, "Quark.java"); 
030    
031      /**
032       * Tests the ccnData abstraction.
033       */
034      @Test 
035      public void  testCcnData() {
036        CcnData ccnData = new CcnData(makeFiles(), makeFunctions());
037        assertEquals("Test Baz ccn", "1", ccnData.getCcnData(file1));
038        assertEquals("Test Baz ncss", 1, ccnData.getTotalLines(file1));
039        assertEquals("Test Zob ccn", "2,3", ccnData.getCcnData(file2));
040        assertEquals("Test Zob ncss", 5, ccnData.getTotalLines(file2));
041        assertNull("Test Quark", ccnData.getCcnData(file3));
042      }
043    
044      /**
045       * Creates an example Functions instance for testing.
046       * Has data on two classes: Baz and Zob.  Baz has one method and Qux has two.
047       * That's a total of three function instances inside this Functions object.  
048       * @return The Functions instance. 
049       */
050      private Functions makeFunctions() {
051        Functions functions = new Functions();
052        Function function1 = new Function();
053        function1.setName("foo.bar.Baz.qux()");
054        function1.setCcn(BigInteger.valueOf(1));
055        function1.setNcss("1");
056        Function function2 = new Function();
057        function2.setName("Zob.boffo()");
058        function2.setCcn(BigInteger.valueOf(2));
059        function2.setNcss("2");
060        Function function3 = new Function();
061        function3.setName("Zob.twork()");
062        function3.setCcn(BigInteger.valueOf(3));
063        function3.setNcss("3");
064        functions.getFunction().add(function1);
065        functions.getFunction().add(function2);
066        functions.getFunction().add(function3);
067        return functions;
068      }
069      
070      /**
071       * Creates and returns a list of three files.  Two should have CCN data, but one 
072       * should not. 
073       * @return The list of three files for testing. 
074       */
075      private List<File> makeFiles() {
076        List<File> files = new ArrayList<File>();
077        files.add(file1);
078        files.add(file2);
079        files.add(file3);
080        return files;
081      }
082    
083    }