From c8f71671c7f156572e4216cee72d61f88912f8e1 Mon Sep 17 00:00:00 2001 From: Markus Date: Wed, 3 Aug 2016 13:06:44 +0200 Subject: [PATCH] Test for types and converters in inner classes --- .../TypesInInnerClassTest.java | 27 ++++++++ .../entityannotation/TypesInInnerClass.java | 65 +++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 tests/DaoTestEntityAnnotation/src/androidTest/Java/org/greenrobot/greendao/test/entityannotation/TypesInInnerClassTest.java create mode 100644 tests/DaoTestEntityAnnotation/src/main/java/org/greenrobot/greendao/test/entityannotation/TypesInInnerClass.java diff --git a/tests/DaoTestEntityAnnotation/src/androidTest/Java/org/greenrobot/greendao/test/entityannotation/TypesInInnerClassTest.java b/tests/DaoTestEntityAnnotation/src/androidTest/Java/org/greenrobot/greendao/test/entityannotation/TypesInInnerClassTest.java new file mode 100644 index 000000000..cfad57acf --- /dev/null +++ b/tests/DaoTestEntityAnnotation/src/androidTest/Java/org/greenrobot/greendao/test/entityannotation/TypesInInnerClassTest.java @@ -0,0 +1,27 @@ +package org.greenrobot.greendao.test.entityannotation; + +import org.greenrobot.greendao.test.AbstractDaoTestLongPk; +import org.greenrobot.greendao.test.entityannotation.TypesInInnerClass.MyInnerType; + +public class TypesInInnerClassTest extends AbstractDaoTestLongPk { + + public TypesInInnerClassTest() { + super(TypesInInnerClassDao.class); + } + + @Override + protected TypesInInnerClass createEntity(Long key) { + TypesInInnerClass entity = new TypesInInnerClass(); + entity.setId(key); + entity.setType(new MyInnerType("cafe")); + return entity; + } + + public void testType() { + TypesInInnerClass entity = createEntity(1L); + dao.insert(entity); + TypesInInnerClass entity2 = dao.load(1L); + assertNotSame(entity, entity2); + assertEquals("cafe", entity2.getType().value); + } +} diff --git a/tests/DaoTestEntityAnnotation/src/main/java/org/greenrobot/greendao/test/entityannotation/TypesInInnerClass.java b/tests/DaoTestEntityAnnotation/src/main/java/org/greenrobot/greendao/test/entityannotation/TypesInInnerClass.java new file mode 100644 index 000000000..4a2a7f049 --- /dev/null +++ b/tests/DaoTestEntityAnnotation/src/main/java/org/greenrobot/greendao/test/entityannotation/TypesInInnerClass.java @@ -0,0 +1,65 @@ +package org.greenrobot.greendao.test.entityannotation; + +import org.greenrobot.greendao.annotation.Convert; +import org.greenrobot.greendao.annotation.Entity; +import org.greenrobot.greendao.annotation.Generated; +import org.greenrobot.greendao.annotation.Id; +import org.greenrobot.greendao.converter.PropertyConverter; + +@Entity +public class TypesInInnerClass { + static class MyInnerType { + + public MyInnerType(String value) { + this.value = value; + } + + String value; + } + + static class MyInnerTypeConverter implements PropertyConverter { + + @Override + public MyInnerType convertToEntityProperty(Long databaseValue) { + return databaseValue!=null? new MyInnerType(Long.toHexString(databaseValue)): null; + } + + @Override + public Long convertToDatabaseValue(MyInnerType entityProperty) { + return entityProperty!= null? Long.parseLong(entityProperty.value, 16): null; + } + } + + @Id + Long id; + + @Convert(converter = MyInnerTypeConverter.class, columnType = Long.class) + MyInnerType type; + + public MyInnerType getType() { + return this.type; + } + + public void setType(MyInnerType type) { + this.type = type; + } + + public Long getId() { + return this.id; + } + + public void setId(Long id) { + this.id = id; + } + + @Generated(hash = 1322981681) + public TypesInInnerClass(Long id, MyInnerType type) { + this.id = id; + this.type = type; + } + + @Generated(hash = 1754325029) + public TypesInInnerClass() { + } + +}