INT-2650 Don't Convert byte[]
The problem reported by INT-2630 was more extensive. For example, the unconditional parameter conversion causes arrays to be copied unnecessarily. The BeanFactoryTypeConverter now does a no-op conversion whenever the source type is assignable to the target type. This effectively reverts to the Spring 3.0 behavior, where this assertion resulted in the argument not being added to the argsRequiringConversion array. Polishing Add a couple more tests
This commit is contained in:
committed by
Oleg Zhurakousky
parent
d1d44305f8
commit
4eeab94d59
@@ -5,6 +5,9 @@ package org.springframework.integration.util;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -13,6 +16,7 @@ import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.MessageHeaders;
|
||||
@@ -78,4 +82,33 @@ public class BeanFactoryTypeConverterTests {
|
||||
MessageHistory history = MessageHistory.read(message);
|
||||
assertSame(history, typeConverter.convertValue(history, TypeDescriptor.valueOf(MessageHeaders.class), TypeDescriptor.valueOf(MessageHeaders.class)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testByteArrayNotConverted() {
|
||||
BeanFactoryTypeConverter typeConverter = new BeanFactoryTypeConverter();
|
||||
typeConverter.setBeanFactory(new DefaultListableBeanFactory());
|
||||
byte[] bytes = new byte[1];
|
||||
assertSame(bytes, typeConverter.convertValue(bytes, TypeDescriptor.valueOf(byte[].class), TypeDescriptor.valueOf(byte[].class)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStringToObjectNotConverted() {
|
||||
BeanFactoryTypeConverter typeConverter = new BeanFactoryTypeConverter();
|
||||
typeConverter.setBeanFactory(new DefaultListableBeanFactory());
|
||||
String string = "foo";
|
||||
assertSame(string, typeConverter.convertValue(string, TypeDescriptor.valueOf(String.class), TypeDescriptor.valueOf(Object.class)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObjectToStringIsConverted() {
|
||||
ConversionService conversionService = mock(ConversionService.class);
|
||||
when(conversionService.canConvert(any(TypeDescriptor.class), any(TypeDescriptor.class)))
|
||||
.thenReturn(true);
|
||||
when(conversionService.convert(any(), any(TypeDescriptor.class), any(TypeDescriptor.class)))
|
||||
.thenReturn("foo");
|
||||
BeanFactoryTypeConverter typeConverter = new BeanFactoryTypeConverter(conversionService);
|
||||
typeConverter.setBeanFactory(new DefaultListableBeanFactory());
|
||||
Object object = new Object();
|
||||
assertEquals("foo", typeConverter.convertValue(object, TypeDescriptor.valueOf(Object.class), TypeDescriptor.valueOf(String.class)));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user