Clover coverage report - Dependency Finder
Coverage timestamp: Mon Nov 29 2010 15:00:50 PST
file stats: LOC: 181   Methods: 9
NCLOC: 100   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
TestSymbolGathererWithStrategy.java - 100% 100% 100%
coverage
 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 org.jmock.*;
 36    import org.jmock.integration.junit3.*;
 37   
 38    public class TestSymbolGathererWithStrategy extends MockObjectTestCase {
 39    private SymbolGathererStrategy mockStrategy;
 40   
 41    private SymbolGatherer sut;
 42   
 43  8 protected void setUp() throws Exception {
 44  8 super.setUp();
 45   
 46  8 mockStrategy = mock(SymbolGathererStrategy.class);
 47   
 48  8 sut = new SymbolGatherer(mockStrategy);
 49    }
 50   
 51  1 public void testVisitClassfile_NotMatching() {
 52  1 final Classfile mockClassfile = mock(Classfile.class);
 53   
 54  1 checking(new Expectations() {{
 55  1 one (mockStrategy).isMatching(mockClassfile); will(returnValue(false));
 56   
 57  1 one (mockClassfile).getAttributes();
 58  1 one (mockClassfile).getAllFields();
 59  1 one (mockClassfile).getAllMethods();
 60    }});
 61   
 62  1 sut.visitClassfile(mockClassfile);
 63   
 64  1 assertTrue("Added non-matching class " + sut.getCollection(), sut.getCollection().isEmpty());
 65    }
 66   
 67  1 public void testVisitClassfile_Matching() {
 68  1 final String expectedName = "Foobar";
 69   
 70  1 final Classfile mockClassfile = mock(Classfile.class);
 71   
 72  1 checking(new Expectations() {{
 73  1 one (mockStrategy).isMatching(mockClassfile); will(returnValue(true));
 74  1 one (mockClassfile).getClassName(); will(returnValue(expectedName));
 75   
 76  1 one (mockClassfile).getAttributes();
 77  1 one (mockClassfile).getAllFields();
 78  1 one (mockClassfile).getAllMethods();
 79    }});
 80   
 81  1 sut.visitClassfile(mockClassfile);
 82   
 83  1 assertEquals("Wrong size for " + sut.getCollection(), 1, sut.getCollection().size());
 84  1 assertTrue("Missing class name " + sut.getCollection(), sut.getCollection().contains(expectedName));
 85    }
 86   
 87  1 public void testVisitField_info_NotMatching() {
 88  1 final Field_info mockField = mock(Field_info.class);
 89   
 90  1 checking(new Expectations() {{
 91  1 one (mockStrategy).isMatching(mockField); will(returnValue(false));
 92   
 93  1 one (mockField).getAttributes();
 94    }});
 95   
 96  1 sut.visitField_info(mockField);
 97   
 98  1 assertTrue("Added non-matching class " + sut.getCollection(), sut.getCollection().isEmpty());
 99    }
 100   
 101  1 public void testVisitField_info_Matching() {
 102  1 final String expectedName = "Foobar.foobar";
 103   
 104  1 final Field_info mockField = mock(Field_info.class);
 105   
 106  1 checking(new Expectations() {{
 107  1 one (mockStrategy).isMatching(mockField); will(returnValue(true));
 108  1 one (mockField).getFullSignature(); will(returnValue(expectedName));
 109   
 110  1 one (mockField).getAttributes();
 111    }});
 112   
 113  1 sut.visitField_info(mockField);
 114   
 115  1 assertEquals("Wrong size for " + sut.getCollection(), 1, sut.getCollection().size());
 116  1 assertTrue("Missing class name " + sut.getCollection(), sut.getCollection().contains(expectedName));
 117    }
 118   
 119  1 public void testVisitMethod_info_NotMatching() {
 120  1 final Method_info mockMethod = mock(Method_info.class);
 121   
 122  1 checking(new Expectations() {{
 123  1 one (mockStrategy).isMatching(mockMethod); will(returnValue(false));
 124   
 125  1 one (mockMethod).getAttributes();
 126    }});
 127   
 128  1 sut.visitMethod_info(mockMethod);
 129   
 130  1 assertTrue("Added non-matching class " + sut.getCollection(), sut.getCollection().isEmpty());
 131    }
 132   
 133  1 public void testVisitMethod_info_Matching() {
 134  1 final String expectedName = "Foobar.foobar";
 135   
 136  1 final Method_info mockMethod = mock(Method_info.class);
 137   
 138  1 checking(new Expectations() {{
 139  1 one (mockStrategy).isMatching(mockMethod); will(returnValue(true));
 140  1 one (mockMethod).getFullSignature(); will(returnValue(expectedName));
 141   
 142  1 one (mockMethod).getAttributes();
 143    }});
 144   
 145  1 sut.visitMethod_info(mockMethod);
 146   
 147  1 assertEquals("Wrong size for " + sut.getCollection(), 1, sut.getCollection().size());
 148  1 assertTrue("Missing class name " + sut.getCollection(), sut.getCollection().contains(expectedName));
 149    }
 150   
 151   
 152  1 public void testVisitLocalVariable_NotMatching() {
 153  1 final LocalVariable mockLocalVariable = mock(LocalVariable.class);
 154   
 155  1 checking(new Expectations() {{
 156  1 one (mockStrategy).isMatching(mockLocalVariable); will(returnValue(false));
 157    }});
 158   
 159  1 sut.visitLocalVariable(mockLocalVariable);
 160   
 161  1 assertTrue("Added non-matching class " + sut.getCollection(), sut.getCollection().isEmpty());
 162    }
 163   
 164  1 public void testVisitLocalVariable_Matching() {
 165  1 final String expectedName = "Foobar.foobar";
 166   
 167  1 final Method_info mockMethod = mock(Method_info.class);
 168  1 final LocalVariable mockLocalVariable = mock(LocalVariable.class);
 169   
 170  1 checking(new Expectations() {{
 171  1 one (mockStrategy).isMatching(mockLocalVariable); will(returnValue(true));
 172  1 one (mockMethod).getFullSignature(); will(returnValue(expectedName));
 173  1 one (mockLocalVariable).getName(); will(returnValue(expectedName));
 174    }});
 175   
 176  1 sut.setCurrentMethodForTesting(mockMethod);
 177  1 sut.visitLocalVariable(mockLocalVariable);
 178   
 179  1 assertEquals("Wrong size for " + sut.getCollection(), 1, sut.getCollection().size());
 180    }
 181    }