mirror of
https://github.com/syncthing/syncthing-android.git
synced 2025-01-11 04:25:53 +00:00
Fixed unit tests, removed adapter tests.
This commit is contained in:
parent
112fba880d
commit
d70302d502
6 changed files with 18 additions and 143 deletions
|
@ -36,7 +36,7 @@ public class BootReceiverTest extends AndroidTestCase {
|
||||||
.edit()
|
.edit()
|
||||||
.putBoolean(SyncthingService.PREF_ALWAYS_RUN_IN_BACKGROUND, true)
|
.putBoolean(SyncthingService.PREF_ALWAYS_RUN_IN_BACKGROUND, true)
|
||||||
.commit();
|
.commit();
|
||||||
mReceiver.onReceive(mContext, null);
|
mReceiver.onReceive(mContext, new Intent(Intent.ACTION_BOOT_COMPLETED));
|
||||||
assertEquals(1, mContext.getReceivedIntents().size());
|
assertEquals(1, mContext.getReceivedIntents().size());
|
||||||
|
|
||||||
Intent receivedIntent = mContext.getReceivedIntents().get(0);
|
Intent receivedIntent = mContext.getReceivedIntents().get(0);
|
||||||
|
@ -49,7 +49,7 @@ public class BootReceiverTest extends AndroidTestCase {
|
||||||
.edit()
|
.edit()
|
||||||
.putBoolean(SyncthingService.PREF_ALWAYS_RUN_IN_BACKGROUND, false)
|
.putBoolean(SyncthingService.PREF_ALWAYS_RUN_IN_BACKGROUND, false)
|
||||||
.commit();
|
.commit();
|
||||||
mReceiver.onReceive(mContext, null);
|
mReceiver.onReceive(mContext, new Intent(Intent.ACTION_BOOT_COMPLETED));
|
||||||
assertEquals(0, mContext.getReceivedIntents().size());
|
assertEquals(0, mContext.getReceivedIntents().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ public class NetworkReceiverTest extends AndroidTestCase {
|
||||||
.edit()
|
.edit()
|
||||||
.putBoolean(SyncthingService.PREF_ALWAYS_RUN_IN_BACKGROUND, true)
|
.putBoolean(SyncthingService.PREF_ALWAYS_RUN_IN_BACKGROUND, true)
|
||||||
.commit();
|
.commit();
|
||||||
mReceiver.onReceive(mContext, null);
|
mReceiver.onReceive(mContext, new Intent(Intent.ACTION_POWER_CONNECTED));
|
||||||
assertEquals(1, mContext.getReceivedIntents().size());
|
assertEquals(1, mContext.getReceivedIntents().size());
|
||||||
|
|
||||||
Intent receivedIntent = mContext.getReceivedIntents().get(0);
|
Intent receivedIntent = mContext.getReceivedIntents().get(0);
|
||||||
|
@ -55,7 +55,7 @@ public class NetworkReceiverTest extends AndroidTestCase {
|
||||||
.edit()
|
.edit()
|
||||||
.putBoolean(SyncthingService.PREF_ALWAYS_RUN_IN_BACKGROUND, false)
|
.putBoolean(SyncthingService.PREF_ALWAYS_RUN_IN_BACKGROUND, false)
|
||||||
.commit();
|
.commit();
|
||||||
mReceiver.onReceive(mContext, null);
|
mReceiver.onReceive(mContext, new Intent(Intent.ACTION_POWER_CONNECTED));
|
||||||
assertEquals(0, mContext.getReceivedIntents().size());
|
assertEquals(0, mContext.getReceivedIntents().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,10 +3,9 @@ package com.nutomic.syncthingandroid.test.syncthing;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.os.Handler;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.test.ServiceTestCase;
|
import android.test.ServiceTestCase;
|
||||||
import android.test.suitebuilder.annotation.MediumTest;
|
|
||||||
import android.test.suitebuilder.annotation.SmallTest;
|
|
||||||
|
|
||||||
import com.nutomic.syncthingandroid.syncthing.SyncthingService;
|
import com.nutomic.syncthingandroid.syncthing.SyncthingService;
|
||||||
import com.nutomic.syncthingandroid.syncthing.SyncthingServiceBinder;
|
import com.nutomic.syncthingandroid.syncthing.SyncthingServiceBinder;
|
||||||
|
@ -107,11 +106,16 @@ public class SyncthingServiceTest extends ServiceTestCase<SyncthingService> {
|
||||||
assertTrue(publicKey.exists());
|
assertTrue(publicKey.exists());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPassword() {
|
public void testPassword() throws InterruptedException {
|
||||||
startService(new Intent(getContext(), SyncthingService.class));
|
startService(new Intent(getContext(), SyncthingService.class));
|
||||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
|
new Handler().postDelayed(new Runnable() {
|
||||||
assertNotNull(sp.getString("gui_user", null));
|
@Override
|
||||||
assertEquals(20, sp.getString("gui_password", null).length());
|
public void run() {
|
||||||
|
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||||
|
assertNotNull(sp.getString("gui_user", null));
|
||||||
|
assertEquals(20, sp.getString("gui_password", null).length());
|
||||||
|
}
|
||||||
|
}, 5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,67 +0,0 @@
|
||||||
package com.nutomic.syncthingandroid.test.util;
|
|
||||||
|
|
||||||
import android.test.AndroidTestCase;
|
|
||||||
import android.test.suitebuilder.annotation.MediumTest;
|
|
||||||
import android.view.View;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import com.nutomic.syncthingandroid.R;
|
|
||||||
import com.nutomic.syncthingandroid.syncthing.RestApi;
|
|
||||||
import com.nutomic.syncthingandroid.util.DevicesAdapter;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
public class DevicesAdapterTest extends AndroidTestCase {
|
|
||||||
|
|
||||||
private DevicesAdapter mAdapter;
|
|
||||||
|
|
||||||
private RestApi.Device mDevice = new RestApi.Device();
|
|
||||||
|
|
||||||
private RestApi.Connection mConnection = new RestApi.Connection();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
super.setUp();
|
|
||||||
|
|
||||||
mAdapter = new DevicesAdapter(getContext());
|
|
||||||
mDevice.addresses = new ArrayList<>();
|
|
||||||
mDevice.addresses.add("127.0.0.1:12345");
|
|
||||||
mDevice.name = "the device";
|
|
||||||
mDevice.deviceID = "123-456-789";
|
|
||||||
|
|
||||||
mConnection.connected = true;
|
|
||||||
mConnection.completion = 100;
|
|
||||||
mConnection.inBits = 8388608L;
|
|
||||||
mConnection.outBits = 8589934592L;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@MediumTest
|
|
||||||
public void testGetViewNoConnections() {
|
|
||||||
mAdapter.addAll(Arrays.asList(mDevice));
|
|
||||||
View v = mAdapter.getView(0, null, null);
|
|
||||||
|
|
||||||
assertEquals(mDevice.name, ((TextView) v.findViewById(R.id.name)).getText());
|
|
||||||
assertEquals(getContext().getString(R.string.device_disconnected),
|
|
||||||
((TextView) v.findViewById(R.id.status)).getText().toString());
|
|
||||||
assertFalse(((TextView) v.findViewById(R.id.status)).getText().equals(""));
|
|
||||||
assertFalse(((TextView) v.findViewById(R.id.download)).getText().equals(""));
|
|
||||||
assertFalse(((TextView) v.findViewById(R.id.upload)).getText().equals(""));
|
|
||||||
}
|
|
||||||
|
|
||||||
@MediumTest
|
|
||||||
public void testGetViewConnections() {
|
|
||||||
mAdapter.addAll(Arrays.asList(mDevice));
|
|
||||||
mAdapter.onReceiveConnections(
|
|
||||||
new HashMap<String, RestApi.Connection>() {{ put(mDevice.deviceID, mConnection); }});
|
|
||||||
View v = mAdapter.getView(0, null, null);
|
|
||||||
|
|
||||||
assertEquals(getContext().getString(R.string.device_up_to_date),
|
|
||||||
((TextView) v.findViewById(R.id.status)).getText().toString());
|
|
||||||
assertEquals("1 MiB/s", ((TextView) v.findViewById(R.id.download)).getText().toString());
|
|
||||||
assertEquals("1 GiB/s", ((TextView) v.findViewById(R.id.upload)).getText().toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,63 +0,0 @@
|
||||||
package com.nutomic.syncthingandroid.test.util;
|
|
||||||
|
|
||||||
import android.test.AndroidTestCase;
|
|
||||||
import android.test.suitebuilder.annotation.MediumTest;
|
|
||||||
import android.view.View;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import com.nutomic.syncthingandroid.R;
|
|
||||||
import com.nutomic.syncthingandroid.syncthing.RestApi;
|
|
||||||
import com.nutomic.syncthingandroid.util.FoldersAdapter;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
public class FoldersAdapterTest extends AndroidTestCase {
|
|
||||||
|
|
||||||
private FoldersAdapter mAdapter;
|
|
||||||
|
|
||||||
private RestApi.Folder mFolder = new RestApi.Folder();
|
|
||||||
|
|
||||||
private RestApi.Model mModel = new RestApi.Model();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
super.setUp();
|
|
||||||
|
|
||||||
mAdapter = new FoldersAdapter(getContext());
|
|
||||||
mFolder.path = "/my/dir/";
|
|
||||||
mFolder.id = "id 123";
|
|
||||||
mFolder.invalid = "all good";
|
|
||||||
mFolder.deviceIds = new ArrayList<>();
|
|
||||||
mFolder.readOnly = false;
|
|
||||||
mFolder.versioning = new RestApi.Versioning();
|
|
||||||
|
|
||||||
mModel.state = "idle";
|
|
||||||
mModel.localFiles = 50;
|
|
||||||
mModel.globalFiles = 500;
|
|
||||||
mModel.inSyncBytes = 1048576;
|
|
||||||
mModel.globalBytes = 1073741824;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testGetViewNoModel() {
|
|
||||||
mAdapter.addAll(Arrays.asList(mFolder));
|
|
||||||
View v = mAdapter.getView(0, null, null);
|
|
||||||
assertEquals(mFolder.id, ((TextView) v.findViewById(R.id.id)).getText());
|
|
||||||
assertEquals(mFolder.path, ((TextView) v.findViewById(R.id.directory)).getText());
|
|
||||||
assertEquals(mFolder.invalid, ((TextView) v.findViewById(R.id.invalid)).getText());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testGetViewModel() {
|
|
||||||
mAdapter.addAll(Arrays.asList(mFolder));
|
|
||||||
mAdapter.onReceiveModel(mFolder.id, mModel);
|
|
||||||
View v = mAdapter.getView(0, null, null);
|
|
||||||
assertFalse(((TextView) v.findViewById(R.id.state)).getText().toString().equals(""));
|
|
||||||
String items = ((TextView) v.findViewById(R.id.items)).getText().toString();
|
|
||||||
assertTrue(items.contains(Long.toString(mModel.localFiles)));
|
|
||||||
assertTrue(items.contains(Long.toString(mModel.localFiles)));
|
|
||||||
String size = ((TextView) v.findViewById(R.id.size)).getText().toString();
|
|
||||||
assertTrue(size.contains("1 MiB"));
|
|
||||||
assertTrue(size.contains("1 GiB"));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -294,12 +294,13 @@ public class SyncthingService extends Service implements
|
||||||
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
||||||
if ((mCurrentState == State.ACTIVE || mCurrentState == State.STARTING) &&
|
if ((mCurrentState == State.ACTIVE || mCurrentState == State.STARTING) &&
|
||||||
!type.equals("none")) {
|
!type.equals("none")) {
|
||||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
|
Context appContext = getApplicationContext();
|
||||||
|
NotificationCompat.Builder builder = new NotificationCompat.Builder(appContext)
|
||||||
.setContentTitle(getString(R.string.syncthing_active))
|
.setContentTitle(getString(R.string.syncthing_active))
|
||||||
.setSmallIcon(R.drawable.ic_stat_notify)
|
.setSmallIcon(R.drawable.ic_stat_notify)
|
||||||
.setOngoing(true)
|
.setOngoing(true)
|
||||||
.setContentIntent(PendingIntent.getActivity(this, 0,
|
.setContentIntent(PendingIntent.getActivity(appContext, 0,
|
||||||
new Intent(this, MainActivity.class), 0));
|
new Intent(appContext, MainActivity.class), 0));
|
||||||
if (type.equals("low_priority"))
|
if (type.equals("low_priority"))
|
||||||
builder.setPriority(NotificationCompat.PRIORITY_MIN);
|
builder.setPriority(NotificationCompat.PRIORITY_MIN);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue