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 org.jmock.integration.junit3.*; |
36 | import org.jmock.*; |
37 | |
38 | public class TestFinalMethodOrClassSymbolGathererStrategy extends MockObjectTestCase { |
39 | private FinalMethodOrClassSymbolGathererStrategy sut; |
40 | |
41 | protected void setUp() throws Exception { |
42 | super.setUp(); |
43 | |
44 | sut = new FinalMethodOrClassSymbolGathererStrategy(); |
45 | } |
46 | |
47 | public void testIsMatching_class_notfinal() { |
48 | final Classfile mockClassfile = mock(Classfile.class); |
49 | |
50 | checking(new Expectations() {{ |
51 | one (mockClassfile).isFinal(); |
52 | will(returnValue(false)); |
53 | }}); |
54 | |
55 | assertFalse(sut.isMatching(mockClassfile)); |
56 | } |
57 | |
58 | public void testIsMatching_class_final() { |
59 | final Classfile mockClassfile = mock(Classfile.class); |
60 | |
61 | checking(new Expectations() {{ |
62 | one (mockClassfile).isFinal(); |
63 | will(returnValue(true)); |
64 | one (mockClassfile).isEnum(); |
65 | will(returnValue(false)); |
66 | one (mockClassfile).isAnonymousClass(); |
67 | will(returnValue(false)); |
68 | }}); |
69 | |
70 | assertTrue(sut.isMatching(mockClassfile)); |
71 | } |
72 | |
73 | public void testIsMatching_class_enum() { |
74 | final Classfile mockClassfile = mock(Classfile.class); |
75 | |
76 | checking(new Expectations() {{ |
77 | one (mockClassfile).isFinal(); |
78 | will(returnValue(true)); |
79 | one (mockClassfile).isEnum(); |
80 | will(returnValue(true)); |
81 | }}); |
82 | |
83 | assertFalse(sut.isMatching(mockClassfile)); |
84 | } |
85 | |
86 | public void testIsMatching_class_anonymous() { |
87 | final Classfile mockClassfile = mock(Classfile.class); |
88 | |
89 | checking(new Expectations() {{ |
90 | one (mockClassfile).isFinal(); |
91 | will(returnValue(true)); |
92 | one (mockClassfile).isEnum(); |
93 | will(returnValue(false)); |
94 | one (mockClassfile).isAnonymousClass(); |
95 | will(returnValue(true)); |
96 | }}); |
97 | |
98 | assertFalse(sut.isMatching(mockClassfile)); |
99 | } |
100 | |
101 | public void testIsMatching_field() { |
102 | final Field_info mockField = mock(Field_info.class); |
103 | assertFalse(sut.isMatching(mockField)); |
104 | } |
105 | |
106 | public void testIsMatching_method_notfinal() { |
107 | final Method_info mockMethod = mock(Method_info.class); |
108 | |
109 | checking(new Expectations() {{ |
110 | one (mockMethod).isFinal(); |
111 | will(returnValue(false)); |
112 | }}); |
113 | |
114 | assertFalse(sut.isMatching(mockMethod)); |
115 | } |
116 | |
117 | public void testIsMatching_method_final() { |
118 | final Method_info mockMethod = mock(Method_info.class); |
119 | |
120 | checking(new Expectations() {{ |
121 | one (mockMethod).isFinal(); |
122 | will(returnValue(true)); |
123 | }}); |
124 | |
125 | assertTrue(sut.isMatching(mockMethod)); |
126 | } |
127 | |
128 | public void testIsMatching_local() { |
129 | final LocalVariable mockLocalVariable = mock(LocalVariable.class); |
130 | assertFalse(sut.isMatching(mockLocalVariable)); |
131 | } |
132 | } |