EasyMock 2.3

Clover coverage report - EasyMock 2.3
Coverage timestamp: mar. juil. 10 2007 02:46:04 CEST
FRAMES NO FRAMES

file stats: | LOC: | 110 |  | Methods: | 12
| NCLOC: | 89 |  | Classes: | 1

Source file | Conditionals | Statements | Methods | TOTAL

LastControl.java

100%

100%

100%

100%

1 |  | /*
2 |  | * Copyright (c) 2001-2007 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 | 1302 | public static synchronized void reportLastControl(MocksControl control) {
22 | 1302 | if (control != null) {
23 | 452 | threadToControl.set(control);
24 |  | } else {
25 | 850 | threadToControl.remove();
26 |  | }
27 |  | }
28 |  |
29 | 429 | public static synchronized MocksControl lastControl() {
30 | 429 | return threadToControl.get();
31 |  | }
32 |  |
33 | 159 | public static synchronized void reportMatcher(IArgumentMatcher matcher) {
34 | 159 | Stack<IArgumentMatcher> stack = threadToArgumentMatcherStack.get();
35 | 159 | if (stack == null) {
36 | 127 | stack = new Stack<IArgumentMatcher>();
37 | 127 | threadToArgumentMatcherStack.set(stack);
38 |  | }
39 | 159 | stack.push(matcher);
40 |  | }
41 |  |
42 | 831 | public static synchronized List<IArgumentMatcher> pullMatchers() {
43 | 831 | Stack<IArgumentMatcher> stack = threadToArgumentMatcherStack.get();
44 | 831 | if (stack == null) {
45 | 705 | return null;
46 |  | }
47 | 126 | threadToArgumentMatcherStack.remove();
48 | 126 | return new ArrayList<IArgumentMatcher>(stack);
49 |  | }
50 |  |
51 | 11 | public static synchronized void reportAnd(int count) {
52 | 11 | Stack<IArgumentMatcher> stack = threadToArgumentMatcherStack.get();
53 | 11 | assertState(stack != null, "no matchers found.");
54 | 11 | stack.push(new And(popLastArgumentMatchers(count)));
55 |  | }
56 |  |
57 | 14 | 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 | 36 | private static List<IArgumentMatcher> popLastArgumentMatchers(int count) {
64 | 36 | Stack<IArgumentMatcher> stack = threadToArgumentMatcherStack.get();
65 | 36 | assertState(stack != null, "no matchers found.");
66 | 36 | assertState(stack.size() >= count, "" + count + " matchers expected, "
67 |  | + stack.size() + " recorded.");
68 | 35 | List<IArgumentMatcher> result = new LinkedList<IArgumentMatcher>();
69 | 35 | result.addAll(stack.subList(stack.size() - count, stack.size()));
70 | 35 | for (int i = 0; i < count; i++) {
71 | 57 | stack.pop();
72 |  | }
73 | 35 | return result;
74 |  | }
75 |  |
76 | 109 | private static void assertState(boolean toAssert, String message) {
77 | 109 | if (!toAssert) {
78 | 2 | threadToArgumentMatcherStack.remove();
79 | 2 | throw new IllegalStateException(message);
80 |  | }
81 |  | }
82 |  |
83 | 12 | 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 | 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 | 522 | public static void pushCurrentArguments(Object[] args) {
98 | 522 | Stack<Object[]> stack = threadToCurrentArguments.get();
99 | 522 | if (stack == null) {
100 | 1 | stack = new Stack<Object[]>();
101 | 1 | threadToCurrentArguments.set(stack);
102 |  | }
103 | 522 | stack.push(args);
104 |  | }
105 |  |
106 | 522 | public static void popCurrentArguments() {
107 | 522 | Stack<Object[]> stack = threadToCurrentArguments.get();
108 | 522 | stack.pop();
109 |  | }
110 |  | }