/
rgd045
/
crypt-file
Обзор
Документация
Войти
/
rgd045
/
crypt-file
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
src/test/java/org/cryptomator/common/keychain/KeychainManagerTest.java
60 строк
2 KB
Sebastian Stenzel
bumped API to 1.1.0-rc1
13 апр 2022, 08:16
Не верифицирован
13 апр 2022, 08:16
9ece1f6
Код
Авторство
О чём код?
package org.cryptomator.common.keychain; import org.cryptomator.integrations.keychain.KeychainAccessException; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import javafx.application.Platform; import javafx.beans.property.ReadOnlyBooleanProperty; import javafx.beans.property.SimpleObjectProperty; import java.time.Duration; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; public class KeychainManagerTest { @Test public void testStoreAndLoad() throws KeychainAccessException { KeychainManager keychainManager = new KeychainManager(new SimpleObjectProperty<>(new MapKeychainAccess())); keychainManager.storePassphrase("test", "Test", "asd"); Assertions.assertArrayEquals("asd".toCharArray(), keychainManager.loadPassphrase("test")); } @Nested public static class WhenObservingProperties { @BeforeAll public static void startup() throws InterruptedException { CountDownLatch latch = new CountDownLatch(1); Platform.startup(latch::countDown); var javafxStarted = latch.await(5, TimeUnit.SECONDS); Assumptions.assumeTrue(javafxStarted); } @Test public void testPropertyChangesWhenStoringPassword() throws KeychainAccessException, InterruptedException { KeychainManager keychainManager = new KeychainManager(new SimpleObjectProperty<>(new MapKeychainAccess())); ReadOnlyBooleanProperty property = keychainManager.getPassphraseStoredProperty("test"); Assertions.assertFalse(property.get()); keychainManager.storePassphrase("test", null,"bar"); AtomicBoolean result = new AtomicBoolean(false); CountDownLatch latch = new CountDownLatch(1); Platform.runLater(() -> { result.set(property.get()); latch.countDown(); }); Assertions.assertTimeoutPreemptively(Duration.ofSeconds(1), () -> latch.await()); Assertions.assertTrue(result.get()); } } }