mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-07 01:28:52 -06:00
Move models.sqlite to uhabits-core
This commit is contained in:
@@ -23,7 +23,6 @@ package org.isoron.uhabits;
|
||||
import org.isoron.androidbase.*;
|
||||
import org.isoron.uhabits.core.*;
|
||||
import org.isoron.uhabits.core.tasks.*;
|
||||
import org.isoron.uhabits.models.sqlite.*;
|
||||
|
||||
import dagger.*;
|
||||
|
||||
@@ -32,7 +31,6 @@ import dagger.*;
|
||||
AppContextModule.class,
|
||||
HabitsModule.class,
|
||||
SingleThreadModule.class,
|
||||
SQLModelFactory.class
|
||||
})
|
||||
public interface AndroidTestComponent extends HabitsApplicationComponent
|
||||
{
|
||||
|
||||
@@ -1,86 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.isoron.uhabits.models.sqlite;
|
||||
|
||||
import android.support.test.runner.*;
|
||||
import android.test.suitebuilder.annotation.*;
|
||||
|
||||
import org.isoron.androidbase.storage.*;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
import org.isoron.uhabits.models.sqlite.records.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
import org.junit.*;
|
||||
import org.junit.runner.*;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.*;
|
||||
import static org.hamcrest.core.IsEqual.*;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@MediumTest
|
||||
public class HabitRecordTest extends BaseAndroidTest
|
||||
{
|
||||
private Habit habit;
|
||||
|
||||
private SQLiteRepository<HabitRecord> sqlite =
|
||||
new SQLiteRepository<>(HabitRecord.class, DatabaseUtils.openDatabase());
|
||||
|
||||
@Before
|
||||
@Override
|
||||
public void setUp()
|
||||
{
|
||||
super.setUp();
|
||||
|
||||
habit = component.getModelFactory().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);
|
||||
|
||||
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));
|
||||
|
||||
Reminder reminder = habit.getReminder();
|
||||
assertThat(rec.reminderDays, equalTo(reminder.getDays().toInteger()));
|
||||
assertThat(rec.reminderHour, equalTo(reminder.getHour()));
|
||||
assertThat(rec.reminderMin, equalTo(reminder.getMinute()));
|
||||
|
||||
habit.setReminder(null);
|
||||
rec.copyFrom(habit);
|
||||
|
||||
assertThat(rec.reminderMin, equalTo(null));
|
||||
assertThat(rec.reminderHour, equalTo(null));
|
||||
assertThat(rec.reminderDays, equalTo(0));
|
||||
}
|
||||
}
|
||||
@@ -24,10 +24,12 @@ import android.test.suitebuilder.annotation.*;
|
||||
|
||||
import com.google.common.collect.*;
|
||||
|
||||
import org.isoron.androidbase.storage.*;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.core.db.*;
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
import org.isoron.uhabits.models.sqlite.records.*;
|
||||
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.*;
|
||||
@@ -52,7 +54,7 @@ public class SQLiteHabitListTest extends BaseAndroidTest
|
||||
|
||||
private ModelFactory modelFactory;
|
||||
|
||||
private SQLiteRepository<HabitRecord> repository;
|
||||
private Repository<HabitRecord> repository;
|
||||
|
||||
private ModelObservable.Listener listener;
|
||||
|
||||
@@ -64,9 +66,8 @@ public class SQLiteHabitListTest extends BaseAndroidTest
|
||||
fixtures.purgeHabits(habitList);
|
||||
|
||||
modelFactory = component.getModelFactory();
|
||||
repository =
|
||||
new SQLiteRepository<>(HabitRecord.class,
|
||||
DatabaseUtils.openDatabase());
|
||||
repository = new Repository<>(HabitRecord.class,
|
||||
new AndroidSQLiteDatabase(DatabaseUtils.openDatabase()));
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
|
||||
@@ -23,11 +23,12 @@ import android.support.annotation.*;
|
||||
import android.support.test.runner.*;
|
||||
import android.test.suitebuilder.annotation.*;
|
||||
|
||||
import org.isoron.androidbase.storage.*;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.core.db.*;
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
import org.isoron.uhabits.core.models.sqlite.records.*;
|
||||
import org.isoron.uhabits.core.utils.*;
|
||||
import org.isoron.uhabits.models.sqlite.records.*;
|
||||
import org.isoron.uhabits.database.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
import org.junit.*;
|
||||
import org.junit.runner.*;
|
||||
@@ -50,7 +51,7 @@ public class SQLiteRepetitionListTest extends BaseAndroidTest
|
||||
|
||||
private long day;
|
||||
|
||||
private SQLiteRepository<RepetitionRecord> sqlite;
|
||||
private Repository<RepetitionRecord> sqlite;
|
||||
|
||||
@Override
|
||||
public void setUp()
|
||||
@@ -61,8 +62,8 @@ public class SQLiteRepetitionListTest extends BaseAndroidTest
|
||||
repetitions = habit.getRepetitions();
|
||||
today = DateUtils.getStartOfToday();
|
||||
day = DateUtils.millisecondsInOneDay;
|
||||
sqlite = new SQLiteRepository<>(RepetitionRecord.class,
|
||||
DatabaseUtils.openDatabase());
|
||||
sqlite = new Repository<>(RepetitionRecord.class,
|
||||
new AndroidSQLiteDatabase(DatabaseUtils.openDatabase()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -19,13 +19,14 @@
|
||||
|
||||
package org.isoron.uhabits.models.sqlite;
|
||||
|
||||
import android.database.sqlite.*;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.support.test.runner.*;
|
||||
import android.test.suitebuilder.annotation.*;
|
||||
|
||||
import org.apache.commons.lang3.builder.*;
|
||||
import org.isoron.androidbase.storage.*;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.core.db.*;
|
||||
import org.isoron.uhabits.database.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
import org.junit.*;
|
||||
import org.junit.runner.*;
|
||||
@@ -37,7 +38,7 @@ import static org.junit.Assert.assertThat;
|
||||
@MediumTest
|
||||
public class SQLiteRepositoryTest extends BaseAndroidTest
|
||||
{
|
||||
private SQLiteRepository<ThingRecord> repository;
|
||||
private Repository<ThingRecord> repository;
|
||||
|
||||
private SQLiteDatabase db;
|
||||
|
||||
@@ -47,7 +48,8 @@ public class SQLiteRepositoryTest extends BaseAndroidTest
|
||||
{
|
||||
super.setUp();
|
||||
this.db = DatabaseUtils.openDatabase();
|
||||
repository = new SQLiteRepository<>(ThingRecord.class, db);
|
||||
repository = new Repository<>(ThingRecord.class,
|
||||
new AndroidSQLiteDatabase((db)));
|
||||
|
||||
db.execSQL("drop table if exists tests");
|
||||
db.execSQL("create table tests(" +
|
||||
|
||||
Reference in New Issue
Block a user