When get key/value in a transaction then the value is returned

This commit is contained in:
Paul Campbell 2018-06-15 18:58:53 +01:00
parent c506802224
commit cdd35e8008
2 changed files with 17 additions and 3 deletions

View file

@ -44,8 +44,8 @@ class GitDBTransactionImpl implements GitDBTransaction {
}
@Override
public Optional<String> get(String key) {
return Optional.empty();
public Optional<String> get(String key) throws IOException {
return branch.get(key);
}
@Override

View file

@ -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<String> 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