Your browser does not support JavaScript and this site utilizes JavaScript to build content and provide links to additional information. You should either enable JavaScript in your browser settings or use a browser that supports JavaScript in order to take full advantage of this site.
1 5 package org.easymock.internal; 6 7 import java.util.ArrayList ; 8 import java.util.LinkedList ; 9 import java.util.List ; 10 11 public class ResultList { 12 13 private int callCount; 14 15 private LinkedList <Range> ranges = new LinkedList <Range>(); 16 17 private List <Result> results = new ArrayList <Result>(); 18 19 void add(Result result, Range range) { 20 if (!ranges.isEmpty()) { 21 Range lastRange = ranges.getLast(); 22 if (!lastRange.hasFixedCount()) 23 throw new RuntimeExceptionWrapper( 24 new IllegalStateException ( 25 "last method called on mock already has a non-fixed count set.")); 26 } 27 ranges.add(range); 28 results.add(result); 29 } 30 31 Result next() { 32 int currentPosition = 0; 33 for (int i = 0; i < ranges.size(); i++) { 34 Range interval = ranges.get(i); 35 if (interval.hasOpenCount()) { 36 callCount += 1; 37 return getResult(i); 38 } 39 currentPosition += interval.getMaximum(); 40 if (currentPosition > callCount) { 41 callCount += 1; 42 return getResult(i); 43 } 44 } 45 return null; 46 } 47 48 private Result getResult(int i) { 49 return results.get(i); 50 } 51 52 boolean hasValidCallCount() { 53 return getMainInterval().contains(getCallCount()); 54 } 55 56 String getMessage() { 57 return getMessage(getCallCount()); 58 } 59 60 String getMessage(int count) { 61 return getMainInterval().expectedAndActual(count); 62 } 63 64 private Range getMainInterval() { 65 int min = 0; 66 int max = 0; 67 68 for (Range interval : ranges) { 69 min += interval.getMinimum(); 70 if (interval.hasOpenCount() || max == Integer.MAX_VALUE) { 71 max = Integer.MAX_VALUE; 72 } else { 73 max += interval.getMaximum(); 74 } 75 } 76 77 return new Range(min, max); 78 } 79 80 public int getCallCount() { 81 return callCount; 82 } 83 } 84
| Popular Tags
|