-
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.
Merge remote-tracking branch 'github-team/not-null-entity-test'
- Loading branch information
Showing
2 changed files
with
190 additions
and
0 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
.../src/androidTest/Java/org/greenrobot/greendao/test/entityannotation/NotNullThingTest.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,88 @@ | ||
package org.greenrobot.greendao.test.entityannotation; | ||
|
||
import org.greenrobot.greendao.test.AbstractDaoTestLongPk; | ||
|
||
public class NotNullThingTest extends AbstractDaoTestLongPk<NotNullThingDao, NotNullThing> { | ||
|
||
public NotNullThingTest() { | ||
super(NotNullThingDao.class); | ||
} | ||
|
||
@Override | ||
protected NotNullThing createEntity(Long key) { | ||
NotNullThing thing = new NotNullThing(); | ||
thing.setId(key); | ||
thing.setNotNullBoolean(true); | ||
thing.setNotNullInteger(42); | ||
thing.setNotNullWrappedBoolean(true); | ||
thing.setNotNullWrappedInteger(42); | ||
thing.setNullableBoolean(true); | ||
thing.setNullableInteger(42); | ||
thing.setNullableWrappedBoolean(true); | ||
thing.setNullableWrappedInteger(42); | ||
return thing; | ||
} | ||
|
||
public void testInsertNotNullProperties() { | ||
NotNullThing thing = createEntity(1L); | ||
thing.setNotNullWrappedBoolean(null); | ||
thing.setNotNullWrappedInteger(null); | ||
try { | ||
dao.insert(thing); | ||
fail(); | ||
} catch (NullPointerException ignored) { | ||
} | ||
} | ||
|
||
public void testInsertNullableProperties() { | ||
NotNullThing thing = createEntity(1L); | ||
thing.setNullableWrappedBoolean(null); | ||
thing.setNullableWrappedInteger(null); | ||
dao.insert(thing); | ||
|
||
loadAndAssertNullableProperties(thing); | ||
} | ||
|
||
public void testUpdateNotNullProperties() { | ||
NotNullThing thing = insertEntity(); | ||
|
||
thing.setNotNullWrappedBoolean(null); | ||
thing.setNotNullWrappedInteger(null); | ||
try { | ||
dao.update(thing); | ||
fail(); | ||
} catch (NullPointerException ignored) { | ||
} | ||
} | ||
|
||
public void testUpdateNullableProperties() { | ||
NotNullThing thing = insertEntity(); | ||
|
||
thing.setNullableWrappedBoolean(null); | ||
thing.setNullableWrappedInteger(null); | ||
dao.update(thing); | ||
|
||
loadAndAssertNullableProperties(thing); | ||
} | ||
|
||
private NotNullThing insertEntity() { | ||
NotNullThing thing = createEntity(1L); | ||
dao.insert(thing); | ||
return thing; | ||
} | ||
|
||
private void loadAndAssertNullableProperties(NotNullThing thing) { | ||
NotNullThing loaded = dao.load(thing.getId()); | ||
assertTrue(loaded.getNullableBoolean()); | ||
assertEquals(42, loaded.getNullableInteger()); | ||
assertTrue(loaded.getNotNullBoolean()); | ||
assertEquals(42, loaded.getNotNullInteger()); | ||
|
||
assertNull(loaded.getNullableWrappedBoolean()); | ||
assertNull(loaded.getNullableWrappedInteger()); | ||
|
||
assertNotNull(loaded.getNotNullWrappedBoolean()); | ||
assertNotNull(loaded.getNotNullWrappedInteger()); | ||
} | ||
|
||
} |
102 changes: 102 additions & 0 deletions
102
...yAnnotation/src/main/java/org/greenrobot/greendao/test/entityannotation/NotNullThing.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,102 @@ | ||
package org.greenrobot.greendao.test.entityannotation; | ||
|
||
import org.greenrobot.greendao.annotation.Entity; | ||
import org.greenrobot.greendao.annotation.Generated; | ||
import org.greenrobot.greendao.annotation.Id; | ||
import org.greenrobot.greendao.annotation.NotNull; | ||
|
||
@Entity | ||
public class NotNullThing { | ||
|
||
@Id | ||
private Long id; | ||
|
||
boolean nullableBoolean; | ||
int nullableInteger; | ||
Boolean nullableWrappedBoolean; | ||
Integer nullableWrappedInteger; | ||
|
||
@NotNull | ||
boolean notNullBoolean; | ||
@NotNull | ||
int notNullInteger; | ||
@NotNull | ||
Boolean notNullWrappedBoolean; | ||
@NotNull | ||
Integer notNullWrappedInteger; | ||
|
||
@Generated(hash = 1109392169) | ||
public NotNullThing(Long id, boolean nullableBoolean, int nullableInteger, | ||
Boolean nullableWrappedBoolean, Integer nullableWrappedInteger, | ||
boolean notNullBoolean, int notNullInteger, | ||
@NotNull Boolean notNullWrappedBoolean, | ||
@NotNull Integer notNullWrappedInteger) { | ||
this.id = id; | ||
this.nullableBoolean = nullableBoolean; | ||
this.nullableInteger = nullableInteger; | ||
this.nullableWrappedBoolean = nullableWrappedBoolean; | ||
this.nullableWrappedInteger = nullableWrappedInteger; | ||
this.notNullBoolean = notNullBoolean; | ||
this.notNullInteger = notNullInteger; | ||
this.notNullWrappedBoolean = notNullWrappedBoolean; | ||
this.notNullWrappedInteger = notNullWrappedInteger; | ||
} | ||
@Generated(hash = 521031743) | ||
public NotNullThing() { | ||
} | ||
public Long getId() { | ||
return this.id; | ||
} | ||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
public boolean getNullableBoolean() { | ||
return this.nullableBoolean; | ||
} | ||
public void setNullableBoolean(boolean nullableBoolean) { | ||
this.nullableBoolean = nullableBoolean; | ||
} | ||
public int getNullableInteger() { | ||
return this.nullableInteger; | ||
} | ||
public void setNullableInteger(int nullableInteger) { | ||
this.nullableInteger = nullableInteger; | ||
} | ||
public Boolean getNullableWrappedBoolean() { | ||
return this.nullableWrappedBoolean; | ||
} | ||
public void setNullableWrappedBoolean(Boolean nullableWrappedBoolean) { | ||
this.nullableWrappedBoolean = nullableWrappedBoolean; | ||
} | ||
public Integer getNullableWrappedInteger() { | ||
return this.nullableWrappedInteger; | ||
} | ||
public void setNullableWrappedInteger(Integer nullableWrappedInteger) { | ||
this.nullableWrappedInteger = nullableWrappedInteger; | ||
} | ||
public boolean getNotNullBoolean() { | ||
return this.notNullBoolean; | ||
} | ||
public void setNotNullBoolean(boolean notNullBoolean) { | ||
this.notNullBoolean = notNullBoolean; | ||
} | ||
public int getNotNullInteger() { | ||
return this.notNullInteger; | ||
} | ||
public void setNotNullInteger(int notNullInteger) { | ||
this.notNullInteger = notNullInteger; | ||
} | ||
public Boolean getNotNullWrappedBoolean() { | ||
return this.notNullWrappedBoolean; | ||
} | ||
public void setNotNullWrappedBoolean(Boolean notNullWrappedBoolean) { | ||
this.notNullWrappedBoolean = notNullWrappedBoolean; | ||
} | ||
public Integer getNotNullWrappedInteger() { | ||
return this.notNullWrappedInteger; | ||
} | ||
public void setNotNullWrappedInteger(Integer notNullWrappedInteger) { | ||
this.notNullWrappedInteger = notNullWrappedInteger; | ||
} | ||
|
||
} |