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.integration.junit3.*; |
38 | import org.jmock.*; |
39 | |
40 | public class TestFileFilteringLoadListener extends MockObjectTestCase { |
41 | private LoadListener mockDelegate; |
42 | |
43 | private List<String> includes; |
44 | private List<String> excludes; |
45 | |
46 | public LoadListener sut; |
47 | |
48 | protected void setUp() throws Exception { |
49 | super.setUp(); |
50 | |
51 | mockDelegate = mock(LoadListener.class); |
52 | |
53 | includes = new LinkedList<String>(); |
54 | excludes = new LinkedList<String>(); |
55 | |
56 | sut = new FileFilteringLoadListener(mockDelegate, includes, excludes); |
57 | } |
58 | |
59 | public void testBeginFileWithMatchingFileName() { |
60 | includes.add("/Foo/"); |
61 | final LoadEvent testEvent = new LoadEvent(this, "", "Foo.class", null); |
62 | |
63 | checking(new Expectations() {{ |
64 | one (mockDelegate).beginFile(testEvent); |
65 | }}); |
66 | |
67 | sut.beginFile(testEvent); |
68 | } |
69 | |
70 | public void testBeginFileMatchingFileNameOnSecondRE() { |
71 | includes.add("/Foo/"); |
72 | includes.add("/Bar/"); |
73 | final LoadEvent testEvent = new LoadEvent(this, "", "Bar.class", null); |
74 | |
75 | checking(new Expectations() {{ |
76 | one (mockDelegate).beginFile(testEvent); |
77 | }}); |
78 | |
79 | sut.beginFile(testEvent); |
80 | } |
81 | |
82 | public void testBeginFileNonMatchingFileName() { |
83 | includes.add("/Foo/"); |
84 | final LoadEvent testEvent = new LoadEvent(this, "", "Bar.class", null); |
85 | |
86 | checking(new Expectations() {{ |
87 | never (mockDelegate).beginFile(testEvent); |
88 | }}); |
89 | |
90 | sut.beginFile(testEvent); |
91 | } |
92 | |
93 | public void testBeginFileExcludingFileName() { |
94 | includes.add("/Foo/"); |
95 | excludes.add("/Bar/"); |
96 | final LoadEvent testEvent = new LoadEvent(this, "", "FooBar.class", null); |
97 | |
98 | checking(new Expectations() {{ |
99 | never (mockDelegate).beginFile(testEvent); |
100 | }}); |
101 | |
102 | sut.beginFile(testEvent); |
103 | } |
104 | |
105 | public void testEndFileWithMatchingFileName() { |
106 | includes.add("/Foo/"); |
107 | final LoadEvent testEvent = new LoadEvent(this, "", "Foo.class", null); |
108 | |
109 | checking(new Expectations() {{ |
110 | one (mockDelegate).endFile(testEvent); |
111 | }}); |
112 | |
113 | sut.endFile(testEvent); |
114 | } |
115 | |
116 | public void testEndFileMatchingFileNameOnSecondRE() { |
117 | includes.add("/Foo/"); |
118 | includes.add("/Bar/"); |
119 | final LoadEvent testEvent = new LoadEvent(this, "", "Bar.class", null); |
120 | |
121 | checking(new Expectations() {{ |
122 | one (mockDelegate).endFile(testEvent); |
123 | }}); |
124 | |
125 | sut.endFile(testEvent); |
126 | } |
127 | |
128 | public void testEndFileNonMatchingFileName() { |
129 | includes.add("/Foo/"); |
130 | final LoadEvent testEvent = new LoadEvent(this, "", "Bar.class", null); |
131 | |
132 | checking(new Expectations() {{ |
133 | never (mockDelegate).endFile(testEvent); |
134 | }}); |
135 | |
136 | sut.endFile(testEvent); |
137 | } |
138 | |
139 | public void testEndFileExcludingFileName() { |
140 | includes.add("/Foo/"); |
141 | excludes.add("/Bar/"); |
142 | final LoadEvent testEvent = new LoadEvent(this, "", "FooBar.class", null); |
143 | |
144 | checking(new Expectations() {{ |
145 | never (mockDelegate).endFile(testEvent); |
146 | }}); |
147 | |
148 | sut.endFile(testEvent); |
149 | } |
150 | } |