From e31e06b288be0be0e58ffe4ae7ed925819896277 Mon Sep 17 00:00:00 2001 From: Sebastian Stenzel Date: Mon, 18 Sep 2023 10:13:51 +0200 Subject: [PATCH] added `@VisibleForTesting` --- src/main/java/org/cryptomator/common/Environment.java | 3 ++- src/main/java/org/cryptomator/common/ErrorCode.java | 5 +++-- .../cryptomator/common/mount/MountWithinParentUtil.java | 9 +++++---- .../org/cryptomator/common/settings/VaultSettings.java | 3 ++- .../org/cryptomator/launcher/FileOpenRequestHandler.java | 3 ++- .../cryptomator/ui/addvaultwizard/ReadmeGenerator.java | 6 ++++-- .../ui/convertvault/HubToPasswordConvertController.java | 7 ++++--- .../cryptomator/ui/recoverykey/RecoveryKeyFactory.java | 3 ++- 8 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/cryptomator/common/Environment.java b/src/main/java/org/cryptomator/common/Environment.java index 8e378b93d..17816df96 100644 --- a/src/main/java/org/cryptomator/common/Environment.java +++ b/src/main/java/org/cryptomator/common/Environment.java @@ -2,6 +2,7 @@ package org.cryptomator.common; import com.google.common.base.Splitter; import com.google.common.base.Strings; +import org.jetbrains.annotations.VisibleForTesting; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -128,7 +129,7 @@ public class Environment { return Optional.ofNullable(value).map(Paths::get); } - // visible for testing + @VisibleForTesting Stream getPaths(String propertyName) { Stream rawSettingsPaths = getRawList(propertyName, System.getProperty("path.separator").charAt(0)); return rawSettingsPaths.filter(Predicate.not(Strings::isNullOrEmpty)).map(Path::of); diff --git a/src/main/java/org/cryptomator/common/ErrorCode.java b/src/main/java/org/cryptomator/common/ErrorCode.java index 7363e2278..d75ab97d0 100644 --- a/src/main/java/org/cryptomator/common/ErrorCode.java +++ b/src/main/java/org/cryptomator/common/ErrorCode.java @@ -3,6 +3,7 @@ package org.cryptomator.common; import com.google.common.base.Preconditions; import com.google.common.base.Strings; import com.google.common.base.Throwables; +import org.jetbrains.annotations.VisibleForTesting; import java.util.Locale; import java.util.Objects; @@ -114,7 +115,7 @@ public class ErrorCode { * @param bottomFrames Other stack frames, potentially forming the bottom of the stack of allFrames * @return The number of additional frames in allFrames. In most cases this should be equal to the difference in size. */ - // visible for testing + @VisibleForTesting static int countTopmostFrames(StackTraceElement[] allFrames, StackTraceElement[] bottomFrames) { if (allFrames.length < bottomFrames.length) { // if frames had been stacked on top of bottomFrames, allFrames would be larger @@ -124,7 +125,7 @@ public class ErrorCode { } } - // visible for testing + @VisibleForTesting static int commonSuffixLength(T[] set, T[] subset) { Preconditions.checkArgument(set.length >= subset.length); // iterate items backwards as long as they are identical diff --git a/src/main/java/org/cryptomator/common/mount/MountWithinParentUtil.java b/src/main/java/org/cryptomator/common/mount/MountWithinParentUtil.java index b632923a8..b436bc19a 100644 --- a/src/main/java/org/cryptomator/common/mount/MountWithinParentUtil.java +++ b/src/main/java/org/cryptomator/common/mount/MountWithinParentUtil.java @@ -1,6 +1,7 @@ package org.cryptomator.common.mount; import org.apache.commons.lang3.SystemUtils; +import org.jetbrains.annotations.VisibleForTesting; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -66,7 +67,7 @@ public final class MountWithinParentUtil { } } - //visible for testing + @VisibleForTesting static MountPointState getMountPointState(Path path) throws IOException, IllegalMountPointException { if (Files.notExists(path, LinkOption.NOFOLLOW_LINKS)) { return MountPointState.NOT_EXISTING; @@ -82,7 +83,7 @@ public final class MountWithinParentUtil { return MountPointState.BROKEN_JUNCTION; } - //visible for testing + @VisibleForTesting enum MountPointState { NOT_EXISTING, @@ -93,7 +94,7 @@ public final class MountWithinParentUtil { } - //visible for testing + @VisibleForTesting static void removeResidualHideaway(Path mountPoint, Path hideaway) throws IOException { checkIsHideawayDirectory(mountPoint, hideaway); Files.delete(hideaway); //Fails if not empty @@ -155,7 +156,7 @@ public final class MountWithinParentUtil { } } - //visible for testing + @VisibleForTesting static Path getHideaway(Path mountPoint) { return mountPoint.resolveSibling(HIDEAWAY_PREFIX + mountPoint.getFileName().toString() + HIDEAWAY_SUFFIX); } diff --git a/src/main/java/org/cryptomator/common/settings/VaultSettings.java b/src/main/java/org/cryptomator/common/settings/VaultSettings.java index 7b7e319c9..6662f61ff 100644 --- a/src/main/java/org/cryptomator/common/settings/VaultSettings.java +++ b/src/main/java/org/cryptomator/common/settings/VaultSettings.java @@ -9,6 +9,7 @@ import com.google.common.base.CharMatcher; import com.google.common.base.Strings; import com.google.common.io.BaseEncoding; import org.apache.commons.lang3.SystemUtils; +import org.jetbrains.annotations.VisibleForTesting; import javafx.beans.Observable; import javafx.beans.binding.Bindings; @@ -126,7 +127,7 @@ public class VaultSettings { return json; } - //visible for testing + @VisibleForTesting static String normalizeDisplayName(String original) { if (original.isBlank() || ".".equals(original) || "..".equals(original)) { return "_"; diff --git a/src/main/java/org/cryptomator/launcher/FileOpenRequestHandler.java b/src/main/java/org/cryptomator/launcher/FileOpenRequestHandler.java index eb2418c69..dbdb37823 100644 --- a/src/main/java/org/cryptomator/launcher/FileOpenRequestHandler.java +++ b/src/main/java/org/cryptomator/launcher/FileOpenRequestHandler.java @@ -6,6 +6,7 @@ *******************************************************************************/ package org.cryptomator.launcher; +import org.jetbrains.annotations.VisibleForTesting; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -48,7 +49,7 @@ class FileOpenRequestHandler { handleLaunchArgs(FileSystems.getDefault(), args); } - // visible for testing + @VisibleForTesting void handleLaunchArgs(FileSystem fs, List args) { Collection pathsToOpen = args.stream().map(str -> { try { diff --git a/src/main/java/org/cryptomator/ui/addvaultwizard/ReadmeGenerator.java b/src/main/java/org/cryptomator/ui/addvaultwizard/ReadmeGenerator.java index 5cf14444a..2ffda4d73 100644 --- a/src/main/java/org/cryptomator/ui/addvaultwizard/ReadmeGenerator.java +++ b/src/main/java/org/cryptomator/ui/addvaultwizard/ReadmeGenerator.java @@ -1,5 +1,7 @@ package org.cryptomator.ui.addvaultwizard; +import org.jetbrains.annotations.VisibleForTesting; + import javax.inject.Inject; import java.util.List; import java.util.ResourceBundle; @@ -51,7 +53,7 @@ public class ReadmeGenerator { resourceBundle.getString("addvault.new.readme.accessLocation.4"))); } - // visible for testing + @VisibleForTesting String createDocument(Iterable paragraphs) { StringBuilder sb = new StringBuilder(RTF_HEADER); for (String p : paragraphs) { @@ -63,7 +65,7 @@ public class ReadmeGenerator { return sb.toString(); } - // visible for testing + @VisibleForTesting String escapeNonAsciiChars(CharSequence input) { StringBuilder sb = new StringBuilder(); appendEscaped(sb, input); diff --git a/src/main/java/org/cryptomator/ui/convertvault/HubToPasswordConvertController.java b/src/main/java/org/cryptomator/ui/convertvault/HubToPasswordConvertController.java index 51ff65ec1..fd6d49b89 100644 --- a/src/main/java/org/cryptomator/ui/convertvault/HubToPasswordConvertController.java +++ b/src/main/java/org/cryptomator/ui/convertvault/HubToPasswordConvertController.java @@ -16,6 +16,7 @@ import org.cryptomator.ui.common.FxmlFile; import org.cryptomator.ui.common.FxmlScene; import org.cryptomator.ui.fxapp.FxApplicationWindows; import org.cryptomator.ui.recoverykey.RecoveryKeyFactory; +import org.jetbrains.annotations.VisibleForTesting; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -116,7 +117,7 @@ public class HubToPasswordConvertController implements FxController { }, Platform::runLater); // } - //visible for testing + @VisibleForTesting void convertInternal() throws CompletionException, IllegalArgumentException { var passphrase = newPasswordController.getNewPassword(); var vaultPath = vault.getPath(); @@ -141,7 +142,7 @@ public class HubToPasswordConvertController implements FxController { } } - //visible for testing + @VisibleForTesting void backupHubConfig(Path hubConfigPath) throws IOException { byte[] hubConfigBytes = Files.readAllBytes(hubConfigPath); Path backupPath = hubConfigPath.resolveSibling(VAULTCONFIG_FILENAME + BackupHelper.generateFileIdSuffix(hubConfigBytes) + MASTERKEY_BACKUP_SUFFIX); @@ -149,7 +150,7 @@ public class HubToPasswordConvertController implements FxController { LOG.debug("Successfully created hub config backup {}", backupPath.getFileName()); } - //visible for testing + @VisibleForTesting Path createPasswordConfig(Path passwordConfigPath, Path masterkeyFile, Passphrase passphrase) throws IOException, MasterkeyLoadingFailedException { var unverifiedVaultConfig = vault.getVaultConfigCache().get(); try (var masterkey = masterkeyFileAccess.load(masterkeyFile, passphrase)) { diff --git a/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyFactory.java b/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyFactory.java index 73279396d..8f5bb0500 100644 --- a/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyFactory.java +++ b/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyFactory.java @@ -8,6 +8,7 @@ import org.cryptomator.cryptolib.api.InvalidPassphraseException; import org.cryptomator.cryptolib.api.Masterkey; import org.cryptomator.cryptolib.common.MasterkeyFileAccess; import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.VisibleForTesting; import javax.inject.Inject; import javax.inject.Singleton; @@ -58,7 +59,7 @@ public class RecoveryKeyFactory { } } - // visible for testing + @VisibleForTesting String createRecoveryKey(byte[] rawKey) { Preconditions.checkArgument(rawKey.length == 64, "key should be 64 bytes"); byte[] paddedKey = Arrays.copyOf(rawKey, 66);