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
36   108   17   5,14
18   74   0,47   7
7     2,43  
1    
 
  Results       Line # 27 36 0% 17 0 100% 1.0
 
  (496)
 
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.io.Serializable;
20    import java.util.ArrayList;
21    import java.util.LinkedList;
22    import java.util.List;
23   
24    /**
25    * @author OFFIS, Tammo Freese
26    */
 
27    public class Results implements Serializable {
28   
29    private static final long serialVersionUID = -2722051869610289637L;
30   
31    private int callCount;
32   
33    private final LinkedList<Range> ranges = new LinkedList<Range>();
34   
35    private final List<Result> results = new ArrayList<Result>();
36   
 
37  1266 toggle public void add(final Result result, final Range range) {
38  1266 if (!ranges.isEmpty()) {
39  88 final Range lastRange = ranges.getLast();
40  88 if (!lastRange.hasFixedCount()) {
41  4 throw new RuntimeExceptionWrapper(new IllegalStateException(
42    "last method called on mock already has a non-fixed count set."));
43    }
44    }
45  1262 ranges.add(range);
46  1262 results.add(result);
47    }
48   
 
49  3358 toggle public boolean hasResults() {
50  3358 int currentPosition = 0;
51  5108 for (int i = 0; i < ranges.size(); i++) {
52  3548 final Range interval = ranges.get(i);
53  3548 if (interval.hasOpenCount()) {
54  162 return true;
55    }
56  3386 currentPosition += interval.getMaximum();
57  3386 if (currentPosition > callCount) {
58  1636 return true;
59    }
60    }
61  1560 return false;
62    }
63   
 
64  1264 toggle public Result next() {
65  1264 int currentPosition = 0;
66  1414 for (int i = 0; i < ranges.size(); i++) {
67  1412 final Range interval = ranges.get(i);
68  1412 if (interval.hasOpenCount()) {
69  100 callCount += 1;
70  100 return results.get(i);
71    }
72  1312 currentPosition += interval.getMaximum();
73  1312 if (currentPosition > callCount) {
74  1162 callCount += 1;
75  1162 return results.get(i);
76    }
77    }
78  2 return null;
79    }
80   
 
81  1748 toggle public boolean hasValidCallCount() {
82  1748 return getMainInterval().contains(getCallCount());
83    }
84   
 
85  234 toggle @Override
86    public String toString() {
87  234 return getMainInterval().expectedCount();
88    }
89   
 
90  1982 toggle private Range getMainInterval() {
91  1982 int min = 0, max = 0;
92   
93  1982 for (final Range interval : ranges) {
94  2184 min += interval.getMinimum();
95  2184 if (interval.hasOpenCount() || max == Integer.MAX_VALUE) {
96  148 max = Integer.MAX_VALUE;
97    } else {
98  2036 max += interval.getMaximum();
99    }
100    }
101   
102  1982 return new Range(min, max);
103    }
104   
 
105  1982 toggle public int getCallCount() {
106  1982 return callCount;
107    }
108    }