When select a branch that doesn't exist then an empty Optional is returned
This commit is contained in:
parent
79a5818242
commit
11575f53e7
4 changed files with 40 additions and 14 deletions
|
@ -26,6 +26,7 @@ import org.eclipse.jgit.errors.RepositoryNotFoundException;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main API for connecting to a Git repo as a database.
|
* Main API for connecting to a Git repo as a database.
|
||||||
|
@ -63,4 +64,12 @@ public interface GitDB {
|
||||||
throw new GitDBRepoNotFoundException(dbDir, e);
|
throw new GitDBRepoNotFoundException(dbDir, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Select the named branch.
|
||||||
|
*
|
||||||
|
* @param name the branch to select
|
||||||
|
* @return an Optional containing the branch if it exists
|
||||||
|
*/
|
||||||
|
Optional<GitDBBranch> branch(String name);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,14 +21,10 @@
|
||||||
|
|
||||||
package net.kemitix.gitdb;
|
package net.kemitix.gitdb;
|
||||||
|
|
||||||
//import net.kemitix.mon.TypeAlias;
|
/**
|
||||||
|
* API for interacting with a branch in a GirDB.
|
||||||
//public class Branch extends TypeAlias<String> {
|
*
|
||||||
// protected Branch(final String value) {
|
* @author Paul Campbell (pcampbell@kemitix.net)
|
||||||
// super(value);
|
*/
|
||||||
// }
|
public interface GitDBBranch {
|
||||||
//
|
}
|
||||||
// static Branch name(final String name) {
|
|
||||||
// return new Branch(name);
|
|
||||||
// }
|
|
||||||
//}
|
|
|
@ -31,6 +31,7 @@ import java.io.IOException;
|
||||||
import java.nio.file.DirectoryNotEmptyException;
|
import java.nio.file.DirectoryNotEmptyException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.NotDirectoryException;
|
import java.nio.file.NotDirectoryException;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of GitDB for working with a local Repo.
|
* Implementation of GitDB for working with a local Repo.
|
||||||
|
@ -99,6 +100,11 @@ class GitDBLocal implements GitDB {
|
||||||
return initCommand.setGitDir(dbDir).setBare(true).call();
|
return initCommand.setGitDir(dbDir).setBare(true).call();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<GitDBBranch> branch(final String name) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
// @Override
|
// @Override
|
||||||
// @SneakyThrows
|
// @SneakyThrows
|
||||||
// public <T> T get(Branch branch, Key key, Class<T> type) {
|
// public <T> T get(Branch branch, Key key, Class<T> type) {
|
||||||
|
|
|
@ -11,6 +11,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.*;
|
import java.nio.file.*;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import static org.mockito.BDDMockito.given;
|
import static org.mockito.BDDMockito.given;
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
@ -173,21 +174,35 @@ class GitDBTest implements WithAssertions {
|
||||||
@Test
|
@Test
|
||||||
void openRepo_whenGitDB_thenReturnGitDB() throws IOException {
|
void openRepo_whenGitDB_thenReturnGitDB() throws IOException {
|
||||||
//given
|
//given
|
||||||
final Path dir = gitDBRepo();
|
final Path dir = gitDBRepoPath();
|
||||||
//when
|
//when
|
||||||
final GitDBLocal gitDB = GitDB.openLocal(dir);
|
final GitDBLocal gitDB = GitDB.openLocal(dir);
|
||||||
//then
|
//then
|
||||||
assertThat(gitDB).isNotNull();
|
assertThat(gitDB).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Path gitDBRepo() throws IOException {
|
private Path gitDBRepoPath() throws IOException {
|
||||||
final Path dbDir = dirDoesNotExist();
|
final Path dbDir = dirDoesNotExist();
|
||||||
GitDB.initLocal(dbDir);
|
GitDB.initLocal(dbDir);
|
||||||
return dbDir;
|
return dbDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Given a valid GitDb handle
|
// Given a valid GitDb handle
|
||||||
// When select a branch that doesn't exist then an exception is thrown
|
// When select a branch that doesn't exist then an empty Optional is returned
|
||||||
|
@Test
|
||||||
|
void selectBranch_branchNotExist_thenEmptyOptional() throws IOException {
|
||||||
|
//given
|
||||||
|
final GitDB gitDb = newGitDBRepo();
|
||||||
|
//when
|
||||||
|
final Optional<GitDBBranch> branch = gitDb.branch("unknown");
|
||||||
|
//then
|
||||||
|
assertThat(branch).isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
private GitDB newGitDBRepo() throws IOException {
|
||||||
|
return GitDB.initLocal(dirDoesNotExist());
|
||||||
|
}
|
||||||
|
|
||||||
// When select a valid branch then a GitDbBranch is returned
|
// When select a valid branch then a GitDbBranch is returned
|
||||||
|
|
||||||
// Given a valid GitDbBranch handle
|
// Given a valid GitDbBranch handle
|
||||||
|
|
Loading…
Reference in a new issue