ByteBufferConverter explicitly declares applicability to byte[]

Includes an optimization for simple ByteBuffer duplication.

Issue: SPR-13056
This commit is contained in:
Juergen Hoeller
2015-05-22 11:19:17 +02:00
parent 2dc674f356
commit 792b7b9d11
2 changed files with 17 additions and 11 deletions
@@ -30,6 +30,7 @@ import static org.junit.Assert.*;
* Tests for {@link ByteBufferConverter}.
*
* @author Phillip Webb
* @author Juergen Hoeller
*/
public class ByteBufferConverterTests {
@@ -38,8 +39,7 @@ public class ByteBufferConverterTests {
@Before
public void setup() {
this.conversionService = new GenericConversionService();
this.conversionService.addConverter(new ByteBufferConverter(conversionService));
this.conversionService = new DefaultConversionService();
this.conversionService.addConverter(new ByteArrayToOtherTypeConverter());
this.conversionService.addConverter(new OtherTypeToByteArrayConverter());
}
@@ -87,6 +87,8 @@ public class ByteBufferConverterTests {
ByteBuffer convert = this.conversionService.convert(byteBuffer, ByteBuffer.class);
assertThat(convert, not(sameInstance(byteBuffer.rewind())));
assertThat(convert, equalTo(byteBuffer.rewind()));
assertThat(convert, equalTo(ByteBuffer.wrap(bytes)));
assertThat(convert.array(), equalTo(bytes));
}