From 42ea369595b76e3f14c208430d87473664dddff5 Mon Sep 17 00:00:00 2001 From: jan-vcapgemini Date: Tue, 23 Jan 2024 13:25:40 +0100 Subject: [PATCH] #56: implemented requested changes fixed typo added TODO --- .../CompletionCandidateCollectorAdapter.java | 9 +++++--- .../tools/ide/completion/CompleteTest.java | 23 +++++++++++-------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/cli/src/main/java/com/devonfw/tools/ide/completion/CompletionCandidateCollectorAdapter.java b/cli/src/main/java/com/devonfw/tools/ide/completion/CompletionCandidateCollectorAdapter.java index 71ff315bc..2b3c1fd7e 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/completion/CompletionCandidateCollectorAdapter.java +++ b/cli/src/main/java/com/devonfw/tools/ide/completion/CompletionCandidateCollectorAdapter.java @@ -1,12 +1,13 @@ package com.devonfw.tools.ide.completion; +import java.util.List; + import com.devonfw.tools.ide.commandlet.Commandlet; import com.devonfw.tools.ide.property.Property; -import java.util.List; - /** - * Implementation of {@link CompletionCandidateCollector} that wraps and existing {@link CompletionCandidateCollector} adding a prefix. + * Implementation of {@link CompletionCandidateCollector} that wraps an existing {@link CompletionCandidateCollector} + * adding a prefix. */ public class CompletionCandidateCollectorAdapter implements CompletionCandidateCollector { @@ -21,6 +22,7 @@ public class CompletionCandidateCollectorAdapter implements CompletionCandidateC * @param delegate the {@link CompletionCandidateCollector} to wrap. */ public CompletionCandidateCollectorAdapter(String prefix, CompletionCandidateCollector delegate) { + super(); this.prefix = prefix; this.delegate = delegate; @@ -28,6 +30,7 @@ public CompletionCandidateCollectorAdapter(String prefix, CompletionCandidateCol @Override public void add(String text, Property property, Commandlet commandlet) { + this.delegate.add(this.prefix + text, property, commandlet); } diff --git a/cli/src/test/java/com/devonfw/tools/ide/completion/CompleteTest.java b/cli/src/test/java/com/devonfw/tools/ide/completion/CompleteTest.java index 92eae1582..fff112616 100644 --- a/cli/src/test/java/com/devonfw/tools/ide/completion/CompleteTest.java +++ b/cli/src/test/java/com/devonfw/tools/ide/completion/CompleteTest.java @@ -1,17 +1,18 @@ package com.devonfw.tools.ide.completion; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; + import com.devonfw.tools.ide.cli.CliArguments; import com.devonfw.tools.ide.commandlet.Commandlet; import com.devonfw.tools.ide.commandlet.ContextCommandlet; import com.devonfw.tools.ide.context.AbstractIdeContext; import com.devonfw.tools.ide.context.IdeTestContextMock; import com.devonfw.tools.ide.property.Property; -import org.assertj.core.api.Assertions; -import org.junit.jupiter.api.Test; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; /** * Test of {@link AbstractIdeContext#complete(CliArguments, boolean) auto-completion}. @@ -75,7 +76,8 @@ public void testCompleteShortOptsCombined() { // act List candidates = context.complete(args, true); // assert - assertThat(candidates.stream().map(CompletionCandidate::text)).containsExactly("-f", "-fb", "-fd", "-fo", "-fq", "-ft", "-fv"); + assertThat(candidates.stream().map(CompletionCandidate::text)).containsExactly("-f", "-fb", "-fd", "-fo", "-fq", + "-ft", "-fv"); } /** Test of {@link AbstractIdeContext#complete(CliArguments, boolean) auto-completion} for input "-fbdoqt". */ @@ -99,11 +101,13 @@ public void testCompleteHelpEmptyArgs() { AbstractIdeContext context = IdeTestContextMock.get(); CliArguments args = CliArguments.ofCompletion("help", ""); List expectedCandidates = getExpectedCandidates(context, true, false); + // TODO: fix the hacky workaround, see: https://github.com/devonfw/IDEasy/issues/188 expectedCandidates.remove("-v"); // hackish solution, improve me please // act List candidates = context.complete(args, true); // assert - assertThat(candidates.stream().map(CompletionCandidate::text)).containsExactly(expectedCandidates.toArray(String[]::new)); + assertThat(candidates.stream().map(CompletionCandidate::text)) + .containsExactly(expectedCandidates.toArray(String[]::new)); } /** Test of {@link AbstractIdeContext#complete(CliArguments, boolean) auto-completion} for input "help", "". */ @@ -119,7 +123,8 @@ public void testCompleteVersionNoMoreArgs() { assertThat(candidates).isEmpty(); } - private static List getExpectedCandidates(AbstractIdeContext context, boolean commandlets, boolean ctxOptions) { + private static List getExpectedCandidates(AbstractIdeContext context, boolean commandlets, + boolean ctxOptions) { List expectedCandidates = new ArrayList<>(); if (ctxOptions) {