Coverage Report - com.jeantessier.dependencyfinder.ant.TestListSymbols
 
Classes in this File Line Coverage Branch Coverage Complexity
TestListSymbols
96%
105/109
N/A
1.133
 
 1  
 /*
 2  
  *  Copyright (c) 2001-2009, Jean Tessier
 3  
  *  All rights reserved.
 4  
  *
 5  
  *  Redistribution and use in source and binary forms, with or without
 6  
  *  modification, are permitted provided that the following conditions
 7  
  *  are met:
 8  
  *
 9  
  *      * Redistributions of source code must retain the above copyright
 10  
  *        notice, this list of conditions and the following disclaimer.
 11  
  *
 12  
  *      * Redistributions in binary form must reproduce the above copyright
 13  
  *        notice, this list of conditions and the following disclaimer in the
 14  
  *        documentation and/or other materials provided with the distribution.
 15  
  *
 16  
  *      * Neither the name of Jean Tessier nor the names of his contributors
 17  
  *        may be used to endorse or promote products derived from this software
 18  
  *        without specific prior written permission.
 19  
  *
 20  
  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 21  
  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 22  
  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 23  
  *  A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR
 24  
  *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 25  
  *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 26  
  *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 27  
  *  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 28  
  *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 29  
  *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 30  
  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 31  
  */
 32  
 
 33  
 package com.jeantessier.dependencyfinder.ant;
 34  
 
 35  
 import java.util.*;
 36  
 import java.io.*;
 37  
 
 38  
 import org.jmock.integration.junit3.*;
 39  
 import org.apache.tools.ant.*;
 40  
 
 41  
 import com.jeantessier.classreader.*;
 42  
 
 43  14
 public class TestListSymbols extends MockObjectTestCase {
 44  
     private Classfile mockClassfile;
 45  
     private Field_info mockField;
 46  
     private Method_info mockMethod;
 47  
     private LocalVariable mockLocalVariable;
 48  
 
 49  
     private ListSymbols sut;
 50  
 
 51  
     protected void setUp() throws Exception {
 52  14
         super.setUp();
 53  
 
 54  14
         mockClassfile = mock(Classfile.class);
 55  14
         mockField = mock(Field_info.class);
 56  14
         mockMethod = mock(Method_info.class);
 57  14
         mockLocalVariable = mock(LocalVariable.class);
 58  
 
 59  14
         sut = new ListSymbols();
 60  14
     }
 61  
 
 62  
     public void testAllMandatoryParameters() {
 63  1
         sut.createPath();
 64  1
         sut.setDestfile(new File("foobar"));
 65  
 
 66  1
         sut.validateParameters();
 67  1
     }
 68  
 
 69  
     public void testPathNotSet() {
 70  
         try {
 71  1
             sut.validateParameters();
 72  0
             fail("executed without path being set");
 73  1
         } catch (BuildException ex) {
 74  1
             assertEquals("Wrong message", "path must be set!", ex.getMessage());
 75  0
         }
 76  1
     }
 77  
 
 78  
     public void testMissingDestfile() {
 79  1
         sut.createPath();
 80  
 
 81  
         try {
 82  1
             sut.validateParameters();
 83  0
             fail("executed without destfile being set");
 84  1
         } catch (BuildException ex) {
 85  1
             assertEquals("Wrong message", "destfile must be set!", ex.getMessage());
 86  0
         }
 87  1
     }
 88  
 
 89  
     public void testCreateStrategy_default() {
 90  1
         FilteringSymbolGathererStrategy strategy = (FilteringSymbolGathererStrategy) sut.createStrategy();
 91  1
         assertEquals("strategy class", FilteringSymbolGathererStrategy.class, strategy.getClass());
 92  1
         List<String> includes = strategy.getIncludes();
 93  1
         assertEquals("filter includes", 1, includes.size());
 94  1
         assertEquals("filter includes", "//", includes.get(0));
 95  1
         List<String> excludes = strategy.getExcludes();
 96  1
         assertEquals("filter excludes", 0, excludes.size());
 97  
 
 98  1
         SymbolGathererStrategy delegateStrategy = strategy.getDelegate();
 99  1
         assertEquals("delegate strategy class", DefaultSymbolGathererStrategy.class, delegateStrategy.getClass());
 100  1
         assertTrue("class names", delegateStrategy.isMatching(mockClassfile));
 101  1
         assertTrue("field names", delegateStrategy.isMatching(mockField));
 102  1
         assertTrue("method names", delegateStrategy.isMatching(mockMethod));
 103  1
         assertTrue("local variable names", delegateStrategy.isMatching(mockLocalVariable));
 104  1
     }
 105  
 
 106  
     public void testCreateStrategy_classnames() {
 107  1
         sut.setClassnames(true);
 108  
 
 109  1
         SymbolGathererStrategy strategy = ((SymbolGathererStrategyDecorator) sut.createStrategy()).getDelegate();
 110  1
         assertEquals("strategy class", DefaultSymbolGathererStrategy.class, strategy.getClass());
 111  1
         assertTrue("class names", strategy.isMatching(mockClassfile));
 112  1
         assertFalse("field names", strategy.isMatching(mockField));
 113  1
         assertFalse("method names", strategy.isMatching(mockMethod));
 114  1
         assertFalse("local variable names", strategy.isMatching(mockLocalVariable));
 115  1
     }
 116  
 
 117  
     public void testCreateStrategy_fieldnames() {
 118  1
         sut.setFieldnames(true);
 119  
 
 120  1
         SymbolGathererStrategy strategy = ((SymbolGathererStrategyDecorator) sut.createStrategy()).getDelegate();
 121  1
         assertEquals("strategy class", DefaultSymbolGathererStrategy.class, strategy.getClass());
 122  1
         assertFalse("class names", strategy.isMatching(mockClassfile));
 123  1
         assertTrue("field names", strategy.isMatching(mockField));
 124  1
         assertFalse("method names", strategy.isMatching(mockMethod));
 125  1
         assertFalse("local variable names", strategy.isMatching(mockLocalVariable));
 126  1
     }
 127  
 
 128  
     public void testCreateStrategy_methodnames() {
 129  1
         sut.setMethodnames(true);
 130  
 
 131  1
         SymbolGathererStrategy strategy = ((SymbolGathererStrategyDecorator) sut.createStrategy()).getDelegate();
 132  1
         assertEquals("strategy class", DefaultSymbolGathererStrategy.class, strategy.getClass());
 133  1
         assertFalse("class names", strategy.isMatching(mockClassfile));
 134  1
         assertFalse("field names", strategy.isMatching(mockField));
 135  1
         assertTrue("method names", strategy.isMatching(mockMethod));
 136  1
         assertFalse("local variable names", strategy.isMatching(mockLocalVariable));
 137  1
     }
 138  
 
 139  
     public void testCreateStrategy_localnames() {
 140  1
         sut.setLocalnames(true);
 141  
 
 142  1
         SymbolGathererStrategy strategy = ((SymbolGathererStrategyDecorator) sut.createStrategy()).getDelegate();
 143  1
         assertEquals("strategy class", DefaultSymbolGathererStrategy.class, strategy.getClass());
 144  1
         assertFalse("class names", strategy.isMatching(mockClassfile));
 145  1
         assertFalse("field names", strategy.isMatching(mockField));
 146  1
         assertFalse("method names", strategy.isMatching(mockMethod));
 147  1
         assertTrue("local variable names", strategy.isMatching(mockLocalVariable));
 148  1
     }
 149  
 
 150  
     public void testCreateStrategy_nonprivatefieldnames() {
 151  1
         sut.setNonprivatefieldnames(true);
 152  
 
 153  1
         SymbolGathererStrategy strategy = ((SymbolGathererStrategyDecorator) sut.createStrategy()).getDelegate();
 154  1
         assertEquals("strategy class", NonPrivateFieldSymbolGathererStrategy.class, strategy.getClass());
 155  1
     }
 156  
 
 157  
     public void testCreateStrategy_finalmethodorclassnames() {
 158  1
         sut.setFinalmethodorclassnames(true);
 159  
 
 160  1
         SymbolGathererStrategy strategy = ((SymbolGathererStrategyDecorator) sut.createStrategy()).getDelegate();
 161  1
         assertEquals("strategy class", FinalMethodOrClassSymbolGathererStrategy.class, strategy.getClass());
 162  1
     }
 163  
 
 164  
     public void testCreateStrategy_singleincludes() {
 165  1
         sut.setIncludes("/some/");
 166  
 
 167  1
         FilteringSymbolGathererStrategy strategy = (FilteringSymbolGathererStrategy) sut.createStrategy();
 168  1
         assertEquals("strategy class", FilteringSymbolGathererStrategy.class, strategy.getClass());
 169  1
         List<String> includes = strategy.getIncludes();
 170  1
         assertEquals("filter includes", 1, includes.size());
 171  1
         assertEquals("filter includes", "/some/", includes.get(0));
 172  1
     }
 173  
 
 174  
     public void testCreateStrategy_multipleincludes() {
 175  1
         sut.setIncludes("/some/, /other/");
 176  
 
 177  1
         FilteringSymbolGathererStrategy strategy = (FilteringSymbolGathererStrategy) sut.createStrategy();
 178  1
         assertEquals("strategy class", FilteringSymbolGathererStrategy.class, strategy.getClass());
 179  1
         List<String> includes = strategy.getIncludes();
 180  1
         assertEquals("filter includes", 2, includes.size());
 181  1
         assertEquals("filter includes", "/some/", includes.get(0));
 182  1
         assertEquals("filter includes", "/other/", includes.get(1));
 183  1
     }
 184  
 
 185  
     public void testCreateStrategy_singleexcludes() {
 186  1
         sut.setExcludes("/some/");
 187  
 
 188  1
         FilteringSymbolGathererStrategy strategy = (FilteringSymbolGathererStrategy) sut.createStrategy();
 189  1
         assertEquals("strategy class", FilteringSymbolGathererStrategy.class, strategy.getClass());
 190  1
         List<String> excludes = strategy.getExcludes();
 191  1
         assertEquals("filter excludes", 1, excludes.size());
 192  1
         assertEquals("filter excludes", "/some/", excludes.get(0));
 193  1
     }
 194  
 
 195  
     public void testCreateStrategy_multipleexcludes() {
 196  1
         sut.setExcludes("/some/, /other/");
 197  
 
 198  1
         FilteringSymbolGathererStrategy strategy = (FilteringSymbolGathererStrategy) sut.createStrategy();
 199  1
         assertEquals("strategy class", FilteringSymbolGathererStrategy.class, strategy.getClass());
 200  1
         List<String> excludes = strategy.getExcludes();
 201  1
         assertEquals("filter excludes", 2, excludes.size());
 202  1
         assertEquals("filter excludes", "/some/", excludes.get(0));
 203  1
         assertEquals("filter excludes", "/other/", excludes.get(1));
 204  1
     }
 205  
 }