forked from upstream-mirrors/OpenTracks
@@ -17,18 +17,17 @@
|
|||||||
package de.dennisguse.opentracks.content;
|
package de.dennisguse.opentracks.content;
|
||||||
|
|
||||||
import android.content.ContentUris;
|
import android.content.ContentUris;
|
||||||
import android.content.Context;
|
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.platform.app.InstrumentationRegistry;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.rule.provider.ProviderTestRule;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -39,6 +38,8 @@ import de.dennisguse.opentracks.content.SearchEngine.SearchQuery;
|
|||||||
import de.dennisguse.opentracks.content.data.Track;
|
import de.dennisguse.opentracks.content.data.Track;
|
||||||
import de.dennisguse.opentracks.content.data.Waypoint;
|
import de.dennisguse.opentracks.content.data.Waypoint;
|
||||||
import de.dennisguse.opentracks.content.provider.ContentProviderUtils;
|
import de.dennisguse.opentracks.content.provider.ContentProviderUtils;
|
||||||
|
import de.dennisguse.opentracks.content.provider.CustomContentProvider;
|
||||||
|
import de.dennisguse.opentracks.content.provider.CustomSQLiteOpenHelper;
|
||||||
import de.dennisguse.opentracks.stats.TrackStatistics;
|
import de.dennisguse.opentracks.stats.TrackStatistics;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -48,25 +49,29 @@ import de.dennisguse.opentracks.stats.TrackStatistics;
|
|||||||
*
|
*
|
||||||
* @author Rodrigo Damazio
|
* @author Rodrigo Damazio
|
||||||
*/
|
*/
|
||||||
@RunWith(AndroidJUnit4.class)
|
|
||||||
public class SearchEngineTest {
|
public class SearchEngineTest {
|
||||||
|
|
||||||
|
private static final String TAG = SearchEngineTest.class.getSimpleName();
|
||||||
|
|
||||||
private static final Location HERE = new Location("gps");
|
private static final Location HERE = new Location("gps");
|
||||||
private static final long NOW = SearchEngine.OLDEST_ALLOWED_TIMESTAMP + 1000; // After OLDEST_ALLOWED_TIMESTAMP
|
private static final long NOW = SearchEngine.OLDEST_ALLOWED_TIMESTAMP + 1000;
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public ProviderTestRule sqliteContentProviderRule = new ProviderTestRule.Builder(CustomContentProvider.class, ContentProviderUtils.AUTHORITY_PACKAGE).setPrefix(TAG).build();
|
||||||
|
|
||||||
private ContentProviderUtils providerUtils;
|
private ContentProviderUtils providerUtils;
|
||||||
private SearchEngine engine;
|
private SearchEngine engine;
|
||||||
|
|
||||||
private final Context context = ApplicationProvider.getApplicationContext();
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
providerUtils = new ContentProviderUtils(context);
|
providerUtils = new ContentProviderUtils(sqliteContentProviderRule.getResolver());
|
||||||
|
|
||||||
engine = new SearchEngine(providerUtils);
|
engine = new SearchEngine(providerUtils);
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() {
|
public void tearDown() {
|
||||||
providerUtils.deleteAllTracks(context);
|
InstrumentationRegistry.getInstrumentation().getTargetContext().deleteDatabase(TAG + CustomSQLiteOpenHelper.DATABASE_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
private long insertTrack(String title, String description, String category, long hoursAgo) {
|
private long insertTrack(String title, String description, String category, long hoursAgo) {
|
||||||
|
|||||||
@@ -56,7 +56,8 @@ public class ContentProviderUtils {
|
|||||||
private static final int MAX_LATITUDE = 90000000;
|
private static final int MAX_LATITUDE = 90000000;
|
||||||
|
|
||||||
// The authority (the first part of the URI) for the app's content provider.
|
// The authority (the first part of the URI) for the app's content provider.
|
||||||
static final String AUTHORITY_PACKAGE = BuildConfig.APPLICATION_ID + ".content";
|
@VisibleForTesting
|
||||||
|
public static final String AUTHORITY_PACKAGE = BuildConfig.APPLICATION_ID + ".content";
|
||||||
|
|
||||||
// The base URI for the app's content provider.
|
// The base URI for the app's content provider.
|
||||||
public static final String CONTENT_BASE_URI = "content://" + AUTHORITY_PACKAGE;
|
public static final String CONTENT_BASE_URI = "content://" + AUTHORITY_PACKAGE;
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ import de.dennisguse.opentracks.content.data.WaypointsColumns;
|
|||||||
*
|
*
|
||||||
* @author Leif Hendrik Wilden
|
* @author Leif Hendrik Wilden
|
||||||
*/
|
*/
|
||||||
public abstract class CustomContentProvider extends ContentProvider {
|
public class CustomContentProvider extends ContentProvider {
|
||||||
|
|
||||||
private static final String TAG = CustomContentProvider.class.getSimpleName();
|
private static final String TAG = CustomContentProvider.class.getSimpleName();
|
||||||
|
|
||||||
|
|||||||
@@ -20,13 +20,14 @@ import de.dennisguse.opentracks.util.UUIDUtils;
|
|||||||
* Database helper for creating and upgrading the database.
|
* Database helper for creating and upgrading the database.
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
class CustomSQLiteOpenHelper extends SQLiteOpenHelper {
|
public class CustomSQLiteOpenHelper extends SQLiteOpenHelper {
|
||||||
|
|
||||||
private static final String TAG = CustomSQLiteOpenHelper.class.getSimpleName();
|
private static final String TAG = CustomSQLiteOpenHelper.class.getSimpleName();
|
||||||
|
|
||||||
private static final int DATABASE_VERSION = 26;
|
private static final int DATABASE_VERSION = 26;
|
||||||
|
|
||||||
private static final String DATABASE_NAME = "database.db";
|
@VisibleForTesting
|
||||||
|
public static final String DATABASE_NAME = "database.db";
|
||||||
|
|
||||||
public CustomSQLiteOpenHelper(Context context) {
|
public CustomSQLiteOpenHelper(Context context) {
|
||||||
this(context, DATABASE_NAME);
|
this(context, DATABASE_NAME);
|
||||||
|
|||||||
Reference in New Issue
Block a user