-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test for types and converters in inner classes
- Loading branch information
1 parent
a6192e6
commit c8f7167
Showing
2 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
...androidTest/Java/org/greenrobot/greendao/test/entityannotation/TypesInInnerClassTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<TypesInInnerClassDao, TypesInInnerClass> { | ||
|
||
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); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
...tation/src/main/java/org/greenrobot/greendao/test/entityannotation/TypesInInnerClass.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<MyInnerType, Long> { | ||
|
||
@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() { | ||
} | ||
|
||
} |