Rebuild order after removing habit

This commit is contained in:
2017-06-22 22:50:27 -04:00
parent 6801d1d1ae
commit ea640a8a17
16 changed files with 96 additions and 88 deletions

View File

@@ -140,7 +140,7 @@ public class CommandParserTest extends BaseUnitTest
public void testDecodeToggleCommand() throws JSONException
{
ToggleRepetitionCommand original, decoded;
original = new ToggleRepetitionCommand(habit, 1000);
original = new ToggleRepetitionCommand(habitList, habit, 1000);
decoded = (ToggleRepetitionCommand) parser.parse(original.toJson());
MatcherAssert.assertThat(decoded.getId(), equalTo(original.getId()));

View File

@@ -45,7 +45,7 @@ public class ToggleRepetitionCommandTest extends BaseUnitTest
habitList.add(habit);
today = DateUtils.getStartOfToday();
command = new ToggleRepetitionCommand(habit, today);
command = new ToggleRepetitionCommand(habitList, habit, today);
}
@Test

View File

@@ -25,6 +25,7 @@ import org.junit.*;
import java.util.*;
import static junit.framework.TestCase.*;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.*;
import static org.mockito.Mockito.*;
@@ -70,11 +71,6 @@ public class StreakListTest extends BaseUnitTest
public void testFindBeginning_withLongHistory()
{
streaks.rebuild();
assertThat(streaks.findBeginning(), equalTo(today - day));
streaks.invalidateNewerThan(today - 20 * day);
assertThat(streaks.findBeginning(), equalTo(today - 28 * day));
streaks.invalidateNewerThan(0);
assertThat(streaks.findBeginning(), equalTo(today - 120 * day));
}
@@ -111,20 +107,6 @@ public class StreakListTest extends BaseUnitTest
assertThat(best.get(1).getLength(), equalTo(6L));
}
@Test
public void testGetNewestComputed() throws Exception
{
Streak s = streaks.getNewestComputed();
assertThat(s.getEnd(), equalTo(today));
assertThat(s.getStart(), equalTo(today - day));
streaks.invalidateNewerThan(today - 8 * day);
s = streaks.getNewestComputed();
assertThat(s.getEnd(), equalTo(today - 12 * day));
assertThat(s.getStart(), equalTo(today - 12 * day));
}
@Test
public void testInvalidateNewer()
{
@@ -135,6 +117,6 @@ public class StreakListTest extends BaseUnitTest
verify(listener).onModelChange();
s = streaks.getNewestComputed();
assertThat(s.getEnd(), equalTo(today - 12 * day));
assertNull(s);
}
}

View File

@@ -168,4 +168,19 @@ public class SQLiteHabitListTest extends BaseUnitTest
h2.setId(1000L);
assertThat(habitList.indexOf(h2), equalTo(-1));
}
@Test
public void testRemove() throws Exception
{
Habit h = habitList.getByPosition(2);
habitList.remove(h);
assertThat(habitList.indexOf(h), equalTo(-1));
HabitRecord rec = repository.find(2L);
assertNull(rec);
rec = repository.find(3L);
assertNotNull(rec);
assertThat(rec.position, equalTo(2));
}
}

View File

@@ -86,7 +86,7 @@ public class HabitCardListCacheTest extends BaseUnitTest
{
Habit h2 = habitList.getByPosition(2);
long today = DateUtils.getStartOfToday();
commandRunner.execute(new ToggleRepetitionCommand(h2, today),
commandRunner.execute(new ToggleRepetitionCommand(habitList, h2, today),
h2.getId());
verify(listener).onItemChanged(2);