| Classes in this File | Line Coverage | Branch Coverage | Complexity | |||||||
| DefaultProxyMockNameResolver |
|
| 1.0;1 |
| 1 | /** |
|
| 2 | Copyright 2007 Dan Oxlade |
|
| 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 | package org.doxla.spring.automock.resolver; |
|
| 17 | ||
| 18 | import org.jmock.cglib.Mock; |
|
| 19 | ||
| 20 | /** |
|
| 21 | * The default and at time of writing only included {@link ProxyMockNameResolver}. |
|
| 22 | * Simply appends 'mock' to the beginning of the class name (without package prefix) |
|
| 23 | * for the {@link Mock} bean and camelcases the class name for the proxied object. |
|
| 24 | * |
|
| 25 | * @author danoxlade |
|
| 26 | */ |
|
| 27 | 6 | public class DefaultProxyMockNameResolver implements ProxyMockNameResolver { |
| 28 | ||
| 29 | private static final String MOCK_BEAN_PRE_NAME = "mock"; |
|
| 30 | ||
| 31 | public String proxyNameFromClass(Class clazz) { |
|
| 32 | 4 | String name = getActualClassName(clazz); |
| 33 | // camelCase |
|
| 34 | 4 | name = name.substring(0, 1).toLowerCase() + name.substring(1); |
| 35 | 4 | return name; } |
| 36 | ||
| 37 | public String mockNameFromClass(Class clazz) { |
|
| 38 | 4 | return MOCK_BEAN_PRE_NAME + getActualClassName(clazz); |
| 39 | } |
|
| 40 | ||
| 41 | private String getActualClassName(Class clazz) { |
|
| 42 | 8 | String className = clazz.getName(); |
| 43 | 8 | String packageName = clazz.getPackage().getName() + "."; |
| 44 | 8 | String name = className.replaceFirst(packageName,""); |
| 45 | 8 | return name; |
| 46 | } |
|
| 47 | } |