Clover Coverage Report - EasyMock 3.0
Coverage timestamp: sam. mai 8 2010 14:37:27 CEST
../../../img/srcFileCovDistChart10.png 0% of files have more coverage
45   136   20   3,75
14   94   0,44   12
12     1,67  
1    
1,4% of code in this file is excluded from these metrics.
 
  LastControl       Line # 32 45 1,4% 20 0 100% 1.0
 
  (777)
 
1    /**
2    * Copyright 2001-2010 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10    * Unless required by applicable law or agreed to in writing, software
11    * distributed under the License is distributed on an "AS IS" BASIS,
12    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    * See the License for the specific language governing permissions and
14    * limitations under the License.
15    */
16   
17    package org.easymock.internal;
18   
19    import java.util.ArrayList;
20    import java.util.LinkedList;
21    import java.util.List;
22    import java.util.Stack;
23   
24    import org.easymock.IArgumentMatcher;
25    import org.easymock.internal.matchers.And;
26    import org.easymock.internal.matchers.Not;
27    import org.easymock.internal.matchers.Or;
28   
29    /**
30    * @author OFFIS, Tammo Freese
31    */
 
32    public final class LastControl {
33   
34    private static final String NO_MATCHERS_FOUND = "no matchers found.";
35   
36    private static final ThreadLocal<MocksControl> threadToControl = new ThreadLocal<MocksControl>();
37   
38    private static final ThreadLocal<Stack<Invocation>> threadToCurrentInvocation = new ThreadLocal<Stack<Invocation>>();
39   
40    private static final ThreadLocal<Stack<IArgumentMatcher>> threadToArgumentMatcherStack = new ThreadLocal<Stack<IArgumentMatcher>>();
41   
42    // ///CLOVER:OFF
 
43    toggle private LastControl() {
44    }
45   
46    // ///CLOVER:ON
47   
 
48  3378 toggle public static void reportLastControl(final MocksControl control) {
49  3378 if (control != null) {
50  1464 threadToControl.set(control);
51    } else {
52  1914 threadToControl.remove();
53    }
54    }
55   
 
56  1068 toggle public static MocksControl lastControl() {
57  1068 return threadToControl.get();
58    }
59   
 
60  532 toggle public static void reportMatcher(final IArgumentMatcher matcher) {
61  532 Stack<IArgumentMatcher> stack = threadToArgumentMatcherStack.get();
62  532 if (stack == null) {
63  418 stack = new Stack<IArgumentMatcher>();
64  418 threadToArgumentMatcherStack.set(stack);
65    }
66  532 stack.push(matcher);
67    }
68   
 
69  2260 toggle public static List<IArgumentMatcher> pullMatchers() {
70  2260 final Stack<IArgumentMatcher> stack = threadToArgumentMatcherStack.get();
71  2260 if (stack == null) {
72  1844 return null;
73    }
74  416 threadToArgumentMatcherStack.remove();
75  416 return new ArrayList<IArgumentMatcher>(stack);
76    }
77   
 
78  34 toggle public static void reportAnd(final int count) {
79  34 final Stack<IArgumentMatcher> stack = threadToArgumentMatcherStack.get();
80  34 assertState(stack != null, NO_MATCHERS_FOUND);
81  34 stack.push(new And(popLastArgumentMatchers(count)));
82    }
83   
 
84  28 toggle public static void reportNot() {
85  28 final Stack<IArgumentMatcher> stack = threadToArgumentMatcherStack.get();
86  28 assertState(stack != null, NO_MATCHERS_FOUND);
87  26 stack.push(new Not(popLastArgumentMatchers(1).get(0)));
88    }
89   
 
90  84 toggle private static List<IArgumentMatcher> popLastArgumentMatchers(final int count) {
91  84 final Stack<IArgumentMatcher> stack = threadToArgumentMatcherStack.get();
92  84 assertState(stack != null, NO_MATCHERS_FOUND);
93  84 assertState(stack.size() >= count, "" + count + " matchers expected, " + stack.size() + " recorded.");
94  82 final List<IArgumentMatcher> result = new LinkedList<IArgumentMatcher>();
95  82 result.addAll(stack.subList(stack.size() - count, stack.size()));
96  220 for (int i = 0; i < count; i++) {
97  138 stack.pop();
98    }
99  82 return result;
100    }
101   
 
102  254 toggle private static void assertState(final boolean toAssert, final String message) {
103  254 if (!toAssert) {
104  4 threadToArgumentMatcherStack.remove();
105  4 throw new IllegalStateException(message);
106    }
107    }
108   
 
109  24 toggle public static void reportOr(final int count) {
110  24 final Stack<IArgumentMatcher> stack = threadToArgumentMatcherStack.get();
111  24 assertState(stack != null, NO_MATCHERS_FOUND);
112  24 stack.push(new Or(popLastArgumentMatchers(count)));
113    }
114   
 
115  154 toggle public static Invocation getCurrentInvocation() {
116  154 final Stack<Invocation> stack = threadToCurrentInvocation.get();
117  154 if (stack == null || stack.empty()) {
118  2 return null;
119    }
120  152 return stack.lastElement();
121    }
122   
 
123  1756 toggle public static void pushCurrentInvocation(final Invocation invocation) {
124  1756 Stack<Invocation> stack = threadToCurrentInvocation.get();
125  1756 if (stack == null) {
126  48 stack = new Stack<Invocation>();
127  48 threadToCurrentInvocation.set(stack);
128    }
129  1756 stack.push(invocation);
130    }
131   
 
132  1756 toggle public static void popCurrentInvocation() {
133  1756 final Stack<Invocation> stack = threadToCurrentInvocation.get();
134  1756 stack.pop();
135    }
136    }