mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-09 18:48:51 -06:00
Fix handling of null values in AndroidDatabase
This commit is contained in:
@@ -47,7 +47,7 @@ public class RepositoryTest extends BaseUnitTest
|
||||
db.execute("create table tests(" +
|
||||
"id integer not null primary key autoincrement, " +
|
||||
"color_number integer not null, score float not null, " +
|
||||
"name string not null)");
|
||||
"name string)");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -82,6 +82,21 @@ public class RepositoryTest extends BaseUnitTest
|
||||
assertThat(record, equalTo(repository.find(50L)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSave_withNull() throws Exception
|
||||
{
|
||||
ThingRecord record = new ThingRecord();
|
||||
record.color = 50;
|
||||
record.name = null;
|
||||
record.score = 12.0;
|
||||
repository.save(record);
|
||||
|
||||
ThingRecord retrieved = repository.find(record.id);
|
||||
assertNotNull(retrieved);
|
||||
assertNull(retrieved.name);
|
||||
assertThat(record, equalTo(retrieved));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSave_withoutId() throws Exception
|
||||
{
|
||||
|
||||
@@ -32,7 +32,7 @@ public class HabitRecordTest extends BaseUnitTest
|
||||
{
|
||||
|
||||
@Test
|
||||
public void testCopyFrom()
|
||||
public void testCopyRestore1()
|
||||
{
|
||||
Habit original = modelFactory.buildHabit();
|
||||
original.setName("Hello world");
|
||||
@@ -52,4 +52,30 @@ public class HabitRecordTest extends BaseUnitTest
|
||||
|
||||
assertThat(original.getData(), equalTo(duplicate.getData()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCopyRestore2()
|
||||
{
|
||||
Habit original = modelFactory.buildHabit();
|
||||
original.setName("Hello world");
|
||||
original.setDescription("Did you greet the world today?");
|
||||
original.setColor(5);
|
||||
original.setArchived(false);
|
||||
original.setFrequency(Frequency.DAILY);
|
||||
original.setReminder(null);
|
||||
original.setId(1L);
|
||||
original.setPosition(15);
|
||||
original.setType(Habit.NUMBER_HABIT);
|
||||
original.setTargetValue(100);
|
||||
original.setTargetType(Habit.AT_LEAST);
|
||||
original.setUnit("miles");
|
||||
|
||||
HabitRecord record = new HabitRecord();
|
||||
record.copyFrom(original);
|
||||
|
||||
Habit duplicate = modelFactory.buildHabit();
|
||||
record.copyTo(duplicate);
|
||||
|
||||
assertThat(original.getData(), equalTo(duplicate.getData()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user