From 377615a1aa703041870d6ebe42ab22d9b33f031f Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Mon, 29 Sep 2014 00:43:59 +0300 Subject: [PATCH] Test fixes, removed RestAPI tests that require activity. These tests could not be executed reliably, not even using activity tests. --- .../syncthingandroid/test/MockRestApi.java | 10 ++---- .../test/MockSyncthingService.java | 2 +- .../test/syncthing/RestApiTest.java | 36 ------------------- .../syncthing/SyncthingRunnable.java | 4 +-- 4 files changed, 6 insertions(+), 46 deletions(-) diff --git a/src/androidTest/java/com/nutomic/syncthingandroid/test/MockRestApi.java b/src/androidTest/java/com/nutomic/syncthingandroid/test/MockRestApi.java index f674bdda..5c1b5a90 100644 --- a/src/androidTest/java/com/nutomic/syncthingandroid/test/MockRestApi.java +++ b/src/androidTest/java/com/nutomic/syncthingandroid/test/MockRestApi.java @@ -10,13 +10,9 @@ import java.util.List; public class MockRestApi extends RestApi { - public MockRestApi(Context context, String url, OnApiAvailableListener listener) { - super(context, url, listener); - } - - @Override - public void setApiKey(String apiKey) { - throw new UnsupportedOperationException(); + public MockRestApi(Context context, String url, String apiKey, + OnApiAvailableListener listener) { + super(context, url, apiKey, listener); } @Override diff --git a/src/androidTest/java/com/nutomic/syncthingandroid/test/MockSyncthingService.java b/src/androidTest/java/com/nutomic/syncthingandroid/test/MockSyncthingService.java index 9d44d6bc..da4fa1cc 100644 --- a/src/androidTest/java/com/nutomic/syncthingandroid/test/MockSyncthingService.java +++ b/src/androidTest/java/com/nutomic/syncthingandroid/test/MockSyncthingService.java @@ -49,7 +49,7 @@ public class MockSyncthingService extends SyncthingService { @Override public RestApi getApi() { - return new MockRestApi(this, null, null); + return new MockRestApi(this, null, null, null); } @Override diff --git a/src/androidTest/java/com/nutomic/syncthingandroid/test/syncthing/RestApiTest.java b/src/androidTest/java/com/nutomic/syncthingandroid/test/syncthing/RestApiTest.java index 4e0f9c97..d6a2c7e5 100644 --- a/src/androidTest/java/com/nutomic/syncthingandroid/test/syncthing/RestApiTest.java +++ b/src/androidTest/java/com/nutomic/syncthingandroid/test/syncthing/RestApiTest.java @@ -1,8 +1,6 @@ package com.nutomic.syncthingandroid.test.syncthing; -import android.app.Activity; import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.LargeTest; import android.test.suitebuilder.annotation.MediumTest; import android.test.suitebuilder.annotation.SmallTest; @@ -14,7 +12,6 @@ import com.nutomic.syncthingandroid.syncthing.SyncthingService; import com.nutomic.syncthingandroid.test.MockContext; import com.nutomic.syncthingandroid.util.ConfigXml; -import java.util.ArrayList; import java.util.Map; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -139,39 +136,6 @@ public class RestApiTest extends AndroidTestCase { latch.await(1, TimeUnit.SECONDS); } - @LargeTest - public void testModifyNode() throws InterruptedException { - final RestApi.Node node = new RestApi.Node(); - node.NodeID = "P56IOI7-MZJNU2Y-IQGDREY-DM2MGTI-MGL3BXN-PQ6W5BM-TBBZ4TJ-XZWICQ2"; - node.Addresses = "dynamic"; - node.Name = "my node"; - final CountDownLatch latch = new CountDownLatch(1); - mApi.editNode(node, new Activity(), new RestApi.OnNodeIdNormalizedListener() { - @Override - public void onNodeIdNormalized(String normalizedId, String error) { - assertEquals(node.NodeID, normalizedId); - assertEquals(null, error); - latch.countDown(); - } - }); - latch.await(10, TimeUnit.SECONDS); - - assertTrue(mApi.deleteNode(node, new Activity())); - } - - @SmallTest - public void testModifyRepo() { - RestApi.Repo repo = new RestApi.Repo(); - repo.Directory = "/my/dir"; - repo.ID = "my-repo"; - repo.NodeIds = new ArrayList<>(); - repo.ReadOnly = false; - repo.Versioning = new RestApi.Versioning(); - assertTrue(mApi.editRepo(repo, true, new Activity())); - - assertTrue(mApi.deleteRepo(repo, new Activity())); - } - @MediumTest public void testNormalizeNodeId() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); diff --git a/src/main/java/com/nutomic/syncthingandroid/syncthing/SyncthingRunnable.java b/src/main/java/com/nutomic/syncthingandroid/syncthing/SyncthingRunnable.java index f9b4aaa2..241050ed 100644 --- a/src/main/java/com/nutomic/syncthingandroid/syncthing/SyncthingRunnable.java +++ b/src/main/java/com/nutomic/syncthingandroid/syncthing/SyncthingRunnable.java @@ -82,9 +82,9 @@ public class SyncthingRunnable implements Runnable { .setOnlyAlertOnce(true); Notification n = new NotificationCompat.BigTextStyle(b) .bigText(mContext.getString(R.string.binary_crashed_message, ret)).build(); - NotificationManager mNotificationManager = (NotificationManager) + NotificationManager nm = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); - mNotificationManager.notify(NOTIFICATION_CRASHED, n); + nm.notify(NOTIFICATION_CRASHED, n); } } }