Coverage Report - com.jeantessier.classreader.impl.TestAttributeBase
 
Classes in this File Line Coverage Branch Coverage Complexity
TestAttributeBase
92%
74/80
N/A
1
TestAttributeBase$1
100%
5/5
N/A
1
TestAttributeBase$10
100%
6/6
N/A
1
TestAttributeBase$11
100%
6/6
N/A
1
TestAttributeBase$12
0%
0/6
N/A
1
TestAttributeBase$13
100%
6/6
N/A
1
TestAttributeBase$2
100%
5/5
N/A
1
TestAttributeBase$3
100%
5/5
N/A
1
TestAttributeBase$4
100%
4/4
N/A
1
TestAttributeBase$5
100%
5/5
N/A
1
TestAttributeBase$6
100%
6/6
N/A
1
TestAttributeBase$7
100%
8/8
N/A
1
TestAttributeBase$8
100%
6/6
N/A
1
TestAttributeBase$9
100%
6/6
N/A
1
 
 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.impl;
 34  
 
 35  
 import java.io.*;
 36  
 
 37  
 import org.jmock.*;
 38  
 import org.jmock.integration.junit3.*;
 39  
 import org.jmock.lib.legacy.*;
 40  
 
 41  
 import com.jeantessier.classreader.*;
 42  
 
 43  153
 public class TestAttributeBase extends MockObjectTestCase {
 44  
     protected Classfile mockClassfile;
 45  
     protected ConstantPool mockConstantPool;
 46  
     protected Visitable mockOwner;
 47  
     protected DataInput mockIn;
 48  
 
 49  
     protected Sequence dataReads;
 50  
 
 51  
     protected void setUp() throws Exception {
 52  153
         super.setUp();
 53  
 
 54  153
         setImposteriser(ClassImposteriser.INSTANCE);
 55  
 
 56  153
         mockClassfile = mock(Classfile.class);
 57  153
         mockConstantPool = mock(ConstantPool.class);
 58  153
         mockOwner = mock(Visitable.class);
 59  153
         mockIn = mock(DataInput.class);
 60  
 
 61  153
         dataReads = sequence("dataReads");
 62  153
     }
 63  
 
 64  
     protected void expectReadAttributeLength(final int length) throws IOException {
 65  79
         expectReadU4(length);
 66  79
     }
 67  
 
 68  
     protected void expectReadNumAnnotations(int numAnnotations) throws IOException {
 69  30
         expectReadU2(numAnnotations);
 70  30
     }
 71  
 
 72  
     protected void expectReadNumParameters(int numParameters) throws IOException {
 73  14
         expectReadU1(numParameters);
 74  14
     }
 75  
 
 76  
     protected void expectReadAnnotation(int typeIndex, int numElementValuePairs) throws IOException {
 77  11
         expectReadTypeIndex(typeIndex);
 78  11
         expectReadNumElementValuePairs(numElementValuePairs);
 79  11
     }
 80  
 
 81  
     protected void expectReadTypeIndex(int typeIndex) throws IOException {
 82  18
         expectReadU2(typeIndex);
 83  18
     }
 84  
 
 85  
     protected void expectReadNumElementValuePairs(int numElementValuePairs) throws IOException {
 86  18
         expectReadU2(numElementValuePairs);
 87  18
     }
 88  
 
 89  
     protected void expectReadU1(final int i) throws IOException {
 90  29
         checking(new Expectations() {{
 91  29
             one (mockIn).readUnsignedByte();
 92  29
                 inSequence(dataReads);
 93  29
                 will(returnValue(i));
 94  29
         }});
 95  29
     }
 96  
 
 97  
     protected void expectReadU2(final int i) throws IOException {
 98  201
         checking(new Expectations() {{
 99  201
             one (mockIn).readUnsignedShort();
 100  201
                 inSequence(dataReads);
 101  201
                 will(returnValue(i));
 102  201
         }});
 103  201
     }
 104  
 
 105  
     protected void expectReadU4(final int i) throws IOException {
 106  86
         checking(new Expectations() {{
 107  86
             one (mockIn).readInt();
 108  86
                 inSequence(dataReads);
 109  86
                 will(returnValue(i));
 110  86
         }});
 111  86
     }
 112  
 
 113  
     protected void expectReadFully() throws IOException {
 114  11
         checking(new Expectations() {{
 115  11
             one (mockIn).readFully((byte[]) with(any(Object.class)));
 116  11
                 inSequence(dataReads);
 117  11
         }});
 118  11
     }
 119  
 
 120  
     protected void expectReadUtf(final String s) throws IOException {
 121  3
         checking(new Expectations() {{
 122  3
             one (mockIn).readUTF();
 123  3
                 inSequence(dataReads);
 124  3
                 will(returnValue(s));
 125  3
         }});
 126  3
     }
 127  
 
 128  
     protected void expectLookupClass(final int index, final String value) {
 129  2
         expectLookupClass(index, value, mock(Class_info.class));
 130  2
     }
 131  
 
 132  
     protected void expectLookupClass(final int index, final String value, String mockName) {
 133  4
         expectLookupClass(index, value, mock(Class_info.class, mockName));
 134  4
     }
 135  
 
 136  
     private void expectLookupClass(final int index, final String value, final Class_info mockClass_info) {
 137  6
         checking(new Expectations() {{
 138  6
             one (mockConstantPool).get(index);
 139  6
                 will(returnValue(mockClass_info));
 140  6
             one (mockClass_info).getName();
 141  6
                 will(returnValue(value));
 142  6
         }});
 143  6
     }
 144  
 
 145  
     protected void expectLookupNameAndType(final int index, final String name, final String type) {
 146  2
         expectLookupNameAndType(index, name, type, mock(NameAndType_info.class));
 147  2
     }
 148  
 
 149  
     protected void expectLookupNameAndType(final int index, final String name, final String type, String mockName) {
 150  4
         expectLookupNameAndType(index, name, type, mock(NameAndType_info.class, mockName));
 151  4
     }
 152  
 
 153  
     private void expectLookupNameAndType(final int index, final String name, final String type, final NameAndType_info mockNameAndType_info) {
 154  6
         checking(new Expectations() {{
 155  6
             one (mockConstantPool).get(index);
 156  6
                 will(returnValue(mockNameAndType_info));
 157  6
             one (mockNameAndType_info).getName();
 158  6
                 will(returnValue(name));
 159  6
             one (mockNameAndType_info).getType();
 160  6
                 will(returnValue(type));
 161  6
         }});
 162  6
     }
 163  
 
 164  
     protected void expectLookupInteger(int index, int value) {
 165  13
         expectLookupInteger(index, value, mock(Integer_info.class));
 166  13
     }
 167  
 
 168  
     protected void expectLookupInteger(int index, int value, String mockName) {
 169  17
         expectLookupInteger(index, value, mock(Integer_info.class, mockName));
 170  17
     }
 171  
 
 172  
     private void expectLookupInteger(final int index, final int value, final Integer_info mockInteger_info) {
 173  30
         checking(new Expectations() {{
 174  30
             one (mockConstantPool).get(index);
 175  30
                 will(returnValue(mockInteger_info));
 176  30
             one (mockInteger_info).getValue();
 177  30
                 will(returnValue(value));
 178  30
         }});
 179  30
     }
 180  
 
 181  
     protected void expectLookupLong(final int index, final long value) {
 182  2
         expectLookupLong(index, value, mock(Long_info.class));
 183  2
     }
 184  
 
 185  
     protected void expectLookupLong(final int index, final long value, String mockName) {
 186  3
         expectLookupLong(index, value, mock(Long_info.class, mockName));
 187  3
     }
 188  
 
 189  
     private void expectLookupLong(final int index, final long value, final Long_info mockLong_info) {
 190  5
         checking(new Expectations() {{
 191  5
             one (mockConstantPool).get(index);
 192  5
                 will(returnValue(mockLong_info));
 193  5
             one (mockLong_info).getValue();
 194  5
                 will(returnValue(value));
 195  5
         }});
 196  5
     }
 197  
 
 198  
     protected void expectLookupFloat(final int index, final float value) {
 199  2
         expectLookupFloat(index, value, mock(Float_info.class));
 200  2
     }
 201  
 
 202  
     protected void expectLookupFloat(final int index, final float value, String mockName) {
 203  3
         expectLookupFloat(index, value, mock(Float_info.class, mockName));
 204  3
     }
 205  
 
 206  
     private void expectLookupFloat(final int index, final float value, final Float_info mockFloat_info) {
 207  5
         checking(new Expectations() {{
 208  5
             one (mockConstantPool).get(index);
 209  5
                 will(returnValue(mockFloat_info));
 210  5
             one (mockFloat_info).getValue();
 211  5
                 will(returnValue(value));
 212  5
         }});
 213  5
     }
 214  
 
 215  
     protected void expectLookupDouble(final int index, final double value) {
 216  2
         expectLookupDouble(index, value, mock(Double_info.class));
 217  2
     }
 218  
 
 219  
     protected void expectLookupDouble(final int index, final double value, String mockName) {
 220  3
         expectLookupDouble(index, value, mock(Double_info.class, mockName));
 221  3
     }
 222  
 
 223  
     private void expectLookupDouble(final int index, final double value, final Double_info mockDouble_info) {
 224  5
         checking(new Expectations() {{
 225  5
             one (mockConstantPool).get(index);
 226  5
                 will(returnValue(mockDouble_info));
 227  5
             one (mockDouble_info).getValue();
 228  5
                 will(returnValue(value));
 229  5
         }});
 230  5
     }
 231  
 
 232  
     protected void expectLookupString(final int index, final String value) {
 233  0
         expectLookupString(index, value, mock(String_info.class));
 234  0
     }
 235  
 
 236  
     protected void expectLookupString(final int index, final String value, String mockName) {
 237  0
         expectLookupString(index, value, mock(String_info.class, mockName));
 238  0
     }
 239  
 
 240  
     private void expectLookupString(final int index, final String value, final String_info mockString_info) {
 241  0
         checking(new Expectations() {{
 242  0
             one (mockConstantPool).get(index);
 243  0
                 will(returnValue(mockString_info));
 244  0
             one (mockString_info).getValue();
 245  0
                 will(returnValue(value));
 246  0
         }});
 247  0
     }
 248  
 
 249  
     protected void expectLookupUtf8(int index, String value) {
 250  22
         expectLookupUtf8(index, value, mock(UTF8_info.class));
 251  22
     }
 252  
 
 253  
     protected void expectLookupUtf8(int index, String value, String mockName) {
 254  23
         expectLookupUtf8(index, value, mock(UTF8_info.class, mockName));
 255  23
     }
 256  
 
 257  
     private void expectLookupUtf8(final int index, final String value, final UTF8_info mockUtf8_info) {
 258  45
         checking(new Expectations() {{
 259  45
             one (mockConstantPool).get(index);
 260  45
                 will(returnValue(mockUtf8_info));
 261  45
             one (mockUtf8_info).getValue();
 262  45
                 will(returnValue(value));
 263  45
         }});
 264  45
     }
 265  
 }