Skip to content

Commit 4d01d43

Browse files
committed
Test String to char[] conversion
Issue: SPR-9793
1 parent 05ba366 commit 4d01d43

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

spring-core/src/test/java/org/springframework/core/convert/support/DefaultConversionTests.java

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,7 +16,14 @@
1616

1717
package org.springframework.core.convert.support;
1818

19-
import static org.junit.Assert.*;
19+
import static org.hamcrest.Matchers.equalTo;
20+
import static org.junit.Assert.assertArrayEquals;
21+
import static org.junit.Assert.assertEquals;
22+
import static org.junit.Assert.assertFalse;
23+
import static org.junit.Assert.assertNull;
24+
import static org.junit.Assert.assertSame;
25+
import static org.junit.Assert.assertThat;
26+
import static org.junit.Assert.assertTrue;
2027

2128
import java.awt.Color;
2229
import java.math.BigDecimal;
@@ -773,6 +780,30 @@ public void convertObjectToObjectFinderMethodWithIdConversion() {
773780
assertEquals(new Long(1), e.getId());
774781
}
775782

783+
@Test
784+
public void convertCharArrayToString() throws Exception {
785+
String converted = conversionService.convert(new char[] { 'a', 'b', 'c' }, String.class);
786+
assertThat(converted, equalTo("a,b,c"));
787+
}
788+
789+
@Test
790+
public void convertStringToCharArray() throws Exception {
791+
char[] converted = conversionService.convert("a,b,c", char[].class);
792+
assertThat(converted, equalTo(new char[] { 'a', 'b', 'c' }));
793+
}
794+
795+
@Test
796+
public void convertStringToCustomCharArray() throws Exception {
797+
conversionService.addConverter(new Converter<String, char[]>() {
798+
@Override
799+
public char[] convert(String source) {
800+
return source.toCharArray();
801+
}
802+
});
803+
char[] converted = conversionService.convert("abc", char[].class);
804+
assertThat(converted, equalTo(new char[] { 'a', 'b', 'c' }));
805+
}
806+
776807
public static class TestEntity {
777808

778809
private Long id;

0 commit comments

Comments
 (0)