Clover coverage report - Dependency Finder
Coverage timestamp: Mon Nov 29 2010 15:00:50 PST
file stats: LOC: 139   Methods: 9
NCLOC: 83   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
TestSignatureAttribute.java 75% 98% 100% 96.8%
coverage 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.io.*;
 36    import java.util.*;
 37   
 38    import junit.framework.*;
 39   
 40    public class TestSignatureAttribute extends TestCase {
 41    public static final String TEST_GENERIC_CLASS_CLASS = "testgenericclass";
 42    public static final String TEST_GENERIC_METHODS_CLASS = "testgenericmethods";
 43    public static final String TEST_GENERIC_CLASS_FILENAME = "classes" + File.separator + TEST_GENERIC_CLASS_CLASS + ".class";
 44    public static final String TEST_GENERIC_METHODS_FILENAME = "classes" + File.separator + TEST_GENERIC_METHODS_CLASS + ".class";
 45   
 46    private ClassfileLoader loader;
 47   
 48  7 protected void setUp() throws Exception {
 49  7 super.setUp();
 50   
 51  7 loader = new AggregatingClassfileLoader();
 52   
 53  7 loader.load(Collections.singleton(TEST_GENERIC_CLASS_FILENAME));
 54  7 loader.load(Collections.singleton(TEST_GENERIC_METHODS_FILENAME));
 55    }
 56   
 57  1 public void testClassDoesNotHaveSignatureAttribute() {
 58  1 Classfile nonGenericClass = loader.getClassfile(TEST_GENERIC_METHODS_CLASS);
 59   
 60  1 Signature_attribute signatureAttribute = findSingleSignatureAttribute(nonGenericClass.getAttributes());
 61  1 assertNull("Found Signature attribute: " + signatureAttribute, signatureAttribute);
 62  1 assertFalse("Classfile with Signature attribute is not generic", nonGenericClass.isGeneric());
 63    }
 64   
 65  1 public void testClassHasSignatureAttribute() {
 66  1 Classfile genericClass = loader.getClassfile(TEST_GENERIC_CLASS_CLASS);
 67   
 68  1 Signature_attribute signatureAttribute = findSingleSignatureAttribute(genericClass.getAttributes());
 69  1 assertNotNull("Signature attribute missing", signatureAttribute);
 70  1 assertEquals("Signature", "<T:Ljava/lang/Object;>Ljava/lang/Object;", signatureAttribute.getSignature());
 71  1 assertTrue("Classfile with Signature attribute is not generic", genericClass.isGeneric());
 72    }
 73   
 74  1 public void testConstructorHasSignatureAttribute() {
 75  1 Classfile genericClass = loader.getClassfile(TEST_GENERIC_CLASS_CLASS);
 76  1 Method_info method = genericClass.getMethod(TEST_GENERIC_CLASS_CLASS + "(java.lang.Object)");
 77   
 78  1 Signature_attribute signatureAttribute = findSingleSignatureAttribute(method.getAttributes());
 79  1 assertNotNull("Signature attribute missing", signatureAttribute);
 80  1 assertEquals("Signature", "(TT;)V", signatureAttribute.getSignature());
 81  1 assertTrue("Method with Signature attribute is not generic", method.isGeneric());
 82    }
 83   
 84  1 public void testGenericConstructorHasSignatureAttribute() {
 85  1 Classfile genericClass = loader.getClassfile(TEST_GENERIC_METHODS_CLASS);
 86  1 Method_info method = genericClass.getMethod(TEST_GENERIC_METHODS_CLASS + "(java.lang.Object)");
 87   
 88  1 Signature_attribute signatureAttribute = findSingleSignatureAttribute(method.getAttributes());
 89  1 assertNotNull("Signature attribute missing", signatureAttribute);
 90  1 assertEquals("Signature", "<T:Ljava/lang/Object;>(TT;)V", signatureAttribute.getSignature());
 91  1 assertTrue("Method with Signature attribute is not generic", method.isGeneric());
 92    }
 93   
 94  1 public void testMethodHasSignatureAttribute() {
 95  1 Classfile genericClass = loader.getClassfile(TEST_GENERIC_CLASS_CLASS);
 96  1 Method_info method = genericClass.getMethod("testmethod(java.lang.Object)");
 97   
 98  1 Signature_attribute signatureAttribute = findSingleSignatureAttribute(method.getAttributes());
 99  1 assertNotNull("Signature attribute missing", signatureAttribute);
 100  1 assertEquals("Signature", "(TT;)TT;", signatureAttribute.getSignature());
 101  1 assertTrue("Method with Signature attribute is not generic", method.isGeneric());
 102    }
 103   
 104  1 public void testGenericMethodHasSignatureAttribute() {
 105  1 Classfile genericClass = loader.getClassfile(TEST_GENERIC_METHODS_CLASS);
 106  1 Method_info method = genericClass.getMethod("testmethod(java.lang.Object)");
 107   
 108  1 Signature_attribute signatureAttribute = findSingleSignatureAttribute(method.getAttributes());
 109  1 assertNotNull("Signature attribute missing", signatureAttribute);
 110  1 assertEquals("Signature", "<T:Ljava/lang/Object;>(TT;)TT;", signatureAttribute.getSignature());
 111  1 assertTrue("Method with Signature attribute is not generic", method.isGeneric());
 112    }
 113   
 114  1 public void testFieldHasSignatureAttribute() {
 115  1 Classfile genericClass = loader.getClassfile(TEST_GENERIC_CLASS_CLASS);
 116  1 Field_info field = genericClass.getField("testfield");
 117   
 118  1 Signature_attribute signatureAttribute = findSingleSignatureAttribute(field.getAttributes());
 119  1 assertNotNull("Signature attribute missing", signatureAttribute);
 120  1 assertEquals("Signature", "TT;", signatureAttribute.getSignature());
 121  1 assertTrue("Field with Signature attribute is not generic", field.isGeneric());
 122    }
 123   
 124  7 private Signature_attribute findSingleSignatureAttribute(Collection<? extends Attribute_info> attributes) {
 125  7 Signature_attribute result = null;
 126   
 127  7 for (Attribute_info attribute : attributes) {
 128  14 if (attribute instanceof Signature_attribute) {
 129  6 if (result == null) {
 130  6 result = (Signature_attribute) attribute;
 131    } else {
 132  0 fail("Multiple Signature attributes");
 133    }
 134    }
 135    }
 136   
 137  7 return result;
 138    }
 139    }