diff --git a/src/main/java/io/zold/api/Wallet.java b/src/main/java/io/zold/api/Wallet.java index 682d947..00924fb 100644 --- a/src/main/java/io/zold/api/Wallet.java +++ b/src/main/java/io/zold/api/Wallet.java @@ -70,8 +70,9 @@ public interface Wallet { /** * This wallet's RSA key. * @return This wallet's RSA key + * @throws IOException If an IO error occurs */ - String key(); + String key() throws IOException; /** * A Fake {@link Wallet}. @@ -275,14 +276,19 @@ public Iterable ledger() { ); } - // @todo #54:30min Implement key method. This should return the - // public RSA key of the wallet owner in Base64. Also add a unit test - // to replace WalletTest.keyIsNotYetImplemented(). @Override - public String key() { - throw new UnsupportedOperationException( - "key() not yet supported" - ); + public String key() throws IOException { + // @checkstyle ProhibitLineSeparatorInStringsCheck (10 lines) + return new Checked<>( + () -> new ListOf<>( + new Split( + new TextOf(this.path), + "\n" + ) + // @checkstyle MagicNumberCheck (1 line) + ).get(3).asString(), + e -> new IOException(e) + ).value(); } } } diff --git a/src/test/java/io/zold/api/WalletTest.java b/src/test/java/io/zold/api/WalletTest.java index 175bac7..4fc279f 100644 --- a/src/test/java/io/zold/api/WalletTest.java +++ b/src/test/java/io/zold/api/WalletTest.java @@ -195,11 +195,13 @@ public void walletShouldBeAbleToReturnLedger() throws Exception { } @Test - public void keyIsNotYetImplemented() throws IOException { - final Path path = this.folder.newFile().toPath(); - Assertions.assertThrows( - UnsupportedOperationException.class, - () -> new Wallet.File(path).key() + public void readsPublicKey() throws IOException { + MatcherAssert.assertThat( + new Wallet.File(this.wallet(5_124_095_577_148_911L)).key(), + Matchers.is( + // @checkstyle LineLengthCheck (1 line) + "MIGeMA0GCSqGSIb3DQEBAQUAA4GMADCBiAKBgGZCr/9hBChqsChd4sRAIpKNRinjhSW+J+S7PU5malVMiRHVoKjeooLDpWpij0A6vkzOvjrMldAZT0Fzgp0cJ15TOVwiQanQ5WuQDgRkLoxrdh/qyBApoDvk4OUEozOQPNwfpZOFfaUALPsPnv9995TlY9WcdSKW5dj041p1tJmlAgMBAAE=" + ) ); }