diff --git a/bolts-tasks/src/main/java/com/parse/boltsinternal/CancellationTokenSource.java b/bolts-tasks/src/main/java/com/parse/boltsinternal/CancellationTokenSource.java index 2ca4a19f9..210eae9cf 100644 --- a/bolts-tasks/src/main/java/com/parse/boltsinternal/CancellationTokenSource.java +++ b/bolts-tasks/src/main/java/com/parse/boltsinternal/CancellationTokenSource.java @@ -46,7 +46,9 @@ public boolean isCancellationRequested() { } } - /** @return the token that can be passed to asynchronous method to control cancellation. */ + /** + * @return the token that can be passed to asynchronous method to control cancellation. + */ public CancellationToken getToken() { synchronized (lock) { throwIfClosed(); diff --git a/bolts-tasks/src/main/java/com/parse/boltsinternal/Task.java b/bolts-tasks/src/main/java/com/parse/boltsinternal/Task.java index 8e73588b2..34da3dcb3 100644 --- a/bolts-tasks/src/main/java/com/parse/boltsinternal/Task.java +++ b/bolts-tasks/src/main/java/com/parse/boltsinternal/Task.java @@ -541,28 +541,36 @@ public boolean isCompleted() { } } - /** @return {@code true} if the task was cancelled, {@code false} otherwise. */ + /** + * @return {@code true} if the task was cancelled, {@code false} otherwise. + */ public boolean isCancelled() { synchronized (lock) { return cancelled; } } - /** @return {@code true} if the task has an error, {@code false} otherwise. */ + /** + * @return {@code true} if the task has an error, {@code false} otherwise. + */ public boolean isFaulted() { synchronized (lock) { return getError() != null; } } - /** @return The result of the task, if set. {@code null} otherwise. */ + /** + * @return The result of the task, if set. {@code null} otherwise. + */ public TResult getResult() { synchronized (lock) { return result; } } - /** @return The error for the task, if set. {@code null} otherwise. */ + /** + * @return The error for the task, if set. {@code null} otherwise. + */ public Exception getError() { synchronized (lock) { if (error != null) { diff --git a/bolts-tasks/src/main/java/com/parse/boltsinternal/TaskCompletionSource.java b/bolts-tasks/src/main/java/com/parse/boltsinternal/TaskCompletionSource.java index 4406cefbd..4513b76d6 100644 --- a/bolts-tasks/src/main/java/com/parse/boltsinternal/TaskCompletionSource.java +++ b/bolts-tasks/src/main/java/com/parse/boltsinternal/TaskCompletionSource.java @@ -24,7 +24,9 @@ public TaskCompletionSource() { task = new Task<>(); } - /** @return the Task associated with this TaskCompletionSource. */ + /** + * @return the Task associated with this TaskCompletionSource. + */ public Task getTask() { return task; } diff --git a/build.gradle b/build.gradle index 7f0b633e7..8d392d916 100644 --- a/build.gradle +++ b/build.gradle @@ -11,7 +11,7 @@ buildscript { classpath "org.jacoco:org.jacoco.core:$jacocoVersion" classpath "com.dicedmelon.gradle:jacoco-android:0.1.5" classpath "io.freefair.gradle:android-gradle-plugins:4.2.0-m1" - classpath "com.diffplug.spotless:spotless-plugin-gradle:5.17.1" + classpath "com.diffplug.spotless:spotless-plugin-gradle:6.7.1" } } diff --git a/parse/src/main/java/com/parse/EncryptedFileObjectStore.java b/parse/src/main/java/com/parse/EncryptedFileObjectStore.java index b31ca647b..59caa1a3e 100644 --- a/parse/src/main/java/com/parse/EncryptedFileObjectStore.java +++ b/parse/src/main/java/com/parse/EncryptedFileObjectStore.java @@ -1,19 +1,19 @@ package com.parse; import android.content.Context; - import androidx.security.crypto.EncryptedFile; import androidx.security.crypto.MasterKey; import com.parse.boltsinternal.Task; -import org.json.JSONException; -import org.json.JSONObject; import java.io.File; import java.io.IOException; import java.security.GeneralSecurityException; import java.util.concurrent.Callable; +import org.json.JSONException; +import org.json.JSONObject; /** - * a file based {@link ParseObjectStore} using Jetpack's {@link EncryptedFile} class to protect files from a malicious copy. + * a file based {@link ParseObjectStore} using Jetpack's {@link EncryptedFile} class to protect + * files from a malicious copy. */ class EncryptedFileObjectStore implements ParseObjectStore { @@ -32,7 +32,15 @@ public EncryptedFileObjectStore(String className, File file, ParseObjectCurrentC this.coder = coder; Context context = ParsePlugins.get().applicationContext(); try { - encryptedFile = new EncryptedFile.Builder(context, file, new MasterKey.Builder(context).setKeyScheme(MasterKey.KeyScheme.AES256_GCM).build(), EncryptedFile.FileEncryptionScheme.AES256_GCM_HKDF_4KB).build(); + encryptedFile = + new EncryptedFile.Builder( + context, + file, + new MasterKey.Builder(context) + .setKeyScheme(MasterKey.KeyScheme.AES256_GCM) + .build(), + EncryptedFile.FileEncryptionScheme.AES256_GCM_HKDF_4KB) + .build(); } catch (GeneralSecurityException | IOException e) { throw new RuntimeException(e.getMessage()); } @@ -46,8 +54,9 @@ private static ParseObjectSubclassingController getSubclassingController() { * Saves the {@code ParseObject} to the a file on disk as JSON in /2/ format. * * @param current ParseObject which needs to be saved to disk. - * @throws IOException thrown if an error occurred during writing of the file - * @throws GeneralSecurityException thrown if there is an error with encryption keys or during the encryption of the file + * @throws IOException thrown if an error occurred during writing of the file + * @throws GeneralSecurityException thrown if there is an error with encryption keys or during + * the encryption of the file */ private void saveToDisk(ParseObject current) throws IOException, GeneralSecurityException { JSONObject json = coder.encode(current.getState(), null, PointerEncoder.get()); @@ -58,41 +67,54 @@ private void saveToDisk(ParseObject current) throws IOException, GeneralSecurity * Retrieves a {@code ParseObject} from a file on disk in /2/ format. * * @return The {@code ParseObject} that was retrieved. If the file wasn't found, or the contents - * of the file is an invalid {@code ParseObject}, returns {@code null}. - * @throws GeneralSecurityException thrown if there is an error with encryption keys or during the encryption of the file - * @throws JSONException thrown if an error occurred during the decoding process of the ParseObject to a JSONObject - * @throws IOException thrown if an error occurred during writing of the file + * of the file is an invalid {@code ParseObject}, returns {@code null}. + * @throws GeneralSecurityException thrown if there is an error with encryption keys or during + * the encryption of the file + * @throws JSONException thrown if an error occurred during the decoding process of the + * ParseObject to a JSONObject + * @throws IOException thrown if an error occurred during writing of the file */ private T getFromDisk() throws GeneralSecurityException, JSONException, IOException { - return ParseObject.from(coder.decode(ParseObject.State.newBuilder(className), ParseFileUtils.readFileToJSONObject(encryptedFile), ParseDecoder.get()).isComplete(true).build()); + return ParseObject.from( + coder.decode( + ParseObject.State.newBuilder(className), + ParseFileUtils.readFileToJSONObject(encryptedFile), + ParseDecoder.get()) + .isComplete(true) + .build()); } @Override public Task getAsync() { - return Task.call(new Callable() { - @Override - public T call() throws Exception { - if (!file.exists()) return null; - try { - return getFromDisk(); - } catch (GeneralSecurityException e) { - throw new RuntimeException(e.getMessage()); - } - } - }, ParseExecutors.io()); + return Task.call( + new Callable() { + @Override + public T call() throws Exception { + if (!file.exists()) return null; + try { + return getFromDisk(); + } catch (GeneralSecurityException e) { + throw new RuntimeException(e.getMessage()); + } + } + }, + ParseExecutors.io()); } @Override public Task setAsync(T object) { - return Task.call(() -> { - if (file.exists() && !ParseFileUtils.deleteQuietly(file)) throw new RuntimeException("Unable to delete"); - try { - saveToDisk(object); - } catch (GeneralSecurityException e) { - throw new RuntimeException(e.getMessage()); - } - return null; - }, ParseExecutors.io()); + return Task.call( + () -> { + if (file.exists() && !ParseFileUtils.deleteQuietly(file)) + throw new RuntimeException("Unable to delete"); + try { + saveToDisk(object); + } catch (GeneralSecurityException e) { + throw new RuntimeException(e.getMessage()); + } + return null; + }, + ParseExecutors.io()); } @Override @@ -102,9 +124,12 @@ public Task existsAsync() { @Override public Task deleteAsync() { - return Task.call(() -> { - if (file.exists() && !ParseFileUtils.deleteQuietly(file)) throw new RuntimeException("Unable to delete"); - return null; - }, ParseExecutors.io()); + return Task.call( + () -> { + if (file.exists() && !ParseFileUtils.deleteQuietly(file)) + throw new RuntimeException("Unable to delete"); + return null; + }, + ParseExecutors.io()); } } diff --git a/parse/src/main/java/com/parse/ManifestInfo.java b/parse/src/main/java/com/parse/ManifestInfo.java index 31b221976..276fcd14b 100644 --- a/parse/src/main/java/com/parse/ManifestInfo.java +++ b/parse/src/main/java/com/parse/ManifestInfo.java @@ -150,7 +150,9 @@ private static ApplicationInfo getApplicationInfo(Context context, int flags) { } } - /** @return A {@link Bundle} if meta-data is specified in AndroidManifest, otherwise null. */ + /** + * @return A {@link Bundle} if meta-data is specified in AndroidManifest, otherwise null. + */ public static Bundle getApplicationMetadata(Context context) { ApplicationInfo info = getApplicationInfo(context, PackageManager.GET_META_DATA); if (info != null) { diff --git a/parse/src/main/java/com/parse/Parse.java b/parse/src/main/java/com/parse/Parse.java index c3ad5c1ee..66fa2502a 100644 --- a/parse/src/main/java/com/parse/Parse.java +++ b/parse/src/main/java/com/parse/Parse.java @@ -288,7 +288,9 @@ public static void destroy() { allowCustomObjectId = false; } - /** @return {@code True} if {@link #initialize} has been called, otherwise {@code false}. */ + /** + * @return {@code True} if {@link #initialize} has been called, otherwise {@code false}. + */ static boolean isInitialized() { return ParsePlugins.get() != null; } diff --git a/parse/src/main/java/com/parse/ParseClassName.java b/parse/src/main/java/com/parse/ParseClassName.java index d2f4a3562..ab5b436a2 100644 --- a/parse/src/main/java/com/parse/ParseClassName.java +++ b/parse/src/main/java/com/parse/ParseClassName.java @@ -21,6 +21,8 @@ @Inherited @Documented public @interface ParseClassName { - /** @return The Parse class name associated with the ParseObject subclass. */ + /** + * @return The Parse class name associated with the ParseObject subclass. + */ String value(); } diff --git a/parse/src/main/java/com/parse/ParseCorePlugins.java b/parse/src/main/java/com/parse/ParseCorePlugins.java index ed18f230d..420ba9233 100644 --- a/parse/src/main/java/com/parse/ParseCorePlugins.java +++ b/parse/src/main/java/com/parse/ParseCorePlugins.java @@ -135,8 +135,11 @@ public ParseCurrentUserController getCurrentUserController() { Parse.isLocalDatastoreEnabled() ? new OfflineObjectStore<>(ParseUser.class, PIN_CURRENT_USER, fileStore) : fileStore; - EncryptedFileObjectStore encryptedFileObjectStore = new EncryptedFileObjectStore<>(ParseUser.class, file, ParseUserCurrentCoder.get()); - ParseObjectStoreMigrator storeMigrator = new ParseObjectStoreMigrator<>(encryptedFileObjectStore, store); + EncryptedFileObjectStore encryptedFileObjectStore = + new EncryptedFileObjectStore<>( + ParseUser.class, file, ParseUserCurrentCoder.get()); + ParseObjectStoreMigrator storeMigrator = + new ParseObjectStoreMigrator<>(encryptedFileObjectStore, store); ParseCurrentUserController controller = new CachedCurrentUserController(storeMigrator); currentUserController.compareAndSet(null, controller); currentUserController.compareAndSet(null, controller); diff --git a/parse/src/main/java/com/parse/ParseFileUtils.java b/parse/src/main/java/com/parse/ParseFileUtils.java index 804f8c140..d0c0d1732 100644 --- a/parse/src/main/java/com/parse/ParseFileUtils.java +++ b/parse/src/main/java/com/parse/ParseFileUtils.java @@ -19,7 +19,6 @@ import android.net.Uri; import androidx.annotation.NonNull; import androidx.security.crypto.EncryptedFile; - import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -67,7 +66,6 @@ public static byte[] readFileToByteArray(File file) throws IOException { // ----------------------------------------------------------------------- /** - * * Reads the contents of an encrypted file into a byte array. The file is always closed. * * @param file the encrypted file to read, must not be null @@ -75,7 +73,8 @@ public static byte[] readFileToByteArray(File file) throws IOException { * @throws IOException in case of an I/O error * @throws GeneralSecurityException in case of an encryption related error */ - public static byte[] readFileToByteArray(EncryptedFile file) throws IOException, GeneralSecurityException { + public static byte[] readFileToByteArray(EncryptedFile file) + throws IOException, GeneralSecurityException { InputStream in = null; try { in = file.openFileInput(); @@ -85,8 +84,6 @@ public static byte[] readFileToByteArray(EncryptedFile file) throws IOException, } } - - /** * Opens a {@link FileInputStream} for the specified file, providing better error messages than * simply calling new FileInputStream(file). @@ -148,7 +145,8 @@ public static void writeByteArrayToFile(File file, byte[] data) throws IOExcepti * @throws IOException in case of an I/O error * @throws GeneralSecurityException in case of an encryption related error */ - public static void writeByteArrayToFile(EncryptedFile file, byte[] data) throws IOException, GeneralSecurityException { + public static void writeByteArrayToFile(EncryptedFile file, byte[] data) + throws IOException, GeneralSecurityException { OutputStream out = null; try { out = file.openFileOutput(); @@ -158,8 +156,6 @@ public static void writeByteArrayToFile(EncryptedFile file, byte[] data) throws } } - - /** * Writes a content uri to a file creating the file if it does not exist. * @@ -596,27 +592,31 @@ public static boolean isSymlink(final File file) throws IOException { /** * @param file the encrypted file to read * @param encoding the file encoding used when written to disk - * @return Reads the contents of an encrypted file into a {@link String}. The file is always closed. + * @return Reads the contents of an encrypted file into a {@link String}. The file is always + * closed. * @throws IOException thrown if an error occurred during writing of the file - * @throws GeneralSecurityException thrown if there is an error with encryption keys or during the encryption of the file + * @throws GeneralSecurityException thrown if there is an error with encryption keys or during + * the encryption of the file */ - public static String readFileToString(EncryptedFile file, Charset encoding) throws IOException, GeneralSecurityException { + public static String readFileToString(EncryptedFile file, Charset encoding) + throws IOException, GeneralSecurityException { return new String(readFileToByteArray(file), encoding); } /** * @param file the encrypted file to read * @param encoding the file encoding used when written to disk - * @return Reads the contents of an encrypted file into a {@link String}. The file is always closed. + * @return Reads the contents of an encrypted file into a {@link String}. The file is always + * closed. * @throws IOException thrown if an error occurred during writing of the file - * @throws GeneralSecurityException thrown if there is an error with encryption keys or during the encryption of the file + * @throws GeneralSecurityException thrown if there is an error with encryption keys or during + * the encryption of the file */ - public static String readFileToString(EncryptedFile file, String encoding) throws IOException, GeneralSecurityException { + public static String readFileToString(EncryptedFile file, String encoding) + throws IOException, GeneralSecurityException { return readFileToString(file, Charset.forName(encoding)); } - - // region String public static String readFileToString(File file, Charset encoding) throws IOException { @@ -638,28 +638,34 @@ public static void writeStringToFile(File file, String string, String encoding) } /** - * Writes a {@link JSONObject} to an encrypted file, will throw an error if the file already exists. + * Writes a {@link JSONObject} to an encrypted file, will throw an error if the file already + * exists. + * * @param file the encrypted file to use for writing. * @param string the text to write. * @param encoding the encoding used for the text written. * @throws IOException thrown if an error occurred during writing of the file - * @throws GeneralSecurityException thrown if there is an error with encryption keys or during the encryption of the file + * @throws GeneralSecurityException thrown if there is an error with encryption keys or during + * the encryption of the file */ public static void writeStringToFile(EncryptedFile file, String string, Charset encoding) - throws IOException, GeneralSecurityException { + throws IOException, GeneralSecurityException { writeByteArrayToFile(file, string.getBytes(encoding)); } /** - * Writes a {@link JSONObject} to an encrypted file, will throw an error if the file already exists. + * Writes a {@link JSONObject} to an encrypted file, will throw an error if the file already + * exists. + * * @param file the encrypted file to use for writing. * @param string the text to write. * @param encoding the encoding used for the text written. * @throws IOException thrown if an error occurred during writing of the file - * @throws GeneralSecurityException thrown if there is an error with encryption keys or during the encryption of the file + * @throws GeneralSecurityException thrown if there is an error with encryption keys or during + * the encryption of the file */ public static void writeStringToFile(EncryptedFile file, String string, String encoding) - throws IOException, GeneralSecurityException { + throws IOException, GeneralSecurityException { writeStringToFile(file, string, Charset.forName(encoding)); } @@ -678,18 +684,23 @@ public static void writeJSONObjectToFile(File file, JSONObject json) throws IOEx ParseFileUtils.writeByteArrayToFile(file, json.toString().getBytes("UTF-8")); } - /** Reads the contents of an encrypted file into a {@link JSONObject}. The file is always closed. */ - public static JSONObject readFileToJSONObject(EncryptedFile file) throws IOException, JSONException, GeneralSecurityException { + /** + * Reads the contents of an encrypted file into a {@link JSONObject}. The file is always closed. + */ + public static JSONObject readFileToJSONObject(EncryptedFile file) + throws IOException, JSONException, GeneralSecurityException { String content = readFileToString(file, "UTF-8"); return new JSONObject(content); } - /** Writes a {@link JSONObject} to an encrypted file, will throw an error if the file already exists. */ - public static void writeJSONObjectToFile(EncryptedFile file, JSONObject json) throws IOException, GeneralSecurityException { + /** + * Writes a {@link JSONObject} to an encrypted file, will throw an error if the file already + * exists. + */ + public static void writeJSONObjectToFile(EncryptedFile file, JSONObject json) + throws IOException, GeneralSecurityException { ParseFileUtils.writeByteArrayToFile(file, json.toString().getBytes("UTF-8")); } - - // endregion } diff --git a/parse/src/main/java/com/parse/ParseObjectStoreMigrator.java b/parse/src/main/java/com/parse/ParseObjectStoreMigrator.java index 47da1ecde..13218d100 100644 --- a/parse/src/main/java/com/parse/ParseObjectStoreMigrator.java +++ b/parse/src/main/java/com/parse/ParseObjectStoreMigrator.java @@ -2,19 +2,16 @@ import com.parse.boltsinternal.Continuation; import com.parse.boltsinternal.Task; - import java.util.Arrays; -/** - * Use this utility class to migrate from one {@link ParseObjectStore} to another - */ +/** Use this utility class to migrate from one {@link ParseObjectStore} to another */ class ParseObjectStoreMigrator implements ParseObjectStore { private final ParseObjectStore store; private final ParseObjectStore legacy; /** - * @param store the new {@link ParseObjectStore} to migrate to + * @param store the new {@link ParseObjectStore} to migrate to * @param legacy the old {@link ParseObjectStore} to migrate from */ public ParseObjectStoreMigrator(ParseObjectStore store, ParseObjectStore legacy) { @@ -24,20 +21,32 @@ public ParseObjectStoreMigrator(ParseObjectStore store, ParseObjectStore l @Override public Task getAsync() { - return store.getAsync().continueWithTask(new Continuation>() { - @Override - public Task then(Task task) throws Exception { - if (task.getResult() != null) return task; - return legacy.getAsync().continueWithTask(new Continuation>() { - @Override - public Task then(Task task) throws Exception { - T object = task.getResult(); - if (object == null) return task; - return legacy.deleteAsync().continueWith(task1 -> ParseTaskUtils.wait(store.setAsync(object))).onSuccess(task1 -> object); - } - }); - } - }); + return store.getAsync() + .continueWithTask( + new Continuation>() { + @Override + public Task then(Task task) throws Exception { + if (task.getResult() != null) return task; + return legacy.getAsync() + .continueWithTask( + new Continuation>() { + @Override + public Task then(Task task) + throws Exception { + T object = task.getResult(); + if (object == null) return task; + return legacy.deleteAsync() + .continueWith( + task1 -> + ParseTaskUtils.wait( + store + .setAsync( + object))) + .onSuccess(task1 -> object); + } + }); + } + }); } @Override @@ -47,23 +56,27 @@ public Task setAsync(T object) { @Override public Task existsAsync() { - return store.existsAsync().continueWithTask(new Continuation>() { - @Override - public Task then(Task task) throws Exception { - if (task.getResult()) return Task.forResult(true); - return legacy.existsAsync(); - } - }); + return store.existsAsync() + .continueWithTask( + new Continuation>() { + @Override + public Task then(Task task) throws Exception { + if (task.getResult()) return Task.forResult(true); + return legacy.existsAsync(); + } + }); } @Override public Task deleteAsync() { Task storeTask = store.deleteAsync(); - return Task.whenAll(Arrays.asList(legacy.deleteAsync(), storeTask)).continueWithTask(new Continuation>() { - @Override - public Task then(Task task1) throws Exception { - return storeTask; - } - }); + return Task.whenAll(Arrays.asList(legacy.deleteAsync(), storeTask)) + .continueWithTask( + new Continuation>() { + @Override + public Task then(Task task1) throws Exception { + return storeTask; + } + }); } } diff --git a/parse/src/main/java/com/parse/ParseQuery.java b/parse/src/main/java/com/parse/ParseQuery.java index 132ad4e39..67c44b3ef 100644 --- a/parse/src/main/java/com/parse/ParseQuery.java +++ b/parse/src/main/java/com/parse/ParseQuery.java @@ -282,7 +282,9 @@ public T getFirst() throws ParseException { return ParseTaskUtils.wait(getFirstInBackground()); } - /** @return the caching policy. */ + /** + * @return the caching policy. + */ public CachePolicy getCachePolicy() { return builder.getCachePolicy(); } diff --git a/parse/src/main/java/com/parse/ParseSession.java b/parse/src/main/java/com/parse/ParseSession.java index a2d5b2e4d..a656966d0 100644 --- a/parse/src/main/java/com/parse/ParseSession.java +++ b/parse/src/main/java/com/parse/ParseSession.java @@ -122,7 +122,9 @@ public static ParseQuery getQuery() { return !READ_ONLY_KEYS.contains(key); } - /** @return the session token for a user, if they are logged in. */ + /** + * @return the session token for a user, if they are logged in. + */ public String getSessionToken() { return getString(KEY_SESSION_TOKEN); } diff --git a/parse/src/main/java/com/parse/ParseUser.java b/parse/src/main/java/com/parse/ParseUser.java index 6fdf91845..c52c34862 100644 --- a/parse/src/main/java/com/parse/ParseUser.java +++ b/parse/src/main/java/com/parse/ParseUser.java @@ -717,7 +717,9 @@ public void remove(@NonNull String key) { } } - /** @return the session token for a user, if they are logged in. */ + /** + * @return the session token for a user, if they are logged in. + */ public String getSessionToken() { return getState().sessionToken(); } diff --git a/parse/src/test/java/com/parse/EncryptedFileObjectStoreTest.java b/parse/src/test/java/com/parse/EncryptedFileObjectStoreTest.java index 78458853c..e48afc39c 100644 --- a/parse/src/test/java/com/parse/EncryptedFileObjectStoreTest.java +++ b/parse/src/test/java/com/parse/EncryptedFileObjectStoreTest.java @@ -17,10 +17,12 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.skyscreamer.jsonassert.JSONAssert.assertEquals; + import android.content.Context; import androidx.security.crypto.EncryptedFile; import androidx.security.crypto.MasterKey; import androidx.test.platform.app.InstrumentationRegistry; +import java.io.File; import org.json.JSONObject; import org.junit.After; import org.junit.Before; @@ -30,20 +32,21 @@ import org.junit.runner.RunWith; import org.robolectric.RobolectricTestRunner; import org.skyscreamer.jsonassert.JSONCompareMode; -import java.io.File; -import kotlin.jvm.JvmStatic; @RunWith(RobolectricTestRunner.class) public class EncryptedFileObjectStoreTest { - @Rule - public final TemporaryFolder temporaryFolder = new TemporaryFolder(); + @Rule public final TemporaryFolder temporaryFolder = new TemporaryFolder(); @Before public void setUp() { RobolectricKeyStore.INSTANCE.getSetup(); ParseObject.registerSubclass(ParseUser.class); - Parse.initialize(new Parse.Configuration.Builder(InstrumentationRegistry.getInstrumentation().getTargetContext()).server("http://parse.com").build()); + Parse.initialize( + new Parse.Configuration.Builder( + InstrumentationRegistry.getInstrumentation().getTargetContext()) + .server("http://parse.com") + .build()); } @After @@ -59,16 +62,24 @@ public void testSetAsync() throws Exception { JSONObject json = new JSONObject(); json.put("foo", "bar"); ParseUserCurrentCoder coder = mock(ParseUserCurrentCoder.class); - when(coder.encode(eq(state), isNull(), any(PointerEncoder.class))) - .thenReturn(json); - EncryptedFileObjectStore store = new EncryptedFileObjectStore<>(ParseUser.class, file, coder); + when(coder.encode(eq(state), isNull(), any(PointerEncoder.class))).thenReturn(json); + EncryptedFileObjectStore store = + new EncryptedFileObjectStore<>(ParseUser.class, file, coder); ParseUser user = mock(ParseUser.class); when(user.getState()).thenReturn(state); ParseTaskUtils.wait(store.setAsync(user)); Context context = InstrumentationRegistry.getInstrumentation().getContext(); - EncryptedFile encryptedFile = new EncryptedFile.Builder(context, file, new MasterKey.Builder(context).setKeyScheme(MasterKey.KeyScheme.AES256_GCM).build(), EncryptedFile.FileEncryptionScheme.AES256_GCM_HKDF_4KB).build(); + EncryptedFile encryptedFile = + new EncryptedFile.Builder( + context, + file, + new MasterKey.Builder(context) + .setKeyScheme(MasterKey.KeyScheme.AES256_GCM) + .build(), + EncryptedFile.FileEncryptionScheme.AES256_GCM_HKDF_4KB) + .build(); JSONObject jsonAgain = ParseFileUtils.readFileToJSONObject(encryptedFile); assertEquals(json, jsonAgain, JSONCompareMode.STRICT); } @@ -78,7 +89,15 @@ public void testGetAsync() throws Exception { File file = new File(temporaryFolder.getRoot(), "test"); Context context = InstrumentationRegistry.getInstrumentation().getContext(); - EncryptedFile encryptedFile = new EncryptedFile.Builder(context, file, new MasterKey.Builder(context).setKeyScheme(MasterKey.KeyScheme.AES256_GCM).build(), EncryptedFile.FileEncryptionScheme.AES256_GCM_HKDF_4KB).build(); + EncryptedFile encryptedFile = + new EncryptedFile.Builder( + context, + file, + new MasterKey.Builder(context) + .setKeyScheme(MasterKey.KeyScheme.AES256_GCM) + .build(), + EncryptedFile.FileEncryptionScheme.AES256_GCM_HKDF_4KB) + .build(); JSONObject json = new JSONObject(); ParseFileUtils.writeJSONObjectToFile(encryptedFile, json); @@ -87,11 +106,12 @@ public void testGetAsync() throws Exception { builder.put("foo", "bar"); ParseUserCurrentCoder coder = mock(ParseUserCurrentCoder.class); when(coder.decode( - any(ParseUser.State.Builder.class), - any(JSONObject.class), - any(ParseDecoder.class))) - .thenReturn(builder); - EncryptedFileObjectStore store = new EncryptedFileObjectStore<>(ParseUser.class, file, coder); + any(ParseUser.State.Builder.class), + any(JSONObject.class), + any(ParseDecoder.class))) + .thenReturn(builder); + EncryptedFileObjectStore store = + new EncryptedFileObjectStore<>(ParseUser.class, file, coder); ParseUser user = ParseTaskUtils.wait(store.getAsync()); assertEquals("bar", user.getState().get("foo")); @@ -100,7 +120,8 @@ public void testGetAsync() throws Exception { @Test public void testExistsAsync() throws Exception { File file = temporaryFolder.newFile("test"); - EncryptedFileObjectStore store = new EncryptedFileObjectStore<>(ParseUser.class, file, null); + EncryptedFileObjectStore store = + new EncryptedFileObjectStore<>(ParseUser.class, file, null); assertTrue(ParseTaskUtils.wait(store.existsAsync())); temporaryFolder.delete(); @@ -110,7 +131,8 @@ public void testExistsAsync() throws Exception { @Test public void testDeleteAsync() throws Exception { File file = temporaryFolder.newFile("test"); - EncryptedFileObjectStore store = new EncryptedFileObjectStore<>(ParseUser.class, file, null); + EncryptedFileObjectStore store = + new EncryptedFileObjectStore<>(ParseUser.class, file, null); assertTrue(file.exists()); ParseTaskUtils.wait(store.deleteAsync()); diff --git a/twitter/src/main/java/com/parse/twitter/ParseTwitterUtils.java b/twitter/src/main/java/com/parse/twitter/ParseTwitterUtils.java index 76707cb6f..2966df279 100644 --- a/twitter/src/main/java/com/parse/twitter/ParseTwitterUtils.java +++ b/twitter/src/main/java/com/parse/twitter/ParseTwitterUtils.java @@ -108,7 +108,9 @@ private static void checkInitialization() { } } - /** @return {@code true} if the user is linked to a Twitter account. */ + /** + * @return {@code true} if the user is linked to a Twitter account. + */ public static boolean isLinked(ParseUser user) { return user.isLinked(AUTH_TYPE); }