mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-09 18:48:51 -06:00
Fix order by position
This commit is contained in:
@@ -118,18 +118,22 @@ public class HabitListTest extends BaseUnitTest
|
||||
Habit h1 = fixtures.createEmptyHabit();
|
||||
h1.setName("A Habit");
|
||||
h1.setColor(2);
|
||||
h1.setPosition(1);
|
||||
|
||||
Habit h2 = fixtures.createEmptyHabit();
|
||||
h2.setName("B Habit");
|
||||
h2.setColor(2);
|
||||
h2.setPosition(3);
|
||||
|
||||
Habit h3 = fixtures.createEmptyHabit();
|
||||
h3.setName("C Habit");
|
||||
h3.setColor(0);
|
||||
h3.setPosition(0);
|
||||
|
||||
Habit h4 = fixtures.createEmptyHabit();
|
||||
h4.setName("D Habit");
|
||||
h4.setColor(1);
|
||||
h4.setPosition(2);
|
||||
|
||||
list.add(h3);
|
||||
list.add(h1);
|
||||
@@ -157,6 +161,12 @@ public class HabitListTest extends BaseUnitTest
|
||||
assertThat(list.getByPosition(1), equalTo(h4));
|
||||
assertThat(list.getByPosition(2), equalTo(h1));
|
||||
assertThat(list.getByPosition(3), equalTo(h2));
|
||||
|
||||
list.setOrder(BY_POSITION);
|
||||
assertThat(list.getByPosition(0), equalTo(h3));
|
||||
assertThat(list.getByPosition(1), equalTo(h1));
|
||||
assertThat(list.getByPosition(2), equalTo(h4));
|
||||
assertThat(list.getByPosition(3), equalTo(h2));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -30,47 +30,26 @@ import static org.hamcrest.core.IsEqual.*;
|
||||
|
||||
public class HabitRecordTest extends BaseUnitTest
|
||||
{
|
||||
private Habit habit;
|
||||
|
||||
@Before
|
||||
@Override
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
|
||||
habit = modelFactory.buildHabit();
|
||||
habit.setName("Hello world");
|
||||
habit.setDescription("Did you greet the world today?");
|
||||
habit.setColor(1);
|
||||
habit.setArchived(true);
|
||||
habit.setFrequency(Frequency.THREE_TIMES_PER_WEEK);
|
||||
habit.setReminder(new Reminder(8, 30, WeekdayList.EVERY_DAY));
|
||||
habit.setId(1000L);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCopyFrom()
|
||||
{
|
||||
HabitRecord rec = new HabitRecord();
|
||||
rec.copyFrom(habit);
|
||||
Habit original = modelFactory.buildHabit();
|
||||
original.setName("Hello world");
|
||||
original.setDescription("Did you greet the world today?");
|
||||
original.setColor(1);
|
||||
original.setArchived(true);
|
||||
original.setFrequency(Frequency.THREE_TIMES_PER_WEEK);
|
||||
original.setReminder(new Reminder(8, 30, WeekdayList.EVERY_DAY));
|
||||
original.setId(1000L);
|
||||
original.setPosition(20);
|
||||
|
||||
assertThat(rec.name, equalTo(habit.getName()));
|
||||
assertThat(rec.description, equalTo(habit.getDescription()));
|
||||
assertThat(rec.color, equalTo(habit.getColor()));
|
||||
assertThat(rec.archived, equalTo(1));
|
||||
assertThat(rec.freqDen, equalTo(7));
|
||||
assertThat(rec.freqNum, equalTo(3));
|
||||
HabitRecord record = new HabitRecord();
|
||||
record.copyFrom(original);
|
||||
|
||||
Reminder reminder = habit.getReminder();
|
||||
assertThat(rec.reminderDays, equalTo(reminder.getDays().toInteger()));
|
||||
assertThat(rec.reminderHour, equalTo(reminder.getHour()));
|
||||
assertThat(rec.reminderMin, equalTo(reminder.getMinute()));
|
||||
Habit duplicate = modelFactory.buildHabit();
|
||||
record.copyTo(duplicate);
|
||||
|
||||
habit.setReminder(null);
|
||||
rec.copyFrom(habit);
|
||||
|
||||
assertThat(rec.reminderMin, equalTo(null));
|
||||
assertThat(rec.reminderHour, equalTo(null));
|
||||
assertThat(rec.reminderDays, equalTo(0));
|
||||
assertThat(original.getData(), equalTo(duplicate.getData()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user