1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-11-26 22:31:16 +00:00

Fixed tests

This commit is contained in:
Felix Ableitner 2016-10-31 22:28:06 +09:00
parent eb99ed9082
commit 6a595952db
3 changed files with 26 additions and 41 deletions

View file

@ -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 <T> void setValue(String name, String key, T value, boolean isArray, Activity activity) {
public List<Device> getDevices(boolean includeLocal) {
throw new UnsupportedOperationException();
}
@Override
public List<Device> getDevices(boolean includeLocal) {
return new ArrayList<>();
}
@Override
public void getSystemInfo(final OnReceiveSystemInfoListener listener) {
public void getSystemInfo(OnResultListener1<SystemInfo> listener) {
throw new UnsupportedOperationException();
}
@Override
public List<Folder> 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<Map<String, Connection>> listener) {
throw new UnsupportedOperationException();
}
@Override
public boolean deleteDevice(Device device, Activity activity) {
public void getModel(String folderId, OnResultListener2<String, Model> 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<String> listener, OnResultListener1<String> errorListener) {
throw new UnsupportedOperationException();
}

View file

@ -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");
}
}

View file

@ -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 {