|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2012 the original author or authors. |
| 2 | + * Copyright 2002-2013 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
16 | 16 |
|
17 | 17 | package org.springframework.core.convert.support;
|
18 | 18 |
|
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; |
20 | 27 |
|
21 | 28 | import java.awt.Color;
|
22 | 29 | import java.math.BigDecimal;
|
@@ -773,6 +780,30 @@ public void convertObjectToObjectFinderMethodWithIdConversion() {
|
773 | 780 | assertEquals(new Long(1), e.getId());
|
774 | 781 | }
|
775 | 782 |
|
| 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 | + |
776 | 807 | public static class TestEntity {
|
777 | 808 |
|
778 | 809 | private Long id;
|
|
0 commit comments