Polish whitespace for conversion service packages

This commit is contained in:
Phillip Webb 2012-10-26 14:09:26 -07:00
parent 61186b0b56
commit 01272fb0e6
27 changed files with 127 additions and 125 deletions

View File

@ -35,7 +35,7 @@ abstract class AbstractDescriptor {
Assert.notNull(type, "Type must not be null");
this.type = type;
}
public Class<?> getType() {
return this.type;
@ -48,13 +48,13 @@ abstract class AbstractDescriptor {
}
else if (isArray()) {
Class<?> elementType = getType().getComponentType();
return new TypeDescriptor(nested(elementType, 0));
return new TypeDescriptor(nested(elementType, 0));
}
else {
return null;
}
}
public TypeDescriptor getMapKeyTypeDescriptor() {
if (isMap()) {
Class<?> keyType = resolveMapKeyType();
@ -64,7 +64,7 @@ abstract class AbstractDescriptor {
return null;
}
}
public TypeDescriptor getMapValueTypeDescriptor() {
if (isMap()) {
Class<?> valueType = resolveMapValueType();
@ -96,33 +96,33 @@ abstract class AbstractDescriptor {
throw new IllegalStateException("Not a collection, array, or map: cannot resolve nested value types");
}
}
// subclassing hooks
public abstract Annotation[] getAnnotations();
protected abstract Class<?> resolveCollectionElementType();
protected abstract Class<?> resolveMapKeyType();
protected abstract Class<?> resolveMapValueType();
protected abstract AbstractDescriptor nested(Class<?> type, int typeIndex);
// internal helpers
private boolean isCollection() {
return Collection.class.isAssignableFrom(getType());
}
private boolean isArray() {
return getType().isArray();
}
private boolean isMap() {
return Map.class.isAssignableFrom(getType());
}
}

View File

@ -29,9 +29,9 @@ class BeanPropertyDescriptor extends AbstractDescriptor {
private final Property property;
private final MethodParameter methodParameter;
private final Annotation[] annotations;
public BeanPropertyDescriptor(Property property) {
super(property.getType());
@ -45,7 +45,7 @@ class BeanPropertyDescriptor extends AbstractDescriptor {
public Annotation[] getAnnotations() {
return this.annotations;
}
@Override
protected Class<?> resolveCollectionElementType() {
return GenericCollectionTypeResolver.getCollectionParameterType(this.methodParameter);
@ -65,10 +65,10 @@ class BeanPropertyDescriptor extends AbstractDescriptor {
protected AbstractDescriptor nested(Class<?> type, int typeIndex) {
MethodParameter methodParameter = new MethodParameter(this.methodParameter);
methodParameter.increaseNestingLevel();
methodParameter.setTypeIndexForCurrentLevel(typeIndex);
methodParameter.setTypeIndexForCurrentLevel(typeIndex);
return new BeanPropertyDescriptor(type, this.property, methodParameter, this.annotations);
}
// internal
@ -78,5 +78,5 @@ class BeanPropertyDescriptor extends AbstractDescriptor {
this.methodParameter = methodParameter;
this.annotations = annotations;
}
}

View File

@ -52,5 +52,5 @@ class ClassDescriptor extends AbstractDescriptor {
protected AbstractDescriptor nested(Class<?> type, int typeIndex) {
return new ClassDescriptor(type);
}
}

View File

@ -22,7 +22,7 @@ import org.springframework.core.NestedRuntimeException;
* Base class for exceptions thrown by the conversion system.
*
* @author Keith Donald
* @since 3.0
* @since 3.0
*/
@SuppressWarnings("serial")
public abstract class ConversionException extends NestedRuntimeException {

View File

@ -63,7 +63,7 @@ public interface ConversionService {
* @throws IllegalArgumentException if targetType is null
*/
<T> T convert(Object source, Class<T> targetType);
/**
* Convert the source to targetType.
* The TypeDescriptors provide additional context about the source and target locations where conversion will occur, often object fields or property locations.
@ -77,4 +77,4 @@ public interface ConversionService {
*/
Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType);
}
}

View File

@ -55,7 +55,7 @@ class FieldDescriptor extends AbstractDescriptor {
public Annotation[] getAnnotations() {
return TypeDescriptor.nullSafeAnnotations(this.field.getAnnotations());
}
@Override
protected Class<?> resolveCollectionElementType() {
return GenericCollectionTypeResolver.getCollectionFieldType(this.field, this.nestingLevel, this.typeIndexesPerLevel);

View File

@ -34,7 +34,7 @@ class ParameterDescriptor extends AbstractDescriptor {
super(methodParameter.getParameterType());
if (methodParameter.getNestingLevel() != 1) {
throw new IllegalArgumentException("MethodParameter argument must have its nestingLevel set to 1");
}
}
this.methodParameter = methodParameter;
}
@ -53,7 +53,7 @@ class ParameterDescriptor extends AbstractDescriptor {
return TypeDescriptor.nullSafeAnnotations(this.methodParameter.getParameterAnnotations());
}
}
@Override
protected Class<?> resolveCollectionElementType() {
return GenericCollectionTypeResolver.getCollectionParameterType(this.methodParameter);

View File

@ -50,7 +50,7 @@ public final class Property {
private final Method writeMethod;
private final String name;
private final MethodParameter methodParameter;
private final Annotation[] annotations;
@ -112,7 +112,7 @@ public final class Property {
// package private
MethodParameter getMethodParameter() {
return this.methodParameter;
}
@ -123,7 +123,7 @@ public final class Property {
// internal helpers
private String resolveName() {
if (this.readMethod != null) {
int index = this.readMethod.getName().indexOf("get");
@ -166,27 +166,27 @@ public final class Property {
}
return write;
}
private MethodParameter resolveReadMethodParameter() {
if (getReadMethod() == null) {
return null;
}
return resolveParameterType(new MethodParameter(getReadMethod(), -1));
return resolveParameterType(new MethodParameter(getReadMethod(), -1));
}
private MethodParameter resolveWriteMethodParameter() {
if (getWriteMethod() == null) {
return null;
}
return resolveParameterType(new MethodParameter(getWriteMethod(), 0));
return resolveParameterType(new MethodParameter(getWriteMethod(), 0));
}
private MethodParameter resolveParameterType(MethodParameter parameter) {
// needed to resolve generic property types that parameterized by sub-classes e.g. T getFoo();
GenericTypeResolver.resolveParameterType(parameter, getObjectType());
return parameter;
return parameter;
}
private Annotation[] resolveAnnotations() {
Map<Class<?>, Annotation> annMap = new LinkedHashMap<Class<?>, Annotation>();
Method readMethod = getReadMethod();
@ -238,4 +238,4 @@ public final class Property {
}
}
}
}

View File

@ -47,5 +47,5 @@ public interface ConditionalGenericConverter extends GenericConverter {
* @return true if conversion should be performed, false otherwise
*/
boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType);
}

View File

@ -21,6 +21,8 @@ package org.springframework.core.convert.converter;
* Implementations of this interface are thread-safe and can be shared.
*
* @author Keith Donald
* @param <S> The source type
* @param <T> The target type
* @since 3.0
*/
public interface Converter<S, T> {

View File

@ -20,7 +20,7 @@ package org.springframework.core.convert.converter;
* A factory for "ranged" converters that can convert objects from S to subtypes of R.
*
* @author Keith Donald
* @since 3.0
* @since 3.0
* @param <S> The source type converters created by this factory can convert from
* @param <R> The target range (or base) type converters created by this factory can convert to;
* for example {@link Number} for a set of number subtypes.

View File

@ -24,7 +24,7 @@ package org.springframework.core.convert.converter;
* @since 3.0
*/
public interface ConverterRegistry {
/**
* Add a plain converter to this registry.
* The convertible sourceType/targetType pair is derived from the Converter's parameterized types.
@ -44,11 +44,11 @@ public interface ConverterRegistry {
* Add a generic converter to this registry.
*/
void addConverter(GenericConverter converter);
/**
* Add a ranged converter factory to this registry.
* The convertible sourceType/rangeType pair is derived from the ConverterFactory's parameterized types.
* @throws IllegalArgumentException if the parameterized types could not be resolved.
* @throws IllegalArgumentException if the parameterized types could not be resolved.
*/
void addConverterFactory(ConverterFactory<?, ?> converterFactory);

View File

@ -27,8 +27,8 @@ import org.springframework.util.ObjectUtils;
/**
* Converts an Array to another Array.
* First adapts the source array to a List, then delegates to {@link CollectionToArrayConverter} to perform the target array conversion.
*
* First adapts the source array to a List, then delegates to {@link CollectionToArrayConverter} to perform the target array conversion.
*
* @author Keith Donald
* @since 3.0
*/
@ -48,7 +48,7 @@ final class ArrayToArrayConverter implements ConditionalGenericConverter {
return this.helperConverter.matches(sourceType, targetType);
}
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
return this.helperConverter.convert(Arrays.asList(ObjectUtils.toObjectArray(source)), sourceType, targetType);
}

View File

@ -32,7 +32,7 @@ import org.springframework.core.convert.converter.ConditionalGenericConverter;
* <p>First, creates a new Collection of the requested targetType.
* Then adds each array element to the target collection.
* Will perform an element conversion from the source component type to the collection's parameterized type if necessary.
*
*
* @author Keith Donald
* @since 3.0
*/
@ -57,7 +57,7 @@ final class ArrayToCollectionConverter implements ConditionalGenericConverter {
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
if (source == null) {
return null;
}
}
int length = Array.getLength(source);
Collection<Object> target = CollectionFactory.createCollection(targetType.getType(), length);
if (targetType.getElementTypeDescriptor() == null) {
@ -73,7 +73,7 @@ final class ArrayToCollectionConverter implements ConditionalGenericConverter {
sourceType.elementTypeDescriptor(sourceElement), targetType.getElementTypeDescriptor());
target.add(targetElement);
}
}
}
return target;
}

View File

@ -26,7 +26,7 @@ import org.springframework.core.convert.converter.ConditionalGenericConverter;
/**
* Converts an Array to an Object by returning the first array element after converting it to the desired targetType.
*
*
* @author Keith Donald
* @since 3.0
*/

View File

@ -28,7 +28,7 @@ import org.springframework.util.ObjectUtils;
/**
* Converts an Array to a comma-delimited String.
* This implementation first adapts the source Array to a List, then delegates to {@link CollectionToStringConverter} to perform the target String conversion.
*
*
* @author Keith Donald
* @since 3.0
*/

View File

@ -36,7 +36,7 @@ import org.springframework.util.NumberUtils;
* @see java.lang.Float
* @see java.lang.Double
* @see java.math.BigDecimal
* @see NumberUtils
* @see NumberUtils
*/
final class CharacterToNumberFactory implements ConverterFactory<Character, Number> {
@ -47,11 +47,11 @@ final class CharacterToNumberFactory implements ConverterFactory<Character, Numb
private static final class CharacterToNumber<T extends Number> implements Converter<Character, T> {
private final Class<T> targetType;
public CharacterToNumber(Class<T> targetType) {
this.targetType = targetType;
}
public T convert(Character source) {
return NumberUtils.convertNumberToTargetClass((short) source.charValue(), this.targetType);
}

View File

@ -61,4 +61,4 @@ final class CollectionToObjectConverter implements ConditionalGenericConverter {
return this.conversionService.convert(firstElement, sourceType.elementTypeDescriptor(firstElement), targetType);
}
}
}

View File

@ -49,4 +49,4 @@ final class FallbackObjectToStringConverter implements ConditionalGenericConvert
return (source != null ? source.toString() : null);
}
}
}

View File

@ -102,7 +102,7 @@ public class GenericConversionService implements ConfigurableConversionService {
GenericConverter.ConvertiblePair typeInfo = new GenericConverter.ConvertiblePair(sourceType, targetType);
addConverter(new ConverterAdapter(typeInfo, converter));
}
public void addConverter(GenericConverter converter) {
Set<GenericConverter.ConvertiblePair> convertibleTypes = converter.getConvertibleTypes();
for (GenericConverter.ConvertiblePair convertibleType : convertibleTypes) {
@ -119,7 +119,7 @@ public class GenericConversionService implements ConfigurableConversionService {
}
addConverter(new ConverterFactoryAdapter(typeInfo, converterFactory));
}
public void removeConvertible(Class<?> sourceType, Class<?> targetType) {
getSourceConverterMap(sourceType).remove(targetType);
invalidateCache();
@ -131,7 +131,7 @@ public class GenericConversionService implements ConfigurableConversionService {
public boolean canConvert(Class<?> sourceType, Class<?> targetType) {
if (targetType == null) {
throw new IllegalArgumentException("The targetType to convert to cannot be null");
}
}
return canConvert(sourceType != null ? TypeDescriptor.valueOf(sourceType) : null, TypeDescriptor.valueOf(targetType));
}
@ -150,7 +150,7 @@ public class GenericConversionService implements ConfigurableConversionService {
public <T> T convert(Object source, Class<T> targetType) {
if (targetType == null) {
throw new IllegalArgumentException("The targetType to convert to cannot be null");
}
}
return (T) convert(source, TypeDescriptor.forObject(source), TypeDescriptor.valueOf(targetType));
}
@ -172,7 +172,7 @@ public class GenericConversionService implements ConfigurableConversionService {
return handleResult(sourceType, targetType, result);
}
else {
return handleConverterNotFound(source, sourceType, targetType);
return handleConverterNotFound(source, sourceType, targetType);
}
}
@ -189,7 +189,7 @@ public class GenericConversionService implements ConfigurableConversionService {
public Object convert(Object source, TypeDescriptor targetType) {
return convert(source, TypeDescriptor.forObject(source), targetType);
}
public String toString() {
List<String> converterStrings = new ArrayList<String>();
for (Map<Class<?>, MatchableConverters> targetConverters : this.converters.values()) {
@ -203,7 +203,7 @@ public class GenericConversionService implements ConfigurableConversionService {
for (String converterString : converterStrings) {
builder.append("\t");
builder.append(converterString);
builder.append("\n");
builder.append("\n");
}
return builder.toString();
}
@ -243,7 +243,7 @@ public class GenericConversionService implements ConfigurableConversionService {
else {
converter = findConverterForClassPair(sourceType, targetType);
if (converter == null) {
converter = getDefaultConverter(sourceType, targetType);
converter = getDefaultConverter(sourceType, targetType);
}
if (converter != null) {
this.converterCache.put(key, converter);
@ -285,7 +285,7 @@ public class GenericConversionService implements ConfigurableConversionService {
}
return matchable;
}
private void invalidateCache() {
this.converterCache.clear();
}
@ -366,7 +366,7 @@ public class GenericConversionService implements ConfigurableConversionService {
}
}
Map<Class<?>, MatchableConverters> objectConverters = getTargetConvertersForSource(Object.class);
return getMatchingConverterForTarget(sourceType, targetType, objectConverters);
return getMatchingConverterForTarget(sourceType, targetType, objectConverters);
}
}
@ -473,9 +473,9 @@ public class GenericConversionService implements ConfigurableConversionService {
}
else {
throw new ConverterNotFoundException(sourceType, targetType);
}
}
}
private Object handleResult(TypeDescriptor sourceType, TypeDescriptor targetType, Object result) {
if (result == null) {
assertNotPrimitiveTargetType(sourceType, targetType);
@ -486,9 +486,9 @@ public class GenericConversionService implements ConfigurableConversionService {
if (targetType.isPrimitive()) {
throw new ConversionFailedException(sourceType, targetType, null,
new IllegalArgumentException("A null value cannot be assigned to a primitive type"));
}
}
}
@SuppressWarnings("unchecked")
private final class ConverterAdapter implements GenericConverter {
@ -516,7 +516,7 @@ public class GenericConversionService implements ConfigurableConversionService {
}
return this.converter.convert(source);
}
public String toString() {
return this.typeInfo.getSourceType().getName() + " -> " + this.typeInfo.getTargetType().getName() +
" : " + this.converter.toString();
@ -613,14 +613,14 @@ public class GenericConversionService implements ConfigurableConversionService {
private static final class ConverterCacheKey {
private final TypeDescriptor sourceType;
private final TypeDescriptor targetType;
public ConverterCacheKey(TypeDescriptor sourceType, TypeDescriptor targetType) {
this.sourceType = sourceType;
this.targetType = targetType;
}
public boolean equals(Object other) {
if (this == other) {
return true;
@ -631,11 +631,11 @@ public class GenericConversionService implements ConfigurableConversionService {
ConverterCacheKey otherKey = (ConverterCacheKey) other;
return this.sourceType.equals(otherKey.sourceType) && this.targetType.equals(otherKey.targetType);
}
public int hashCode() {
return this.sourceType.hashCode() * 29 + this.targetType.hashCode();
}
public String toString() {
return "ConverterCacheKey [sourceType = " + this.sourceType + ", targetType = " + this.targetType + "]";
}

View File

@ -84,7 +84,7 @@ final class ObjectToObjectConverter implements ConditionalGenericConverter {
private static Method getValueOfMethodOn(Class<?> clazz, Class<?> sourceParameterType) {
return ClassUtils.getStaticMethod(clazz, "valueOf", sourceParameterType);
}
private static Constructor<?> getConstructor(Class<?> clazz, Class<?> sourceParameterType) {
return ClassUtils.getConstructorIfAvailable(clazz, sourceParameterType);
}

View File

@ -28,7 +28,7 @@ import org.springframework.util.StringUtils;
/**
* Converts a comma-delimited String to an Array.
* Only matches if String.class can be converted to the target array element type.
*
*
* @author Keith Donald
* @since 3.0
*/
@ -47,11 +47,11 @@ final class StringToArrayConverter implements ConditionalGenericConverter {
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
return this.conversionService.canConvert(sourceType, targetType.getElementTypeDescriptor());
}
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
if (source == null) {
return null;
}
}
String string = (String) source;
String[] fields = StringUtils.commaDelimitedListToStringArray(string);
Object target = Array.newInstance(targetType.getElementTypeDescriptor().getType(), fields.length);
@ -63,4 +63,4 @@ final class StringToArrayConverter implements ConditionalGenericConverter {
return target;
}
}
}

View File

@ -45,7 +45,7 @@ final class StringToBooleanConverter implements Converter<String, Boolean> {
falseValues.add("no");
falseValues.add("0");
}
public Boolean convert(String source) {
String value = source.trim();
if ("".equals(value)) {

View File

@ -54,7 +54,7 @@ final class StringToCollectionConverter implements ConditionalGenericConverter {
}
@SuppressWarnings("unchecked")
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
if (source == null) {
return null;
}
@ -64,14 +64,14 @@ final class StringToCollectionConverter implements ConditionalGenericConverter {
if (targetType.getElementTypeDescriptor() == null) {
for (String field : fields) {
target.add(field.trim());
}
}
} else {
for (String field : fields) {
Object targetElement = this.conversionService.convert(field.trim(), sourceType, targetType.getElementTypeDescriptor());
target.add(targetElement);
}
}
}
return target;
}
}
}

View File

@ -24,7 +24,7 @@ import org.springframework.core.convert.converter.Converter;
/**
* Converts a String to a Properties by calling Properties#load(java.io.InputStream).
* Uses ISO-8559-1 encoding required by Properties.
*
*
* @author Keith Donald
* @since 3.0
*/

View File

@ -68,13 +68,13 @@ public class CollectionToCollectionConverterTests {
}
conversionService.addConverterFactory(new StringToNumberConverterFactory());
assertTrue(conversionService.canConvert(sourceType, targetType));
@SuppressWarnings("unchecked")
@SuppressWarnings("unchecked")
List<String> result = (List<String>) conversionService.convert(list, sourceType, targetType);
assertFalse(list.equals(result));
assertEquals((Integer) 9, result.get(0));
assertEquals((Integer) 37, result.get(1));
}
public ArrayList<Integer> scalarListTarget;
@Test
@ -148,7 +148,7 @@ public class CollectionToCollectionConverterTests {
}
public List<List<List<Integer>>> objectToCollection;
@Test
@SuppressWarnings("unchecked")
public void stringToCollection() throws Exception {
@ -157,7 +157,7 @@ public class CollectionToCollectionConverterTests {
list.add(Arrays.asList("37,23"));
conversionService.addConverterFactory(new StringToNumberConverterFactory());
conversionService.addConverter(new StringToCollectionConverter(conversionService));
conversionService.addConverter(new ObjectToCollectionConverter(conversionService));
conversionService.addConverter(new ObjectToCollectionConverter(conversionService));
conversionService.addConverter(new CollectionToObjectConverter(conversionService));
TypeDescriptor sourceType = TypeDescriptor.forObject(list);
TypeDescriptor targetType = new TypeDescriptor(getClass().getField("objectToCollection"));
@ -204,10 +204,10 @@ public class CollectionToCollectionConverterTests {
List<String> resources = new ArrayList<String>();
resources.add(null);
resources.add(null);
TypeDescriptor sourceType = new TypeDescriptor(getClass().getField("strings"));
TypeDescriptor sourceType = new TypeDescriptor(getClass().getField("strings"));
assertEquals(resources, conversionService.convert(resources, sourceType, new TypeDescriptor(getClass().getField("resources"))));
}
public List<String> strings;
@Test(expected=ConversionFailedException.class)
@ -271,9 +271,9 @@ public class CollectionToCollectionConverterTests {
return null;
}
}
public static class TestResource extends BaseResource {
}
@Test

View File

@ -60,7 +60,7 @@ public class DefaultConversionTests {
public void testStringToCharacter() {
assertEquals(Character.valueOf('1'), conversionService.convert("1", Character.class));
}
@Test
public void testStringToCharacterEmptyString() {
assertEquals(null, conversionService.convert("", Character.class));
@ -208,7 +208,7 @@ public class DefaultConversionTests {
public void testStringToEnum() throws Exception {
assertEquals(Foo.BAR, conversionService.convert("BAR", Foo.class));
}
@Test
public void testStringToEnumEmptyString() {
assertEquals(null, conversionService.convert("", Foo.class));
@ -233,12 +233,12 @@ public class DefaultConversionTests {
String str = "test";
assertSame(str, conversionService.convert(str, String.class));
}
@Test
public void testNumberToNumber() {
assertEquals(Long.valueOf(1), conversionService.convert(Integer.valueOf(1), Long.class));
}
@Test(expected=ConversionFailedException.class)
public void testNumberToNumberNotSupportedNumber() {
conversionService.convert(Integer.valueOf(1), CustomNumber.class);
@ -265,9 +265,9 @@ public class DefaultConversionTests {
public long longValue() {
return 0;
}
}
@Test
public void testNumberToCharacter() {
assertEquals(Character.valueOf('A'), conversionService.convert(Integer.valueOf(65), Character.class));
@ -312,11 +312,11 @@ public class DefaultConversionTests {
public class ColorConverter implements Converter<String, Color> {
public Color convert(String source) { if (!source.startsWith("#")) source = "#" + source; return Color.decode(source); }
}
public void handlerMethod(List<Color> color) {
}
@Test
public void convertArrayToCollectionImpl() {
LinkedList<?> result = conversionService.convert(new String[] { "1", "2", "3" }, LinkedList.class);
@ -333,7 +333,7 @@ public class DefaultConversionTests {
public static enum FooEnum {
BAR, BAZ
}
@Test
public void convertArrayToString() {
String result = conversionService.convert(new String[] { "1", "2", "3" }, String.class);
@ -505,7 +505,7 @@ public class DefaultConversionTests {
Object result = conversionService.convert(source, new TypeDescriptor(getClass().getField("assignableTarget")));
assertEquals(source, result);
}
@Test
public void convertObjectToCollection() {
List<String> result = (List<String>) conversionService.convert(3L, List.class);
@ -592,7 +592,7 @@ public class DefaultConversionTests {
assertEquals(new Integer(2), bar.get(1));
assertEquals(new Integer(3), bar.get(2));
}
@Test
public void collection() {
List<String> strings = new ArrayList<String>();
@ -652,7 +652,7 @@ public class DefaultConversionTests {
assertEquals("baz", result.get("bar"));
assertEquals("boop", result.get("baz"));
}
// generic object conversion
@Test
@ -664,7 +664,7 @@ public class DefaultConversionTests {
public void convertObjectToStringStringConstructorPresent() {
assertEquals("123456789", conversionService.convert(new SSN("123456789"), String.class));
}
@Test
public void convertObjectToStringNotSupported() {
assertFalse(conversionService.canConvert(TestEntity.class, String.class));
@ -685,17 +685,17 @@ public class DefaultConversionTests {
public void convertObjectToObjectNoValueOFMethodOrConstructor() {
conversionService.convert(new Long(3), SSN.class);
}
public Object assignableTarget;
private static class SSN {
private String value;
public SSN(String value) {
this.value = value;
}
public boolean equals(Object o) {
if (!(o instanceof SSN)) {
return false;
@ -703,24 +703,24 @@ public class DefaultConversionTests {
SSN ssn = (SSN) o;
return this.value.equals(ssn.value);
}
public int hashCode() {
return value.hashCode();
}
public String toString() {
return value;
}
}
private static class ISBN {
private String value;
private ISBN(String value) {
this.value = value;
}
public boolean equals(Object o) {
if (!(o instanceof ISBN)) {
return false;
@ -728,20 +728,20 @@ public class DefaultConversionTests {
ISBN isbn = (ISBN) o;
return this.value.equals(isbn.value);
}
public int hashCode() {
return value.hashCode();
}
public String toString() {
return value;
}
public static ISBN valueOf(String value) {
return new ISBN(value);
}
}
@Test
public void convertObjectToObjectFinderMethod() {
TestEntity e = conversionService.convert(1L, TestEntity.class);
@ -763,18 +763,18 @@ public class DefaultConversionTests {
public static class TestEntity {
private Long id;
public TestEntity(Long id) {
this.id = id;
}
public Long getId() {
return id;
}
public static TestEntity findTestEntity(Long id) {
return new TestEntity(id);
}
}
}