Coverage Report - com.jeantessier.classreader.impl.TestMethod_info
 
Classes in this File Line Coverage Branch Coverage Complexity
TestMethod_info
100%
24/24
N/A
1
TestMethod_info$1
100%
4/4
N/A
1
TestMethod_info$2
100%
5/5
N/A
1
TestMethod_info$3
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 static org.hamcrest.Matchers.*;
 38  
 import org.jmock.*;
 39  
 import org.jmock.integration.junit4.*;
 40  
 import org.jmock.lib.legacy.*;
 41  
 import static org.junit.Assert.*;
 42  
 import org.junit.*;
 43  
 import org.junit.runner.*;
 44  
 
 45  
 @RunWith(JMock.class)
 46  12
 public class TestMethod_info {
 47  
     private static final int TEST_ACCESS_FLAG = 0x0008;
 48  
     private static final int TEST_NAME_INDEX = 123;
 49  
     private static final int TEST_SIGNATURE_INDEX = 456;
 50  
     private static final int TEST_NB_ATTRIBUTES = 0;
 51  
 
 52  
     private Mockery context;
 53  
 
 54  
     private DataInput mockIn;
 55  
     private ConstantPool mockConstantPool;
 56  
 
 57  
     private Sequence dataReads;
 58  
 
 59  
     @Before
 60  
     public void setUp() {
 61  1
         context = new Mockery();
 62  1
         context.setImposteriser(ClassImposteriser.INSTANCE);
 63  
 
 64  1
         mockIn = context.mock(DataInput.class);
 65  1
         mockConstantPool = context.mock(ConstantPool.class);
 66  
 
 67  1
         dataReads = context.sequence("dataReads");
 68  1
     }
 69  
 
 70  
     @Test
 71  
     public void testDeclarationForStaticInitializer() throws IOException {
 72  1
         final Classfile mockClassfile = context.mock(Classfile.class);
 73  
 
 74  1
         context.checking(new Expectations() {{
 75  1
             allowing (mockClassfile).getConstantPool();
 76  1
                 will(returnValue(mockConstantPool));
 77  1
         }});
 78  
 
 79  1
         expectReadU2(TEST_ACCESS_FLAG);
 80  1
         expectReadU2(TEST_NAME_INDEX);
 81  1
         expectLookupUtf8(TEST_NAME_INDEX, "<clinit>", "name");
 82  1
         expectReadU2(TEST_SIGNATURE_INDEX);
 83  1
         expectLookupUtf8(TEST_SIGNATURE_INDEX, "()V", "signature");
 84  1
         expectReadU2(TEST_NB_ATTRIBUTES);
 85  
 
 86  1
         Method_info sut = new Method_info(mockClassfile, mockIn);
 87  1
         assertThat("declaration", sut.getDeclaration(), is("static {}"));
 88  1
     }
 89  
 
 90  
     protected void expectReadU2(final int i) throws IOException {
 91  4
         context.checking(new Expectations() {{
 92  4
             one (mockIn).readUnsignedShort();
 93  4
                 inSequence(dataReads);
 94  4
                 will(returnValue(i));
 95  4
         }});
 96  4
     }
 97  
 
 98  
     protected void expectLookupUtf8(int index, String value, String mockName) {
 99  2
         expectLookupUtf8(index, value, context.mock(UTF8_info.class, mockName));
 100  2
     }
 101  
 
 102  
     private void expectLookupUtf8(final int index, final String value, final UTF8_info mockUtf8_info) {
 103  2
         context.checking(new Expectations() {{
 104  2
             atLeast(1).of (mockConstantPool).get(index);
 105  2
                 will(returnValue(mockUtf8_info));
 106  2
             atLeast(1).of (mockUtf8_info).getValue();
 107  2
                 will(returnValue(value));
 108  2
         }});
 109  2
     }
 110  
 }