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
21   118   16   1,5
0   76   0,76   3,5
14     1,14  
4    
 
  Result       Line # 28 9 0% 8 0 100% 1.0
  Result.ThrowingAnswer       Line # 42 2 0% 2 0 100% 1.0
  Result.ReturningAnswer       Line # 59 2 0% 2 0 100% 1.0
  Result.DelegatingAnswer       Line # 76 8 0% 4 0 100% 1.0
 
  (562)
 
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.lang.reflect.InvocationTargetException;
21    import java.lang.reflect.Method;
22   
23    import org.easymock.IAnswer;
24   
25    /**
26    * @author OFFIS, Tammo Freese
27    */
 
28    public final class Result implements IAnswer<Object>, Serializable {
29   
30    private static final long serialVersionUID = 5476251941213917681L;
31   
32    private final IAnswer<?> value;
33   
34    private final boolean shouldFillInStackTrace;
35   
 
36  1490 toggle private Result(final IAnswer<?> value, final boolean shouldFillInStackTrace) {
37  1490 this.value = value;
38  1490 this.shouldFillInStackTrace = shouldFillInStackTrace;
39    }
40   
 
41  106 toggle public static Result createThrowResult(final Throwable throwable) {
 
42    class ThrowingAnswer implements IAnswer<Object>, Serializable {
43   
44    private static final long serialVersionUID = -332797751209289222L;
45   
 
46  156 toggle public Object answer() throws Throwable {
47  156 throw throwable;
48    }
49   
 
50  2 toggle @Override
51    public String toString() {
52  2 return "Answer throwing " + throwable;
53    }
54    }
55  106 return new Result(new ThrowingAnswer(), true);
56    }
57   
 
58  1334 toggle public static Result createReturnResult(final Object value) {
 
59    class ReturningAnswer implements IAnswer<Object>, Serializable {
60   
61    private static final long serialVersionUID = 6973893913593916866L;
62   
 
63  1336 toggle public Object answer() throws Throwable {
64  1336 return value;
65    }
66   
 
67  2 toggle @Override
68    public String toString() {
69  2 return "Answer returning " + value;
70    }
71    }
72  1334 return new Result(new ReturningAnswer(), true);
73    }
74   
 
75  20 toggle public static Result createDelegatingResult(final Object value) {
 
76    class DelegatingAnswer implements IAnswer<Object>, Serializable {
77   
78    private static final long serialVersionUID = -5699326678580460103L;
79   
 
80  24 toggle public Object answer() throws Throwable {
81  24 final Invocation invocation = LastControl.getCurrentInvocation();
82  24 try {
83  24 final Method m = invocation.getMethod();
84  24 m.setAccessible(true);
85  24 return m.invoke(value, invocation.getArguments());
86    } catch (final IllegalArgumentException e) {
87  2 throw new IllegalArgumentException("Delegation to object [" + value
88    + "] is not implementing the mocked method [" + invocation.getMethod() + "]", e);
89    } catch (final InvocationTargetException e) {
90  4 throw e.getCause();
91    }
92    }
93   
 
94  2 toggle @Override
95    public String toString() {
96  2 return "Delegated to " + value;
97    }
98    }
99  20 return new Result(new DelegatingAnswer(), false);
100    }
101   
 
102  30 toggle public static Result createAnswerResult(final IAnswer<?> answer) {
103  30 return new Result(answer, false);
104    }
105   
 
106  1560 toggle public Object answer() throws Throwable {
107  1560 return value.answer();
108    }
109   
 
110  166 toggle public boolean shouldFillInStackTrace() {
111  166 return shouldFillInStackTrace;
112    }
113   
 
114  6 toggle @Override
115    public String toString() {
116  6 return value.toString();
117    }
118    }