Add StringToUUIDConverter

Conversion to and from UUID objects is now supported by the
DefaultConversionService.

Issue: SPR-9765
This commit is contained in:
Phillip Webb
2012-10-12 14:24:07 -07:00
parent c8c0e827b4
commit 6adb49b7a9
3 changed files with 55 additions and 3 deletions

View File

@@ -16,7 +16,7 @@
package org.springframework.core.convert.support;
import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -36,8 +36,8 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.core.convert.ConversionFailedException;
import org.springframework.core.convert.ConverterNotFoundException;
@@ -382,6 +382,15 @@ public class GenericConversionServiceTests {
assertSame(value, result);
}
@Test
public void testConvertUUID() throws Exception {
GenericConversionService service = new DefaultConversionService();
UUID uuid = UUID.randomUUID();
String convertToString = service.convert(uuid, String.class);
UUID convertToUUID = service.convert(convertToString, UUID.class);
assertEquals(uuid, convertToUUID);
}
@Test
public void testPerformance1() {
GenericConversionService conversionService = new DefaultConversionService();