Skip to content

Commit

Permalink
removed processResult from Mock
Browse files Browse the repository at this point in the history
  • Loading branch information
alfeilex committed Jan 14, 2025
1 parent 9df8953 commit bca3a12
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,21 @@ public class ProcessContextGitMock implements ProcessContext {

private final Path directory;

private ProcessResult processResult;
private List<OutputMessage> outputMessages;

/**
* @param directory the {@link Path} to the git repository.
*/
public ProcessContextGitMock(Path directory) {

this.arguments = new ArrayList<>();
this.processResult = new ProcessResultImpl("git", "", 0, new ArrayList<>());
this.directory = directory;
this.now = LocalDateTime.now();
this.outputMessages = new ArrayList<OutputMessage>();
}

/**
* @return the mocked {@link ProcessResult}
*/
public ProcessResult getProcessResult() {

return this.processResult;
}

/**
* @param exitCode th exit code.
* @param output the list of {@link OutputMessage}}
* @return the mocked {@link ProcessResult}
*/
public void setProcessResult(int exitCode, List<OutputMessage> output) {

this.processResult = new ProcessResultImpl("git", "", exitCode, output);
public void addOutputMessage(OutputMessage message) {
this.outputMessages.add(message);
}

@Override
Expand Down Expand Up @@ -121,7 +107,7 @@ public ProcessResult run(ProcessMode processMode) {
if (this.arguments.contains("ls-files")) {
if (Files.exists(this.directory.resolve("new-folder"))) {
OutputMessage outputMessage = new OutputMessage(false, "new-folder");
processResult.getOutputMessages().add(outputMessage);
this.outputMessages.add(outputMessage);
}
}
if (this.arguments.contains("clone")) {
Expand Down Expand Up @@ -161,8 +147,7 @@ public ProcessResult run(ProcessMode processMode) {
}
}
this.arguments.clear();
setProcessResult(exitCode, this.processResult.getOutputMessages());
return this.processResult;
return new ProcessResultImpl("git", "", exitCode, this.outputMessages);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void testRunGitClone(@TempDir Path tempDir) {
String gitRepoUrl = "https://github.com/test";
IdeTestContext context = newGitContext(tempDir);
OutputMessage outputMessage = new OutputMessage(false, "test-remote");
this.processContext.getProcessResult().getOutputMessages().add(outputMessage);
this.processContext.addOutputMessage(outputMessage);
// act
context.getGitContext().pullOrClone(GitUrl.of(gitRepoUrl), tempDir);
// assert
Expand All @@ -92,7 +92,7 @@ public void testRunGitPullWithoutForce(@TempDir Path tempDir) {
String gitRepoUrl = "https://github.com/test";
IdeTestContext context = newGitContext(tempDir);
OutputMessage outputMessage = new OutputMessage(false, "test-remote");
this.processContext.getProcessResult().getOutputMessages().add(outputMessage);
this.processContext.addOutputMessage(outputMessage);
FileAccess fileAccess = new FileAccessImpl(context);
Path gitFolderPath = tempDir.resolve(".git");
fileAccess.mkdirs(gitFolderPath);
Expand Down Expand Up @@ -133,7 +133,7 @@ public void testRunGitPullWithForceStartsReset(@TempDir Path tempDir) {
}
IdeTestContext context = newGitContext(tempDir);
OutputMessage outputMessage = new OutputMessage(false, "test-remote");
this.processContext.getProcessResult().getOutputMessages().add(outputMessage);
this.processContext.addOutputMessage(outputMessage);
// act
context.getGitContext().pullOrCloneAndResetIfNeeded(new GitUrl(gitRepoUrl, "master"), tempDir, "origin");
// assert
Expand All @@ -152,7 +152,7 @@ public void testRunGitPullWithForceStartsCleanup(@TempDir Path tempDir) {
String gitRepoUrl = "https://github.com/test";
IdeTestContext context = newGitContext(tempDir);
OutputMessage outputMessage = new OutputMessage(false, "test-remote");
this.processContext.getProcessResult().getOutputMessages().add(outputMessage);
this.processContext.addOutputMessage(outputMessage);
GitContext gitContext = context.getGitContext();
FileAccess fileAccess = context.getFileAccess();
Path gitFolderPath = tempDir.resolve(".git");
Expand Down

0 comments on commit bca3a12

Please sign in to comment.