我在我的代码中使用 JGit 库来添加和提交新文件。但我不确定如何通过 Mockito 编写单元测试。
这是使用 JGit 设置存储库的模板。
private static final String PACKAGE_NAME = "ABC";
private static final String CLONED_REPO_PATH = String.format("/tmp/%s", PACKAGE_NAME);
final File gitFile = new File(String.join("/", CLONED_REPO_PATH, ".git"));
final Git openedRepo = Git.open(gitFile);
我想为这些特定语句编写单元测试:
openedRepo.checkout().setCreateBranch(true).setName(branchName).call();
openedRepo.add().addFilepattern(<some file>).call();
openedRepo.commit().setMessage(commitMessage).call();
当我尝试使用此测试代码测试 [1](结帐分支步骤)时出现错误:
git.checkout().setCreateBranch(true).setName("test2").call();
Ref HEAD 无法解析