Refactor MainActivity and Preferences

This commit is contained in:
2016-05-26 16:35:47 -04:00
parent 83ef8564e1
commit 6445bf62bc
21 changed files with 740 additions and 509 deletions

View File

@@ -23,6 +23,7 @@ import android.os.Build;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.SmallTest;
import org.isoron.uhabits.BaseTest;
import org.isoron.uhabits.HabitsApplication;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -34,7 +35,7 @@ import static org.hamcrest.Matchers.containsString;
@RunWith(AndroidJUnit4.class)
@SmallTest
public class HabitsApplicationTest
public class HabitsApplicationTest extends BaseTest
{
@Test
public void test_getLogcat() throws IOException
@@ -45,7 +46,10 @@ public class HabitsApplicationTest
String msg = "LOGCAT TEST";
new RuntimeException(msg).printStackTrace();
String log = HabitsApplication.getLogcat();
HabitsApplication app = HabitsApplication.getInstance();
assert(app != null);
String log = app.getLogcat();
assertThat(log, containsString(msg));
}
}

View File

@@ -21,7 +21,6 @@ package org.isoron.uhabits.unit.tasks;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.SmallTest;
import android.widget.ProgressBar;
import org.isoron.uhabits.BaseTest;
import org.isoron.uhabits.models.Habit;
@@ -55,9 +54,8 @@ public class ExportCSVTaskTest extends BaseTest
{
HabitFixtures.createShortHabit();
List<Habit> habits = Habit.getAll(true);
ProgressBar bar = new ProgressBar(targetContext);
ExportCSVTask task = new ExportCSVTask(habits, bar);
ExportCSVTask task = new ExportCSVTask(habits, null);
task.setListener(new ExportCSVTask.Listener()
{
@Override

View File

@@ -19,11 +19,8 @@
package org.isoron.uhabits.unit.tasks;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.SmallTest;
import android.widget.ProgressBar;
import org.isoron.uhabits.BaseTest;
import org.isoron.uhabits.tasks.ExportDBTask;
@@ -52,10 +49,7 @@ public class ExportDBTaskTest extends BaseTest
@Test
public void testExportCSV() throws Throwable
{
Context context = InstrumentationRegistry.getContext();
ProgressBar bar = new ProgressBar(context);
ExportDBTask task = new ExportDBTask(bar);
ExportDBTask task = new ExportDBTask(null);
task.setListener(new ExportDBTask.Listener()
{
@Override

View File

@@ -22,11 +22,10 @@ package org.isoron.uhabits.unit.tasks;
import android.support.annotation.NonNull;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.SmallTest;
import android.widget.ProgressBar;
import org.isoron.uhabits.BaseTest;
import org.isoron.uhabits.utils.FileUtils;
import org.isoron.uhabits.tasks.ImportDataTask;
import org.isoron.uhabits.utils.FileUtils;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -67,7 +66,7 @@ public class ImportDataTaskTest extends BaseTest
task.setListener(new ImportDataTask.Listener()
{
@Override
public void onImportFinished(int result)
public void onImportDataFinished(int result)
{
assertThat(result, equalTo(expectedResult));
}
@@ -80,11 +79,9 @@ public class ImportDataTaskTest extends BaseTest
@NonNull
private ImportDataTask createTask(String assetFilename) throws IOException
{
ProgressBar bar = new ProgressBar(targetContext);
File file = new File(String.format("%s/%s", baseDir.getPath(), assetFilename));
copyAssetToFile(assetFilename, file);
return new ImportDataTask(file, bar);
return new ImportDataTask(file, null);
}
@Test