Clover coverage report - Dependency Finder
Coverage timestamp: Mon Nov 29 2010 15:00:50 PST
file stats: LOC: 172   Methods: 8
NCLOC: 112   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
TestLocalVariableFinder.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 java.util.*;
 36   
 37    import org.jmock.*;
 38    import org.jmock.integration.junit3.*;
 39   
 40    public class TestLocalVariableFinder extends MockObjectTestCase {
 41    private static final int LOCAL_VARIABLE_INDEX = 1;
 42    private static final int START_PC = 3;
 43    private static final int LENGTH = 5;
 44   
 45  1 public void testVisitCode_attribute() {
 46  1 final Code_attribute mockCode_attribute = mock(Code_attribute.class);
 47  1 final Attribute_info mockAttribute = mock(Attribute_info.class);
 48   
 49  1 final LocalVariableFinder sut = new LocalVariableFinder(LOCAL_VARIABLE_INDEX, START_PC + 1);
 50   
 51  1 checking(new Expectations() {{
 52  1 atLeast(1).of (mockCode_attribute).getAttributes();
 53  1 will(returnValue(Collections.singleton(mockAttribute)));
 54  1 one (mockAttribute).accept(sut);
 55    }});
 56   
 57  1 sut.visitCode_attribute(mockCode_attribute);
 58    }
 59   
 60  1 public void testVisitLocalVariable_MatchingIndexMatchingPcRange() {
 61  1 final LocalVariable mockLocalVariable = mock(LocalVariable.class);
 62   
 63  1 checking(new Expectations() {{
 64  1 one (mockLocalVariable).getIndex();
 65  1 will(returnValue(LOCAL_VARIABLE_INDEX));
 66  1 atLeast(1).of (mockLocalVariable).getStartPC();
 67  1 will(returnValue(START_PC));
 68  1 atLeast(1).of (mockLocalVariable).getLength();
 69  1 will(returnValue(LENGTH));
 70    }});
 71   
 72  1 LocalVariableFinder sut = new LocalVariableFinder(LOCAL_VARIABLE_INDEX, START_PC + 1);
 73  1 sut.visitLocalVariable(mockLocalVariable);
 74  1 assertSame(mockLocalVariable, sut.getLocalVariable());
 75    }
 76   
 77  1 public void testVisitLocalVariable_NotMatchingIndex() {
 78  1 final LocalVariable mockLocalVariable = mock(LocalVariable.class);
 79   
 80  1 checking(new Expectations() {{
 81  1 one (mockLocalVariable).getIndex();
 82  1 will(returnValue(LOCAL_VARIABLE_INDEX + 1));
 83    }});
 84   
 85  1 LocalVariableFinder sut = new LocalVariableFinder(LOCAL_VARIABLE_INDEX, START_PC);
 86  1 sut.visitLocalVariable(mockLocalVariable);
 87  1 assertNull(sut.getLocalVariable());
 88    }
 89   
 90  1 public void testVisitLocalVariable_InstructionIsBeforeValidRange() {
 91  1 final LocalVariable mockLocalVariable = mock(LocalVariable.class);
 92   
 93  1 checking(new Expectations() {{
 94  1 one (mockLocalVariable).getIndex();
 95  1 will(returnValue(LOCAL_VARIABLE_INDEX));
 96  1 one (mockLocalVariable).getStartPC();
 97  1 will(returnValue(START_PC));
 98    }});
 99   
 100  1 LocalVariableFinder sut = new LocalVariableFinder(LOCAL_VARIABLE_INDEX, START_PC - 1);
 101  1 sut.visitLocalVariable(mockLocalVariable);
 102  1 assertNull(sut.getLocalVariable());
 103    }
 104   
 105  1 public void testVisitLocalVariable_InstructionIsAtBeginningOfValidRange() {
 106  1 final LocalVariable mockLocalVariable = mock(LocalVariable.class);
 107   
 108  1 checking(new Expectations() {{
 109  1 one (mockLocalVariable).getIndex();
 110  1 will(returnValue(LOCAL_VARIABLE_INDEX));
 111  1 atLeast(1).of (mockLocalVariable).getStartPC();
 112  1 will(returnValue(START_PC));
 113  1 atLeast(1).of (mockLocalVariable).getLength();
 114  1 will(returnValue(LENGTH));
 115    }});
 116   
 117  1 LocalVariableFinder sut = new LocalVariableFinder(LOCAL_VARIABLE_INDEX, START_PC);
 118  1 sut.visitLocalVariable(mockLocalVariable);
 119  1 assertSame(mockLocalVariable, sut.getLocalVariable());
 120    }
 121   
 122  1 public void testVisitLocalVariable_InstructionIsAtBeginningOfValidRangeOfLengthZero() {
 123  1 final LocalVariable mockLocalVariable = mock(LocalVariable.class);
 124   
 125  1 checking(new Expectations() {{
 126  1 one (mockLocalVariable).getIndex();
 127  1 will(returnValue(LOCAL_VARIABLE_INDEX));
 128  1 atLeast(1).of (mockLocalVariable).getStartPC();
 129  1 will(returnValue(START_PC));
 130  1 atLeast(1).of (mockLocalVariable).getLength();
 131  1 will(returnValue(0));
 132    }});
 133   
 134  1 LocalVariableFinder sut = new LocalVariableFinder(LOCAL_VARIABLE_INDEX, START_PC);
 135  1 sut.visitLocalVariable(mockLocalVariable);
 136  1 assertSame(mockLocalVariable, sut.getLocalVariable());
 137    }
 138   
 139  1 public void testVisitLocalVariable_InstructionIsJustAfterPcRange() {
 140  1 final LocalVariable mockLocalVariable = mock(LocalVariable.class);
 141   
 142  1 checking(new Expectations() {{
 143  1 one (mockLocalVariable).getIndex();
 144  1 will(returnValue(LOCAL_VARIABLE_INDEX));
 145  1 atLeast(1).of (mockLocalVariable).getStartPC();
 146  1 will(returnValue(START_PC));
 147  1 atLeast(1).of (mockLocalVariable).getLength();
 148  1 will(returnValue(LENGTH));
 149    }});
 150   
 151  1 LocalVariableFinder sut = new LocalVariableFinder(LOCAL_VARIABLE_INDEX, START_PC + LENGTH);
 152  1 sut.visitLocalVariable(mockLocalVariable);
 153  1 assertNull(sut.getLocalVariable());
 154    }
 155   
 156  1 public void testVisitLocalVariable_InstructionIsWellAfterPcRange() {
 157  1 final LocalVariable mockLocalVariable = mock(LocalVariable.class);
 158   
 159  1 checking(new Expectations() {{
 160  1 one (mockLocalVariable).getIndex();
 161  1 will(returnValue(LOCAL_VARIABLE_INDEX));
 162  1 atLeast(1).of (mockLocalVariable).getStartPC();
 163  1 will(returnValue(START_PC));
 164  1 atLeast(1).of (mockLocalVariable).getLength();
 165  1 will(returnValue(LENGTH));
 166    }});
 167   
 168  1 LocalVariableFinder sut = new LocalVariableFinder(LOCAL_VARIABLE_INDEX, START_PC + LENGTH + 1);
 169  1 sut.visitLocalVariable(mockLocalVariable);
 170  1 assertNull(sut.getLocalVariable());
 171    }
 172    }