Clover Coverage Report - EasyMock 2.4
Coverage timestamp: mer. juil. 2 2008 02:17:38 CEST
11   67   7   2,2
6   31   0,64   5
5     1,4  
1    
 
 
  Capture       Line # 15 11 7 100% 1.0
 
  (6)
 
1    /*
2    * Copyright (c) 2003-2008 OFFIS, Henri Tremblay.
3    * This program is made available under the terms of the MIT License.
4    */
5    package org.easymock;
6   
7    import java.io.Serializable;
8   
9    /**
10    * Will contain what was captured by the <code>capture()</code> matcher. Knows if
11    * something was captured or not (allows to capture a null value).
12    *
13    * @param <T> Type of the captured element
14    */
 
15    public class Capture<T> implements Serializable {
16   
17    private static final long serialVersionUID = -4214363692271370781L;
18   
19    private boolean captured = false;
20   
21    private T value;
22   
23    /**
24    * Will reset capture to a "nothing captured yet" state
25    */
 
26  1 toggle public void reset() {
27  1 value = null;
28  1 captured = false;
29    }
30   
31    /**
32    * @return true if something was captured
33    */
 
34  5 toggle public boolean hasCaptured() {
35  5 return captured;
36    }
37   
38    /**
39    * Return the captured value
40    *
41    * @throws AssertionError if nothing was captured yet
42    * @return What was captured
43    */
 
44  14 toggle public T getValue() {
45  14 if (!captured) {
46  2 throw new AssertionError("Nothing captured yet");
47    }
48  12 return value;
49    }
50   
51    /**
52    * Used internally by the EasyMock framework to set the captured value
53    * @param value Value captured
54    */
 
55  14 toggle public void setValue(T value) {
56  14 this.value = value;
57  14 this.captured = true;
58    }
59   
 
60  6 toggle @Override
61    public String toString() {
62  6 if (!captured) {
63  2 return "Nothing captured yet";
64    }
65  4 return value == null ? null : value.toString();
66    }
67    }