Coverage Report - com.jeantessier.classreader.TestFilteringSymbolGathererStrategy
 
Classes in this File Line Coverage Branch Coverage Complexity
TestFilteringSymbolGathererStrategy
88%
128/144
N/A
1.276
TestFilteringSymbolGathererStrategy$1
100%
5/5
N/A
1.276
TestFilteringSymbolGathererStrategy$10
100%
3/3
N/A
1.276
TestFilteringSymbolGathererStrategy$11
100%
3/3
N/A
1.276
TestFilteringSymbolGathererStrategy$12
100%
4/4
N/A
1.276
TestFilteringSymbolGathererStrategy$13
100%
5/5
N/A
1.276
TestFilteringSymbolGathererStrategy$14
100%
3/3
N/A
1.276
TestFilteringSymbolGathererStrategy$15
100%
5/5
N/A
1.276
TestFilteringSymbolGathererStrategy$16
100%
4/4
N/A
1.276
TestFilteringSymbolGathererStrategy$17
100%
3/3
N/A
1.276
TestFilteringSymbolGathererStrategy$18
100%
3/3
N/A
1.276
TestFilteringSymbolGathererStrategy$19
100%
4/4
N/A
1.276
TestFilteringSymbolGathererStrategy$2
100%
4/4
N/A
1.276
TestFilteringSymbolGathererStrategy$20
100%
5/5
N/A
1.276
TestFilteringSymbolGathererStrategy$21
100%
3/3
N/A
1.276
TestFilteringSymbolGathererStrategy$22
100%
5/5
N/A
1.276
TestFilteringSymbolGathererStrategy$23
100%
4/4
N/A
1.276
TestFilteringSymbolGathererStrategy$24
100%
3/3
N/A
1.276
TestFilteringSymbolGathererStrategy$25
100%
3/3
N/A
1.276
TestFilteringSymbolGathererStrategy$26
100%
4/4
N/A
1.276
TestFilteringSymbolGathererStrategy$27
100%
5/5
N/A
1.276
TestFilteringSymbolGathererStrategy$28
100%
3/3
N/A
1.276
TestFilteringSymbolGathererStrategy$3
100%
3/3
N/A
1.276
TestFilteringSymbolGathererStrategy$4
100%
3/3
N/A
1.276
TestFilteringSymbolGathererStrategy$5
100%
4/4
N/A
1.276
TestFilteringSymbolGathererStrategy$6
100%
5/5
N/A
1.276
TestFilteringSymbolGathererStrategy$7
100%
3/3
N/A
1.276
TestFilteringSymbolGathererStrategy$8
100%
5/5
N/A
1.276
TestFilteringSymbolGathererStrategy$9
100%
4/4
N/A
1.276
 
 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.classreader;
 34  
 
 35  
 import java.util.*;
 36  
 
 37  
 import org.jmock.integration.junit3.*;
 38  
 import org.jmock.*;
 39  
 import org.apache.oro.text.*;
 40  
 
 41  72
 public class TestFilteringSymbolGathererStrategy extends MockObjectTestCase {
 42  
     private static final String SOME_PACKAGE_NAME = "some.package";
 43  
     private static final String SOME_CLASS_NAME = SOME_PACKAGE_NAME + ".SomeClass";
 44  
     private static final String SOME_FIELD_SIGNATURE = SOME_CLASS_NAME + ".someField";
 45  
     private static final String SOME_METHOD_SIGNATURE = SOME_CLASS_NAME + ".someMethod()";
 46  
     private static final String SOME_LOCAL_VARIABLE_NAME = "someLocalVariable";
 47  
     private static final String ANOTHER_PACKAGE_NAME = "another.package";
 48  
     private static final String ANOTHER_CLASS_NAME = ANOTHER_PACKAGE_NAME + ".AnotherClass";
 49  
     private static final String ANOTHER_FIELD_SIGNATURE = ANOTHER_CLASS_NAME + ".anotherField";
 50  
     private static final String ANOTHER_METHOD_SIGNATURE = ANOTHER_CLASS_NAME + ".anotherMethod()";
 51  
     private static final String ANOTHER_LOCAL_VARIABLE_NAME = "anotherLocalVariable";
 52  
 
 53  
     private Classfile mockClassfile;
 54  
     private Field_info mockField;
 55  
     private Method_info mockMethod;
 56  
     private LocalVariable mockLocalVariable;
 57  
     private SymbolGathererStrategy mockStrategy;
 58  
 
 59  
     protected void setUp() throws Exception {
 60  28
         super.setUp();
 61  
 
 62  28
         mockClassfile = mock(Classfile.class);
 63  28
         mockField = mock(Field_info.class);
 64  28
         mockMethod = mock(Method_info.class);
 65  28
         mockLocalVariable = mock(LocalVariable.class);
 66  28
         mockStrategy = mock(SymbolGathererStrategy.class);
 67  28
     }
 68  
 
 69  
     /*
 70  
      * Classes
 71  
      */
 72  
 
 73  
     public void testIsMatching_class_matchingincludes() {
 74  1
         checking(new Expectations() {{
 75  1
             one (mockClassfile).getClassName();
 76  1
             will(returnValue(SOME_CLASS_NAME));
 77  1
             one (mockStrategy).isMatching(mockClassfile);
 78  1
         }});
 79  
 
 80  1
         FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.singletonList("/some/"), Collections.<String>emptyList());
 81  1
         sut.isMatching(mockClassfile);
 82  1
     }
 83  
 
 84  
     public void testIsMatching_class_notmatchingincludes() {
 85  1
         checking(new Expectations() {{
 86  1
             one (mockClassfile).getClassName();
 87  1
             will(returnValue(ANOTHER_CLASS_NAME));
 88  1
         }});
 89  
 
 90  1
         FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.singletonList("/some/"), Collections.<String>emptyList());
 91  1
         assertFalse(sut.isMatching(mockClassfile));
 92  1
     }
 93  
 
 94  
     public void testIsMatching_class_noincludes() {
 95  1
         checking(new Expectations() {{
 96  1
             one (mockClassfile).getClassName();
 97  1
         }});
 98  
 
 99  1
         FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.<String>emptyList(), Collections.<String>emptyList());
 100  1
         assertFalse(sut.isMatching(mockClassfile));
 101  1
     }
 102  
 
 103  
     public void testIsMatching_class_badincludes() {
 104  1
         checking(new Expectations() {{
 105  1
             one (mockClassfile).getClassName();
 106  1
         }});
 107  
 
 108  1
         FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.singletonList("/some"), Collections.<String>emptyList());
 109  
         try {
 110  1
             sut.isMatching(mockClassfile);
 111  0
             fail("did not throw expection for bad excludes regular expression");
 112  1
         } catch (MalformedCachePatternException ex) {
 113  
             // expected
 114  0
         }
 115  1
     }
 116  
 
 117  
     public void testIsMatching_class_matchingexcludes() {
 118  1
         checking(new Expectations() {{
 119  1
             one (mockClassfile).getClassName();
 120  1
             will(returnValue(SOME_CLASS_NAME));
 121  1
         }});
 122  
 
 123  1
         FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.singletonList("//"), Collections.singletonList("/some/"));
 124  1
         assertFalse(sut.isMatching(mockClassfile));
 125  1
     }
 126  
 
 127  
     public void testIsMatching_class_notmatchingexcludes() {
 128  1
         checking(new Expectations() {{
 129  1
             one (mockClassfile).getClassName();
 130  1
             will(returnValue(ANOTHER_CLASS_NAME));
 131  1
             one (mockStrategy).isMatching(mockClassfile);
 132  1
         }});
 133  
 
 134  1
         FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.singletonList("//"), Collections.singletonList("/some/"));
 135  1
         sut.isMatching(mockClassfile);
 136  1
     }
 137  
 
 138  
     public void testIsMatching_class_badexcludes() {
 139  1
         checking(new Expectations() {{
 140  1
             one (mockClassfile).getClassName();
 141  1
         }});
 142  
 
 143  1
         FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.singletonList("//"), Collections.singletonList("/some"));
 144  
         try {
 145  1
             sut.isMatching(mockClassfile);
 146  0
             fail("did not throw expection for bad includes regular expression");
 147  1
         } catch (MalformedCachePatternException ex) {
 148  
             // expected
 149  0
         }
 150  1
     }
 151  
 
 152  
     /*
 153  
      * Fields
 154  
      */
 155  
 
 156  
     public void testIsMatching_field_matchingincludes() {
 157  1
         checking(new Expectations() {{
 158  1
             one (mockField).getFullSignature();
 159  1
             will(returnValue(SOME_FIELD_SIGNATURE));
 160  1
             one (mockStrategy).isMatching(mockField);
 161  1
         }});
 162  
 
 163  1
         FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.singletonList("/some/"), Collections.<String>emptyList());
 164  1
         sut.isMatching(mockField);
 165  1
     }
 166  
 
 167  
     public void testIsMatching_field_notmatchingincludes() {
 168  1
         checking(new Expectations() {{
 169  1
             one (mockField).getFullSignature();
 170  1
             will(returnValue(ANOTHER_FIELD_SIGNATURE));
 171  1
         }});
 172  
 
 173  1
         FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.singletonList("/some/"), Collections.<String>emptyList());
 174  1
         assertFalse(sut.isMatching(mockField));
 175  1
     }
 176  
 
 177  
     public void testIsMatching_field_noincludes() {
 178  1
         checking(new Expectations() {{
 179  1
             one (mockField).getFullSignature();
 180  1
         }});
 181  
 
 182  1
         FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.<String>emptyList(), Collections.<String>emptyList());
 183  1
         assertFalse(sut.isMatching(mockField));
 184  1
     }
 185  
 
 186  
     public void testIsMatching_field_badincludes() {
 187  1
         checking(new Expectations() {{
 188  1
             one (mockField).getFullSignature();
 189  1
         }});
 190  
 
 191  1
         FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.singletonList("/some"), Collections.<String>emptyList());
 192  
         try {
 193  1
             sut.isMatching(mockField);
 194  0
             fail("did not throw expection for bad excludes regular expression");
 195  1
         } catch (MalformedCachePatternException ex) {
 196  
             // expected
 197  0
         }
 198  1
     }
 199  
 
 200  
     public void testIsMatching_field_matchingexcludes() {
 201  1
         checking(new Expectations() {{
 202  1
             one (mockField).getFullSignature();
 203  1
             will(returnValue(SOME_FIELD_SIGNATURE));
 204  1
         }});
 205  
 
 206  1
         FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.singletonList("//"), Collections.singletonList("/some/"));
 207  1
         assertFalse(sut.isMatching(mockField));
 208  1
     }
 209  
 
 210  
     public void testIsMatching_field_notmatchingexcludes() {
 211  1
         checking(new Expectations() {{
 212  1
             one (mockField).getFullSignature();
 213  1
             will(returnValue(ANOTHER_FIELD_SIGNATURE));
 214  1
             one (mockStrategy).isMatching(mockField);
 215  1
         }});
 216  
 
 217  1
         FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.singletonList("//"), Collections.singletonList("/some/"));
 218  1
         sut.isMatching(mockField);
 219  1
     }
 220  
 
 221  
     public void testIsMatching_field_badexcludes() {
 222  1
         checking(new Expectations() {{
 223  1
             one (mockField).getFullSignature();
 224  1
         }});
 225  
 
 226  1
         FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.singletonList("//"), Collections.singletonList("/some"));
 227  
         try {
 228  1
             sut.isMatching(mockField);
 229  0
             fail("did not throw expection for bad includes regular expression");
 230  1
         } catch (MalformedCachePatternException ex) {
 231  
             // expected
 232  0
         }
 233  1
     }
 234  
 
 235  
     /*
 236  
      * Methods
 237  
      */
 238  
 
 239  
     public void testIsMatching_method_matchingincludes() {
 240  1
         checking(new Expectations() {{
 241  1
             one (mockMethod).getFullSignature();
 242  1
             will(returnValue(SOME_METHOD_SIGNATURE));
 243  1
             one (mockStrategy).isMatching(mockMethod);
 244  1
         }});
 245  
 
 246  1
         FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.singletonList("/some/"), Collections.<String>emptyList());
 247  1
         sut.isMatching(mockMethod);
 248  1
     }
 249  
 
 250  
     public void testIsMatching_method_notmatchingincludes() {
 251  1
         checking(new Expectations() {{
 252  1
             one (mockMethod).getFullSignature();
 253  1
             will(returnValue(ANOTHER_METHOD_SIGNATURE));
 254  1
         }});
 255  
 
 256  1
         FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.singletonList("/some/"), Collections.<String>emptyList());
 257  1
         assertFalse(sut.isMatching(mockMethod));
 258  1
     }
 259  
 
 260  
     public void testIsMatching_method_noincludes() {
 261  1
         checking(new Expectations() {{
 262  1
             one (mockMethod).getFullSignature();
 263  1
         }});
 264  
 
 265  1
         FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.<String>emptyList(), Collections.<String>emptyList());
 266  1
         assertFalse(sut.isMatching(mockMethod));
 267  1
     }
 268  
 
 269  
     public void testIsMatching_method_badincludes() {
 270  1
         checking(new Expectations() {{
 271  1
             one (mockMethod).getFullSignature();
 272  1
         }});
 273  
 
 274  1
         FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.singletonList("/some"), Collections.<String>emptyList());
 275  
         try {
 276  1
             sut.isMatching(mockMethod);
 277  0
             fail("did not throw expection for bad excludes regular expression");
 278  1
         } catch (MalformedCachePatternException ex) {
 279  
             // expected
 280  0
         }
 281  1
     }
 282  
 
 283  
     public void testIsMatching_method_matchingexcludes() {
 284  1
         checking(new Expectations() {{
 285  1
             one (mockMethod).getFullSignature();
 286  1
             will(returnValue(SOME_METHOD_SIGNATURE));
 287  1
         }});
 288  
 
 289  1
         FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.singletonList("//"), Collections.singletonList("/some/"));
 290  1
         assertFalse(sut.isMatching(mockMethod));
 291  1
     }
 292  
 
 293  
     public void testIsMatching_method_notmatchingexcludes() {
 294  1
         checking(new Expectations() {{
 295  1
             one (mockMethod).getFullSignature();
 296  1
             will(returnValue(ANOTHER_METHOD_SIGNATURE));
 297  1
             one (mockStrategy).isMatching(mockMethod);
 298  1
         }});
 299  
 
 300  1
         FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.singletonList("//"), Collections.singletonList("/some/"));
 301  1
         sut.isMatching(mockMethod);
 302  1
     }
 303  
 
 304  
     public void testIsMatching_method_badexcludes() {
 305  1
         checking(new Expectations() {{
 306  1
             one (mockMethod).getFullSignature();
 307  1
         }});
 308  
 
 309  1
         FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.singletonList("//"), Collections.singletonList("/some"));
 310  
         try {
 311  1
             sut.isMatching(mockMethod);
 312  0
             fail("did not throw expection for bad includes regular expression");
 313  1
         } catch (MalformedCachePatternException ex) {
 314  
             // expected
 315  0
         }
 316  1
     }
 317  
 
 318  
     /*
 319  
      * Local variables
 320  
      */
 321  
 
 322  
     public void testIsMatching_local_matchingincludes() {
 323  1
         checking(new Expectations() {{
 324  1
             one (mockLocalVariable).getName();
 325  1
             will(returnValue(SOME_LOCAL_VARIABLE_NAME));
 326  1
             one (mockStrategy).isMatching(mockLocalVariable);
 327  1
         }});
 328  
 
 329  1
         FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.singletonList("/some/"), Collections.<String>emptyList());
 330  1
         sut.isMatching(mockLocalVariable);
 331  1
     }
 332  
 
 333  
     public void testIsMatching_local_notmatchingincludes() {
 334  1
         checking(new Expectations() {{
 335  1
             one (mockLocalVariable).getName();
 336  1
             will(returnValue(ANOTHER_LOCAL_VARIABLE_NAME));
 337  1
         }});
 338  
 
 339  1
         FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.singletonList("/some/"), Collections.<String>emptyList());
 340  1
         assertFalse(sut.isMatching(mockLocalVariable));
 341  1
     }
 342  
 
 343  
     public void testIsMatching_local_noincludes() {
 344  1
         checking(new Expectations() {{
 345  1
             one (mockLocalVariable).getName();
 346  1
         }});
 347  
 
 348  1
         FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.<String>emptyList(), Collections.<String>emptyList());
 349  1
         assertFalse(sut.isMatching(mockLocalVariable));
 350  1
     }
 351  
 
 352  
     public void testIsMatching_local_badincludes() {
 353  1
         checking(new Expectations() {{
 354  1
             one (mockLocalVariable).getName();
 355  1
         }});
 356  
 
 357  1
         FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.singletonList("/some"), Collections.<String>emptyList());
 358  
         try {
 359  1
             sut.isMatching(mockLocalVariable);
 360  0
             fail("did not throw expection for bad excludes regular expression");
 361  1
         } catch (MalformedCachePatternException ex) {
 362  
             // expected
 363  0
         }
 364  1
     }
 365  
 
 366  
     public void testIsMatching_local_matchingexcludes() {
 367  1
         checking(new Expectations() {{
 368  1
             one (mockLocalVariable).getName();
 369  1
             will(returnValue(SOME_LOCAL_VARIABLE_NAME));
 370  1
         }});
 371  
 
 372  1
         FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.singletonList("//"), Collections.singletonList("/some/"));
 373  1
         assertFalse(sut.isMatching(mockLocalVariable));
 374  1
     }
 375  
 
 376  
     public void testIsMatching_local_notmatchingexcludes() {
 377  1
         checking(new Expectations() {{
 378  1
             one (mockLocalVariable).getName();
 379  1
             will(returnValue(ANOTHER_LOCAL_VARIABLE_NAME));
 380  1
             one (mockStrategy).isMatching(mockLocalVariable);
 381  1
         }});
 382  
 
 383  1
         FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.singletonList("//"), Collections.singletonList("/some/"));
 384  1
         sut.isMatching(mockLocalVariable);
 385  1
     }
 386  
 
 387  
     public void testIsMatching_local_badexcludes() {
 388  1
         checking(new Expectations() {{
 389  1
             one (mockLocalVariable).getName();
 390  1
         }});
 391  
 
 392  1
         FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.singletonList("//"), Collections.singletonList("/some"));
 393  
         try {
 394  1
             sut.isMatching(mockLocalVariable);
 395  0
             fail("did not throw expection for bad includes regular expression");
 396  1
         } catch (MalformedCachePatternException ex) {
 397  
             // expected
 398  0
         }
 399  1
     }
 400  
 }