diff --git a/main/commons/src/test/java/org/cryptomator/common/SemVerComparatorTest.java b/main/commons/src/test/java/org/cryptomator/common/SemVerComparatorTest.java index cf22dcecc..52a9366c9 100644 --- a/main/commons/src/test/java/org/cryptomator/common/SemVerComparatorTest.java +++ b/main/commons/src/test/java/org/cryptomator/common/SemVerComparatorTest.java @@ -8,10 +8,10 @@ *******************************************************************************/ package org.cryptomator.common; -import java.util.Comparator; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; -import org.junit.Assert; -import org.junit.Test; +import java.util.Comparator; public class SemVerComparatorTest { @@ -21,38 +21,38 @@ public class SemVerComparatorTest { @Test public void compareEqualVersions() { - Assert.assertEquals(0, Integer.signum(semVerComparator.compare("1.23.4", "1.23.4"))); - Assert.assertEquals(0, Integer.signum(semVerComparator.compare("1.23.4-alpha", "1.23.4-alpha"))); - Assert.assertEquals(0, Integer.signum(semVerComparator.compare("1.23.4+20170101", "1.23.4+20171231"))); - Assert.assertEquals(0, Integer.signum(semVerComparator.compare("1.23.4-alpha+20170101", "1.23.4-alpha+20171231"))); + Assertions.assertEquals(0, Integer.signum(semVerComparator.compare("1.23.4", "1.23.4"))); + Assertions.assertEquals(0, Integer.signum(semVerComparator.compare("1.23.4-alpha", "1.23.4-alpha"))); + Assertions.assertEquals(0, Integer.signum(semVerComparator.compare("1.23.4+20170101", "1.23.4+20171231"))); + Assertions.assertEquals(0, Integer.signum(semVerComparator.compare("1.23.4-alpha+20170101", "1.23.4-alpha+20171231"))); } // newer versions in first argument @Test public void compareHigherToLowerVersions() { - Assert.assertEquals(1, Integer.signum(semVerComparator.compare("1.23.5", "1.23.4"))); - Assert.assertEquals(1, Integer.signum(semVerComparator.compare("1.24.4", "1.23.4"))); - Assert.assertEquals(1, Integer.signum(semVerComparator.compare("1.23.4", "1.23"))); - Assert.assertEquals(1, Integer.signum(semVerComparator.compare("1.23.4", "1.23.4-SNAPSHOT"))); - Assert.assertEquals(1, Integer.signum(semVerComparator.compare("1.23.4", "1.23.4-56.78"))); - Assert.assertEquals(1, Integer.signum(semVerComparator.compare("1.23.4-beta", "1.23.4-alpha"))); - Assert.assertEquals(1, Integer.signum(semVerComparator.compare("1.23.4-alpha.1", "1.23.4-alpha"))); - Assert.assertEquals(1, Integer.signum(semVerComparator.compare("1.23.4-56.79", "1.23.4-56.78"))); + Assertions.assertEquals(1, Integer.signum(semVerComparator.compare("1.23.5", "1.23.4"))); + Assertions.assertEquals(1, Integer.signum(semVerComparator.compare("1.24.4", "1.23.4"))); + Assertions.assertEquals(1, Integer.signum(semVerComparator.compare("1.23.4", "1.23"))); + Assertions.assertEquals(1, Integer.signum(semVerComparator.compare("1.23.4", "1.23.4-SNAPSHOT"))); + Assertions.assertEquals(1, Integer.signum(semVerComparator.compare("1.23.4", "1.23.4-56.78"))); + Assertions.assertEquals(1, Integer.signum(semVerComparator.compare("1.23.4-beta", "1.23.4-alpha"))); + Assertions.assertEquals(1, Integer.signum(semVerComparator.compare("1.23.4-alpha.1", "1.23.4-alpha"))); + Assertions.assertEquals(1, Integer.signum(semVerComparator.compare("1.23.4-56.79", "1.23.4-56.78"))); } // newer versions in second argument @Test public void compareLowerToHigherVersions() { - Assert.assertEquals(-1, Integer.signum(semVerComparator.compare("1.23.4", "1.23.5"))); - Assert.assertEquals(-1, Integer.signum(semVerComparator.compare("1.23.4", "1.24.4"))); - Assert.assertEquals(-1, Integer.signum(semVerComparator.compare("1.23", "1.23.4"))); - Assert.assertEquals(-1, Integer.signum(semVerComparator.compare("1.23.4-SNAPSHOT", "1.23.4"))); - Assert.assertEquals(-1, Integer.signum(semVerComparator.compare("1.23.4-56.78", "1.23.4"))); - Assert.assertEquals(-1, Integer.signum(semVerComparator.compare("1.23.4-alpha", "1.23.4-beta"))); - Assert.assertEquals(-1, Integer.signum(semVerComparator.compare("1.23.4-alpha", "1.23.4-alpha.1"))); - Assert.assertEquals(-1, Integer.signum(semVerComparator.compare("1.23.4-56.78", "1.23.4-56.79"))); + Assertions.assertEquals(-1, Integer.signum(semVerComparator.compare("1.23.4", "1.23.5"))); + Assertions.assertEquals(-1, Integer.signum(semVerComparator.compare("1.23.4", "1.24.4"))); + Assertions.assertEquals(-1, Integer.signum(semVerComparator.compare("1.23", "1.23.4"))); + Assertions.assertEquals(-1, Integer.signum(semVerComparator.compare("1.23.4-SNAPSHOT", "1.23.4"))); + Assertions.assertEquals(-1, Integer.signum(semVerComparator.compare("1.23.4-56.78", "1.23.4"))); + Assertions.assertEquals(-1, Integer.signum(semVerComparator.compare("1.23.4-alpha", "1.23.4-beta"))); + Assertions.assertEquals(-1, Integer.signum(semVerComparator.compare("1.23.4-alpha", "1.23.4-alpha.1"))); + Assertions.assertEquals(-1, Integer.signum(semVerComparator.compare("1.23.4-56.78", "1.23.4-56.79"))); } } diff --git a/main/commons/src/test/java/org/cryptomator/common/settings/SettingsJsonAdapterTest.java b/main/commons/src/test/java/org/cryptomator/common/settings/SettingsJsonAdapterTest.java index cee09295a..2d0e31d2a 100644 --- a/main/commons/src/test/java/org/cryptomator/common/settings/SettingsJsonAdapterTest.java +++ b/main/commons/src/test/java/org/cryptomator/common/settings/SettingsJsonAdapterTest.java @@ -5,10 +5,10 @@ *******************************************************************************/ package org.cryptomator.common.settings; -import java.io.IOException; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; -import org.junit.Assert; -import org.junit.Test; +import java.io.IOException; public class SettingsJsonAdapterTest { @@ -26,12 +26,12 @@ public class SettingsJsonAdapterTest { Settings settings = adapter.fromJson(json); - Assert.assertTrue(settings.checkForUpdates().get()); - Assert.assertEquals(2, settings.getDirectories().size()); - Assert.assertEquals(8080, settings.port().get()); - Assert.assertEquals(42, settings.numTrayNotifications().get()); - Assert.assertEquals("dav", settings.preferredGvfsScheme().get()); - Assert.assertEquals(VolumeImpl.FUSE, settings.preferredVolumeImpl().get()); + Assertions.assertTrue(settings.checkForUpdates().get()); + Assertions.assertEquals(2, settings.getDirectories().size()); + Assertions.assertEquals(8080, settings.port().get()); + Assertions.assertEquals(42, settings.numTrayNotifications().get()); + Assertions.assertEquals("dav", settings.preferredGvfsScheme().get()); + Assertions.assertEquals(VolumeImpl.FUSE, settings.preferredVolumeImpl().get()); } } diff --git a/main/commons/src/test/java/org/cryptomator/common/settings/SettingsTest.java b/main/commons/src/test/java/org/cryptomator/common/settings/SettingsTest.java index 320d0504c..6aadb27b3 100644 --- a/main/commons/src/test/java/org/cryptomator/common/settings/SettingsTest.java +++ b/main/commons/src/test/java/org/cryptomator/common/settings/SettingsTest.java @@ -5,12 +5,12 @@ *******************************************************************************/ package org.cryptomator.common.settings; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + import java.io.IOException; import java.util.function.Consumer; -import org.junit.Test; -import org.mockito.Mockito; - public class SettingsTest { @Test diff --git a/main/commons/src/test/java/org/cryptomator/common/settings/VaultSettingsJsonAdapterTest.java b/main/commons/src/test/java/org/cryptomator/common/settings/VaultSettingsJsonAdapterTest.java index e3f31251e..32f393842 100644 --- a/main/commons/src/test/java/org/cryptomator/common/settings/VaultSettingsJsonAdapterTest.java +++ b/main/commons/src/test/java/org/cryptomator/common/settings/VaultSettingsJsonAdapterTest.java @@ -5,15 +5,14 @@ *******************************************************************************/ package org.cryptomator.common.settings; +import com.google.gson.stream.JsonReader; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + import java.io.IOException; import java.io.StringReader; import java.nio.file.Paths; -import org.junit.Assert; -import org.junit.Test; - -import com.google.gson.stream.JsonReader; - public class VaultSettingsJsonAdapterTest { private final VaultSettingsJsonAdapter adapter = new VaultSettingsJsonAdapter(); @@ -24,11 +23,11 @@ public class VaultSettingsJsonAdapterTest { JsonReader jsonReader = new JsonReader(new StringReader(json)); VaultSettings vaultSettings = adapter.read(jsonReader); - Assert.assertEquals("foo", vaultSettings.getId()); - Assert.assertEquals(Paths.get("/foo/bar"), vaultSettings.path().get()); - Assert.assertEquals("test", vaultSettings.mountName().get()); - Assert.assertEquals("X", vaultSettings.winDriveLetter().get()); - Assert.assertEquals("/home/test/crypto", vaultSettings.individualMountPath().get()); + Assertions.assertEquals("foo", vaultSettings.getId()); + Assertions.assertEquals(Paths.get("/foo/bar"), vaultSettings.path().get()); + Assertions.assertEquals("test", vaultSettings.mountName().get()); + Assertions.assertEquals("X", vaultSettings.winDriveLetter().get()); + Assertions.assertEquals("/home/test/crypto", vaultSettings.individualMountPath().get()); } } diff --git a/main/commons/src/test/java/org/cryptomator/common/settings/VaultSettingsTest.java b/main/commons/src/test/java/org/cryptomator/common/settings/VaultSettingsTest.java index 9aeac9b7a..042ff9896 100644 --- a/main/commons/src/test/java/org/cryptomator/common/settings/VaultSettingsTest.java +++ b/main/commons/src/test/java/org/cryptomator/common/settings/VaultSettingsTest.java @@ -8,9 +8,9 @@ *******************************************************************************/ package org.cryptomator.common.settings; -import static org.junit.Assert.assertEquals; +import org.junit.jupiter.api.Test; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; public class VaultSettingsTest { diff --git a/main/keychain/src/test/java/org/cryptomator/keychain/KeychainModuleTest.java b/main/keychain/src/test/java/org/cryptomator/keychain/KeychainModuleTest.java index 1bd556061..c177060a3 100644 --- a/main/keychain/src/test/java/org/cryptomator/keychain/KeychainModuleTest.java +++ b/main/keychain/src/test/java/org/cryptomator/keychain/KeychainModuleTest.java @@ -5,20 +5,20 @@ *******************************************************************************/ package org.cryptomator.keychain; -import java.util.Optional; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; -import org.junit.Assert; -import org.junit.Test; +import java.util.Optional; public class KeychainModuleTest { @Test public void testGetKeychain() { Optional keychainAccess = DaggerTestKeychainComponent.builder().keychainModule(new TestKeychainModule()).build().keychainAccess(); - Assert.assertTrue(keychainAccess.isPresent()); - Assert.assertTrue(keychainAccess.get() instanceof MapKeychainAccess); + Assertions.assertTrue(keychainAccess.isPresent()); + Assertions.assertTrue(keychainAccess.get() instanceof MapKeychainAccess); keychainAccess.get().storePassphrase("test", "asd"); - Assert.assertArrayEquals("asd".toCharArray(), keychainAccess.get().loadPassphrase("test")); + Assertions.assertArrayEquals("asd".toCharArray(), keychainAccess.get().loadPassphrase("test")); } } diff --git a/main/keychain/src/test/java/org/cryptomator/keychain/WindowsProtectedKeychainAccessTest.java b/main/keychain/src/test/java/org/cryptomator/keychain/WindowsProtectedKeychainAccessTest.java index c058baadc..88c23ffa1 100644 --- a/main/keychain/src/test/java/org/cryptomator/keychain/WindowsProtectedKeychainAccessTest.java +++ b/main/keychain/src/test/java/org/cryptomator/keychain/WindowsProtectedKeychainAccessTest.java @@ -5,32 +5,27 @@ *******************************************************************************/ package org.cryptomator.keychain; +import org.cryptomator.jni.WinDataProtection; +import org.cryptomator.jni.WinFunctions; +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 org.mockito.stubbing.Answer; + import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.util.Optional; -import org.cryptomator.jni.WinDataProtection; -import org.cryptomator.jni.WinFunctions; -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 org.mockito.stubbing.Answer; - public class WindowsProtectedKeychainAccessTest { - @Rule - public final ExpectedException thrown = ExpectedException.none(); - private Path tmpFile; private WindowsProtectedKeychainAccess keychain; - @Before - public void setup() throws IOException, ReflectiveOperationException { + @BeforeEach + public void setup() throws IOException { tmpFile = Files.createTempFile("unit-tests", ".tmp"); System.setProperty("cryptomator.keychainPath", tmpFile.toAbsolutePath().normalize().toString()); WinFunctions winFunctions = Mockito.mock(WinFunctions.class); @@ -42,7 +37,7 @@ public class WindowsProtectedKeychainAccessTest { keychain = new WindowsProtectedKeychainAccess(Optional.of(winFunctions)); } - @After + @AfterEach public void teardown() throws IOException { Files.deleteIfExists(tmpFile); } @@ -55,11 +50,11 @@ public class WindowsProtectedKeychainAccessTest { keychain.storePassphrase("myOtherPassword", storedPw2); String loadedPw1 = new String(keychain.loadPassphrase("myPassword")); String loadedPw2 = new String(keychain.loadPassphrase("myOtherPassword")); - Assert.assertEquals(storedPw1, loadedPw1); - Assert.assertEquals(storedPw2, loadedPw2); + Assertions.assertEquals(storedPw1, loadedPw1); + Assertions.assertEquals(storedPw2, loadedPw2); keychain.deletePassphrase("myPassword"); - Assert.assertNull(keychain.loadPassphrase("myPassword")); - Assert.assertNull(keychain.loadPassphrase("nonExistingPassword")); + Assertions.assertNull(keychain.loadPassphrase("myPassword")); + Assertions.assertNull(keychain.loadPassphrase("nonExistingPassword")); } } diff --git a/main/launcher/src/test/java/org/cryptomator/launcher/FileOpenRequestHandlerTest.java b/main/launcher/src/test/java/org/cryptomator/launcher/FileOpenRequestHandlerTest.java index 54acb065c..9bf8cd2be 100644 --- a/main/launcher/src/test/java/org/cryptomator/launcher/FileOpenRequestHandlerTest.java +++ b/main/launcher/src/test/java/org/cryptomator/launcher/FileOpenRequestHandlerTest.java @@ -5,6 +5,10 @@ *******************************************************************************/ package org.cryptomator.launcher; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + import java.io.IOException; import java.nio.file.FileSystem; import java.nio.file.InvalidPathException; @@ -14,10 +18,6 @@ import java.nio.file.spi.FileSystemProvider; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.BlockingQueue; -import org.junit.Assert; -import org.junit.Test; -import org.mockito.Mockito; - public class FileOpenRequestHandlerTest { @Test @@ -37,8 +37,8 @@ public class FileOpenRequestHandlerTest { FileOpenRequestHandler handler = new FileOpenRequestHandler(queue); handler.handleLaunchArgs(fs, new String[] {"foo", "bar"}); - Assert.assertEquals(p1, queue.poll()); - Assert.assertEquals(p2, queue.poll()); + Assertions.assertEquals(p1, queue.poll()); + Assertions.assertEquals(p2, queue.poll()); } @Test diff --git a/main/launcher/src/test/java/org/cryptomator/launcher/InterProcessCommunicatorTest.java b/main/launcher/src/test/java/org/cryptomator/launcher/InterProcessCommunicatorTest.java index 81c62aca3..2b7d553b9 100644 --- a/main/launcher/src/test/java/org/cryptomator/launcher/InterProcessCommunicatorTest.java +++ b/main/launcher/src/test/java/org/cryptomator/launcher/InterProcessCommunicatorTest.java @@ -5,6 +5,11 @@ *******************************************************************************/ package org.cryptomator.launcher; +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.ByteBuffer; import java.nio.channels.SeekableByteChannel; @@ -15,11 +20,6 @@ import java.nio.file.attribute.BasicFileAttributes; import java.nio.file.spi.FileSystemProvider; import java.util.concurrent.atomic.AtomicInteger; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mockito; - public class InterProcessCommunicatorTest { Path portFilePath = Mockito.mock(Path.class); @@ -30,7 +30,7 @@ public class InterProcessCommunicatorTest { SeekableByteChannel portFileChannel = Mockito.mock(SeekableByteChannel.class); AtomicInteger port = new AtomicInteger(-1); - @Before + @BeforeEach public void setup() throws IOException { Mockito.when(portFilePath.getFileSystem()).thenReturn(fs); Mockito.when(portFilePath.toAbsolutePath()).thenReturn(portFilePath); @@ -53,15 +53,17 @@ public class InterProcessCommunicatorTest { }); } - @Test(expected = UnsupportedOperationException.class) + @Test public void testStartWithDummyPort1() throws IOException { port.set(0); InterProcessCommunicationProtocol protocol = Mockito.mock(InterProcessCommunicationProtocol.class); try (InterProcessCommunicator result = InterProcessCommunicator.start(portFilePath, protocol)) { - Assert.assertTrue(result.isServer()); + Assertions.assertTrue(result.isServer()); Mockito.verify(provider).createDirectory(portFileParentPath); Mockito.verifyZeroInteractions(protocol); - result.handleLaunchArgs(new String[] {"foo"}); + Assertions.assertThrows(UnsupportedOperationException.class, () -> { + result.handleLaunchArgs(new String[] {"foo"}); + }); } } @@ -71,7 +73,7 @@ public class InterProcessCommunicatorTest { InterProcessCommunicationProtocol protocol = Mockito.mock(InterProcessCommunicationProtocol.class); try (InterProcessCommunicator result = InterProcessCommunicator.start(portFilePath, protocol)) { - Assert.assertTrue(result.isServer()); + Assertions.assertTrue(result.isServer()); Mockito.verify(provider).createDirectory(portFileParentPath); Mockito.verifyZeroInteractions(protocol); } @@ -82,14 +84,14 @@ public class InterProcessCommunicatorTest { port.set(-1); InterProcessCommunicationProtocol protocol = Mockito.mock(InterProcessCommunicationProtocol.class); try (InterProcessCommunicator result1 = InterProcessCommunicator.start(portFilePath, protocol)) { - Assert.assertTrue(result1.isServer()); + Assertions.assertTrue(result1.isServer()); Mockito.verify(provider, Mockito.times(1)).createDirectory(portFileParentPath); Mockito.verifyZeroInteractions(protocol); try (InterProcessCommunicator result2 = InterProcessCommunicator.start(portFilePath, null)) { - Assert.assertFalse(result2.isServer()); + Assertions.assertFalse(result2.isServer()); Mockito.verify(provider, Mockito.times(1)).createDirectory(portFileParentPath); - Assert.assertNotSame(result1, result2); + Assertions.assertNotSame(result1, result2); result2.handleLaunchArgs(new String[] {"foo"}); Mockito.verify(protocol).handleLaunchArgs(new String[] {"foo"}); diff --git a/main/launcher/src/test/java/org/cryptomator/logging/LaunchBasedTriggeringPolicyTest.java b/main/launcher/src/test/java/org/cryptomator/logging/LaunchBasedTriggeringPolicyTest.java index 2896398ab..16385d949 100644 --- a/main/launcher/src/test/java/org/cryptomator/logging/LaunchBasedTriggeringPolicyTest.java +++ b/main/launcher/src/test/java/org/cryptomator/logging/LaunchBasedTriggeringPolicyTest.java @@ -5,12 +5,12 @@ *******************************************************************************/ package org.cryptomator.logging; -import java.io.File; - -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.io.File; + public class LaunchBasedTriggeringPolicyTest { @Test @@ -21,15 +21,15 @@ public class LaunchBasedTriggeringPolicyTest { // 1st invocation boolean triggered = policy.isTriggeringEvent(activeFile, event); - Assert.assertTrue(triggered); + Assertions.assertTrue(triggered); // 2nd invocation triggered = policy.isTriggeringEvent(activeFile, event); - Assert.assertFalse(triggered); + Assertions.assertFalse(triggered); // 3rd invocation triggered = policy.isTriggeringEvent(activeFile, event); - Assert.assertFalse(triggered); + Assertions.assertFalse(triggered); Mockito.verifyZeroInteractions(activeFile); Mockito.verifyZeroInteractions(event); diff --git a/main/pom.xml b/main/pom.xml index a03e4e420..add0f6161 100644 --- a/main/pom.xml +++ b/main/pom.xml @@ -45,10 +45,9 @@ 1.7.25 1.2.3 - 4.12 - 4.12.1 - 2.23.0 - 1.3 + 5.4.0 + 2.24.0 + 1.3 @@ -201,20 +200,10 @@ - junit - junit - ${junit.version} - - - hamcrest-core - org.hamcrest - - - - - de.bechte.junit - junit-hierarchicalcontextrunner - ${junit.hierarchicalrunner.version} + org.junit.jupiter + junit-jupiter + ${junit.jupiter.version} + test org.mockito @@ -236,9 +225,8 @@ slf4j-api - junit - junit - test + org.junit.jupiter + junit-jupiter org.hamcrest @@ -250,11 +238,6 @@ mockito-core test - - de.bechte.junit - junit-hierarchicalcontextrunner - test - @@ -345,6 +328,11 @@ + + org.apache.maven.plugins + maven-surefire-plugin + 2.22.1 + diff --git a/main/ui/src/test/java/org/cryptomator/ui/l10n/LocalizationTest.java b/main/ui/src/test/java/org/cryptomator/ui/l10n/LocalizationTest.java index 9644d103f..24609365b 100644 --- a/main/ui/src/test/java/org/cryptomator/ui/l10n/LocalizationTest.java +++ b/main/ui/src/test/java/org/cryptomator/ui/l10n/LocalizationTest.java @@ -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) { diff --git a/main/ui/src/test/java/org/cryptomator/ui/model/UpgradeVersion3to4Test.java b/main/ui/src/test/java/org/cryptomator/ui/model/UpgradeVersion3to4Test.java index 8b1f18e88..b1d430ceb 100644 --- a/main/ui/src/test/java/org/cryptomator/ui/model/UpgradeVersion3to4Test.java +++ b/main/ui/src/test/java/org/cryptomator/ui/model/UpgradeVersion3to4Test.java @@ -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)); } } diff --git a/main/ui/src/test/java/org/cryptomator/ui/util/PasswordStrengthUtilTest.java b/main/ui/src/test/java/org/cryptomator/ui/util/PasswordStrengthUtilTest.java index 2a9411077..553d54027 100644 --- a/main/ui/src/test/java/org/cryptomator/ui/util/PasswordStrengthUtilTest.java +++ b/main/ui/src/test/java/org/cryptomator/ui/util/PasswordStrengthUtilTest.java @@ -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()); + }); } }