mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-11-23 04:41:16 +00:00
Moved SyncthingServiceTest back to androidTest
This commit is contained in:
parent
c749e563e2
commit
29370b9a03
2 changed files with 31 additions and 26 deletions
|
@ -3,7 +3,7 @@ buildscript {
|
||||||
jcenter()
|
jcenter()
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:2.2.0'
|
classpath 'com.android.tools.build:gradle:2.2.1'
|
||||||
classpath 'com.github.ben-manes:gradle-versions-plugin:0.13.0'
|
classpath 'com.github.ben-manes:gradle-versions-plugin:0.13.0'
|
||||||
classpath 'com.github.triplet.gradle:play-publisher:1.1.4'
|
classpath 'com.github.triplet.gradle:play-publisher:1.1.4'
|
||||||
}
|
}
|
||||||
|
@ -23,8 +23,7 @@ dependencies {
|
||||||
compile 'com.google.zxing:android-integration:3.3.0'
|
compile 'com.google.zxing:android-integration:3.3.0'
|
||||||
compile 'com.google.code.gson:gson:2.7'
|
compile 'com.google.code.gson:gson:2.7'
|
||||||
compile 'org.mindrot:jbcrypt:0.3m'
|
compile 'org.mindrot:jbcrypt:0.3m'
|
||||||
testCompile 'junit:junit:4.12'
|
androidTestCompile 'com.android.support.test:rules:0.5'
|
||||||
testCompile 'org.robolectric:robolectric:3.1.2'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
project.archivesBaseName = 'syncthing'
|
project.archivesBaseName = 'syncthing'
|
||||||
|
|
|
@ -1,49 +1,55 @@
|
||||||
package com.nutomic.syncthingandroid.syncthing;
|
package com.nutomic.syncthingandroid.test.syncthing;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import com.nutomic.syncthingandroid.BuildConfig;
|
import android.support.test.InstrumentationRegistry;
|
||||||
|
import android.support.test.rule.ServiceTestRule;
|
||||||
|
|
||||||
|
import com.nutomic.syncthingandroid.syncthing.SyncthingService;
|
||||||
|
import com.nutomic.syncthingandroid.syncthing.SyncthingServiceBinder;
|
||||||
import com.nutomic.syncthingandroid.util.ConfigXml;
|
import com.nutomic.syncthingandroid.util.ConfigXml;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.robolectric.Robolectric;
|
|
||||||
import org.robolectric.RobolectricTestRunner;
|
|
||||||
import org.robolectric.annotation.Config;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.concurrent.TimeoutException;
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* These tests assume that syncthing keys have already been generated. If not, tests may fail
|
* These tests assume that syncthing keys have already been generated. If not, tests may fail
|
||||||
* because startup takes too long.
|
* because startup takes too long.
|
||||||
*/
|
*/
|
||||||
@RunWith(RobolectricTestRunner.class)
|
|
||||||
@Config(constants = BuildConfig.class)
|
|
||||||
public class SyncthingServiceTest {
|
public class SyncthingServiceTest {
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public final ServiceTestRule mServiceRule = new ServiceTestRule();
|
||||||
|
|
||||||
private SyncthingService mService;
|
private SyncthingService mService;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() throws TimeoutException {
|
||||||
mService = Robolectric.buildService(SyncthingService.class).get();
|
Intent intent =
|
||||||
mService.onCreate();
|
new Intent(InstrumentationRegistry.getTargetContext(), SyncthingService.class);
|
||||||
|
SyncthingServiceBinder binder = (SyncthingServiceBinder) mServiceRule.bindService(intent);
|
||||||
|
mService = binder.getService();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFirstStart() {
|
public void testFirstStart() {
|
||||||
assertTrue(mService.isFirstStart());
|
Assert.assertTrue(mService.isFirstStart());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNotFirstStart() throws IOException {
|
public void testNotFirstStart() throws IOException {
|
||||||
new File(mService.getFilesDir(), SyncthingService.PUBLIC_KEY_FILE).createNewFile();
|
new File(mService.getFilesDir(), SyncthingService.PUBLIC_KEY_FILE).createNewFile();
|
||||||
assertFalse(mService.isFirstStart());
|
Assert.assertFalse(mService.isFirstStart());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -57,7 +63,7 @@ public class SyncthingServiceTest {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
latch.await(1, TimeUnit.SECONDS);
|
latch.await(1, TimeUnit.SECONDS);
|
||||||
assertNotNull(mService);
|
Assert.assertNotNull(mService);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -71,7 +77,7 @@ public class SyncthingServiceTest {
|
||||||
privateKey.createNewFile();
|
privateKey.createNewFile();
|
||||||
publicKey.createNewFile();
|
publicKey.createNewFile();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
fail();
|
Assert.fail();
|
||||||
}
|
}
|
||||||
|
|
||||||
mService.exportConfig();
|
mService.exportConfig();
|
||||||
|
@ -80,10 +86,10 @@ public class SyncthingServiceTest {
|
||||||
privateKey.delete();
|
privateKey.delete();
|
||||||
publicKey.delete();
|
publicKey.delete();
|
||||||
|
|
||||||
assertTrue(mService.importConfig());
|
Assert.assertTrue(mService.importConfig());
|
||||||
assertTrue(config.exists());
|
Assert.assertTrue(config.exists());
|
||||||
assertTrue(privateKey.exists());
|
Assert.assertTrue(privateKey.exists());
|
||||||
assertTrue(publicKey.exists());
|
Assert.assertTrue(publicKey.exists());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -92,8 +98,8 @@ public class SyncthingServiceTest {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mService);
|
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mService);
|
||||||
assertNotNull(sp.getString("gui_user", null));
|
Assert.assertNotNull(sp.getString("gui_user", null));
|
||||||
assertEquals(20, sp.getString("gui_password", null).length());
|
Assert.assertEquals(20, sp.getString("gui_password", null).length());
|
||||||
}
|
}
|
||||||
}, 5000);
|
}, 5000);
|
||||||
}
|
}
|
Loading…
Reference in a new issue