From 3bfbcd727684ab7898a6923dfa6df850270a073f Mon Sep 17 00:00:00 2001 From: Keith Donald Date: Thu, 19 Nov 2009 09:11:19 +0000 Subject: [PATCH] moved generic converter to spi; added entity converter; removed various service impls in favor of service factory --- .../convert/support/EntityConverterTests.java | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 org.springframework.core/src/test/java/org/springframework/core/convert/support/EntityConverterTests.java diff --git a/org.springframework.core/src/test/java/org/springframework/core/convert/support/EntityConverterTests.java b/org.springframework.core/src/test/java/org/springframework/core/convert/support/EntityConverterTests.java new file mode 100644 index 0000000000..96c6abd3c8 --- /dev/null +++ b/org.springframework.core/src/test/java/org/springframework/core/convert/support/EntityConverterTests.java @@ -0,0 +1,47 @@ +package org.springframework.core.convert.support; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +public class EntityConverterTests { + + private GenericConversionService conversionService = new GenericConversionService(); + + @Before + public void setUp() { + conversionService.addConverter(new ObjectToStringConverter()); + conversionService.addGenericConverter(new EntityConverter(conversionService)); + } + + @Test + public void testToEntityReference() { + conversionService.addConverterFactory(new StringToNumberConverterFactory()); + TestEntity e = conversionService.convert("1", TestEntity.class); + assertEquals(new Long(1), e.getId()); + } + + @Test + public void testToEntityId() { + String id = conversionService.convert(new TestEntity(1L), String.class); + assertEquals("1", id); + } + + public static class TestEntity { + + private Long id; + + public TestEntity(Long id) { + this.id = id; + } + + public Long getId() { + return id; + } + + public static TestEntity findTestEntity(Long id) { + return new TestEntity(id); + } + } +}