/**
* Executes the given SQL query on the repository.
- *
+ *
* The query can be of any kind. For example, complex deletes and updates
* are allowed. The repository does not perform any checks to guarantee
* that the query is valid, however the underlying database might.
*/
public void execSQL(String query, Object... params)
{
- db.execSQL(query, params);
+ db.execute(query, params);
}
/**
* Executes the given callback inside a database transaction.
- *
+ *
* If the callback terminates without throwing any exceptions, the
* transaction is considered successful. If any exceptions are thrown,
* the transaction is aborted. Nesting transactions is not allowed.
@@ -124,12 +122,12 @@ public class Repository
/**
* Saves the record on the database.
- *
+ *
* If the id of the given record is null, it is assumed that the record has
* not been inserted in the repository yet. The record will be inserted, a
* new id will be automatically generated, and the id of the given record
* will be updated.
- *
+ *
* If the given record has a non-null id, then an update will be performed
* instead. That is, the previous record will be overwritten by the one
* provided.
@@ -150,7 +148,7 @@ public class Repository
if (id != null) affectedRows =
db.update(getTableName(), values, getIdName() + "=?",
- new String[]{ id.toString() });
+ id.toString());
if (id == null || affectedRows == 0)
{
@@ -176,8 +174,7 @@ public class Repository
Long id = (Long) getIdField().get(record);
if (id == null) return;
- db.delete(getTableName(), getIdName() + "=?",
- new String[]{ id.toString() });
+ db.delete(getTableName(), getIdName() + "=?", id.toString());
getIdField().set(record, null);
}
catch (Exception e)
diff --git a/uhabits-android/src/main/java/org/isoron/uhabits/database/SQLParser.java b/uhabits-core/src/main/java/org/isoron/uhabits/core/db/SQLParser.java
similarity index 83%
rename from uhabits-android/src/main/java/org/isoron/uhabits/database/SQLParser.java
rename to uhabits-core/src/main/java/org/isoron/uhabits/core/db/SQLParser.java
index b72959b4e..439f02ba3 100644
--- a/uhabits-android/src/main/java/org/isoron/uhabits/database/SQLParser.java
+++ b/uhabits-core/src/main/java/org/isoron/uhabits/core/db/SQLParser.java
@@ -1,25 +1,20 @@
/*
- * Copyright (C) 2017 Álinson Santos Xavier
+ * Copyright (C) 2014 Markus Pfeiffer
*
- * This file is part of Loop Habit Tracker.
- *
- * Loop Habit Tracker is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by the
- * Free Software Foundation, either version 3 of the License, or (at your
- * option) any later version.
- *
- * Loop Habit Tracker is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program. If not, see .
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
*
+ * http://www.apache.org/licenses/LICENSE-2.0
*
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
-package org.isoron.uhabits.database;
+package org.isoron.uhabits.core.db;
import java.io.BufferedInputStream;
import java.io.IOException;
diff --git a/uhabits-core/src/main/java/org/isoron/uhabits/core/db/Table.java b/uhabits-core/src/main/java/org/isoron/uhabits/core/db/Table.java
index 97aa0f16d..4906dfd00 100644
--- a/uhabits-core/src/main/java/org/isoron/uhabits/core/db/Table.java
+++ b/uhabits-core/src/main/java/org/isoron/uhabits/core/db/Table.java
@@ -15,8 +15,6 @@
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see .
- *
- *
*/
package org.isoron.uhabits.core.db;
diff --git a/uhabits-core/src/main/resources/migrations/10.sql b/uhabits-core/src/main/resources/migrations/10.sql
new file mode 100644
index 000000000..e13df67f7
--- /dev/null
+++ b/uhabits-core/src/main/resources/migrations/10.sql
@@ -0,0 +1,3 @@
+delete from Score;
+delete from Streak;
+delete from Checkmarks;
\ No newline at end of file
diff --git a/uhabits-core/src/main/resources/migrations/11.sql b/uhabits-core/src/main/resources/migrations/11.sql
new file mode 100644
index 000000000..4c9493cc1
--- /dev/null
+++ b/uhabits-core/src/main/resources/migrations/11.sql
@@ -0,0 +1 @@
+alter table Habits add column reminder_days integer not null default 127;
\ No newline at end of file
diff --git a/uhabits-core/src/main/resources/migrations/12.sql b/uhabits-core/src/main/resources/migrations/12.sql
new file mode 100644
index 000000000..e13df67f7
--- /dev/null
+++ b/uhabits-core/src/main/resources/migrations/12.sql
@@ -0,0 +1,3 @@
+delete from Score;
+delete from Streak;
+delete from Checkmarks;
\ No newline at end of file
diff --git a/uhabits-core/src/main/resources/migrations/13.sql b/uhabits-core/src/main/resources/migrations/13.sql
new file mode 100644
index 000000000..3df9bc5de
--- /dev/null
+++ b/uhabits-core/src/main/resources/migrations/13.sql
@@ -0,0 +1,4 @@
+create index idx_score_habit_timestamp on Score(habit, timestamp);
+create index idx_checkmark_habit_timestamp on Checkmarks(habit, timestamp);
+create index idx_repetitions_habit_timestamp on Repetitions(habit, timestamp);
+create index idx_streak_habit_end on Streak(habit, end);
\ No newline at end of file
diff --git a/uhabits-core/src/main/resources/migrations/14.sql b/uhabits-core/src/main/resources/migrations/14.sql
new file mode 100644
index 000000000..e267afc2c
--- /dev/null
+++ b/uhabits-core/src/main/resources/migrations/14.sql
@@ -0,0 +1,14 @@
+update habits set color=0 where color=-2937041;
+update habits set color=1 where color=-1684967;
+update habits set color=2 where color=-415707;
+update habits set color=3 where color=-5262293;
+update habits set color=4 where color=-13070788;
+update habits set color=5 where color=-16742021;
+update habits set color=6 where color=-16732991;
+update habits set color=7 where color=-16540699;
+update habits set color=8 where color=-10603087;
+update habits set color=9 where color=-7461718;
+update habits set color=10 where color=-2614432;
+update habits set color=11 where color=-13619152;
+update habits set color=12 where color=-5592406;
+update habits set color=0 where color<0 or color>12;
\ No newline at end of file
diff --git a/uhabits-core/src/main/resources/migrations/15.sql b/uhabits-core/src/main/resources/migrations/15.sql
new file mode 100644
index 000000000..e13df67f7
--- /dev/null
+++ b/uhabits-core/src/main/resources/migrations/15.sql
@@ -0,0 +1,3 @@
+delete from Score;
+delete from Streak;
+delete from Checkmarks;
\ No newline at end of file
diff --git a/uhabits-core/src/main/resources/migrations/16.sql b/uhabits-core/src/main/resources/migrations/16.sql
new file mode 100644
index 000000000..7a7746f63
--- /dev/null
+++ b/uhabits-core/src/main/resources/migrations/16.sql
@@ -0,0 +1,2 @@
+alter table Habits add column type integer not null default 0;
+alter table Repetitions add column value integer not null default 2;
\ No newline at end of file
diff --git a/uhabits-core/src/main/resources/migrations/17.sql b/uhabits-core/src/main/resources/migrations/17.sql
new file mode 100644
index 000000000..fa8f50719
--- /dev/null
+++ b/uhabits-core/src/main/resources/migrations/17.sql
@@ -0,0 +1,11 @@
+drop table Score;
+create table Score (
+ id integer primary key autoincrement,
+ habit integer references habits(id),
+ score real,
+ timestamp integer);
+
+create index idx_score_habit_timestamp on Score(habit, timestamp);
+
+delete from streak;
+delete from checkmarks;
\ No newline at end of file
diff --git a/uhabits-core/src/main/resources/migrations/18.sql b/uhabits-core/src/main/resources/migrations/18.sql
new file mode 100644
index 000000000..fa6318bcc
--- /dev/null
+++ b/uhabits-core/src/main/resources/migrations/18.sql
@@ -0,0 +1,3 @@
+alter table Habits add column target_type integer not null default 0;
+alter table Habits add column target_value real not null default 0;
+alter table Habits add column unit text not null default "";
\ No newline at end of file
diff --git a/uhabits-core/src/main/resources/migrations/19.sql b/uhabits-core/src/main/resources/migrations/19.sql
new file mode 100644
index 000000000..f7e9ec24b
--- /dev/null
+++ b/uhabits-core/src/main/resources/migrations/19.sql
@@ -0,0 +1,6 @@
+create table Events (
+ id integer primary key autoincrement,
+ timestamp integer,
+ message text,
+ server_id integer
+);
\ No newline at end of file
diff --git a/uhabits-core/src/main/resources/migrations/20.sql b/uhabits-core/src/main/resources/migrations/20.sql
new file mode 100644
index 000000000..7a8a44177
--- /dev/null
+++ b/uhabits-core/src/main/resources/migrations/20.sql
@@ -0,0 +1,3 @@
+drop table checkmarks;
+drop table streak;
+drop table score;
diff --git a/uhabits-core/src/main/resources/migrations/21.sql b/uhabits-core/src/main/resources/migrations/21.sql
new file mode 100644
index 000000000..20cd9fe89
--- /dev/null
+++ b/uhabits-core/src/main/resources/migrations/21.sql
@@ -0,0 +1,12 @@
+update habits set color=19 where color=12;
+update habits set color=17 where color=11;
+update habits set color=15 where color=10;
+update habits set color=14 where color=9;
+update habits set color=13 where color=8;
+update habits set color=10 where color=7;
+update habits set color=9 where color=6;
+update habits set color=8 where color=5;
+update habits set color=7 where color=4;
+update habits set color=5 where color=3;
+update habits set color=4 where color=2;
+update habits set color=0 where color<0 or color>19;
\ No newline at end of file
diff --git a/uhabits-core/src/main/resources/migrations/9.sql b/uhabits-core/src/main/resources/migrations/9.sql
new file mode 100644
index 000000000..5fb4502b4
--- /dev/null
+++ b/uhabits-core/src/main/resources/migrations/9.sql
@@ -0,0 +1,41 @@
+create table Habits (
+ id integer primary key autoincrement,
+ archived integer,
+ color integer,
+ description text,
+ freq_den integer,
+ freq_num integer,
+ highlight integer,
+ name text,
+ position integer,
+ reminder_hour integer,
+ reminder_min integer
+);
+
+create table Checkmarks (
+ id integer primary key autoincrement,
+ habit integer references habits(id),
+ timestamp integer,
+ value integer
+);
+
+create table Repetitions (
+ id integer primary key autoincrement,
+ habit integer references habits(id),
+ timestamp integer
+);
+
+create table Streak (
+ id integer primary key autoincrement,
+ end integer,
+ habit integer references habits(id),
+ length integer,
+ start integer
+);
+
+create table Score (
+ id integer primary key autoincrement,
+ habit integer references habits(id),
+ score integer,
+ timestamp integer
+);
diff --git a/uhabits-core/src/test/java/org/isoron/uhabits/BaseUnitTest.java b/uhabits-core/src/test/java/org/isoron/uhabits/BaseUnitTest.java
index 6279258db..2b65756fa 100644
--- a/uhabits-core/src/test/java/org/isoron/uhabits/BaseUnitTest.java
+++ b/uhabits-core/src/test/java/org/isoron/uhabits/BaseUnitTest.java
@@ -20,6 +20,7 @@
package org.isoron.uhabits;
import org.isoron.uhabits.core.commands.*;
+import org.isoron.uhabits.core.db.*;
import org.isoron.uhabits.core.models.*;
import org.isoron.uhabits.core.models.memory.*;
import org.isoron.uhabits.core.tasks.*;
@@ -29,9 +30,11 @@ import org.junit.*;
import org.junit.runner.*;
import org.mockito.junit.*;
+import java.sql.*;
import java.util.*;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.validateMockitoUsage;
@RunWith(MockitoJUnitRunner.class)
public class BaseUnitTest
@@ -51,7 +54,7 @@ public class BaseUnitTest
protected static final long FIXED_LOCAL_TIME = 1422172800000L;
@Before
- public void setUp()
+ public void setUp() throws Exception
{
DateUtils.setFixedLocalTime(FIXED_LOCAL_TIME);
@@ -81,4 +84,16 @@ public class BaseUnitTest
{
}
+
+ protected Database buildMemoryDatabase()
+ {
+ try
+ {
+ return new JdbcDatabase(DriverManager.getConnection("jdbc:sqlite::memory:"));
+ }
+ catch (SQLException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
}
diff --git a/uhabits-core/src/test/java/org/isoron/uhabits/core/commands/ArchiveHabitsCommandTest.java b/uhabits-core/src/test/java/org/isoron/uhabits/core/commands/ArchiveHabitsCommandTest.java
index fc2df1508..628173e7b 100644
--- a/uhabits-core/src/test/java/org/isoron/uhabits/core/commands/ArchiveHabitsCommandTest.java
+++ b/uhabits-core/src/test/java/org/isoron/uhabits/core/commands/ArchiveHabitsCommandTest.java
@@ -37,7 +37,7 @@ public class ArchiveHabitsCommandTest extends BaseUnitTest
@Override
@Before
- public void setUp()
+ public void setUp() throws Exception
{
super.setUp();
diff --git a/uhabits-core/src/test/java/org/isoron/uhabits/core/commands/ChangeHabitColorCommandTest.java b/uhabits-core/src/test/java/org/isoron/uhabits/core/commands/ChangeHabitColorCommandTest.java
index 790aa259e..03b7ca7f2 100644
--- a/uhabits-core/src/test/java/org/isoron/uhabits/core/commands/ChangeHabitColorCommandTest.java
+++ b/uhabits-core/src/test/java/org/isoron/uhabits/core/commands/ChangeHabitColorCommandTest.java
@@ -36,7 +36,7 @@ public class ChangeHabitColorCommandTest extends BaseUnitTest
@Override
@Before
- public void setUp()
+ public void setUp() throws Exception
{
super.setUp();
diff --git a/uhabits-core/src/test/java/org/isoron/uhabits/core/commands/CommandParserTest.java b/uhabits-core/src/test/java/org/isoron/uhabits/core/commands/CommandParserTest.java
index 07ad02c02..c1e8bc1a6 100644
--- a/uhabits-core/src/test/java/org/isoron/uhabits/core/commands/CommandParserTest.java
+++ b/uhabits-core/src/test/java/org/isoron/uhabits/core/commands/CommandParserTest.java
@@ -42,7 +42,7 @@ public class CommandParserTest extends BaseUnitTest
@Override
@Before
- public void setUp()
+ public void setUp() throws Exception
{
super.setUp();
parser = new CommandParser(habitList, modelFactory);
diff --git a/uhabits-core/src/test/java/org/isoron/uhabits/core/commands/CreateHabitCommandTest.java b/uhabits-core/src/test/java/org/isoron/uhabits/core/commands/CreateHabitCommandTest.java
index 9237b04b5..917341515 100644
--- a/uhabits-core/src/test/java/org/isoron/uhabits/core/commands/CreateHabitCommandTest.java
+++ b/uhabits-core/src/test/java/org/isoron/uhabits/core/commands/CreateHabitCommandTest.java
@@ -35,7 +35,7 @@ public class CreateHabitCommandTest extends BaseUnitTest
@Override
@Before
- public void setUp()
+ public void setUp() throws Exception
{
super.setUp();
diff --git a/uhabits-core/src/test/java/org/isoron/uhabits/core/commands/CreateRepetitionCommandTest.java b/uhabits-core/src/test/java/org/isoron/uhabits/core/commands/CreateRepetitionCommandTest.java
index f82d0ad0c..4f14c29b4 100644
--- a/uhabits-core/src/test/java/org/isoron/uhabits/core/commands/CreateRepetitionCommandTest.java
+++ b/uhabits-core/src/test/java/org/isoron/uhabits/core/commands/CreateRepetitionCommandTest.java
@@ -39,7 +39,7 @@ public class CreateRepetitionCommandTest extends BaseUnitTest
@Override
@Before
- public void setUp()
+ public void setUp() throws Exception
{
super.setUp();
diff --git a/uhabits-core/src/test/java/org/isoron/uhabits/core/commands/DeleteHabitsCommandTest.java b/uhabits-core/src/test/java/org/isoron/uhabits/core/commands/DeleteHabitsCommandTest.java
index 77d3e0523..7e48340aa 100644
--- a/uhabits-core/src/test/java/org/isoron/uhabits/core/commands/DeleteHabitsCommandTest.java
+++ b/uhabits-core/src/test/java/org/isoron/uhabits/core/commands/DeleteHabitsCommandTest.java
@@ -40,7 +40,7 @@ public class DeleteHabitsCommandTest extends BaseUnitTest
@Override
@Before
- public void setUp()
+ public void setUp() throws Exception
{
super.setUp();
selected = new LinkedList<>();
diff --git a/uhabits-core/src/test/java/org/isoron/uhabits/core/commands/EditHabitCommandTest.java b/uhabits-core/src/test/java/org/isoron/uhabits/core/commands/EditHabitCommandTest.java
index 003cdf6bd..da0950548 100644
--- a/uhabits-core/src/test/java/org/isoron/uhabits/core/commands/EditHabitCommandTest.java
+++ b/uhabits-core/src/test/java/org/isoron/uhabits/core/commands/EditHabitCommandTest.java
@@ -36,7 +36,7 @@ public class EditHabitCommandTest extends BaseUnitTest
@Override
@Before
- public void setUp()
+ public void setUp() throws Exception
{
super.setUp();
diff --git a/uhabits-core/src/test/java/org/isoron/uhabits/core/commands/ToggleRepetitionCommandTest.java b/uhabits-core/src/test/java/org/isoron/uhabits/core/commands/ToggleRepetitionCommandTest.java
index 554d631d7..8ba9acc9e 100644
--- a/uhabits-core/src/test/java/org/isoron/uhabits/core/commands/ToggleRepetitionCommandTest.java
+++ b/uhabits-core/src/test/java/org/isoron/uhabits/core/commands/ToggleRepetitionCommandTest.java
@@ -37,7 +37,7 @@ public class ToggleRepetitionCommandTest extends BaseUnitTest
@Override
@Before
- public void setUp()
+ public void setUp() throws Exception
{
super.setUp();
diff --git a/uhabits-core/src/test/java/org/isoron/uhabits/core/commands/UnarchiveHabitsCommandTest.java b/uhabits-core/src/test/java/org/isoron/uhabits/core/commands/UnarchiveHabitsCommandTest.java
index 81c1d2465..dca8023dc 100644
--- a/uhabits-core/src/test/java/org/isoron/uhabits/core/commands/UnarchiveHabitsCommandTest.java
+++ b/uhabits-core/src/test/java/org/isoron/uhabits/core/commands/UnarchiveHabitsCommandTest.java
@@ -36,7 +36,7 @@ public class UnarchiveHabitsCommandTest extends BaseUnitTest
@Override
@Before
- public void setUp()
+ public void setUp() throws Exception
{
super.setUp();
diff --git a/uhabits-core/src/test/java/org/isoron/uhabits/core/models/CheckmarkListTest.java b/uhabits-core/src/test/java/org/isoron/uhabits/core/models/CheckmarkListTest.java
index 158807a1e..36b7e6236 100644
--- a/uhabits-core/src/test/java/org/isoron/uhabits/core/models/CheckmarkListTest.java
+++ b/uhabits-core/src/test/java/org/isoron/uhabits/core/models/CheckmarkListTest.java
@@ -45,7 +45,7 @@ public class CheckmarkListTest extends BaseUnitTest
private Habit numericalHabit;
@Override
- public void setUp()
+ public void setUp() throws Exception
{
super.setUp();
diff --git a/uhabits-core/src/test/java/org/isoron/uhabits/core/models/HabitListTest.java b/uhabits-core/src/test/java/org/isoron/uhabits/core/models/HabitListTest.java
index f5cb6218e..d94d7a73c 100644
--- a/uhabits-core/src/test/java/org/isoron/uhabits/core/models/HabitListTest.java
+++ b/uhabits-core/src/test/java/org/isoron/uhabits/core/models/HabitListTest.java
@@ -49,7 +49,7 @@ public class HabitListTest extends BaseUnitTest
private HabitList reminderHabits;
@Override
- public void setUp()
+ public void setUp() throws Exception
{
super.setUp();
habitsArray = new ArrayList<>();
diff --git a/uhabits-core/src/test/java/org/isoron/uhabits/core/models/HabitTest.java b/uhabits-core/src/test/java/org/isoron/uhabits/core/models/HabitTest.java
index 6b5343827..4c96e87a2 100644
--- a/uhabits-core/src/test/java/org/isoron/uhabits/core/models/HabitTest.java
+++ b/uhabits-core/src/test/java/org/isoron/uhabits/core/models/HabitTest.java
@@ -33,7 +33,7 @@ public class HabitTest extends BaseUnitTest
public final ExpectedException exception = ExpectedException.none();
@Override
- public void setUp()
+ public void setUp() throws Exception
{
super.setUp();
}
diff --git a/uhabits-core/src/test/java/org/isoron/uhabits/core/models/RepetitionListTest.java b/uhabits-core/src/test/java/org/isoron/uhabits/core/models/RepetitionListTest.java
index 68a089730..e165456e0 100644
--- a/uhabits-core/src/test/java/org/isoron/uhabits/core/models/RepetitionListTest.java
+++ b/uhabits-core/src/test/java/org/isoron/uhabits/core/models/RepetitionListTest.java
@@ -52,7 +52,7 @@ public class RepetitionListTest extends BaseUnitTest
@Override
@Before
- public void setUp()
+ public void setUp() throws Exception
{
super.setUp();
habit = fixtures.createEmptyHabit();
diff --git a/uhabits-core/src/test/java/org/isoron/uhabits/core/models/ScoreListTest.java b/uhabits-core/src/test/java/org/isoron/uhabits/core/models/ScoreListTest.java
index 0d38d8e02..4d32e501e 100644
--- a/uhabits-core/src/test/java/org/isoron/uhabits/core/models/ScoreListTest.java
+++ b/uhabits-core/src/test/java/org/isoron/uhabits/core/models/ScoreListTest.java
@@ -38,7 +38,7 @@ public class ScoreListTest extends BaseUnitTest
@Override
@Before
- public void setUp()
+ public void setUp() throws Exception
{
super.setUp();
habit = fixtures.createEmptyHabit();
diff --git a/uhabits-core/src/test/java/org/isoron/uhabits/core/models/ScoreTest.java b/uhabits-core/src/test/java/org/isoron/uhabits/core/models/ScoreTest.java
index 6a90a406c..7ff707903 100644
--- a/uhabits-core/src/test/java/org/isoron/uhabits/core/models/ScoreTest.java
+++ b/uhabits-core/src/test/java/org/isoron/uhabits/core/models/ScoreTest.java
@@ -32,7 +32,7 @@ public class ScoreTest extends BaseUnitTest
@Override
@Before
- public void setUp()
+ public void setUp() throws Exception
{
super.setUp();
}
diff --git a/uhabits-core/src/test/java/org/isoron/uhabits/core/models/StreakListTest.java b/uhabits-core/src/test/java/org/isoron/uhabits/core/models/StreakListTest.java
index 0f9571e2f..184b48c4d 100644
--- a/uhabits-core/src/test/java/org/isoron/uhabits/core/models/StreakListTest.java
+++ b/uhabits-core/src/test/java/org/isoron/uhabits/core/models/StreakListTest.java
@@ -42,7 +42,7 @@ public class StreakListTest extends BaseUnitTest
private ModelObservable.Listener listener;
@Override
- public void setUp()
+ public void setUp() throws Exception
{
super.setUp();
habit = fixtures.createLongHabit();
diff --git a/uhabits-android/src/androidTest/java/org/isoron/uhabits/models/sqlite/SQLiteHabitListTest.java b/uhabits-core/src/test/java/org/isoron/uhabits/core/models/sqlite/SQLiteHabitListTest.java
similarity index 78%
rename from uhabits-android/src/androidTest/java/org/isoron/uhabits/models/sqlite/SQLiteHabitListTest.java
rename to uhabits-core/src/test/java/org/isoron/uhabits/core/models/sqlite/SQLiteHabitListTest.java
index 6cb649562..5f08bf60b 100644
--- a/uhabits-android/src/androidTest/java/org/isoron/uhabits/models/sqlite/SQLiteHabitListTest.java
+++ b/uhabits-core/src/test/java/org/isoron/uhabits/core/models/sqlite/SQLiteHabitListTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 Álinson Santos Xavier
+ * Copyright (C) 2017 Álinson Santos Xavier
*
* This file is part of Loop Habit Tracker.
*
@@ -15,59 +15,44 @@
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see .
+ *
+ *
*/
-package org.isoron.uhabits.models.sqlite;
-
-import android.support.test.runner.*;
-import android.test.suitebuilder.annotation.*;
-
-import com.google.common.collect.*;
+package org.isoron.uhabits.core.models.sqlite;
import org.isoron.uhabits.*;
import org.isoron.uhabits.core.db.*;
import org.isoron.uhabits.core.models.*;
-import org.isoron.uhabits.core.models.sqlite.*;
import org.isoron.uhabits.core.models.sqlite.records.*;
-import org.isoron.uhabits.database.*;
-import org.isoron.uhabits.utils.*;
import org.junit.*;
import org.junit.rules.*;
-import org.junit.runner.*;
-
-import java.util.*;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.core.IsEqual.*;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
-@SuppressWarnings("JavaDoc")
-@RunWith(AndroidJUnit4.class)
-@MediumTest
-public class SQLiteHabitListTest extends BaseAndroidTest
+public class SQLiteHabitListTest extends BaseUnitTest
{
@Rule
public ExpectedException exception = ExpectedException.none();
private SQLiteHabitList habitList;
- private ModelFactory modelFactory;
-
private Repository repository;
private ModelObservable.Listener listener;
@Override
- public void setUp()
+ public void setUp() throws Exception
{
super.setUp();
- this.habitList = (SQLiteHabitList) super.habitList;
- fixtures.purgeHabits(habitList);
-
- modelFactory = component.getModelFactory();
- repository = new Repository<>(HabitRecord.class,
- new AndroidSQLiteDatabase(DatabaseUtils.openDatabase()));
+ Database db = buildMemoryDatabase();
+ repository = new Repository<>(HabitRecord.class, db);
+ habitList = new SQLiteHabitList(new SQLModelFactory(db));
for (int i = 0; i < 10; i++)
{
@@ -89,7 +74,7 @@ public class SQLiteHabitListTest extends BaseAndroidTest
}
@Override
- protected void tearDown() throws Exception
+ public void tearDown()
{
habitList.getObservable().removeListener(listener);
super.tearDown();
@@ -142,14 +127,6 @@ public class SQLiteHabitListTest extends BaseAndroidTest
assertThat(habitList.size(), equalTo(10));
}
- @Test
- public void testGetAll_withArchived()
- {
- List habits = Lists.newArrayList(habitList.iterator());
- assertThat(habits.size(), equalTo(10));
- assertThat(habits.get(3).getName(), equalTo("habit 3"));
- }
-
@Test
public void testGetById()
{
diff --git a/uhabits-core/src/test/java/org/isoron/uhabits/core/models/sqlite/records/HabitRecordTest.java b/uhabits-core/src/test/java/org/isoron/uhabits/core/models/sqlite/records/HabitRecordTest.java
index 5b94e8a1e..213a1fd74 100644
--- a/uhabits-core/src/test/java/org/isoron/uhabits/core/models/sqlite/records/HabitRecordTest.java
+++ b/uhabits-core/src/test/java/org/isoron/uhabits/core/models/sqlite/records/HabitRecordTest.java
@@ -23,7 +23,6 @@ package org.isoron.uhabits.core.models.sqlite.records;
import org.isoron.uhabits.*;
import org.isoron.uhabits.core.models.*;
-import org.isoron.uhabits.core.models.sqlite.records.*;
import org.junit.*;
import static org.hamcrest.MatcherAssert.*;
@@ -35,7 +34,7 @@ public class HabitRecordTest extends BaseUnitTest
@Before
@Override
- public void setUp()
+ public void setUp() throws Exception
{
super.setUp();
diff --git a/uhabits-core/src/test/java/org/isoron/uhabits/core/reminders/ReminderSchedulerTest.java b/uhabits-core/src/test/java/org/isoron/uhabits/core/reminders/ReminderSchedulerTest.java
index 352e8e5bb..46cdfc119 100644
--- a/uhabits-core/src/test/java/org/isoron/uhabits/core/reminders/ReminderSchedulerTest.java
+++ b/uhabits-core/src/test/java/org/isoron/uhabits/core/reminders/ReminderSchedulerTest.java
@@ -43,7 +43,7 @@ public class ReminderSchedulerTest extends BaseUnitTest
@Before
@Override
- public void setUp()
+ public void setUp() throws Exception
{
super.setUp();
habit = fixtures.createEmptyHabit();
diff --git a/uhabits-core/src/test/java/org/isoron/uhabits/core/tasks/SingleThreadTaskRunnerTest.java b/uhabits-core/src/test/java/org/isoron/uhabits/core/tasks/SingleThreadTaskRunnerTest.java
index 3f7e3090e..79d0eaa99 100644
--- a/uhabits-core/src/test/java/org/isoron/uhabits/core/tasks/SingleThreadTaskRunnerTest.java
+++ b/uhabits-core/src/test/java/org/isoron/uhabits/core/tasks/SingleThreadTaskRunnerTest.java
@@ -35,7 +35,7 @@ public class SingleThreadTaskRunnerTest extends BaseUnitTest
private Task task;
@Override
- public void setUp()
+ public void setUp() throws Exception
{
super.setUp();
runner = new SingleThreadTaskRunner();
diff --git a/uhabits-core/src/test/java/org/isoron/uhabits/core/ui/screens/about/AboutBehaviorTest.java b/uhabits-core/src/test/java/org/isoron/uhabits/core/ui/screens/about/AboutBehaviorTest.java
index f39984abb..379a9f276 100644
--- a/uhabits-core/src/test/java/org/isoron/uhabits/core/ui/screens/about/AboutBehaviorTest.java
+++ b/uhabits-core/src/test/java/org/isoron/uhabits/core/ui/screens/about/AboutBehaviorTest.java
@@ -39,8 +39,9 @@ public class AboutBehaviorTest extends BaseUnitTest
private AboutBehavior.Screen screen;
@Before
- public void setUp()
+ public void setUp() throws Exception
{
+ super.setUp();
behavior = new AboutBehavior(prefs, screen);
}
diff --git a/uhabits-core/src/test/java/org/isoron/uhabits/core/ui/screens/habits/list/HabitCardListCacheTest.java b/uhabits-core/src/test/java/org/isoron/uhabits/core/ui/screens/habits/list/HabitCardListCacheTest.java
index abad82464..97a7f760a 100644
--- a/uhabits-core/src/test/java/org/isoron/uhabits/core/ui/screens/habits/list/HabitCardListCacheTest.java
+++ b/uhabits-core/src/test/java/org/isoron/uhabits/core/ui/screens/habits/list/HabitCardListCacheTest.java
@@ -40,7 +40,7 @@ public class HabitCardListCacheTest extends BaseUnitTest
private HabitCardListCache.Listener listener;
@Override
- public void setUp()
+ public void setUp() throws Exception
{
super.setUp();
habitList.removeAll();
diff --git a/uhabits-core/src/test/java/org/isoron/uhabits/core/ui/screens/habits/list/HintListTest.java b/uhabits-core/src/test/java/org/isoron/uhabits/core/ui/screens/habits/list/HintListTest.java
index f7509b1a0..1cad7f922 100644
--- a/uhabits-core/src/test/java/org/isoron/uhabits/core/ui/screens/habits/list/HintListTest.java
+++ b/uhabits-core/src/test/java/org/isoron/uhabits/core/ui/screens/habits/list/HintListTest.java
@@ -46,7 +46,7 @@ public class HintListTest extends BaseUnitTest
private long yesterday;
@Override
- public void setUp()
+ public void setUp() throws Exception
{
super.setUp();
today = DateUtils.getStartOfToday();
diff --git a/uhabits-core/src/test/java/org/isoron/uhabits/core/ui/screens/habits/list/ListHabitsBehaviorTest.java b/uhabits-core/src/test/java/org/isoron/uhabits/core/ui/screens/habits/list/ListHabitsBehaviorTest.java
index ac3c1d1ea..5741a226b 100644
--- a/uhabits-core/src/test/java/org/isoron/uhabits/core/ui/screens/habits/list/ListHabitsBehaviorTest.java
+++ b/uhabits-core/src/test/java/org/isoron/uhabits/core/ui/screens/habits/list/ListHabitsBehaviorTest.java
@@ -67,7 +67,7 @@ public class ListHabitsBehaviorTest extends BaseUnitTest
@Override
@Before
- public void setUp()
+ public void setUp() throws Exception
{
super.setUp();
habit1 = fixtures.createShortHabit();
diff --git a/uhabits-core/src/test/java/org/isoron/uhabits/core/ui/screens/habits/list/ListHabitsMenuBehaviorTest.java b/uhabits-core/src/test/java/org/isoron/uhabits/core/ui/screens/habits/list/ListHabitsMenuBehaviorTest.java
index af71677a3..170381f2d 100644
--- a/uhabits-core/src/test/java/org/isoron/uhabits/core/ui/screens/habits/list/ListHabitsMenuBehaviorTest.java
+++ b/uhabits-core/src/test/java/org/isoron/uhabits/core/ui/screens/habits/list/ListHabitsMenuBehaviorTest.java
@@ -55,7 +55,7 @@ public class ListHabitsMenuBehaviorTest extends BaseUnitTest
private ArgumentCaptor orderCaptor;
@Override
- public void setUp()
+ public void setUp() throws Exception
{
super.setUp();
behavior =
diff --git a/uhabits-core/src/test/java/org/isoron/uhabits/core/ui/screens/habits/list/ListHabitsSelectionMenuBehaviorTest.java b/uhabits-core/src/test/java/org/isoron/uhabits/core/ui/screens/habits/list/ListHabitsSelectionMenuBehaviorTest.java
index 506baee68..3a95eba9b 100644
--- a/uhabits-core/src/test/java/org/isoron/uhabits/core/ui/screens/habits/list/ListHabitsSelectionMenuBehaviorTest.java
+++ b/uhabits-core/src/test/java/org/isoron/uhabits/core/ui/screens/habits/list/ListHabitsSelectionMenuBehaviorTest.java
@@ -139,7 +139,7 @@ public class ListHabitsSelectionMenuBehaviorTest extends BaseUnitTest
}
@Override
- public void setUp()
+ public void setUp() throws Exception
{
super.setUp();
diff --git a/uhabits-core/src/test/java/org/isoron/uhabits/core/ui/screens/habits/show/ShowHabitMenuBehaviorTest.java b/uhabits-core/src/test/java/org/isoron/uhabits/core/ui/screens/habits/show/ShowHabitMenuBehaviorTest.java
index b0ca4d0ba..5a44559d3 100644
--- a/uhabits-core/src/test/java/org/isoron/uhabits/core/ui/screens/habits/show/ShowHabitMenuBehaviorTest.java
+++ b/uhabits-core/src/test/java/org/isoron/uhabits/core/ui/screens/habits/show/ShowHabitMenuBehaviorTest.java
@@ -42,7 +42,7 @@ public class ShowHabitMenuBehaviorTest extends BaseUnitTest
private ShowHabitMenuBehavior menu;
@Override
- public void setUp()
+ public void setUp() throws Exception
{
super.setUp();
system = mock(ShowHabitMenuBehavior.System.class);