Clover coverage report - JFCUnit Test Coverage
Coverage timestamp: Mon Dec 20 2004 23:38:10 MST
file stats: LOC: 256   Methods: 15
NCLOC: 138   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
PathDataT.java 62.5% 94.7% 93.3% 91.3%
coverage coverage
 1   
 package junit.extensions.jfcunit.eventdata;
 2   
 
 3   
 import java.awt.Insets;
 4   
 import javax.swing.JMenuItem;
 5   
 import javax.swing.JTree;
 6   
 import javax.swing.tree.DefaultMutableTreeNode;
 7   
 import javax.swing.tree.TreePath;
 8   
 
 9   
 import junit.framework.TestCase;
 10   
 
 11   
 /**
 12   
  * <p>Title: Test the PathData.</p>
 13   
  * <p>Copyright: Copyright (c) 2003</p>
 14   
  * <p>Company: JFCUnit OpenSource Project</p>
 15   
  * @author Kevin Wilson
 16   
  * @version 1.0
 17   
  */
 18   
 public class PathDataT
 19   
     extends TestCase {
 20   
   /**
 21   
    * Test data.
 22   
    */
 23   
   private PathData m_pathData = null;
 24   
 
 25   
   /**
 26   
    * Setup the test.
 27   
    * @throws Exception may be thrown.
 28   
    */
 29  11
   protected void setUp() throws Exception {
 30  11
     super.setUp();
 31  11
     m_pathData = new PathData(0);
 32   
   }
 33   
 
 34   
   /**
 35   
    * Tear down the test.
 36   
    * @throws Exception may be thrown.
 37   
    */
 38  11
   protected void tearDown() throws Exception {
 39  11
     m_pathData = null;
 40  11
     super.tearDown();
 41   
   }
 42   
 
 43   
   /**
 44   
    * Test constructor with menuitem.
 45   
    */
 46  1
   public void testPathData() {
 47   
 //    JMenuItem mi = null;
 48   
 //    m_pathData = new PathData(mi);
 49   
     /**@todo fill in the test code*/
 50   
   }
 51   
 
 52   
   /**
 53   
    * Test constructor with path only.
 54   
    */
 55  1
   public void testPathData1() {
 56   
 //    String[] path = null;
 57   
 //    m_pathData = new PathData(path);
 58   
     /**@todo fill in the test code*/
 59   
   }
 60   
 
 61   
   /**
 62   
    * Test Constructor with path and indexes.
 63   
    */
 64  1
   public void testPathData2() {
 65   
 //    String[] path = null;
 66   
 //    int[] indexes = null;
 67   
 //    m_pathData = new PathData(path, indexes);
 68   
     /**@todo fill in the test code*/
 69   
   }
 70   
 
 71   
   /**
 72   
    * Test consturctor with size.
 73   
    */
 74  1
   public void testPathData3() {
 75  1
     int size = 0;
 76  1
     m_pathData = new PathData(size);
 77   
     /**@todo fill in the test code*/
 78   
   }
 79   
 
 80   
   /**
 81   
    * Test getIndexes().
 82   
    */
 83  1
   public void testGetIndexes() {
 84   
 //    JComponent menu = null;
 85   
 //    int[] expectedReturn = null;
 86   
 //    int[] actualReturn = m_pathData.getIndexes(menu);
 87   
 //    assertEquals("return value", expectedReturn, actualReturn);
 88   
     /**@todo fill in the test code*/
 89   
   }
 90   
 
 91   
   /**
 92   
    * Test getRoot.
 93   
    */
 94  1
   public void testGetRoot() {
 95  1
     JMenuItem mi = null;
 96  1
     Object expectedReturn = null;
 97  1
     Object actualReturn = m_pathData.getRoot(mi);
 98  1
     assertEquals("return value", expectedReturn, actualReturn);
 99   
     /**@todo fill in the test code*/
 100   
   }
 101   
 
 102   
   /**
 103   
    * Test getting the tree path with a null path.
 104   
    */
 105  1
   public void testGetTreePathNull() {
 106  1
     JTree tree = this.createTree();
 107  1
     TreePath expectedReturn = null;
 108  1
     TreePath actualReturn = m_pathData.getTreePath(tree);
 109  1
     assertEquals("return value", expectedReturn, actualReturn);
 110   
   }
 111   
 
 112   
   /**
 113   
    * Test getting the root element.
 114   
    */
 115  1
   public void testGetTreePathRoot() {
 116  1
     JTree tree = this.createTree();
 117  1
     m_pathData = new PathData(new String[] {"TreeDemo"});
 118  1
     TreePath actualReturn = m_pathData.getTreePath(tree);
 119  1
     assertTrue(actualReturn.getPathCount() == 1);
 120   
   }
 121   
 
 122   
   /**
 123   
    * Test getTreePath with 2 elements.
 124   
    */
 125  1
   public void testGetTreePath2Elements() {
 126  1
     JTree tree = this.createTree();
 127  1
     m_pathData = new PathData(new String[] {"TreeDemo",
 128   
                             "Classical",
 129   
                             "Beethoven",
 130   
                             "concertos",
 131   
                             "No. 1 - C"});
 132   
 
 133  1
     TreePath actualReturn = m_pathData.getTreePath(tree);
 134  1
     assertTrue(actualReturn.getPathCount() == 5);
 135   
   }
 136   
 
 137   
   /**
 138   
    * Test the getTreePath with indexes set for multiple
 139   
    * matching record.
 140   
    */
 141  1
   public void testGetTreePathWithCount() {
 142  1
     JTree tree = this.createTree();
 143  1
     m_pathData = new PathData(new String[] {"TreeDemo",
 144   
                             "Classical",
 145   
                             "Beethoven",
 146   
                             "Sonatas",
 147   
                             "Sonata in A Minor 2"},
 148   
                             new int[] {0, // TreeDemo
 149   
                             0, // Classical
 150   
                             0, // Beethoven
 151   
                             1, // Sonatas 2nd of two identical entries.
 152   
                             0, // Sonata in A Minor 2 Only in second sanata branch
 153   
                             });
 154   
 
 155  1
     TreePath actualReturn = m_pathData.getTreePath(tree);
 156  1
     assertTrue(actualReturn.getPathCount() == 5);
 157   
   }
 158   
 
 159   
   /**
 160   
    * Test the set method.
 161   
    */
 162  1
   public void testSet() {
 163   
 //    int i = 0;
 164   
 //    String data = "";
 165   
 //    int index = 0;
 166   
 //    m_pathData.set(i, data, index);
 167   
     /**@todo fill in the test code*/
 168   
   }
 169   
 
 170   
 
 171   
 
 172   
   /**
 173   
    * Creat a sample JTree to be used in testing.
 174   
    * @return JTree Tree containing nodes.
 175   
    */
 176  4
   public JTree createTree() {
 177  4
     DefaultMutableTreeNode top = new DefaultMutableTreeNode("TreeDemo");
 178  4
     DefaultMutableTreeNode catagory = null;
 179  4
     DefaultMutableTreeNode artist = null;
 180  4
     DefaultMutableTreeNode record = null;
 181   
 
 182   
     // read one line at a time, put into tree
 183  4
     for (int i = 0; i < m_nodes.length; i++) {
 184  72
       String line = m_nodes[i];
 185  72
       System.err.println(line);
 186   
       // System.out.println("reading in: ->" + line + "<-");
 187  72
       char linetype = line.charAt(0);
 188  72
       switch (linetype) {
 189  4
         case 'C':
 190  4
           catagory = new DefaultMutableTreeNode(line.substring(2));
 191  4
           top.add(catagory);
 192  4
           break;
 193  4
         case 'A':
 194  4
           if (catagory != null) {
 195  4
             artist = new DefaultMutableTreeNode(line.substring(2));
 196  4
             catagory.add(artist);
 197   
           }
 198  4
           break;
 199  16
         case 'R':
 200  16
           if (artist != null) {
 201  16
             record = new DefaultMutableTreeNode(line.substring(2));
 202  16
             artist.add(record);
 203   
           }
 204  16
           break;
 205  48
         case 'S':
 206  48
           if (record != null) {
 207  48
             record.add(new DefaultMutableTreeNode(line.substring(2)));
 208   
           }
 209  48
           break;
 210  0
         default:
 211  0
           break;
 212   
       }
 213   
 
 214   
     }
 215   
 
 216   
 
 217  4
     return new JTree(top) {
 218  0
       public Insets getInsets() {
 219  0
         return new Insets(5, 5, 5, 5);
 220   
       }
 221   
     };
 222   
   }
 223   
 
 224   
   /**
 225   
    * These are the string used to create the tree.
 226   
    *
 227   
    #     Popular   / Classical                                                    #
 228   
    # ----------------------------                                                 #
 229   
    # A = Artist    / Composer                                                     #
 230   
    # R = Record    / Style                                                        #
 231   
    # S = Song Name / Composition                                                  #
 232   
    # C = Catagory                                                                 #
 233   
    */
 234   
   private String[] m_nodes = new String[] {
 235   
       "C Classical",
 236   
       "A Beethoven",
 237   
       "R concertos",
 238   
       "S No. 1 - C",
 239   
       "S No. 2 - B-Flat Major",
 240   
       "S No. 3 - C Minor",
 241   
       "S No. 4 - G Major",
 242   
       "S No. 5 - E-Flat Major",
 243   
       "R Quartets",
 244   
       "S Six String Quartets",
 245   
       "S Three String Quartets",
 246   
       "S Grosse Fugue for String Quartets",
 247   
       "R Sonatas",
 248   
       "S Sonata in A Minor",
 249   
       "S Sonata in F Major",
 250   
       "R Sonatas",
 251   
       "S Sonata in A Minor 2",
 252   
       "S Sonata in F Major 2",
 253   
   };
 254   
 
 255   
 }
 256