Coverage Report - com.jeantessier.classreader.TestDeprecationDetector
 
Classes in this File Line Coverage Branch Coverage Complexity
TestDeprecationDetector
100%
42/42
N/A
1
TestDeprecationDetector$1
100%
5/5
N/A
1
TestDeprecationDetector$2
100%
5/5
N/A
1
TestDeprecationDetector$3
100%
5/5
N/A
1
TestDeprecationDetector$4
100%
4/4
N/A
1
TestDeprecationDetector$5
100%
5/5
N/A
1
TestDeprecationDetector$6
100%
4/4
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;
 34  
 
 35  
 import java.util.*;
 36  
 
 37  
 import org.jmock.*;
 38  
 import org.jmock.integration.junit3.*;
 39  
 
 40  10
 public class TestDeprecationDetector extends MockObjectTestCase {
 41  
     private DeprecationDetector sut;
 42  
 
 43  
     protected void setUp() throws Exception {
 44  7
         sut = new DeprecationDetector();
 45  7
     }
 46  
 
 47  
     public void testVisitClassfile() {
 48  1
         final Classfile mockClassfile = mock(Classfile.class);
 49  1
         final Attribute_info mockAttribute = mock(Attribute_info.class);
 50  
 
 51  1
         checking(new Expectations() {{
 52  1
             one (mockClassfile).getAttributes();
 53  1
                 will(returnValue(Collections.singleton(mockAttribute)));
 54  1
             one (mockAttribute).accept(sut);
 55  1
         }});
 56  
 
 57  1
         sut.visitClassfile(mockClassfile);
 58  1
         assertFalse(sut.isDeprecated());
 59  1
     }
 60  
 
 61  
     public void testVisitField_info() {
 62  1
         final Field_info mockField = mock(Field_info.class);
 63  1
         final Attribute_info mockAttribute = mock(Attribute_info.class);
 64  
 
 65  1
         checking(new Expectations() {{
 66  1
             one (mockField).getAttributes();
 67  1
                 will(returnValue(Collections.singleton(mockAttribute)));
 68  1
             one (mockAttribute).accept(sut);
 69  1
         }});
 70  
 
 71  1
         sut.visitField_info(mockField);
 72  1
         assertFalse(sut.isDeprecated());
 73  1
     }
 74  
 
 75  
     public void testVisitMethod_info() {
 76  1
         final Method_info mockMethod = mock(Method_info.class);
 77  1
         final Attribute_info mockAttribute = mock(Attribute_info.class);
 78  
 
 79  1
         checking(new Expectations() {{
 80  1
             one (mockMethod).getAttributes();
 81  1
                 will(returnValue(Collections.singleton(mockAttribute)));
 82  1
             one (mockAttribute).accept(sut);
 83  1
         }});
 84  
 
 85  1
         sut.visitMethod_info(mockMethod);
 86  1
         assertFalse(sut.isDeprecated());
 87  1
     }
 88  
 
 89  
     public void testVisitDeprecated_attribute() {
 90  1
         Deprecated_attribute mockDeprecated = mock(Deprecated_attribute.class);
 91  1
         sut.visitDeprecated_attribute(mockDeprecated);
 92  1
         assertTrue(sut.isDeprecated());
 93  1
     }
 94  
 
 95  
     public void testVisitAnnotation_Deprecated() {
 96  1
         final Annotation mockAnnotation = mock(Annotation.class);
 97  
 
 98  1
         checking(new Expectations() {{
 99  1
             one (mockAnnotation).getType();
 100  1
                 will(returnValue(Deprecated.class.getName()));
 101  1
         }});
 102  
 
 103  1
         sut.visitAnnotation(mockAnnotation);
 104  1
         assertTrue("Should be deprecated after seeing @Deprecated", sut.isDeprecated());
 105  1
     }
 106  
 
 107  
     public void testVisitAnnotation_DeprecatedIsSticky() {
 108  1
         final Annotation mockDeprecatedAnnotation = mock(Annotation.class, "@Deprecated");
 109  1
         final Annotation mockOtherAnnotation = mock(Annotation.class);
 110  
 
 111  1
         checking(new Expectations() {{
 112  1
             one (mockDeprecatedAnnotation).getType();
 113  1
                 will(returnValue(Deprecated.class.getName()));
 114  1
             one (mockOtherAnnotation).getType();
 115  1
         }});
 116  
 
 117  1
         sut.visitAnnotation(mockDeprecatedAnnotation);
 118  1
         sut.visitAnnotation(mockOtherAnnotation);
 119  1
         assertTrue("Should be deprecated after having seen @Deprecated", sut.isDeprecated());
 120  1
     }
 121  
 
 122  
     public void testVisitAnnotation_NotDeprecated() {
 123  1
         final Annotation mockAnnotation = mock(Annotation.class);
 124  
 
 125  1
         checking(new Expectations() {{
 126  1
             one (mockAnnotation).getType();
 127  1
                 will(returnValue("abc"));
 128  1
         }});
 129  
 
 130  1
         sut.visitAnnotation(mockAnnotation);
 131  1
         assertFalse("Should not be deprecated after seeing random annotation", sut.isDeprecated());
 132  1
     }
 133  
 }