From cdd35e800892a9436a98b429be78ea3b808d17a9 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Fri, 15 Jun 2018 18:58:53 +0100 Subject: [PATCH] When get key/value in a transaction then the value is returned --- .../kemitix/gitdb/impl/GitDBTransactionImpl.java | 4 ++-- .../java/net/kemitix/gitdb/test/GitDBTest.java | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/kemitix/gitdb/impl/GitDBTransactionImpl.java b/src/main/java/net/kemitix/gitdb/impl/GitDBTransactionImpl.java index a71f5ab..0a16247 100644 --- a/src/main/java/net/kemitix/gitdb/impl/GitDBTransactionImpl.java +++ b/src/main/java/net/kemitix/gitdb/impl/GitDBTransactionImpl.java @@ -44,8 +44,8 @@ class GitDBTransactionImpl implements GitDBTransaction { } @Override - public Optional get(String key) { - return Optional.empty(); + public Optional get(String key) throws IOException { + return branch.get(key); } @Override diff --git a/src/test/java/net/kemitix/gitdb/test/GitDBTest.java b/src/test/java/net/kemitix/gitdb/test/GitDBTest.java index cb00ece..974a65d 100644 --- a/src/test/java/net/kemitix/gitdb/test/GitDBTest.java +++ b/src/test/java/net/kemitix/gitdb/test/GitDBTest.java @@ -246,7 +246,7 @@ class GitDBTest implements WithAssertions { // When getting a key that does exist then the value is returned inside an Optional @Test - void getValue_whenExists_thenReturnValueInOptional() throws IOException, ClassNotFoundException { + void getKey_whenExists_thenReturnValueInOptional() throws IOException, ClassNotFoundException { //given final String key = stringSupplier.get(); final String value = stringSupplier.get(); @@ -434,6 +434,20 @@ class GitDBTest implements WithAssertions { assertThat(formatVersion).contains(GitDB.VERSION); } + // When get key/value in a transaction then the value is returned + @Test + void getKey_whenTransaction_thenReturnValueInOptional() throws IOException { + //given + final String key = stringSupplier.get(); + final String value = stringSupplier.get(); + final GitDBBranch gitDBBranch = gitDBBranchWithKeyValue(key, value); + final GitDBTransaction transaction = gitDBBranch.transaction(); + //when + final Optional result = transaction.get(key); + //then + assertThat(result).contains(value); + } + // Given a GitDbTransaction handle with a added, updated and removed keys // When closing the transaction an GitDbBranch is returned // When closing the transaction the added key/value is found