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
29   98   12   9,67
18   48   0,41   3
3     4  
1    
2% of code in this file is excluded from these metrics.
 
  ArgumentToString       Line # 26 29 2% 12 0 100% 1.0
 
  (157)
 
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.lang.reflect.Array;
20   
21    /**
22    * Utility class to convert method arguments to Strings
23    *
24    * @author Henri Tremblay
25    */
 
26    public final class ArgumentToString {
27   
28    // ///CLOVER:OFF
 
29    toggle private ArgumentToString() {
30    }
31   
32    // ///CLOVER:ON
33   
 
34  388 toggle public static void appendArgument(final Object value, final StringBuffer buffer) {
35  388 if (value == null) {
36  10 buffer.append("null");
37  378 } else if (value instanceof String) {
38  140 buffer.append("\"");
39  140 buffer.append(value);
40  140 buffer.append("\"");
41  238 } else if (value instanceof Character) {
42  6 buffer.append("'");
43  6 buffer.append(value);
44  6 buffer.append("'");
45  232 } else if (value.getClass().isArray()) {
46  16 buffer.append("[");
47  54 for (int i = 0; i < Array.getLength(value); i++) {
48  38 if (i > 0) {
49  22 buffer.append(", ");
50    }
51  38 appendArgument(Array.get(value, i), buffer);
52    }
53  16 buffer.append("]");
54    } else {
55  216 buffer.append(value);
56    }
57    }
58   
59    /**
60    * Converts an argument to a String using
61    * {@link #appendArgument(Object, StringBuffer)}
62    *
63    * @param argument
64    * the argument to convert to a String.
65    * @return a <code>String</code> representation of the argument.
66    */
 
67  146 toggle public static String argumentToString(final Object argument) {
68  146 final StringBuffer result = new StringBuffer();
69  146 ArgumentToString.appendArgument(argument, result);
70  144 return result.toString();
71    }
72   
73    /**
74    * Returns a string representation of the arguments. This convenience
75    * implementation calls {@link #argumentToString(Object)} for every argument
76    * in the given array and returns the string representations of the
77    * arguments separated by commas.
78    *
79    * @param arguments
80    * the arguments to be used in the string representation.
81    * @return a string representation of the matcher.
82    */
 
83  202 toggle public static String argumentsToString(Object... arguments) {
84  202 if (arguments == null) {
85  2 arguments = new Object[0];
86    }
87   
88  202 final StringBuilder result = new StringBuilder();
89   
90  344 for (int i = 0; i < arguments.length; i++) {
91  144 if (i > 0) {
92  16 result.append(", ");
93    }
94  144 result.append(argumentToString(arguments[i]));
95    }
96  200 return result.toString();
97    }
98    }