aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/.settings/org.eclipse.jdt.core.prefs2
-rw-r--r--tests/.settings/org.eclipse.jdt.ui.prefs22
-rw-r--r--tests/res/layout/cgeo_tests_activity.xml3
-rw-r--r--tests/src/cgeo/CGeoTestCase.java8
-rw-r--r--tests/src/cgeo/geocaching/CgeoApplicationTest.java10
-rw-r--r--tests/src/cgeo/geocaching/GeocacheTest.java6
-rw-r--r--tests/src/cgeo/geocaching/StaticMapsProviderTest.java3
-rw-r--r--tests/src/cgeo/geocaching/connector/oc/OkapiClientTest.java11
-rw-r--r--tests/src/cgeo/geocaching/connector/trackable/SwaggieConnectorTest.java29
-rw-r--r--tests/src/cgeo/geocaching/connector/trackable/SwaggieParserTest.java34
-rw-r--r--tests/src/cgeo/geocaching/connector/trackable/TravelBugConnectorTest.java6
-rw-r--r--tests/src/cgeo/geocaching/export/ExportTest.java17
-rw-r--r--tests/src/cgeo/geocaching/export/GpxSerializerTest.java24
-rw-r--r--tests/src/cgeo/geocaching/files/GPXParserTest.java5
-rw-r--r--tests/src/cgeo/geocaching/location/GeocoderTest.java39
-rw-r--r--tests/src/cgeo/geocaching/sorting/NameComparatorTest.java9
-rw-r--r--tests/src/cgeo/geocaching/test/WhitespaceTest.java4
-rw-r--r--tests/src/cgeo/geocaching/utils/DateUtilsTest.java12
-rw-r--r--tests/src/cgeo/geocaching/utils/FileUtilsTest.java61
-rw-r--r--tests/src/cgeo/geocaching/utils/ProcessUtilsTest.java4
-rw-r--r--tests/src/cgeo/geocaching/utils/RxUtilsTest.java11
-rw-r--r--tests/src/cgeo/junit/CgeoTestRunner.java39
22 files changed, 262 insertions, 97 deletions
diff --git a/tests/.settings/org.eclipse.jdt.core.prefs b/tests/.settings/org.eclipse.jdt.core.prefs
index 0c3bd0c..af15cda 100644
--- a/tests/.settings/org.eclipse.jdt.core.prefs
+++ b/tests/.settings/org.eclipse.jdt.core.prefs
@@ -51,7 +51,7 @@ org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=warning
org.eclipse.jdt.core.compiler.problem.missingJavadocComments=ignore
org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=disabled
org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=public
-org.eclipse.jdt.core.compiler.problem.missingJavadocTagDescription=no_tag
+org.eclipse.jdt.core.compiler.problem.missingJavadocTagDescription=all_standard_tags
org.eclipse.jdt.core.compiler.problem.missingJavadocTags=ignore
org.eclipse.jdt.core.compiler.problem.missingJavadocTagsMethodTypeParameters=disabled
org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=disabled
diff --git a/tests/.settings/org.eclipse.jdt.ui.prefs b/tests/.settings/org.eclipse.jdt.ui.prefs
index 1fda530..06e562c 100644
--- a/tests/.settings/org.eclipse.jdt.ui.prefs
+++ b/tests/.settings/org.eclipse.jdt.ui.prefs
@@ -8,7 +8,7 @@ org.eclipse.jdt.ui.ondemandthreshold=99
org.eclipse.jdt.ui.staticondemandthreshold=99
sp_cleanup.add_default_serial_version_id=true
sp_cleanup.add_generated_serial_version_id=false
-sp_cleanup.add_missing_annotations=false
+sp_cleanup.add_missing_annotations=true
sp_cleanup.add_missing_deprecated_annotations=true
sp_cleanup.add_missing_methods=false
sp_cleanup.add_missing_nls_tags=false
@@ -20,16 +20,16 @@ sp_cleanup.always_use_parentheses_in_expressions=false
sp_cleanup.always_use_this_for_non_static_field_access=false
sp_cleanup.always_use_this_for_non_static_method_access=false
sp_cleanup.convert_functional_interfaces=false
-sp_cleanup.convert_to_enhanced_for_loop=false
+sp_cleanup.convert_to_enhanced_for_loop=true
sp_cleanup.correct_indentation=false
sp_cleanup.format_source_code=true
sp_cleanup.format_source_code_changes_only=true
sp_cleanup.insert_inferred_type_arguments=false
-sp_cleanup.make_local_variable_final=false
-sp_cleanup.make_parameters_final=false
-sp_cleanup.make_private_fields_final=false
+sp_cleanup.make_local_variable_final=true
+sp_cleanup.make_parameters_final=true
+sp_cleanup.make_private_fields_final=true
sp_cleanup.make_type_abstract_if_missing_method=false
-sp_cleanup.make_variable_declarations_final=false
+sp_cleanup.make_variable_declarations_final=true
sp_cleanup.never_use_blocks=false
sp_cleanup.never_use_parentheses_in_expressions=true
sp_cleanup.on_save_use_additional_actions=true
@@ -37,16 +37,16 @@ sp_cleanup.organize_imports=true
sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
-sp_cleanup.qualify_static_member_accesses_with_declaring_class=false
+sp_cleanup.qualify_static_member_accesses_with_declaring_class=true
sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
sp_cleanup.remove_private_constructors=true
sp_cleanup.remove_redundant_type_arguments=false
sp_cleanup.remove_trailing_whitespaces=true
sp_cleanup.remove_trailing_whitespaces_all=true
sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
-sp_cleanup.remove_unnecessary_casts=false
-sp_cleanup.remove_unnecessary_nls_tags=false
-sp_cleanup.remove_unused_imports=false
+sp_cleanup.remove_unnecessary_casts=true
+sp_cleanup.remove_unnecessary_nls_tags=true
+sp_cleanup.remove_unused_imports=true
sp_cleanup.remove_unused_local_variables=false
sp_cleanup.remove_unused_private_fields=true
sp_cleanup.remove_unused_private_members=false
@@ -55,7 +55,7 @@ sp_cleanup.remove_unused_private_types=true
sp_cleanup.sort_members=false
sp_cleanup.sort_members_all=false
sp_cleanup.use_anonymous_class_creation=false
-sp_cleanup.use_blocks=false
+sp_cleanup.use_blocks=true
sp_cleanup.use_blocks_only_for_return_and_throw=false
sp_cleanup.use_lambda=false
sp_cleanup.use_parentheses_in_expressions=false
diff --git a/tests/res/layout/cgeo_tests_activity.xml b/tests/res/layout/cgeo_tests_activity.xml
index 43225ac..d035210 100644
--- a/tests/res/layout/cgeo_tests_activity.xml
+++ b/tests/res/layout/cgeo_tests_activity.xml
@@ -13,6 +13,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
+ android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
@@ -27,6 +28,7 @@
android:layout_height="fill_parent"
android:layout_above="@+id/buttonRun"
android:layout_alignParentLeft="true"
+ android:layout_alignParentStart="true"
android:layout_below="@+id/headline" >
<TextView
@@ -43,6 +45,7 @@
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="false"
+ android:layout_alignParentStart="false"
android:onClick="runTests"
android:text="@string/run_tests" />
diff --git a/tests/src/cgeo/CGeoTestCase.java b/tests/src/cgeo/CGeoTestCase.java
index 7fc1e8d..2dbac3d 100644
--- a/tests/src/cgeo/CGeoTestCase.java
+++ b/tests/src/cgeo/CGeoTestCase.java
@@ -29,14 +29,12 @@ public abstract class CGeoTestCase extends ApplicationTestCase<CgeoApplication>
}
/** Remove cache from DB and cache to ensure that the cache is not loaded from the database */
- protected static void deleteCacheFromDB(String geocode) {
+ protected static void deleteCacheFromDB(final String geocode) {
DataStore.removeCache(geocode, LoadFlags.REMOVE_ALL);
}
/**
* remove cache from database and file system
- *
- * @param geocode
*/
protected static void removeCacheCompletely(final String geocode) {
final EnumSet<RemoveFlag> flags = EnumSet.copyOf(LoadFlags.REMOVE_ALL);
@@ -71,10 +69,8 @@ public abstract class CGeoTestCase extends ApplicationTestCase<CgeoApplication>
/**
* can be called after recordMapStoreFlags,
* to set the flags for map storing as necessary
- * @param storeCacheMap
- * @param storeWpMaps
*/
- protected void setMapStoreFlags(boolean storeCacheMap, boolean storeWpMaps) {
+ protected void setMapStoreFlags(final boolean storeCacheMap, final boolean storeWpMaps) {
if (!oldMapStoreFlagsRecorded) {
throw new IllegalStateException("Previous MapStoreFlags havn't been recorded! Setting not allowed");
}
diff --git a/tests/src/cgeo/geocaching/CgeoApplicationTest.java b/tests/src/cgeo/geocaching/CgeoApplicationTest.java
index bb61b34..d9716c0 100644
--- a/tests/src/cgeo/geocaching/CgeoApplicationTest.java
+++ b/tests/src/cgeo/geocaching/CgeoApplicationTest.java
@@ -94,7 +94,7 @@ public class CgeoApplicationTest extends CGeoTestCase {
// no assumption possible: assertThat(tb.getSpottedName()).isEqualTo("Nice place for a break cache");
// we can't check specifics in the log entries since they change, but we can verify data was parsed
- for (LogEntry log : tb.getLogs()) {
+ for (final LogEntry log : tb.getLogs()) {
assertThat(log.date).isGreaterThan(0);
assertThat(log.author).isNotEmpty();
if (log.type == LogType.PLACED_IT || log.type == LogType.RETRIEVED_IT) {
@@ -135,7 +135,6 @@ public class CgeoApplicationTest extends CGeoTestCase {
/**
* Set the login data to the cgeo login, run the given Runnable, and restore the login.
*
- * @param runnable
*/
private static void withMockedLoginDo(final Runnable runnable) {
final ImmutablePair<String, String> login = Settings.getGcCredentials();
@@ -211,9 +210,8 @@ public class CgeoApplicationTest extends CGeoTestCase {
/**
* mock the "exclude disabled caches" and "exclude my caches" options for the execution of the runnable
*
- * @param runnable
*/
- private static void withMockedFilters(Runnable runnable) {
+ private static void withMockedFilters(final Runnable runnable) {
// backup user settings
final boolean excludeMine = Settings.isExcludeMyCaches();
final boolean excludeDisabled = Settings.isExcludeDisabledCaches();
@@ -401,7 +399,7 @@ public class CgeoApplicationTest extends CGeoTestCase {
* Test cache parsing. Esp. useful after a GC.com update
*/
public static void testSearchByGeocodeBasis() {
- for (MockedCache mockedCache : RegExPerformanceTest.MOCKED_CACHES) {
+ for (final MockedCache mockedCache : RegExPerformanceTest.MOCKED_CACHES) {
final String oldUser = mockedCache.getMockedDataUser();
try {
mockedCache.setMockedDataUser(Settings.getUsername());
@@ -425,7 +423,7 @@ public class CgeoApplicationTest extends CGeoTestCase {
}
/** Remove cache from DB and cache to ensure that the cache is not loaded from the database */
- private static void deleteCacheFromDBAndLogout(String geocode) {
+ private static void deleteCacheFromDBAndLogout(final String geocode) {
deleteCacheFromDB(geocode);
GCLogin.getInstance().logout();
diff --git a/tests/src/cgeo/geocaching/GeocacheTest.java b/tests/src/cgeo/geocaching/GeocacheTest.java
index 37b6883..3e29bcf 100644
--- a/tests/src/cgeo/geocaching/GeocacheTest.java
+++ b/tests/src/cgeo/geocaching/GeocacheTest.java
@@ -302,7 +302,7 @@ public class GeocacheTest extends CGeoTestCase {
cache.setType(CacheType.EVENT);
cache.setDescription(StringUtils.EMPTY);
cache.setShortDescription("text 14:20 text");
- assertThat(cache.guessEventTimeMinutes()).isEqualTo(String.valueOf(14 * 60 + 20));
+ assertThat(cache.guessEventTimeMinutes()).isEqualTo(14 * 60 + 20);
}
private static void assertTime(final String description, final int hours, final int minutes) {
@@ -310,14 +310,14 @@ public class GeocacheTest extends CGeoTestCase {
cache.setDescription(description);
cache.setType(CacheType.EVENT);
final int minutesAfterMidnight = hours * 60 + minutes;
- assertThat(cache.guessEventTimeMinutes()).isEqualTo(String.valueOf(minutesAfterMidnight));
+ assertThat(cache.guessEventTimeMinutes()).isEqualTo(minutesAfterMidnight);
}
private static void assertNoTime(final String description) {
final Geocache cache = new Geocache();
cache.setDescription(description);
cache.setType(CacheType.EVENT);
- assertThat(cache.guessEventTimeMinutes()).isNull();
+ assertThat(cache.guessEventTimeMinutes()).isEqualTo(-1);
}
public static void testGetPossibleLogTypes() throws Exception {
diff --git a/tests/src/cgeo/geocaching/StaticMapsProviderTest.java b/tests/src/cgeo/geocaching/StaticMapsProviderTest.java
index b107912..02b1d02 100644
--- a/tests/src/cgeo/geocaching/StaticMapsProviderTest.java
+++ b/tests/src/cgeo/geocaching/StaticMapsProviderTest.java
@@ -7,6 +7,7 @@ import cgeo.geocaching.files.LocalStorage;
import cgeo.geocaching.location.Geopoint;
import cgeo.geocaching.settings.Settings;
import cgeo.geocaching.settings.TestSettings;
+import cgeo.geocaching.utils.FileUtils;
import cgeo.geocaching.utils.RxUtils;
import junit.framework.TestCase;
@@ -78,7 +79,7 @@ public class StaticMapsProviderTest extends TestCase {
private static void deleteCacheDirectory(String geocode) {
File cacheDir = LocalStorage.getStorageDir(geocode);
- LocalStorage.deleteDirectory(cacheDir);
+ FileUtils.deleteDirectory(cacheDir);
}
}
diff --git a/tests/src/cgeo/geocaching/connector/oc/OkapiClientTest.java b/tests/src/cgeo/geocaching/connector/oc/OkapiClientTest.java
index aa66ac9..22b2dbe 100644
--- a/tests/src/cgeo/geocaching/connector/oc/OkapiClientTest.java
+++ b/tests/src/cgeo/geocaching/connector/oc/OkapiClientTest.java
@@ -30,7 +30,7 @@ public class OkapiClientTest extends CGeoTestCase {
public static void testOCSearchMustWorkWithoutOAuthAccessTokens() {
final String geoCode = "OC1234";
- Geocache cache = OkapiClient.getCache(geoCode);
+ final Geocache cache = OkapiClient.getCache(geoCode);
assertThat(cache).overridingErrorMessage("You must have a valid OKAPI key installed for running this test (but you do not need to set credentials in the app).").isNotNull();
assertThat(cache.getName()).isEqualTo("Wupper-Schein");
}
@@ -55,9 +55,16 @@ public class OkapiClientTest extends CGeoTestCase {
final String geoCode = "OC6465";
removeCacheCompletely(geoCode);
- Geocache cache = OkapiClient.getCache(geoCode);
+ final Geocache cache = OkapiClient.getCache(geoCode);
assertThat(cache).as("Cache from OKAPI").isNotNull();
assertThat(cache.getLogCounts().get(LogType.WILL_ATTEND)).isGreaterThan(0);
}
+ public static void testGetAllLogs() {
+ final String geoCode = "OC10CB8";
+ final Geocache cache = OkapiClient.getCache(geoCode);
+ final int defaultLogCount = 10;
+ assertThat(cache.getLogs().size()).isGreaterThan(defaultLogCount);
+ }
+
}
diff --git a/tests/src/cgeo/geocaching/connector/trackable/SwaggieConnectorTest.java b/tests/src/cgeo/geocaching/connector/trackable/SwaggieConnectorTest.java
new file mode 100644
index 0000000..54c3319
--- /dev/null
+++ b/tests/src/cgeo/geocaching/connector/trackable/SwaggieConnectorTest.java
@@ -0,0 +1,29 @@
+package cgeo.geocaching.connector.trackable;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import cgeo.geocaching.Trackable;
+
+import junit.framework.TestCase;
+
+public class SwaggieConnectorTest extends TestCase {
+
+ public static void testCanHandleTrackable() {
+ assertThat(new SwaggieConnector().canHandleTrackable("SW0001")).isTrue();
+ assertThat(new SwaggieConnector().canHandleTrackable("SWABCD")).isFalse();
+ assertThat(new SwaggieConnector().canHandleTrackable("GK82A2")).isFalse();
+ assertThat(new SwaggieConnector().canHandleTrackable("TB1234")).isFalse();
+ assertThat(new SwaggieConnector().canHandleTrackable("UNKNOWN")).isFalse();
+ }
+
+ public static void testGetTrackableCodeFromUrl() throws Exception {
+ assertThat(new SwaggieConnector().getTrackableCodeFromUrl("http://geocaching.com.au/swaggie/sw0017")).isEqualTo("SW0017");
+ }
+
+ public static void testGetUrl() throws Exception {
+ final Trackable trackable = new Trackable();
+ trackable.setGeocode("SW0017");
+ assertThat(new SwaggieConnector().getUrl(trackable)).isEqualTo("http://geocaching.com.au/swaggie/SW0017");
+ }
+
+}
diff --git a/tests/src/cgeo/geocaching/connector/trackable/SwaggieParserTest.java b/tests/src/cgeo/geocaching/connector/trackable/SwaggieParserTest.java
new file mode 100644
index 0000000..2661fb3
--- /dev/null
+++ b/tests/src/cgeo/geocaching/connector/trackable/SwaggieParserTest.java
@@ -0,0 +1,34 @@
+package cgeo.geocaching.connector.trackable;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import cgeo.geocaching.Trackable;
+import cgeo.geocaching.connector.ConnectorFactory;
+import cgeo.geocaching.network.Network;
+
+import junit.framework.TestCase;
+
+public class SwaggieParserTest extends TestCase {
+
+ public static void testParse() {
+ final Trackable trackableIn = new Trackable();
+ trackableIn.setGeocode("SW0017");
+
+ final String trackableUrl = ConnectorFactory.getTrackableConnector(trackableIn.getGeocode()).getUrl(trackableIn);
+ assertThat(trackableUrl).isNotNull();
+
+ final String page = Network.getResponseData(Network.getRequest(trackableUrl));
+ assertThat(page).isNotNull();
+
+ assert page != null;
+ final Trackable trackable = SwaggieParser.parse(page);
+ assertThat(trackable).isNotNull();
+ assert trackable != null;
+
+ assertThat(trackable.getName()).isEqualTo("Law and Order 1");
+ assertThat(trackable.getGeocode()).isEqualTo("SW0017");
+ assertThat(trackable.getDetails()).isEqualTo("A mini CD that may or may not contain a DivX .AVI of the Law and Order: CSI episode that features geocaching as part of the storyline.");
+ assertThat(trackable.getType()).isEqualTo("Swaggie");
+ assertThat(trackable.getOwner()).isEqualTo("Bear_Left");
+ }
+}
diff --git a/tests/src/cgeo/geocaching/connector/trackable/TravelBugConnectorTest.java b/tests/src/cgeo/geocaching/connector/trackable/TravelBugConnectorTest.java
index 8d80822..7123e87 100644
--- a/tests/src/cgeo/geocaching/connector/trackable/TravelBugConnectorTest.java
+++ b/tests/src/cgeo/geocaching/connector/trackable/TravelBugConnectorTest.java
@@ -26,14 +26,16 @@ public class TravelBugConnectorTest extends TestCase {
}
public static void testOnlineSearchBySecretCode() {
- Trackable trackable = getConnector().searchTrackable("GST9HV", null, null);
+ final Trackable trackable = getConnector().searchTrackable("GST9HV", null, null);
assertThat(trackable).isNotNull();
+ assert trackable != null;
assertThat(trackable.getName()).isEqualTo("Deutschland");
}
public static void testOnlineSearchByPublicCode() {
- Trackable trackable = getConnector().searchTrackable("TB4JD36", null, null);
+ final Trackable trackable = getConnector().searchTrackable("TB4JD36", null, null);
assertThat(trackable).isNotNull();
+ assert trackable != null;
assertThat(trackable.getName()).isEqualTo("Mein Kilometerzähler");
}
diff --git a/tests/src/cgeo/geocaching/export/ExportTest.java b/tests/src/cgeo/geocaching/export/ExportTest.java
index bec676f..21c45a0 100644
--- a/tests/src/cgeo/geocaching/export/ExportTest.java
+++ b/tests/src/cgeo/geocaching/export/ExportTest.java
@@ -25,7 +25,7 @@ public class ExportTest extends CGeoTestCase {
final Geocache cache = new Geocache();
cache.setGeocode("GCX1234");
final LogEntry log = new LogEntry(1353244820000L, LogType.FOUND_IT, "Hidden in a tree");
- FieldNotes fieldNotes = new FieldNotes();
+ final FieldNotes fieldNotes = new FieldNotes();
fieldNotes.add(cache, log);
assertEquals("Non matching export " + fieldNotes.getContent(), "GCX1234,2012-11-18T13:20:20Z,Found it,\"Hidden in a tree\"\n", fieldNotes.getContent());
}
@@ -55,8 +55,8 @@ public class ExportTest extends CGeoTestCase {
cache.setDetailed(true);
DataStore.saveCache(cache, LoadFlags.SAVE_ALL);
- List<Geocache> exportList = Collections.singletonList(cache);
- GpxExportTester gpxExport = new GpxExportTester();
+ final List<Geocache> exportList = Collections.singletonList(cache);
+ final GpxExportTester gpxExport = new GpxExportTester();
File result = null;
try {
result = gpxExport.testExportSync(exportList);
@@ -67,17 +67,22 @@ public class ExportTest extends CGeoTestCase {
assertThat(result).isNotNull();
// make sure we actually exported waypoints
- String gpx = org.apache.commons.io.FileUtils.readFileToString(result);
+ final String gpx = org.apache.commons.io.FileUtils.readFileToString(result);
assertThat(gpx).contains("<wpt");
assertThat(gpx).contains(cache.getGeocode());
+ if (cache.getUrl() != null) {
+ assertThat(gpx).contains("<url>");
+ } else {
+ assertThat(gpx).doesNotContain("<url>");
+ }
FileUtils.deleteIgnoringFailure(result);
}
private static class GpxExportTester extends GpxExport {
- public File testExportSync(List<Geocache> caches) throws InterruptedException, ExecutionException {
- final ArrayList<String> geocodes = new ArrayList<String>(caches.size());
+ public File testExportSync(final List<Geocache> caches) throws InterruptedException, ExecutionException {
+ final ArrayList<String> geocodes = new ArrayList<>(caches.size());
for (final Geocache cache : caches) {
geocodes.add(cache.getGeocode());
}
diff --git a/tests/src/cgeo/geocaching/export/GpxSerializerTest.java b/tests/src/cgeo/geocaching/export/GpxSerializerTest.java
index c43ad38..b20b066 100644
--- a/tests/src/cgeo/geocaching/export/GpxSerializerTest.java
+++ b/tests/src/cgeo/geocaching/export/GpxSerializerTest.java
@@ -38,13 +38,13 @@ public class GpxSerializerTest extends AbstractResourceInstrumentationTestCase {
final AtomicReference<Integer> importedCount = new AtomicReference<Integer>(0);
final StringWriter writer = new StringWriter();
- Geocache cache = loadCacheFromResource(R.raw.gc1bkp3_gpx101);
+ final Geocache cache = loadCacheFromResource(R.raw.gc1bkp3_gpx101);
assertThat(cache).isNotNull();
new GpxSerializer().writeGPX(Collections.singletonList("GC1BKP3"), writer, new GpxSerializer.ProgressListener() {
@Override
- public void publishProgress(int countExported) {
+ public void publishProgress(final int countExported) {
importedCount.set(countExported);
}
});
@@ -54,8 +54,6 @@ public class GpxSerializerTest extends AbstractResourceInstrumentationTestCase {
/**
* This test verifies that a loop of import, export, import leads to the same cache information.
*
- * @throws IOException
- * @throws ParserException
*/
public void testStableExportImportExport() throws IOException, ParserException {
final String geocode = "GC1BKP3";
@@ -70,7 +68,7 @@ public class GpxSerializerTest extends AbstractResourceInstrumentationTestCase {
final GPX10Parser parser = new GPX10Parser(StoredList.TEMPORARY_LIST.id);
final InputStream stream = new ByteArrayInputStream(gpxFirst.getBytes(CharEncoding.UTF_8));
- Collection<Geocache> caches = parser.parse(stream, null);
+ final Collection<Geocache> caches = parser.parse(stream, null);
assertThat(caches).isNotNull();
assertThat(caches).hasSize(1);
@@ -78,43 +76,43 @@ public class GpxSerializerTest extends AbstractResourceInstrumentationTestCase {
assertThat(replaceLogIds(gpxSecond)).isEqualTo(replaceLogIds(gpxFirst));
}
- private static String replaceLogIds(String gpx) {
+ private static String replaceLogIds(final String gpx) {
return gpx.replaceAll("log id=\"\\d*\"", "");
}
- private static String getGPXFromCache(String geocode) throws IOException {
+ private static String getGPXFromCache(final String geocode) throws IOException {
final StringWriter writer = new StringWriter();
new GpxSerializer().writeGPX(Collections.singletonList(geocode), writer, null);
return writer.toString();
}
public static void testStateFromStateCountry() throws Exception {
- Geocache cache = withLocation("state, country");
+ final Geocache cache = withLocation("state, country");
assertThat(GpxSerializer.getState(cache)).isEqualTo("state");
}
public static void testCountryFromStateCountry() throws Exception {
- Geocache cache = withLocation("state, country");
+ final Geocache cache = withLocation("state, country");
assertThat(GpxSerializer.getCountry(cache)).isEqualTo("country");
}
public static void testCountryFromCountryOnly() throws Exception {
- Geocache cache = withLocation("somewhere");
+ final Geocache cache = withLocation("somewhere");
assertThat(GpxSerializer.getCountry(cache)).isEqualTo("somewhere");
}
public static void testStateFromCountryOnly() throws Exception {
- Geocache cache = withLocation("somewhere");
+ final Geocache cache = withLocation("somewhere");
assertThat(GpxSerializer.getState(cache)).isEmpty();
}
public static void testCountryFromExternalCommaString() throws Exception {
- Geocache cache = withLocation("first,second"); // this was not created by c:geo, therefore don't split it
+ final Geocache cache = withLocation("first,second"); // this was not created by c:geo, therefore don't split it
assertThat(GpxSerializer.getState(cache)).isEmpty();
}
private static Geocache withLocation(final String location) {
- Geocache cache = new Geocache();
+ final Geocache cache = new Geocache();
cache.setLocation(location);
return cache;
}
diff --git a/tests/src/cgeo/geocaching/files/GPXParserTest.java b/tests/src/cgeo/geocaching/files/GPXParserTest.java
index 2cc1f34..8562087 100644
--- a/tests/src/cgeo/geocaching/files/GPXParserTest.java
+++ b/tests/src/cgeo/geocaching/files/GPXParserTest.java
@@ -6,6 +6,8 @@ import cgeo.geocaching.DataStore;
import cgeo.geocaching.Geocache;
import cgeo.geocaching.LogEntry;
import cgeo.geocaching.Waypoint;
+import cgeo.geocaching.connector.ConnectorFactory;
+import cgeo.geocaching.connector.IConnector;
import cgeo.geocaching.enumerations.CacheSize;
import cgeo.geocaching.enumerations.CacheType;
import cgeo.geocaching.enumerations.LoadFlags;
@@ -411,6 +413,9 @@ public class GPXParserTest extends AbstractResourceInstrumentationTestCase {
assertThat(lab.getName()).isEqualTo("01_Munich Olympic Walk Of Stars_Updated-Project MUNICH2014 - Mia san Giga! Olympiapark");
assertThat(lab.getShortDescription()).isEqualTo("01_Munich Olympic Walk Of Stars_Updated (Giga! Olympia Park)-Project MUNICH2014 - Mia san Giga! Olympiapark");
assertThat(lab.getDescription()).startsWith("DEU:");
+
+ final IConnector unknownConnector = ConnectorFactory.getConnector("ABC123");
+ assertThat(ConnectorFactory.getConnector(lab)).isSameAs(unknownConnector);
}
}
diff --git a/tests/src/cgeo/geocaching/location/GeocoderTest.java b/tests/src/cgeo/geocaching/location/GeocoderTest.java
index 0cc1a79..7cf6d0b 100644
--- a/tests/src/cgeo/geocaching/location/GeocoderTest.java
+++ b/tests/src/cgeo/geocaching/location/GeocoderTest.java
@@ -13,6 +13,9 @@ import rx.Observable;
import android.location.Address;
import android.location.Geocoder;
+import android.test.suitebuilder.annotation.Suppress;
+
+import java.util.Locale;
public class GeocoderTest extends CGeoTestCase {
@@ -23,13 +26,19 @@ public class GeocoderTest extends CGeoTestCase {
private static final Offset<Double> TEST_OFFSET = Offset.offset(0.00050);
public static void testAndroidGeocoder() {
- // Some emulators don't have access to Google Android geocoder
- if (Geocoder.isPresent()) {
- final AndroidGeocoder geocoder = new AndroidGeocoder(CgeoApplication.getInstance());
- testGeocoder(geocoder.getFromLocationName(TEST_ADDRESS), "Android", true);
- testGeocoder(geocoder.getFromLocation(TEST_COORDS), "Android reverse", true);
- } else {
- Log.i("not testing absent Android geocoder");
+ final Locale locale = Locale.getDefault();
+ try {
+ Locale.setDefault(Locale.US);
+ // Some emulators don't have access to Google Android geocoder
+ if (Geocoder.isPresent()) {
+ final AndroidGeocoder geocoder = new AndroidGeocoder(CgeoApplication.getInstance());
+ testGeocoder(geocoder.getFromLocationName(TEST_ADDRESS), "Android", true);
+ testGeocoder(geocoder.getFromLocation(TEST_COORDS), "Android reverse", true);
+ } else {
+ Log.i("not testing absent Android geocoder");
+ }
+ } finally {
+ Locale.setDefault(locale);
}
}
@@ -37,9 +46,16 @@ public class GeocoderTest extends CGeoTestCase {
testGeocoder(GCGeocoder.getFromLocationName(TEST_ADDRESS), "GC", false);
}
+ @Suppress
public static void testMapQuestGeocoder() {
- testGeocoder(MapQuestGeocoder.getFromLocationName(TEST_ADDRESS), "MapQuest", true);
- testGeocoder(MapQuestGeocoder.getFromLocation(TEST_COORDS), "MapQuest reverse", true);
+ final Locale locale = Locale.getDefault();
+ try {
+ Locale.setDefault(Locale.US);
+ testGeocoder(MapQuestGeocoder.getFromLocationName(TEST_ADDRESS), "MapQuest", true);
+ testGeocoder(MapQuestGeocoder.getFromLocation(TEST_COORDS), "MapQuest reverse", true);
+ } finally {
+ Locale.setDefault(locale);
+ }
}
public static void testGeocoder(final Observable<Address> addressObservable, final String geocoder, final boolean withAddress) {
@@ -47,9 +63,10 @@ public class GeocoderTest extends CGeoTestCase {
assertThat(address.getLatitude()).as(describe("latitude", geocoder)).isCloseTo(TEST_LATITUDE, TEST_OFFSET);
assertThat(address.getLongitude()).as(describe("longitude", geocoder)).isCloseTo(TEST_LONGITUDE, TEST_OFFSET);
if (withAddress) {
- assertThat(StringUtils.lowerCase(address.getAddressLine(0))).as(describe("street address", geocoder)).startsWith("46 rue barrault");
+ assertThat(StringUtils.lowerCase(address.getAddressLine(0))).as(describe("street address", geocoder)).contains("barrault");
assertThat(address.getLocality()).as(describe("locality", geocoder)).isEqualTo("Paris");
- assertThat(address.getCountryName()).as(describe("country name", geocoder)).isEqualTo("France");
+ assertThat(address.getCountryCode()).as(describe("country code", geocoder)).isEqualTo("FR");
+ // don't assert on country name, as this can be localized, e.g. with the mapquest geocoder
}
}
diff --git a/tests/src/cgeo/geocaching/sorting/NameComparatorTest.java b/tests/src/cgeo/geocaching/sorting/NameComparatorTest.java
index 533135d..6d4fa46 100644
--- a/tests/src/cgeo/geocaching/sorting/NameComparatorTest.java
+++ b/tests/src/cgeo/geocaching/sorting/NameComparatorTest.java
@@ -18,7 +18,7 @@ public class NameComparatorTest extends AndroidTestCase {
}
}
- private NameComparator comp = new NameComparator();
+ private final NameComparator comp = new NameComparator();
public void testLexical() {
assertSorted(new NamedCache("A"), new NamedCache("Z"));
@@ -38,11 +38,10 @@ public class NameComparatorTest extends AndroidTestCase {
/**
* Assert that a given collection of names is already sorted correctly.
*
- * @param names
*/
- private void assertSortedNames(String... names) {
- ArrayList<Geocache> caches = new ArrayList<Geocache>(names.length);
- for (String name : names) {
+ private void assertSortedNames(final String... names) {
+ final ArrayList<Geocache> caches = new ArrayList<Geocache>(names.length);
+ for (final String name : names) {
caches.add(new NamedCache(name));
}
Collections.sort(caches, comp);
diff --git a/tests/src/cgeo/geocaching/test/WhitespaceTest.java b/tests/src/cgeo/geocaching/test/WhitespaceTest.java
index 1ce7cc8..110cdbc 100644
--- a/tests/src/cgeo/geocaching/test/WhitespaceTest.java
+++ b/tests/src/cgeo/geocaching/test/WhitespaceTest.java
@@ -30,8 +30,6 @@ public class WhitespaceTest extends AbstractResourceInstrumentationTestCase {
* The place for the implementation to prove that the new version of replaceWhitespace is faster than
* BaseUtils.replaceWhitespace()
*
- * @param data
- * @return
*/
public static String replaceWhitespaceManually(final String data) {
final int length = data.length();
@@ -39,7 +37,7 @@ public class WhitespaceTest extends AbstractResourceInstrumentationTestCase {
data.getChars(0, length, chars, 0);
int resultSize = 0;
boolean lastWasWhitespace = true;
- for (char c : chars) {
+ for (final char c : chars) {
if (c == ' ' || c == '\n' || c == '\r' || c == '\t') {
if (!lastWasWhitespace) {
chars[resultSize++] = ' ';
diff --git a/tests/src/cgeo/geocaching/utils/DateUtilsTest.java b/tests/src/cgeo/geocaching/utils/DateUtilsTest.java
index d0a2b4a..44442f6 100644
--- a/tests/src/cgeo/geocaching/utils/DateUtilsTest.java
+++ b/tests/src/cgeo/geocaching/utils/DateUtilsTest.java
@@ -32,7 +32,7 @@ public class DateUtilsTest extends TestCase {
assertPastEvent(start, true);
}
- private static void assertPastEvent(final Calendar start, boolean expectedPast) {
+ private static void assertPastEvent(final Calendar start, final boolean expectedPast) {
final Geocache cache = new Geocache();
cache.setType(CacheType.EVENT);
@@ -40,4 +40,14 @@ public class DateUtilsTest extends TestCase {
assertThat(DateUtils.isPastEvent(cache)).isEqualTo(expectedPast);
}
+ public static void testIsFuture() {
+ final Calendar date = Calendar.getInstance();
+ assertThat(DateUtils.isFuture(date)).isFalse();
+
+ date.add(Calendar.DAY_OF_MONTH, 1);
+ assertThat(DateUtils.isFuture(date)).isFalse();
+
+ date.add(Calendar.DAY_OF_MONTH, 1);
+ assertThat(DateUtils.isFuture(date)).isTrue();
+ }
}
diff --git a/tests/src/cgeo/geocaching/utils/FileUtilsTest.java b/tests/src/cgeo/geocaching/utils/FileUtilsTest.java
new file mode 100644
index 0000000..72554fa
--- /dev/null
+++ b/tests/src/cgeo/geocaching/utils/FileUtilsTest.java
@@ -0,0 +1,61 @@
+package cgeo.geocaching.utils;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import cgeo.geocaching.files.LocalStorage;
+
+import junit.framework.TestCase;
+
+import android.content.Context;
+import android.test.ServiceTestCase;
+
+import java.io.File;
+import java.io.IOException;
+
+public class FileUtilsTest extends TestCase {
+
+ final File testDir = LocalStorage.getStorageDir("automated-tests");
+ final File baseFile = new File(testDir, "prefix.ext");
+ final File alternative1 = new File(testDir, "prefix_1.ext");
+ final File alternative2 = new File(testDir, "prefix_2.ext");
+
+ private Context getTestContext() {
+ try {
+ return (Context) ServiceTestCase.class.getMethod("getTestContext").invoke(this);
+ } catch (final Exception e) {
+ Log.e("Unable to get test context", e);
+ return null;
+ }
+ }
+
+ public void testGetUniqueNamedFile() throws IOException {
+ FileUtils.deleteDirectory(testDir);
+ testDir.mkdirs();
+ try {
+ assertThat(FileUtils.getUniqueNamedFile(baseFile)).isEqualTo(baseFile);
+ baseFile.createNewFile();
+ assertThat(FileUtils.getUniqueNamedFile(baseFile)).isEqualTo(alternative1);
+ alternative1.createNewFile();
+ assertThat(FileUtils.getUniqueNamedFile(baseFile)).isEqualTo(alternative2);
+ assertThat(FileUtils.getUniqueNamedFile(baseFile)).isEqualTo(alternative2);
+ } finally {
+ FileUtils.deleteDirectory(testDir);
+ }
+ }
+
+ public void testFileUrl() {
+ assertThat(FileUtils.isFileUrl("file:///tmp/foo/bar")).isTrue();
+ assertThat(FileUtils.isFileUrl("http://www.google.com")).isFalse();
+ assertThat(FileUtils.fileToUrl(new File("/tmp/foo/bar"))).isEqualTo("file:///tmp/foo/bar");
+ assertThat(FileUtils.urlToFile("file:///tmp/foo/bar").getPath()).isEqualTo("/tmp/foo/bar");
+ }
+
+ public void testCreateRemoveDirectories() {
+ FileUtils.deleteDirectory(testDir);
+ assertThat(testDir.exists()).isFalse();
+ FileUtils.mkdirs(testDir);
+ assertThat(testDir.exists()).isTrue();
+ FileUtils.deleteDirectory(testDir);
+ assertThat(testDir.exists()).isFalse();
+ }
+}
diff --git a/tests/src/cgeo/geocaching/utils/ProcessUtilsTest.java b/tests/src/cgeo/geocaching/utils/ProcessUtilsTest.java
index 2c6ed18..b442c8a 100644
--- a/tests/src/cgeo/geocaching/utils/ProcessUtilsTest.java
+++ b/tests/src/cgeo/geocaching/utils/ProcessUtilsTest.java
@@ -6,7 +6,7 @@ import junit.framework.TestCase;
public class ProcessUtilsTest extends TestCase {
public static void testIsInstalled() {
- assertThat(ProcessUtils.isInstalled("com.android.launcher")).isTrue();
+ assertThat(ProcessUtils.isInstalled("com.android.settings")).isTrue();
}
public static void testIsInstalledNotLaunchable() {
@@ -16,7 +16,7 @@ public class ProcessUtilsTest extends TestCase {
}
public static void testIsLaunchable() {
- assertThat(ProcessUtils.isInstalled("com.android.settings")).isTrue();
+ assertThat(ProcessUtils.isLaunchable("com.android.settings")).isTrue();
}
}
diff --git a/tests/src/cgeo/geocaching/utils/RxUtilsTest.java b/tests/src/cgeo/geocaching/utils/RxUtilsTest.java
index 2487184..cc8589b 100644
--- a/tests/src/cgeo/geocaching/utils/RxUtilsTest.java
+++ b/tests/src/cgeo/geocaching/utils/RxUtilsTest.java
@@ -4,7 +4,6 @@ import static org.assertj.core.api.Assertions.assertThat;
import rx.Observable;
import rx.Subscription;
-import rx.functions.Func1;
import rx.subjects.PublishSubject;
import rx.subjects.ReplaySubject;
@@ -21,16 +20,6 @@ public class RxUtilsTest extends AndroidTestCase {
range.onCompleted();
}
- public static void testTakeUntil() {
- final Observable<Integer> observable = range.lift(RxUtils.operatorTakeUntil(new Func1<Integer, Boolean>() {
- @Override
- public Boolean call(final Integer value) {
- return value > 6;
- }
- }));
- assertThat(observable.toList().toBlocking().single().toArray()).isEqualTo(new int[]{1, 2, 3, 4, 5, 6, 7});
- }
-
public static void testRememberLast() {
final PublishSubject<String> rawObservable = PublishSubject.create();
final Observable<String> observable = RxUtils.rememberLast(rawObservable, "initial");
diff --git a/tests/src/cgeo/junit/CgeoTestRunner.java b/tests/src/cgeo/junit/CgeoTestRunner.java
index 16a5f12..94803cf 100644
--- a/tests/src/cgeo/junit/CgeoTestRunner.java
+++ b/tests/src/cgeo/junit/CgeoTestRunner.java
@@ -11,10 +11,12 @@ import android.util.Log;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
/**
* Test runner which derives from the newer Google instrumentation test runner used by the Espresso test framework. It
- * adds junit report functionality by cloning the behaviour of the {@link JUnitReportTestRunner}.
+ * adds junit report functionality by cloning the behavior of the {@link JUnitReportTestRunner}.
*
*/
public class CgeoTestRunner extends GoogleInstrumentationTestRunner {
@@ -86,21 +88,32 @@ public class CgeoTestRunner extends GoogleInstrumentationTestRunner {
@Override
public void start() {
- mListener = new JUnitReportListener(getContext(), getTargetContext(), mReportFile, mReportDir, mFilterTraces, mMultiFile);
- try {
- Class<?> c = getClass();
- Field bridgeTestRunner = c.getSuperclass().getDeclaredField("bridgeTestRunner");
- bridgeTestRunner.setAccessible(true);
- Object obj = bridgeTestRunner.get(this);
- Method m = obj.getClass().getDeclaredMethod("getAndroidTestRunner", (Class[]) null);
- AndroidTestRunner androidTestRunner = (AndroidTestRunner) m.invoke(obj);
- androidTestRunner.addTestListener(mListener);
- } catch (NoSuchFieldException | InvocationTargetException | IllegalAccessException | NoSuchMethodException | SecurityException x) {
- Log.e(LOG_TAG, x.toString());
- }
+ makeAndroidTestRunnerAccessible();
super.start();
}
+ private void makeAndroidTestRunnerAccessible() {
+ AccessController.doPrivileged(new PrivilegedAction<Void>() {
+ @Override
+ public Void run() {
+ mListener = new JUnitReportListener(getContext(), getTargetContext(), mReportFile, mReportDir, mFilterTraces, mMultiFile);
+ try {
+ Class<?> c = getClass();
+ Field bridgeTestRunner = c.getSuperclass().getDeclaredField("bridgeTestRunner");
+ bridgeTestRunner.setAccessible(true);
+ Object obj = bridgeTestRunner.get(this);
+ Method m = obj.getClass().getDeclaredMethod("getAndroidTestRunner", (Class[]) null);
+ AndroidTestRunner androidTestRunner = (AndroidTestRunner) m.invoke(obj);
+ androidTestRunner.addTestListener(mListener);
+ } catch (NoSuchFieldException | InvocationTargetException | IllegalAccessException
+ | NoSuchMethodException | SecurityException x) {
+ Log.e(LOG_TAG, x.toString());
+ }
+ return null;
+ }
+ });
+ }
+
@Override
public void finish(int resultCode, Bundle results) {
if (mListener != null) {