Skip to content

Commit

Permalink
Try different Test structer
Browse files Browse the repository at this point in the history
  • Loading branch information
rexhoffman committed Sep 25, 2023
1 parent fcb06de commit 08edd3b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public class FreedesktopKeyringBackend implements KeyringBackend {
public FreedesktopKeyringBackend() throws BackendNotSupportedException {
try {
collection = new SimpleCollection();
if (!collection.isConnected()) {
throw new BackendNotSupportedException("Error connecting to dbus");
}
} catch (IOException ex) {
throw new BackendNotSupportedException("Error connecting to dbus", ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ public SimpleCollection() throws IOException {
unlock();
}

public boolean isConnected() {
return this.session.getConnection().isConnected();
}

/*
* A user specified collection.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,6 @@ public class KWalletBackend implements KeyringBackend {

public KWalletBackend() throws BackendNotSupportedException {
try {
// connection = DBusConnectionBuilder.forAddress(BusAddress.of(System.getProperty("DBUS_TCP_SESSION")))
// .withRegisterSelf(true)
// .withShared(true)
// .transportConfig()
// .withAdditionalConfig("TIMEOUT", 10000)
// .back()
// .build();

connection = DBusConnectionBuilder.forSessionBus().build();
wallet = connection.getRemoteObject("org.kde.kwalletd5", "/modules/kwalletd5", KWallet.class, true);
wallet.localWallet(); //attempt connection to wallet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,24 @@
package com.github.javakeyring.internal;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.catchThrowable;
import static org.junit.Assume.assumeTrue;

import org.junit.Test;

import com.github.javakeyring.BackendNotSupportedException;
import com.github.javakeyring.internal.freedesktop.FreedesktopKeyringBackend;
import com.github.javakeyring.internal.kde.KWalletBackend;
import com.sun.jna.Platform;


public class KeyringBackendFactoryTest {

@Test
public void testKeyringBackendFactory() throws BackendNotSupportedException {
assertThatThrownBy(() -> KeyringBackendFactory.create(null)).isInstanceOf(BackendNotSupportedException.class);
assertThat(KeyringBackendFactory.create()).isNotNull();
assumeTrue(Platform.isLinux());
assumeTrue(catchThrowable(KWalletBackend::new) instanceof BackendNotSupportedException);
assertThat(catchThrowable(FreedesktopKeyringBackend::new)).as("Setup should succeed").doesNotThrowAnyException();
}

}

0 comments on commit 08edd3b

Please sign in to comment.