From bca3a12df0d1ef36cf9fc283f90a22b280177420 Mon Sep 17 00:00:00 2001 From: alfeilex <101652401+alfeilex@users.noreply.github.com> Date: Tue, 14 Jan 2025 20:48:19 +0100 Subject: [PATCH] removed processResult from Mock --- .../ide/context/ProcessContextGitMock.java | 27 +++++-------------- .../devonfw/tools/ide/git/GitContextTest.java | 8 +++--- 2 files changed, 10 insertions(+), 25 deletions(-) diff --git a/cli/src/test/java/com/devonfw/tools/ide/context/ProcessContextGitMock.java b/cli/src/test/java/com/devonfw/tools/ide/context/ProcessContextGitMock.java index b0d533a67..9e3411f45 100644 --- a/cli/src/test/java/com/devonfw/tools/ide/context/ProcessContextGitMock.java +++ b/cli/src/test/java/com/devonfw/tools/ide/context/ProcessContextGitMock.java @@ -26,7 +26,7 @@ public class ProcessContextGitMock implements ProcessContext { private final Path directory; - private ProcessResult processResult; + private List outputMessages; /** * @param directory the {@link Path} to the git repository. @@ -34,27 +34,13 @@ public class ProcessContextGitMock implements ProcessContext { 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(); } - /** - * @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 output) { - - this.processResult = new ProcessResultImpl("git", "", exitCode, output); + public void addOutputMessage(OutputMessage message) { + this.outputMessages.add(message); } @Override @@ -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")) { @@ -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); } } diff --git a/cli/src/test/java/com/devonfw/tools/ide/git/GitContextTest.java b/cli/src/test/java/com/devonfw/tools/ide/git/GitContextTest.java index 4b2d31e52..e3fadb19f 100644 --- a/cli/src/test/java/com/devonfw/tools/ide/git/GitContextTest.java +++ b/cli/src/test/java/com/devonfw/tools/ide/git/GitContextTest.java @@ -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 @@ -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); @@ -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 @@ -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");