moved generic converter to spi; added entity converter; removed various service impls in favor of service factory
parent
d85dc01e28
commit
3bfbcd7276
1 changed files with 47 additions and 0 deletions
@ -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); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue