From 6a595952dbcedb1518277a88469a6567d243e860 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Mon, 31 Oct 2016 22:28:06 +0900 Subject: [PATCH] Fixed tests --- .../syncthingandroid/test/MockRestApi.java | 46 ++++++++----------- .../test/syncthing/RestApiTest.java | 14 ++---- .../test/util/FolderObserverTest.java | 7 +-- 3 files changed, 26 insertions(+), 41 deletions(-) diff --git a/src/androidTest/java/com/nutomic/syncthingandroid/test/MockRestApi.java b/src/androidTest/java/com/nutomic/syncthingandroid/test/MockRestApi.java index 1d7222a7..93d4a86f 100644 --- a/src/androidTest/java/com/nutomic/syncthingandroid/test/MockRestApi.java +++ b/src/androidTest/java/com/nutomic/syncthingandroid/test/MockRestApi.java @@ -4,11 +4,17 @@ import android.app.Activity; import android.content.Context; import android.support.annotation.NonNull; +import com.nutomic.syncthingandroid.model.Connection; +import com.nutomic.syncthingandroid.model.Device; +import com.nutomic.syncthingandroid.model.Folder; +import com.nutomic.syncthingandroid.model.Model; +import com.nutomic.syncthingandroid.model.SystemInfo; import com.nutomic.syncthingandroid.service.RestApi; import java.net.URL; import java.util.ArrayList; import java.util.List; +import java.util.Map; public class MockRestApi extends RestApi { @@ -33,66 +39,52 @@ public class MockRestApi extends RestApi { } @Override - public String getValue(String name, String key) { - return ""; - } - - @Override - public void setValue(String name, String key, T value, boolean isArray, Activity activity) { + public List getDevices(boolean includeLocal) { throw new UnsupportedOperationException(); } @Override - public List getDevices(boolean includeLocal) { - return new ArrayList<>(); - } - - @Override - public void getSystemInfo(final OnReceiveSystemInfoListener listener) { + public void getSystemInfo(OnResultListener1 listener) { throw new UnsupportedOperationException(); } @Override public List getFolders() { - return new ArrayList<>(); - } - - @Override - public void getConnections(final OnReceiveConnectionsListener listener) { throw new UnsupportedOperationException(); } @Override - public void getModel(final String folderId, final OnReceiveModelListener listener) { - } - - @Override - public void editDevice(@NonNull Device device, Activity activity, OnDeviceIdNormalizedListener listener) { + public void getConnections(OnResultListener1> listener) { throw new UnsupportedOperationException(); } @Override - public boolean deleteDevice(Device device, Activity activity) { + public void getModel(String folderId, OnResultListener2 listener) { throw new UnsupportedOperationException(); } @Override - public void editFolder(Folder folder, boolean create, Activity activity) { + public void editDevice(Device newDevice) { throw new UnsupportedOperationException(); } @Override - public boolean deleteFolder(Folder folder, Activity activity) { + public void removeDevice(String deviceId) { throw new UnsupportedOperationException(); } @Override - public void normalizeDeviceId(String id, final OnDeviceIdNormalizedListener listener) { + public void editFolder(Folder newFolder) { throw new UnsupportedOperationException(); } @Override - public void copyDeviceId(String id) { + public void removeFolder(String id) { + throw new UnsupportedOperationException(); + } + + @Override + public void normalizeDeviceId(String id, OnResultListener1 listener, OnResultListener1 errorListener) { throw new UnsupportedOperationException(); } 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 31b88d0a..73e6a5a6 100644 --- a/src/androidTest/java/com/nutomic/syncthingandroid/test/syncthing/RestApiTest.java +++ b/src/androidTest/java/com/nutomic/syncthingandroid/test/syncthing/RestApiTest.java @@ -123,19 +123,11 @@ public class RestApiTest { @Test public void testNormalizeDeviceId() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); - mApi.normalizeDeviceId("p56ioi7m--zjnu2iq-gdr-eydm-2mgtmgl3bxnpq6w5btbbz4tjxzwicq", - (normalizedId, error) -> { - Assert.assertEquals("P56IOI7-MZJNU2Y-IQGDREY-DM2MGTI-MGL3BXN-PQ6W5BM-TBBZ4TJ-XZWICQ2", - normalizedId); + mApi.normalizeDeviceId("p56ioi7m--zjnu2iq-gdr-eydm-2mgtmgl3bxnpq6w5btbbz4tjxzwicq", id -> { + Assert.assertEquals("P56IOI7-MZJNU2Y-IQGDREY-DM2MGTI-MGL3BXN-PQ6W5BM-TBBZ4TJ-XZWICQ2", id); latch.countDown(); - }); + }, error -> Assert.fail()); Assert.assertTrue(latch.await(1, TimeUnit.SECONDS)); } - @Test - public void testGetValueEarly() { - // Should never throw an exception. - mApi.getValue("Options", "ListenAddress"); - } - } diff --git a/src/androidTest/java/com/nutomic/syncthingandroid/test/util/FolderObserverTest.java b/src/androidTest/java/com/nutomic/syncthingandroid/test/util/FolderObserverTest.java index 0733a63b..0dbdf565 100644 --- a/src/androidTest/java/com/nutomic/syncthingandroid/test/util/FolderObserverTest.java +++ b/src/androidTest/java/com/nutomic/syncthingandroid/test/util/FolderObserverTest.java @@ -3,6 +3,7 @@ package com.nutomic.syncthingandroid.test.util; import android.support.test.InstrumentationRegistry; import android.support.test.rule.ServiceTestRule; +import com.nutomic.syncthingandroid.model.Folder; import com.nutomic.syncthingandroid.service.RestApi; import com.nutomic.syncthingandroid.test.MockContext; import com.nutomic.syncthingandroid.test.Util; @@ -48,8 +49,8 @@ public class FolderObserverTest implements FolderObserver.OnFolderFileChangeList Assert.assertFalse(relativePath.endsWith("should-not-notifiy")); } - private RestApi.Folder createFolder(String id) { - RestApi.Folder r = new RestApi.Folder(); + private Folder createFolder(String id) { + Folder r = new Folder(); r.path = mTestFolder.getPath(); r.id = id; return r; @@ -106,7 +107,7 @@ public class FolderObserverTest implements FolderObserver.OnFolderFileChangeList @Test public void testNotExisting() throws IOException, InterruptedException { - RestApi.Folder r = new RestApi.Folder(); + Folder r = new Folder(); r.path = new File(new MockContext(InstrumentationRegistry.getTargetContext()).getFilesDir(), "not-existing").getPath(); r.id = "testNotExisting"; try {