Clover Coverage Report - EasyMock 2.4
Coverage timestamp: mer. juil. 2 2008 02:17:38 CEST
45   110   20   3,75
14   89   0,44   12
12     1,67  
1    
 
 
  LastControl       Line # 14 45 20 100% 1.0
 
  (355)
 
1    /*
2    * Copyright (c) 2001-2008 OFFIS, Tammo Freese.
3    * This program is made available under the terms of the MIT License.
4    */
5    package org.easymock.internal;
6   
7    import java.util.*;
8   
9    import org.easymock.IArgumentMatcher;
10    import org.easymock.internal.matchers.And;
11    import org.easymock.internal.matchers.Not;
12    import org.easymock.internal.matchers.Or;
13   
 
14    public class LastControl {
15    private static final ThreadLocal<MocksControl> threadToControl = new ThreadLocal<MocksControl>();
16   
17    private static final ThreadLocal<Stack<Object[]>> threadToCurrentArguments = new ThreadLocal<Stack<Object[]>>();
18   
19    private static final ThreadLocal<Stack<IArgumentMatcher>> threadToArgumentMatcherStack = new ThreadLocal<Stack<IArgumentMatcher>>();
20   
 
21  1393 toggle public static synchronized void reportLastControl(MocksControl control) {
22  1393 if (control != null) {
23  492 threadToControl.set(control);
24    } else {
25  901 threadToControl.remove();
26    }
27    }
28   
 
29  457 toggle public static synchronized MocksControl lastControl() {
30  457 return threadToControl.get();
31    }
32   
 
33  173 toggle public static synchronized void reportMatcher(IArgumentMatcher matcher) {
34  173 Stack<IArgumentMatcher> stack = threadToArgumentMatcherStack.get();
35  173 if (stack == null) {
36  139 stack = new Stack<IArgumentMatcher>();
37  139 threadToArgumentMatcherStack.set(stack);
38    }
39  173 stack.push(matcher);
40    }
41   
 
42  894 toggle public static synchronized List<IArgumentMatcher> pullMatchers() {
43  894 Stack<IArgumentMatcher> stack = threadToArgumentMatcherStack.get();
44  894 if (stack == null) {
45  756 return null;
46    }
47  138 threadToArgumentMatcherStack.remove();
48  138 return new ArrayList<IArgumentMatcher>(stack);
49    }
50   
 
51  13 toggle public static synchronized void reportAnd(int count) {
52  13 Stack<IArgumentMatcher> stack = threadToArgumentMatcherStack.get();
53  13 assertState(stack != null, "no matchers found.");
54  13 stack.push(new And(popLastArgumentMatchers(count)));
55    }
56   
 
57  14 toggle public static synchronized void reportNot() {
58  14 Stack<IArgumentMatcher> stack = threadToArgumentMatcherStack.get();
59  14 assertState(stack != null, "no matchers found.");
60  13 stack.push(new Not(popLastArgumentMatchers(1).get(0)));
61    }
62   
 
63  38 toggle private static List<IArgumentMatcher> popLastArgumentMatchers(int count) {
64  38 Stack<IArgumentMatcher> stack = threadToArgumentMatcherStack.get();
65  38 assertState(stack != null, "no matchers found.");
66  38 assertState(stack.size() >= count, "" + count + " matchers expected, "
67    + stack.size() + " recorded.");
68  37 List<IArgumentMatcher> result = new LinkedList<IArgumentMatcher>();
69  37 result.addAll(stack.subList(stack.size() - count, stack.size()));
70  98 for (int i = 0; i < count; i++) {
71  61 stack.pop();
72    }
73  37 return result;
74    }
75   
 
76  115 toggle private static void assertState(boolean toAssert, String message) {
77  115 if (!toAssert) {
78  2 threadToArgumentMatcherStack.remove();
79  2 throw new IllegalStateException(message);
80    }
81    }
82   
 
83  12 toggle public static void reportOr(int count) {
84  12 Stack<IArgumentMatcher> stack = threadToArgumentMatcherStack.get();
85  12 assertState(stack != null, "no matchers found.");
86  12 stack.push(new Or(popLastArgumentMatchers(count)));
87    }
88   
 
89  11 toggle public static Object[] getCurrentArguments() {
90  11 Stack<Object[]> stack = threadToCurrentArguments.get();
91  11 if (stack == null || stack.empty()) {
92  1 return null;
93    }
94  10 return stack.lastElement();
95    }
96   
 
97  570 toggle public static void pushCurrentArguments(Object[] args) {
98  570 Stack<Object[]> stack = threadToCurrentArguments.get();
99  570 if (stack == null) {
100  12 stack = new Stack<Object[]>();
101  12 threadToCurrentArguments.set(stack);
102    }
103  570 stack.push(args);
104    }
105   
 
106  570 toggle public static void popCurrentArguments() {
107  570 Stack<Object[]> stack = threadToCurrentArguments.get();
108  570 stack.pop();
109    }
110    }