diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/CreateKeyActivityTest.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/CreateKeyActivityTest.java index e81b312ac..049b389b5 100644 --- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/CreateKeyActivityTest.java +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/CreateKeyActivityTest.java @@ -17,17 +17,18 @@ package org.sufficientlysecure.keychain; -import android.support.test.InstrumentationRegistry; + +import android.content.Intent; +import android.support.test.rule.ActivityTestRule; import android.support.test.runner.AndroidJUnit4; -import android.test.ActivityInstrumentationTestCase2; import android.test.suitebuilder.annotation.LargeTest; import android.text.method.HideReturnsTransformationMethod; import android.text.method.PasswordTransformationMethod; -import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; -import org.sufficientlysecure.keychain.ui.CreateKeyActivity; +import org.sufficientlysecure.keychain.ui.MainActivity; import static android.support.test.espresso.Espresso.onView; import static android.support.test.espresso.action.ViewActions.click; @@ -47,25 +48,28 @@ import static org.sufficientlysecure.keychain.matcher.EditTextMatchers.withTrans @RunWith(AndroidJUnit4.class) @LargeTest -public class CreateKeyActivityTest extends ActivityInstrumentationTestCase2 { +public class CreateKeyActivityTest { public static final String SAMPLE_NAME = "Sample Name"; public static final String SAMPLE_EMAIL = "sample_email@gmail.com"; public static final String SAMPLE_ADDITIONAL_EMAIL = "sample_additional_email@gmail.com"; public static final String SAMPLE_PASSWORD = "sample_password"; - public CreateKeyActivityTest() { - super(CreateKeyActivity.class); - } - - @Before - public void setUp() throws Exception { - super.setUp(); - injectInstrumentation(InstrumentationRegistry.getInstrumentation()); - getActivity(); - } + @Rule + public final ActivityTestRule mActivity + = new ActivityTestRule(MainActivity.class) { + @Override + protected Intent getActivityIntent() { + Intent intent = super.getActivityIntent(); + intent.putExtra(MainActivity.EXTRA_SKIP_FIRST_TIME, true); + return intent; + } + }; public void testCreateMyKey() { + + mActivity.getActivity(); + // Clicks create my key onView(withId(R.id.create_key_create_key_button)) .perform(click()); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/OperationResult.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/OperationResult.java index 8c68bda19..f110b9186 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/OperationResult.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/OperationResult.java @@ -22,6 +22,7 @@ import android.app.Activity; import android.content.Intent; import android.os.Parcel; import android.os.Parcelable; +import android.support.annotation.NonNull; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; @@ -101,9 +102,9 @@ public abstract class OperationResult implements Parcelable { } public OperationLog getLog() { - // If there is only a single entry, and it's a compound one, return that log - if (mLog.isSingleCompound()) { - return ((SubLogEntryParcel) mLog.getFirst()).getSubResult().getLog(); + SubLogEntryParcel singleSubLog = mLog.getSubResultIfSingle(); + if (singleSubLog != null) { + return singleSubLog.getSubResult().getLog(); } // Otherwse, return our regular log return mLog; @@ -169,9 +170,9 @@ public abstract class OperationResult implements Parcelable { public static class SubLogEntryParcel extends LogEntryParcel { - OperationResult mSubResult; + @NonNull OperationResult mSubResult; - public SubLogEntryParcel(OperationResult subResult, LogType type, int indent, Object... parameters) { + public SubLogEntryParcel(@NonNull OperationResult subResult, LogType type, int indent, Object... parameters) { super(type, indent, parameters); mSubResult = subResult; @@ -209,6 +210,10 @@ public abstract class OperationResult implements Parcelable { String logText; LogEntryParcel entryParcel = mLog.getLast(); + if (entryParcel == null) { + Log.e(Constants.TAG, "Tried to show empty log!"); + return Notify.create(activity, R.string.error_empty_log, Style.ERROR); + } // special case: first parameter may be a quantity if (entryParcel.mParameters != null && entryParcel.mParameters.length > 0 && entryParcel.mParameters[0] instanceof Integer) { @@ -269,7 +274,7 @@ public abstract class OperationResult implements Parcelable { * mark. * */ - public static enum LogType { + public enum LogType { MSG_INTERNAL_ERROR (LogLevel.ERROR, R.string.msg_internal_error), MSG_OPERATION_CANCELLED (LogLevel.CANCELLED, R.string.msg_cancelled), @@ -765,7 +770,7 @@ public abstract class OperationResult implements Parcelable { } /** Enumeration of possible log levels. */ - public static enum LogLevel { + public enum LogLevel { DEBUG, INFO, WARN, @@ -805,8 +810,15 @@ public abstract class OperationResult implements Parcelable { mParcels.add(new SubLogEntryParcel(subResult, subLog.getFirst().mType, indent, subLog.getFirst().mParameters)); } - boolean isSingleCompound() { - return mParcels.size() == 1 && getFirst() instanceof SubLogEntryParcel; + public SubLogEntryParcel getSubResultIfSingle() { + if (mParcels.size() != 1) { + return null; + } + LogEntryParcel first = getFirst(); + if (first instanceof SubLogEntryParcel) { + return (SubLogEntryParcel) first; + } + return null; } public void clear() { diff --git a/OpenKeychain/src/main/res/values/strings.xml b/OpenKeychain/src/main/res/values/strings.xml index c21b34d55..bf6669441 100644 --- a/OpenKeychain/src/main/res/values/strings.xml +++ b/OpenKeychain/src/main/res/values/strings.xml @@ -1332,5 +1332,6 @@ "Compression enabled." "Compression disabled." Error loading keys! + (error, empty log) diff --git a/README.md b/README.md index c28d35c98..7a75b5ec8 100644 --- a/README.md +++ b/README.md @@ -151,12 +151,13 @@ see http://help.transifex.net/features/client/index.html#user-client ## Coding Style ### Code -* Indentation: 4 spaces, no tabs -* Maximum line width for code and comments: 100 -* Opening braces don't go on their own line +* Indentation: 4 spaces, no tabs. +* Maximum line width for code and comments: 100. +* Opening braces don't go on their own line. * Field names: Non-public, non-static fields start with m. * Acronyms are words: Treat acronyms as words in names, yielding !XmlHttpRequest, getUrl(), etc. * Fully Qualify Imports: Do *not* use wildcard-imports such as ``import foo.*;`` +* Android Studio warnings should be fixed, or suppressed if they are incorrect. The full coding style can be found at http://source.android.com/source/code-style.html