|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Capture | Line # 15 | 11 | 7 | 100% |
1.0
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (6) | |||
| Result | |||
|
1.0
|
org.easymock.tests2.CaptureTest.testCapture
org.easymock.tests2.CaptureTest.testCapture
|
1 PASS | |
|
0.5
|
org.easymock.tests.CapturesMatcherTest.test
org.easymock.tests.CapturesMatcherTest.test
|
1 PASS | |
|
0.4090909
|
org.easymock.tests2.CaptureTest.testCaptureRightOne
org.easymock.tests2.CaptureTest.testCaptureRightOne
|
1 PASS | |
|
0.3181818
|
org.easymock.tests2.CaptureTest.testPrimitive
org.easymock.tests2.CaptureTest.testPrimitive
|
1 PASS | |
|
0.3181818
|
org.easymock.tests2.CaptureTest.testPrimitiveVsObject
org.easymock.tests2.CaptureTest.testPrimitiveVsObject
|
1 PASS | |
|
0.3181818
|
org.easymock.tests2.CaptureTest.testAnd
org.easymock.tests2.CaptureTest.testAnd
|
1 PASS | |
| 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 |
public void reset() { |
| 27 | 1 | value = null; |
| 28 | 1 | captured = false; |
| 29 | } | |
| 30 | ||
| 31 | /** | |
| 32 | * @return true if something was captured | |
| 33 | */ | |
| 34 | 5 |
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 |
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 |
public void setValue(T value) { |
| 56 | 14 | this.value = value; |
| 57 | 14 | this.captured = true; |
| 58 | } | |
| 59 | ||
| 60 | 6 |
@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 | } | |
|
||||||||||