mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-11-30 08:11:17 +00:00
Fixed tests
This commit is contained in:
parent
eb99ed9082
commit
6a595952db
3 changed files with 26 additions and 41 deletions
|
@ -4,11 +4,17 @@ import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.support.annotation.NonNull;
|
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 com.nutomic.syncthingandroid.service.RestApi;
|
||||||
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class MockRestApi extends RestApi {
|
public class MockRestApi extends RestApi {
|
||||||
|
|
||||||
|
@ -33,66 +39,52 @@ public class MockRestApi extends RestApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getValue(String name, String key) {
|
public List<Device> getDevices(boolean includeLocal) {
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public <T> void setValue(String name, String key, T value, boolean isArray, Activity activity) {
|
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Device> getDevices(boolean includeLocal) {
|
public void getSystemInfo(OnResultListener1<SystemInfo> listener) {
|
||||||
return new ArrayList<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void getSystemInfo(final OnReceiveSystemInfoListener listener) {
|
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Folder> getFolders() {
|
public List<Folder> getFolders() {
|
||||||
return new ArrayList<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void getConnections(final OnReceiveConnectionsListener listener) {
|
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void getModel(final String folderId, final OnReceiveModelListener listener) {
|
public void getConnections(OnResultListener1<Map<String, Connection>> listener) {
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void editDevice(@NonNull Device device, Activity activity, OnDeviceIdNormalizedListener listener) {
|
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean deleteDevice(Device device, Activity activity) {
|
public void getModel(String folderId, OnResultListener2<String, Model> listener) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void editFolder(Folder folder, boolean create, Activity activity) {
|
public void editDevice(Device newDevice) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean deleteFolder(Folder folder, Activity activity) {
|
public void removeDevice(String deviceId) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void normalizeDeviceId(String id, final OnDeviceIdNormalizedListener listener) {
|
public void editFolder(Folder newFolder) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void copyDeviceId(String id) {
|
public void removeFolder(String id) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void normalizeDeviceId(String id, OnResultListener1<String> listener, OnResultListener1<String> errorListener) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -123,19 +123,11 @@ public class RestApiTest {
|
||||||
@Test
|
@Test
|
||||||
public void testNormalizeDeviceId() throws InterruptedException {
|
public void testNormalizeDeviceId() throws InterruptedException {
|
||||||
final CountDownLatch latch = new CountDownLatch(1);
|
final CountDownLatch latch = new CountDownLatch(1);
|
||||||
mApi.normalizeDeviceId("p56ioi7m--zjnu2iq-gdr-eydm-2mgtmgl3bxnpq6w5btbbz4tjxzwicq",
|
mApi.normalizeDeviceId("p56ioi7m--zjnu2iq-gdr-eydm-2mgtmgl3bxnpq6w5btbbz4tjxzwicq", id -> {
|
||||||
(normalizedId, error) -> {
|
Assert.assertEquals("P56IOI7-MZJNU2Y-IQGDREY-DM2MGTI-MGL3BXN-PQ6W5BM-TBBZ4TJ-XZWICQ2", id);
|
||||||
Assert.assertEquals("P56IOI7-MZJNU2Y-IQGDREY-DM2MGTI-MGL3BXN-PQ6W5BM-TBBZ4TJ-XZWICQ2",
|
|
||||||
normalizedId);
|
|
||||||
latch.countDown();
|
latch.countDown();
|
||||||
});
|
}, error -> Assert.fail());
|
||||||
Assert.assertTrue(latch.await(1, TimeUnit.SECONDS));
|
Assert.assertTrue(latch.await(1, TimeUnit.SECONDS));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetValueEarly() {
|
|
||||||
// Should never throw an exception.
|
|
||||||
mApi.getValue("Options", "ListenAddress");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.nutomic.syncthingandroid.test.util;
|
||||||
import android.support.test.InstrumentationRegistry;
|
import android.support.test.InstrumentationRegistry;
|
||||||
import android.support.test.rule.ServiceTestRule;
|
import android.support.test.rule.ServiceTestRule;
|
||||||
|
|
||||||
|
import com.nutomic.syncthingandroid.model.Folder;
|
||||||
import com.nutomic.syncthingandroid.service.RestApi;
|
import com.nutomic.syncthingandroid.service.RestApi;
|
||||||
import com.nutomic.syncthingandroid.test.MockContext;
|
import com.nutomic.syncthingandroid.test.MockContext;
|
||||||
import com.nutomic.syncthingandroid.test.Util;
|
import com.nutomic.syncthingandroid.test.Util;
|
||||||
|
@ -48,8 +49,8 @@ public class FolderObserverTest implements FolderObserver.OnFolderFileChangeList
|
||||||
Assert.assertFalse(relativePath.endsWith("should-not-notifiy"));
|
Assert.assertFalse(relativePath.endsWith("should-not-notifiy"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private RestApi.Folder createFolder(String id) {
|
private Folder createFolder(String id) {
|
||||||
RestApi.Folder r = new RestApi.Folder();
|
Folder r = new Folder();
|
||||||
r.path = mTestFolder.getPath();
|
r.path = mTestFolder.getPath();
|
||||||
r.id = id;
|
r.id = id;
|
||||||
return r;
|
return r;
|
||||||
|
@ -106,7 +107,7 @@ public class FolderObserverTest implements FolderObserver.OnFolderFileChangeList
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNotExisting() throws IOException, InterruptedException {
|
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.path = new File(new MockContext(InstrumentationRegistry.getTargetContext()).getFilesDir(), "not-existing").getPath();
|
||||||
r.id = "testNotExisting";
|
r.id = "testNotExisting";
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in a new issue