When getting a key that does not exist then return an empty Optional
This commit is contained in:
parent
a0fc7c28c5
commit
265bd61a11
2 changed files with 30 additions and 0 deletions
|
@ -25,6 +25,8 @@ import lombok.AccessLevel;
|
|||
import lombok.RequiredArgsConstructor;
|
||||
import org.eclipse.jgit.lib.Ref;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* API for interacting with a branch in a GirDB.
|
||||
*
|
||||
|
@ -44,4 +46,16 @@ public class GitDBBranch {
|
|||
public static GitDBBranch withRef(final Ref ref) {
|
||||
return new GitDBBranch(ref);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup a value for the key.
|
||||
*
|
||||
* @param key the key to lookup
|
||||
* @param valueClass the expected class of the value
|
||||
* @param <T> the Class of the value
|
||||
* @return an Optional containing the value, if it exists, or empty if not
|
||||
*/
|
||||
public <T> Optional<T> get(final String key, final Class<T> valueClass) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package net.kemitix.gitdb;
|
||||
|
||||
import org.assertj.core.api.Assumptions;
|
||||
import org.assertj.core.api.WithAssertions;
|
||||
import org.eclipse.jgit.api.Git;
|
||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||
|
@ -13,6 +14,8 @@ import java.io.*;
|
|||
import java.nio.file.*;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.assertj.core.api.Assumptions.assumeThat;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class GitDBTest implements WithAssertions {
|
||||
|
||||
|
@ -193,6 +196,19 @@ class GitDBTest implements WithAssertions {
|
|||
|
||||
// Given a valid GitDbBranch handle
|
||||
// When getting a key that does not exist then return an empty Optional
|
||||
@Test
|
||||
void getKey_whenKeyNotExist_thenReturnEmptyOptional() throws IOException {
|
||||
//given
|
||||
final GitDB gitDB = newGitDBRepo(dirDoesNotExist());
|
||||
final Optional<GitDBBranch> branchOptional = gitDB.branch("master");
|
||||
assumeThat(branchOptional).isNotEmpty();
|
||||
final GitDBBranch master = branchOptional.get();
|
||||
//when
|
||||
final Optional<String> value = master.get("unknown", String.class);
|
||||
//then
|
||||
assertThat(value).isEmpty();
|
||||
}
|
||||
|
||||
// When putting a key/value pair then a GitDbBranch is returned
|
||||
// When getting a key that does exist then the value is returned inside an Optional
|
||||
// When removing a key that does not exist then the GitDbBranch is returned
|
||||
|
|
Loading…
Reference in a new issue