Use delegation rather than inheritance to decouple JLine

Fixes #78
This commit is contained in:
Eric Bottard
2017-05-31 18:12:00 +02:00
parent 50ba8de8b4
commit bc81d3ed9c
19 changed files with 652 additions and 415 deletions

View File

@@ -19,15 +19,12 @@ package org.springframework.shell2.standard;
import java.util.List;
import java.util.stream.Collectors;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Lazy;
import org.springframework.core.MethodParameter;
import org.springframework.shell2.CompletionContext;
import org.springframework.shell2.CompletionProposal;
import org.springframework.shell2.Shell;
import org.springframework.shell2.CommandRegistry;
import org.springframework.stereotype.Component;
/**
@@ -38,17 +35,17 @@ import org.springframework.stereotype.Component;
@Component
public class CommandValueProvider extends ValueProviderSupport {
private final Shell shell;
private final CommandRegistry commandRegistry;
@Lazy
@Autowired
public CommandValueProvider(Shell shell) {
this.shell = shell;
public CommandValueProvider(CommandRegistry commandRegistry) {
this.commandRegistry = commandRegistry;
}
@Override
public List<CompletionProposal> complete(MethodParameter parameter, CompletionContext completionContext, String[] hints) {
return shell.listCommands().keySet().stream()
return commandRegistry.listCommands().keySet().stream()
.map(CompletionProposal::new)
.collect(Collectors.toList());
}

View File

@@ -23,24 +23,19 @@ import static org.mockito.Mockito.when;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.assertj.core.api.Assertions;
import org.hamcrest.CoreMatchers;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.springframework.core.MethodParameter;
import org.springframework.shell2.CompletionContext;
import org.springframework.shell2.CompletionProposal;
import org.springframework.shell2.MethodTarget;
import org.springframework.shell2.Shell;
import org.springframework.shell2.CommandRegistry;
import org.springframework.shell2.Utils;
import org.springframework.util.ReflectionUtils;
@@ -52,7 +47,7 @@ import org.springframework.util.ReflectionUtils;
public class CommandValueProviderTest {
@Mock
private Shell shell;
private CommandRegistry shell;
@Before
public void setUp() {