forked from upstream-mirrors/OpenTracks
Small cleanups and improvements code.
This commit is contained in:
committed by
Román Martínez
parent
acc2627bde
commit
9541a92657
+2
-12
@@ -1,7 +1,6 @@
|
|||||||
package de.dennisguse.opentracks.io.file.importer;
|
package de.dennisguse.opentracks.io.file.importer;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.database.sqlite.SQLiteConstraintException;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
|
|
||||||
@@ -10,9 +9,7 @@ import androidx.test.filters.LargeTest;
|
|||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.junit.runners.JUnit4;
|
import org.junit.runners.JUnit4;
|
||||||
|
|
||||||
@@ -62,9 +59,6 @@ public class ExportImportTest {
|
|||||||
private Track.Id importTrackId;
|
private Track.Id importTrackId;
|
||||||
private final Track.Id trackId = new Track.Id(System.currentTimeMillis());
|
private final Track.Id trackId = new Track.Id(System.currentTimeMillis());
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException exception = ExpectedException.none();
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
Pair<Track, TrackPoint[]> track = TestDataUtil.createTrack(trackId, 10);
|
Pair<Track, TrackPoint[]> track = TestDataUtil.createTrack(trackId, 10);
|
||||||
@@ -179,7 +173,7 @@ public class ExportImportTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@LargeTest
|
@LargeTest
|
||||||
@Test
|
@Test(expected = ImportAlreadyExistsException.class)
|
||||||
public void kml_with_trackdetail_and_sensordata_duplicate_trackUUID() {
|
public void kml_with_trackdetail_and_sensordata_duplicate_trackUUID() {
|
||||||
// given
|
// given
|
||||||
PreferencesUtils.setBoolean(context, R.string.import_prevent_reimport_key, true);
|
PreferencesUtils.setBoolean(context, R.string.import_prevent_reimport_key, true);
|
||||||
@@ -187,8 +181,6 @@ public class ExportImportTest {
|
|||||||
|
|
||||||
TrackExporter trackExporter = TrackFileFormat.KML_WITH_TRACKDETAIL_AND_SENSORDATA.newTrackExporter(context);
|
TrackExporter trackExporter = TrackFileFormat.KML_WITH_TRACKDETAIL_AND_SENSORDATA.newTrackExporter(context);
|
||||||
|
|
||||||
exception.expect(ImportAlreadyExistsException.class);
|
|
||||||
|
|
||||||
// when
|
// when
|
||||||
// 1. export
|
// 1. export
|
||||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
@@ -270,7 +262,7 @@ public class ExportImportTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@LargeTest
|
@LargeTest
|
||||||
@Test
|
@Test(expected = ImportAlreadyExistsException.class)
|
||||||
public void gpx_duplicate_trackUUID() {
|
public void gpx_duplicate_trackUUID() {
|
||||||
// given
|
// given
|
||||||
PreferencesUtils.setBoolean(context, R.string.import_prevent_reimport_key, true);
|
PreferencesUtils.setBoolean(context, R.string.import_prevent_reimport_key, true);
|
||||||
@@ -278,8 +270,6 @@ public class ExportImportTest {
|
|||||||
|
|
||||||
TrackExporter trackExporter = TrackFileFormat.GPX.newTrackExporter(context);
|
TrackExporter trackExporter = TrackFileFormat.GPX.newTrackExporter(context);
|
||||||
|
|
||||||
exception.expect(ImportAlreadyExistsException.class);
|
|
||||||
|
|
||||||
// when
|
// when
|
||||||
// 1. export
|
// 1. export
|
||||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
|
|||||||
+5
-5
@@ -4,6 +4,8 @@ import android.os.Bundle;
|
|||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.ResultReceiver;
|
import android.os.ResultReceiver;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new ResultReceive to receive results.
|
* Create a new ResultReceive to receive results.
|
||||||
* Your {@link #onReceiveResult} method will be called from the thread running <var>handler</var> if given, or from an arbitrary thread if null.
|
* Your {@link #onReceiveResult} method will be called from the thread running <var>handler</var> if given, or from an arbitrary thread if null.
|
||||||
@@ -15,18 +17,16 @@ public class ExportServiceResultReceiver extends ResultReceiver {
|
|||||||
|
|
||||||
public static final String RESULT_EXTRA_TRACK_ID = "result_extra_track_id";
|
public static final String RESULT_EXTRA_TRACK_ID = "result_extra_track_id";
|
||||||
|
|
||||||
private Receiver receiver;
|
private final Receiver receiver;
|
||||||
|
|
||||||
public ExportServiceResultReceiver(Handler handler, Receiver receiver) {
|
public ExportServiceResultReceiver(Handler handler, @NonNull Receiver receiver) {
|
||||||
super(handler);
|
super(handler);
|
||||||
this.receiver = receiver;
|
this.receiver = receiver;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onReceiveResult(int resultCode, Bundle resultData) {
|
protected void onReceiveResult(int resultCode, Bundle resultData) {
|
||||||
if (receiver != null) {
|
receiver.onReceiveResult(resultCode, resultData);
|
||||||
receiver.onReceiveResult(resultCode, resultData);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface Receiver {
|
public interface Receiver {
|
||||||
|
|||||||
+5
-5
@@ -4,6 +4,8 @@ import android.os.Bundle;
|
|||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.ResultReceiver;
|
import android.os.ResultReceiver;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new ResultReceive to receive results.
|
* Create a new ResultReceive to receive results.
|
||||||
* Your {@link #onReceiveResult} method will be called from the thread running <var>handler</var> if given, or from an arbitrary thread if null.
|
* Your {@link #onReceiveResult} method will be called from the thread running <var>handler</var> if given, or from an arbitrary thread if null.
|
||||||
@@ -18,18 +20,16 @@ public class ImportServiceResultReceiver extends ResultReceiver {
|
|||||||
public static final String RESULT_EXTRA_FILENAME = "result_extra_filename";
|
public static final String RESULT_EXTRA_FILENAME = "result_extra_filename";
|
||||||
public static final String RESULT_EXTRA_MESSAGE = "result_extra_message";
|
public static final String RESULT_EXTRA_MESSAGE = "result_extra_message";
|
||||||
|
|
||||||
private Receiver receiver;
|
private final Receiver receiver;
|
||||||
|
|
||||||
public ImportServiceResultReceiver(Handler handler, Receiver receiver) {
|
public ImportServiceResultReceiver(Handler handler, @NonNull Receiver receiver) {
|
||||||
super(handler);
|
super(handler);
|
||||||
this.receiver = receiver;
|
this.receiver = receiver;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onReceiveResult(int resultCode, Bundle resultData) {
|
protected void onReceiveResult(int resultCode, Bundle resultData) {
|
||||||
if (receiver != null) {
|
receiver.onReceiveResult(resultCode, resultData);
|
||||||
receiver.onReceiveResult(resultCode, resultData);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface Receiver {
|
public interface Receiver {
|
||||||
|
|||||||
Reference in New Issue
Block a user