1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
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 | |
} |