When removing a key that does not exist then the GitDbBranch is returned

This commit is contained in:
Paul Campbell 2018-06-13 18:22:45 +01:00
parent 5576b12c83
commit 36d968335e
2 changed files with 21 additions and 2 deletions

View file

@ -66,7 +66,7 @@ public class GitDBBranch {
/** /**
* Lookup a value for the key. * Lookup a value for the key.
* *
* @param key the key to lookup * @param key the key to lookup
* @return an Optional containing the value, if it exists, or empty if not * @return an Optional containing the value, if it exists, or empty if not
* @throws IOException if there was an error reading the value * @throws IOException if there was an error reading the value
*/ */
@ -91,6 +91,16 @@ public class GitDBBranch {
return updateBranch(commitId); return updateBranch(commitId);
} }
/**
* Removes a key and its value from the store.
*
* @param key the key to remove
* @return an updated branch without the key, or the original if the key was not found
*/
public GitDBBranch remove(final String key) {
return this;
}
private ObjectId insertBlob(final byte[] blob) throws IOException { private ObjectId insertBlob(final byte[] blob) throws IOException {
return gitDBRepo.insertBlob(blob); return gitDBRepo.insertBlob(blob);
} }
@ -114,5 +124,4 @@ public class GitDBBranch {
final Ref updatedRef = gitDBRepo.writeHead(branchRef.getName(), commitId); final Ref updatedRef = gitDBRepo.writeHead(branchRef.getName(), commitId);
return GitDBBranch.withRef(updatedRef, gitDBRepo, userName, userEmailAddress); return GitDBBranch.withRef(updatedRef, gitDBRepo, userName, userEmailAddress);
} }
} }

View file

@ -236,6 +236,16 @@ class GitDBTest implements WithAssertions {
} }
// When removing a key that does not exist then the GitDbBranch is returned // When removing a key that does not exist then the GitDbBranch is returned
@Test
void removeKey_whenNotExist_thenReturnOriginal() throws IOException {
//given
final GitDBBranch gitDBBranch = gitDBBranch();
//when
final GitDBBranch result = gitDBBranch.remove("unknown");
//then
assertThat(result).isSameAs(gitDBBranch);
}
// When removing a key that does exist then a GitDbBranch is returned // When removing a key that does exist then a GitDbBranch is returned
// When removing a key that does exist then original GitDbBranch can still find it // When removing a key that does exist then original GitDbBranch can still find it
// When removing a key that does exist then the updated GitDbBranch can't find it // When removing a key that does exist then the updated GitDbBranch can't find it