mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-08-27 19:36:36 +00:00
Upgrade to JUnit 5
This commit is contained in:
@@ -8,6 +8,11 @@
|
||||
*******************************************************************************/
|
||||
package org.cryptomator.ui.l10n;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
@@ -21,11 +26,6 @@ import java.util.ResourceBundle;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class LocalizationTest {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(LocalizationTest.class);
|
||||
@@ -54,7 +54,7 @@ public class LocalizationTest {
|
||||
ResourceBundle lang = loadLanguage(RESOURCE_FOLDER_PATH + langFileName);
|
||||
allGood &= allStringFormatSpecifiersMatchReferenceLanguage(ref, lang, langFileName);
|
||||
}
|
||||
Assert.assertTrue(allGood);
|
||||
Assertions.assertTrue(allGood);
|
||||
}
|
||||
|
||||
private boolean allStringFormatSpecifiersMatchReferenceLanguage(ResourceBundle ref, ResourceBundle lang, String langFileName) {
|
||||
|
||||
@@ -1,25 +1,22 @@
|
||||
package org.cryptomator.ui.model;
|
||||
|
||||
import com.google.common.jimfs.Configuration;
|
||||
import com.google.common.jimfs.Jimfs;
|
||||
import org.cryptomator.ui.l10n.Localization;
|
||||
import org.cryptomator.ui.l10n.LocalizationMock;
|
||||
import org.cryptomator.ui.model.UpgradeStrategy.UpgradeFailedException;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.FileSystem;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import org.cryptomator.ui.l10n.Localization;
|
||||
import org.cryptomator.ui.l10n.LocalizationMock;
|
||||
import org.cryptomator.ui.model.UpgradeStrategy.UpgradeFailedException;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import com.google.common.jimfs.Configuration;
|
||||
import com.google.common.jimfs.Jimfs;
|
||||
|
||||
public class UpgradeVersion3to4Test {
|
||||
|
||||
private static final Localization L10N = new LocalizationMock();
|
||||
@@ -33,8 +30,6 @@ public class UpgradeVersion3to4Test {
|
||||
+ " \"versionMac\": \"iUmRRHITuyJsJbVNqGNw+82YQ4A3Rma7j/y1v0DCVLA=\"" //
|
||||
+ "}";
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
private final UpgradeStrategy upgradeStrategy = new UpgradeVersion3to4(L10N);
|
||||
private FileSystem fs;
|
||||
private Path fsRoot;
|
||||
@@ -42,7 +37,7 @@ public class UpgradeVersion3to4Test {
|
||||
private Path dataDir;
|
||||
private Path metadataDir;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() throws IOException {
|
||||
fs = Jimfs.newFileSystem(Configuration.unix());
|
||||
fsRoot = fs.getPath("/");
|
||||
@@ -54,22 +49,23 @@ public class UpgradeVersion3to4Test {
|
||||
Files.write(fsRoot.resolve("masterkey.cryptomator"), NULL_KEY_CONTENTS.getBytes(StandardCharsets.US_ASCII));
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void teardown() throws IOException {
|
||||
fs.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void upgradeFailsWithWrongPassword() throws UpgradeFailedException {
|
||||
thrown.expect(UpgradeFailedException.class);
|
||||
thrown.expectMessage("unlock.errorMessage.wrongPassword");
|
||||
upgradeStrategy.upgrade(vault, "asdd");
|
||||
UpgradeFailedException e = Assertions.assertThrows(UpgradeFailedException.class, () -> {
|
||||
upgradeStrategy.upgrade(vault, "asdd");
|
||||
});
|
||||
Assertions.assertEquals("unlock.errorMessage.wrongPassword", e.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void upgradeCreatesBackup() throws UpgradeFailedException {
|
||||
upgradeStrategy.upgrade(vault, "asd");
|
||||
Assert.assertTrue(Files.exists(fsRoot.resolve("masterkey.cryptomator.bkup")));
|
||||
Assertions.assertTrue(Files.exists(fsRoot.resolve("masterkey.cryptomator.bkup")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -81,8 +77,8 @@ public class UpgradeVersion3to4Test {
|
||||
|
||||
upgradeStrategy.upgrade(vault, "asd");
|
||||
Path newFile = lvl2Dir.resolve("0ABCDEFGH");
|
||||
Assert.assertTrue(Files.exists(newFile));
|
||||
Assert.assertTrue(Files.notExists(oldFile));
|
||||
Assertions.assertTrue(Files.exists(newFile));
|
||||
Assertions.assertTrue(Files.notExists(oldFile));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -94,8 +90,8 @@ public class UpgradeVersion3to4Test {
|
||||
|
||||
upgradeStrategy.upgrade(vault, "asd");
|
||||
Path newFile = lvl2Dir.resolve("0ABCDEFGH (1)");
|
||||
Assert.assertTrue(Files.exists(newFile));
|
||||
Assert.assertTrue(Files.notExists(oldFile));
|
||||
Assertions.assertTrue(Files.exists(newFile));
|
||||
Assertions.assertTrue(Files.notExists(oldFile));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -106,7 +102,7 @@ public class UpgradeVersion3to4Test {
|
||||
Files.createFile(oldFile);
|
||||
|
||||
upgradeStrategy.upgrade(vault, "asd");
|
||||
Assert.assertTrue(Files.exists(oldFile));
|
||||
Assertions.assertTrue(Files.exists(oldFile));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -123,9 +119,9 @@ public class UpgradeVersion3to4Test {
|
||||
// hex2base32(sha1("0OPQRSTUVWXYZ====")) = DDLCFQ3ODTEAHEZJPHIJQRDHROB3K42G
|
||||
Path newMetadataFile = metadataDir.resolve("DD/LC/DDLCFQ3ODTEAHEZJPHIJQRDHROB3K42G.lng");
|
||||
Path newFile = lvl2Dir.resolve("DDLCFQ3ODTEAHEZJPHIJQRDHROB3K42G.lng");
|
||||
Assert.assertTrue(Files.exists(newFile));
|
||||
Assert.assertTrue(Files.exists(newMetadataFile));
|
||||
Assert.assertTrue(Files.notExists(oldFile));
|
||||
Assertions.assertTrue(Files.exists(newFile));
|
||||
Assertions.assertTrue(Files.exists(newMetadataFile));
|
||||
Assertions.assertTrue(Files.notExists(oldFile));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -142,9 +138,9 @@ public class UpgradeVersion3to4Test {
|
||||
// hex2base32(sha1("0OPQRSTUVWXYZ====")) = DDLCFQ3ODTEAHEZJPHIJQRDHROB3K42G
|
||||
Path newMetadataFile = metadataDir.resolve("DD/LC/DDLCFQ3ODTEAHEZJPHIJQRDHROB3K42G.lng");
|
||||
Path newFile = lvl2Dir.resolve("DDLCFQ3ODTEAHEZJPHIJQRDHROB3K42G (1).lng");
|
||||
Assert.assertTrue(Files.exists(newFile));
|
||||
Assert.assertTrue(Files.exists(newMetadataFile));
|
||||
Assert.assertTrue(Files.notExists(oldFile));
|
||||
Assertions.assertTrue(Files.exists(newFile));
|
||||
Assertions.assertTrue(Files.exists(newMetadataFile));
|
||||
Assertions.assertTrue(Files.notExists(oldFile));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -158,7 +154,7 @@ public class UpgradeVersion3to4Test {
|
||||
Files.write(oldMetadataFile, "OPQRSTUVWXYZ====".getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
upgradeStrategy.upgrade(vault, "asd");
|
||||
Assert.assertTrue(Files.exists(oldFile));
|
||||
Assertions.assertTrue(Files.exists(oldFile));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,20 +1,24 @@
|
||||
package org.cryptomator.ui.util;
|
||||
|
||||
import org.cryptomator.ui.l10n.Localization;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
public class PasswordStrengthUtilTest {
|
||||
|
||||
@Test(timeout = 5000)
|
||||
@Test
|
||||
public void testLongPasswords() {
|
||||
PasswordStrengthUtil util = new PasswordStrengthUtil(Mockito.mock(Localization.class));
|
||||
StringBuilder longPwBuilder = new StringBuilder();
|
||||
for (int i = 0; i < 10000; i++) {
|
||||
longPwBuilder.append('x');
|
||||
}
|
||||
util.computeRate(longPwBuilder.toString());
|
||||
Assertions.assertTimeout(Duration.ofSeconds(5), () -> {
|
||||
util.computeRate(longPwBuilder.toString());
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user