mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-12-24 07:58:50 -05:00
test: move uncachedkeyring test setup into BeforeClass method
This commit is contained in:
parent
a99589e9c4
commit
0afd979665
@ -1,10 +1,9 @@
|
|||||||
package org.sufficientlysecure.keychain.tests;
|
package org.sufficientlysecure.keychain.tests;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.robolectric.*;
|
import org.robolectric.*;
|
||||||
import org.robolectric.shadows.ShadowLog;
|
import org.robolectric.shadows.ShadowLog;
|
||||||
@ -17,7 +16,6 @@ import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
|
|||||||
import org.sufficientlysecure.keychain.support.KeyringBuilder;
|
import org.sufficientlysecure.keychain.support.KeyringBuilder;
|
||||||
import org.sufficientlysecure.keychain.support.KeyringTestingHelper;
|
import org.sufficientlysecure.keychain.support.KeyringTestingHelper;
|
||||||
import org.sufficientlysecure.keychain.support.TestDataUtil;
|
import org.sufficientlysecure.keychain.support.TestDataUtil;
|
||||||
import org.sufficientlysecure.keychain.ui.KeyListActivity;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
|
||||||
@ -25,39 +23,46 @@ import java.util.HashSet;
|
|||||||
@org.robolectric.annotation.Config(emulateSdk = 18) // Robolectric doesn't yet support 19
|
@org.robolectric.annotation.Config(emulateSdk = 18) // Robolectric doesn't yet support 19
|
||||||
public class UncachedKeyringTest {
|
public class UncachedKeyringTest {
|
||||||
|
|
||||||
@Before
|
static UncachedKeyRing staticRing;
|
||||||
public void setUp() throws Exception {
|
UncachedKeyRing ring;
|
||||||
// show Log.x messages in system.out
|
|
||||||
ShadowLog.stream = System.out;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testCreateKey() throws Exception {
|
|
||||||
Activity activity = Robolectric.buildActivity(KeyListActivity.class).create().get();
|
|
||||||
|
|
||||||
|
@BeforeClass public static void setUpOnce() throws Exception {
|
||||||
SaveKeyringParcel parcel = new SaveKeyringParcel();
|
SaveKeyringParcel parcel = new SaveKeyringParcel();
|
||||||
parcel.addSubKeys.add(new SaveKeyringParcel.SubkeyAdd(
|
parcel.addSubKeys.add(new SaveKeyringParcel.SubkeyAdd(
|
||||||
Constants.choice.algorithm.rsa, 1024, KeyFlags.CERTIFY_OTHER, null));
|
Constants.choice.algorithm.rsa, 1024, KeyFlags.CERTIFY_OTHER, null));
|
||||||
// parcel.addSubKeys.add(new SubkeyAdd(algorithm.rsa, 1024, KeyFlags.SIGN_DATA, null));
|
|
||||||
parcel.addUserIds.add("swagerinho");
|
parcel.addUserIds.add("swagerinho");
|
||||||
parcel.newPassphrase = "swag";
|
parcel.newPassphrase = "swag";
|
||||||
PgpKeyOperation op = new PgpKeyOperation(null);
|
PgpKeyOperation op = new PgpKeyOperation(null);
|
||||||
|
|
||||||
OperationResultParcel.OperationLog log = new OperationResultParcel.OperationLog();
|
OperationResultParcel.OperationLog log = new OperationResultParcel.OperationLog();
|
||||||
UncachedKeyRing ring = op.createSecretKeyRing(parcel, log, 0);
|
staticRing = op.createSecretKeyRing(parcel, log, 0);
|
||||||
|
}
|
||||||
|
|
||||||
if (ring == null) {
|
@Before public void setUp() throws Exception {
|
||||||
throw new AssertionError("key creation failed");
|
// show Log.x messages in system.out
|
||||||
}
|
ShadowLog.stream = System.out;
|
||||||
|
ring = staticRing;
|
||||||
|
}
|
||||||
|
|
||||||
if (!"swagerinho".equals(ring.getPublicKey().getPrimaryUserId())) {
|
@Test
|
||||||
throw new AssertionError("incorrect primary user id");
|
public void testCreateKey() throws Exception {
|
||||||
}
|
|
||||||
|
// parcel.addSubKeys.add(new SubkeyAdd(algorithm.rsa, 1024, KeyFlags.SIGN_DATA, null));
|
||||||
|
|
||||||
|
Assert.assertNotNull("key creation failed", ring);
|
||||||
|
|
||||||
|
Assert.assertEquals("incorrect primary user id",
|
||||||
|
"swagerinho", ring.getPublicKey().getPrimaryUserId());
|
||||||
|
|
||||||
|
Assert.assertEquals("wrong number of subkeys",
|
||||||
|
1, ring.getAvailableSubkeys().size());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testVerifySuccess() throws Exception {
|
public void testVerifySuccess() throws Exception {
|
||||||
|
|
||||||
UncachedKeyRing expectedKeyRing = KeyringBuilder.correctRing();
|
UncachedKeyRing expectedKeyRing = KeyringBuilder.correctRing();
|
||||||
UncachedKeyRing inputKeyRing = KeyringBuilder.ringWithExtraIncorrectSignature();
|
UncachedKeyRing inputKeyRing = KeyringBuilder.ringWithExtraIncorrectSignature();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user