Update boot 2.6.1
- Migrate tests to junit5 and assertj as those are on a classpath automatically. - Temporarily use spring.main.allow-circular-references=true to allow time for fixes to remove cycles.
This commit is contained in:
@@ -17,28 +17,28 @@
|
||||
package org.springframework.shell.standard;
|
||||
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.shell.CommandRegistry;
|
||||
import org.springframework.shell.CompletionContext;
|
||||
import org.springframework.shell.CompletionProposal;
|
||||
import org.springframework.shell.MethodTarget;
|
||||
import org.springframework.shell.CommandRegistry;
|
||||
import org.springframework.shell.Utils;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link CommandValueProvider}.
|
||||
*
|
||||
@@ -49,7 +49,7 @@ public class CommandValueProviderTest {
|
||||
@Mock
|
||||
private CommandRegistry shell;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
}
|
||||
|
||||
@@ -16,26 +16,23 @@
|
||||
|
||||
package org.springframework.shell.standard;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.shell.Availability;
|
||||
import org.springframework.shell.ConfigurableCommandRegistry;
|
||||
import org.springframework.shell.MethodTarget;
|
||||
import org.springframework.shell.standard.test1.GroupOneCommands;
|
||||
import org.springframework.shell.standard.test2.GroupTwoCommands;
|
||||
import org.springframework.shell.standard.test2.GroupThreeCommands;
|
||||
import org.springframework.shell.standard.test2.GroupTwoCommands;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import static org.hamcrest.Matchers.hasEntry;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.util.Map;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link StandardMethodTargetRegistrar}.
|
||||
@@ -47,9 +44,6 @@ public class StandardMethodTargetRegistrarTest {
|
||||
private StandardMethodTargetRegistrar registrar = new StandardMethodTargetRegistrar();
|
||||
private ConfigurableCommandRegistry registry = new ConfigurableCommandRegistry();
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void testRegistrations() {
|
||||
ApplicationContext applicationContext = new AnnotationConfigApplicationContext(Sample.class);
|
||||
@@ -57,21 +51,21 @@ public class StandardMethodTargetRegistrarTest {
|
||||
registrar.register(registry);
|
||||
|
||||
MethodTarget methodTarget = registry.listCommands().get("say-hello");
|
||||
assertThat(methodTarget, notNullValue());
|
||||
assertThat(methodTarget.getHelp(), is("some command"));
|
||||
assertThat(methodTarget.getMethod(), is(ReflectionUtils.findMethod(Sample.class, "sayHello", String.class)));
|
||||
assertThat(methodTarget.getAvailability().isAvailable(), is(true));
|
||||
assertThat(methodTarget).isNotNull();
|
||||
assertThat(methodTarget.getHelp()).isEqualTo("some command");
|
||||
assertThat(methodTarget.getMethod()).isEqualTo(ReflectionUtils.findMethod(Sample.class, "sayHello", String.class));
|
||||
assertThat(methodTarget.getAvailability().isAvailable()).isTrue();
|
||||
|
||||
methodTarget = registry.listCommands().get("hi");
|
||||
assertThat(methodTarget, notNullValue());
|
||||
assertThat(methodTarget.getHelp(), is("method with alias"));
|
||||
assertThat(methodTarget.getMethod(), is(ReflectionUtils.findMethod(Sample.class, "greet", String.class)));
|
||||
assertThat(methodTarget.getAvailability().isAvailable(), is(true));
|
||||
assertThat(methodTarget).isNotNull();
|
||||
assertThat(methodTarget.getHelp()).isEqualTo("method with alias");
|
||||
assertThat(methodTarget.getMethod()).isEqualTo(ReflectionUtils.findMethod(Sample.class, "greet", String.class));
|
||||
assertThat(methodTarget.getAvailability().isAvailable()).isTrue();
|
||||
methodTarget = registry.listCommands().get("alias");
|
||||
assertThat(methodTarget, notNullValue());
|
||||
assertThat(methodTarget.getHelp(), is("method with alias"));
|
||||
assertThat(methodTarget.getMethod(), is(ReflectionUtils.findMethod(Sample.class, "greet", String.class)));
|
||||
assertThat(methodTarget.getAvailability().isAvailable(), is(true));
|
||||
assertThat(methodTarget).isNotNull();
|
||||
assertThat(methodTarget.getHelp()).isEqualTo("method with alias");
|
||||
assertThat(methodTarget.getMethod()).isEqualTo(ReflectionUtils.findMethod(Sample.class, "greet", String.class));
|
||||
assertThat(methodTarget.getAvailability().isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@ShellComponent
|
||||
@@ -96,27 +90,27 @@ public class StandardMethodTargetRegistrarTest {
|
||||
SampleWithAvailability sample = applicationContext.getBean(SampleWithAvailability.class);
|
||||
|
||||
MethodTarget methodTarget = registry.listCommands().get("say-hello");
|
||||
assertThat(methodTarget.getMethod(), is(ReflectionUtils.findMethod(SampleWithAvailability.class, "sayHello")));
|
||||
assertThat(methodTarget.getAvailability().isAvailable(), is(true));
|
||||
assertThat(methodTarget.getMethod()).isEqualTo(ReflectionUtils.findMethod(SampleWithAvailability.class, "sayHello"));
|
||||
assertThat(methodTarget.getAvailability().isAvailable()).isTrue();
|
||||
sample.available = false;
|
||||
assertThat(methodTarget.getAvailability().isAvailable(), is(false));
|
||||
assertThat(methodTarget.getAvailability().getReason(), is("sayHelloAvailability"));
|
||||
assertThat(methodTarget.getAvailability().isAvailable()).isFalse();
|
||||
assertThat(methodTarget.getAvailability().getReason()).isEqualTo("sayHelloAvailability");
|
||||
sample.available = true;
|
||||
|
||||
methodTarget = registry.listCommands().get("hi");
|
||||
assertThat(methodTarget.getMethod(), is(ReflectionUtils.findMethod(SampleWithAvailability.class, "hi")));
|
||||
assertThat(methodTarget.getAvailability().isAvailable(), is(true));
|
||||
assertThat(methodTarget.getMethod()).isEqualTo(ReflectionUtils.findMethod(SampleWithAvailability.class, "hi"));
|
||||
assertThat(methodTarget.getAvailability().isAvailable()).isTrue();
|
||||
sample.available = false;
|
||||
assertThat(methodTarget.getAvailability().isAvailable(), is(false));
|
||||
assertThat(methodTarget.getAvailability().getReason(), is("customAvailabilityMethod"));
|
||||
assertThat(methodTarget.getAvailability().isAvailable()).isFalse();
|
||||
assertThat(methodTarget.getAvailability().getReason()).isEqualTo("customAvailabilityMethod");
|
||||
sample.available = true;
|
||||
|
||||
methodTarget = registry.listCommands().get("bonjour");
|
||||
assertThat(methodTarget.getMethod(), is(ReflectionUtils.findMethod(SampleWithAvailability.class, "bonjour")));
|
||||
assertThat(methodTarget.getAvailability().isAvailable(), is(true));
|
||||
assertThat(methodTarget.getMethod()).isEqualTo(ReflectionUtils.findMethod(SampleWithAvailability.class, "bonjour"));
|
||||
assertThat(methodTarget.getAvailability().isAvailable()).isTrue();
|
||||
sample.available = false;
|
||||
assertThat(methodTarget.getAvailability().isAvailable(), is(false));
|
||||
assertThat(methodTarget.getAvailability().getReason(), is("availabilityForSeveralCommands"));
|
||||
assertThat(methodTarget.getAvailability().isAvailable()).isFalse();
|
||||
assertThat(methodTarget.getAvailability().getReason()).isEqualTo("availabilityForSeveralCommands");
|
||||
sample.available = true;
|
||||
}
|
||||
|
||||
@@ -169,12 +163,12 @@ public class StandardMethodTargetRegistrarTest {
|
||||
ApplicationContext applicationContext = new AnnotationConfigApplicationContext(WrongAvailabilityIndicatorOnShellMethod.class);
|
||||
registrar.setApplicationContext(applicationContext);
|
||||
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("When set on a @ShellMethod method, the value of the @ShellMethodAvailability should be a single element");
|
||||
thrown.expectMessage("Found [one, two]");
|
||||
thrown.expectMessage("wrong()");
|
||||
|
||||
registrar.register(registry);
|
||||
assertThatThrownBy(() -> {
|
||||
registrar.register(registry);
|
||||
}).isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessageContaining("When set on a @ShellMethod method, the value of the @ShellMethodAvailability should be a single element")
|
||||
.hasMessageContaining("Found [one, two]")
|
||||
.hasMessageContaining("wrong()");
|
||||
}
|
||||
|
||||
@ShellComponent
|
||||
@@ -192,11 +186,11 @@ public class StandardMethodTargetRegistrarTest {
|
||||
ApplicationContext applicationContext = new AnnotationConfigApplicationContext(WrongAvailabilityIndicatorWildcardNotAlone.class);
|
||||
registrar.setApplicationContext(applicationContext);
|
||||
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("When using '*' as a wildcard for ShellMethodAvailability, this can be the only value. Found [one, *]");
|
||||
thrown.expectMessage("availability()");
|
||||
|
||||
registrar.register(registry);
|
||||
assertThatThrownBy(() -> {
|
||||
registrar.register(registry);
|
||||
}).isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessageContaining("When using '*' as a wildcard for ShellMethodAvailability, this can be the only value. Found [one, *]")
|
||||
.hasMessageContaining("availability()");
|
||||
}
|
||||
|
||||
@ShellComponent
|
||||
@@ -218,13 +212,13 @@ public class StandardMethodTargetRegistrarTest {
|
||||
ApplicationContext applicationContext = new AnnotationConfigApplicationContext(WrongAvailabilityIndicatorAmbiguous.class);
|
||||
registrar.setApplicationContext(applicationContext);
|
||||
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Found several @ShellMethodAvailability");
|
||||
thrown.expectMessage("wrong()");
|
||||
thrown.expectMessage("availability()");
|
||||
thrown.expectMessage("otherAvailability()");
|
||||
|
||||
registrar.register(registry);
|
||||
assertThatThrownBy(() -> {
|
||||
registrar.register(registry);
|
||||
}).isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessageContaining("Found several @ShellMethodAvailability")
|
||||
.hasMessageContaining("wrong()")
|
||||
.hasMessageContaining("availability()")
|
||||
.hasMessageContaining("otherAvailability()");
|
||||
}
|
||||
|
||||
@ShellComponent
|
||||
|
||||
@@ -16,21 +16,14 @@
|
||||
|
||||
package org.springframework.shell.standard;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static java.util.Collections.singletonList;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.shell.ValueResultAsserts.assertThat;
|
||||
import static org.springframework.util.ReflectionUtils.findMethod;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.jline.reader.ParsedLine;
|
||||
import org.jline.reader.impl.DefaultParser;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.core.convert.support.DefaultConversionService;
|
||||
import org.springframework.shell.CompletionContext;
|
||||
import org.springframework.shell.CompletionProposal;
|
||||
@@ -39,6 +32,13 @@ import org.springframework.shell.UnfinishedParameterResolutionException;
|
||||
import org.springframework.shell.Utils;
|
||||
import org.springframework.shell.ValueResult;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static java.util.Collections.singletonList;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.springframework.shell.ValueResultAsserts.assertThat;
|
||||
import static org.springframework.util.ReflectionUtils.findMethod;
|
||||
|
||||
/**
|
||||
* Unit tests for DefaultParameterResolver.
|
||||
* @author Eric Bottard
|
||||
@@ -46,9 +46,6 @@ import org.springframework.shell.ValueResult;
|
||||
*/
|
||||
public class StandardParameterResolverTest {
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private StandardParameterResolver resolver = new StandardParameterResolver(new DefaultConversionService());
|
||||
|
||||
// Tests for resolution
|
||||
@@ -61,16 +58,16 @@ public class StandardParameterResolverTest {
|
||||
ValueResult result0 = resolver.resolve(Utils.createMethodParameter(method, 0), words);
|
||||
assertThat(result0).hasValue(true).usesWords(0).notUsesWordsForValue();
|
||||
assertThat(result0.wordsUsed(words)).containsExactly("--force");
|
||||
|
||||
|
||||
ValueResult result1 = resolver.resolve(Utils.createMethodParameter(method, 1), words);
|
||||
assertThat(result1).hasValue("--foo").usesWords(1, 2).usesWordsForValue(2);
|
||||
assertThat(result1.wordsUsed(words)).containsExactly("--name", "--foo");
|
||||
assertThat(result1.wordsUsedForValue(words)).containsExactly("--foo");
|
||||
|
||||
|
||||
ValueResult result2 = resolver.resolve(Utils.createMethodParameter(method, 2), words);
|
||||
assertThat(result2).hasValue("y").usesWords(3).usesWordsForValue(3);
|
||||
assertThat(result2.wordsUsed(words)).containsExactly("y");
|
||||
|
||||
|
||||
ValueResult result3 = resolver.resolve(Utils.createMethodParameter(method, 3), words);
|
||||
assertThat(result3).hasValue("last").notUsesWords().notUsesWordsForValue();
|
||||
}
|
||||
@@ -88,78 +85,72 @@ public class StandardParameterResolverTest {
|
||||
public void testParameterSpecifiedTwiceViaDifferentAliases() throws Exception {
|
||||
Method method = findMethod(Remote.class, "zap", boolean.class, String.class, String.class, String.class);
|
||||
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Named parameter has been specified multiple times via '--bar, --baz'");
|
||||
|
||||
resolver.resolve(
|
||||
Utils.createMethodParameter(method, 0),
|
||||
asList("--force --name --foo y --bar x --baz z".split(" "))
|
||||
);
|
||||
assertThatThrownBy(() -> {
|
||||
resolver.resolve(
|
||||
Utils.createMethodParameter(method, 0),
|
||||
asList("--force --name --foo y --bar x --baz z".split(" ")));
|
||||
}).isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessageContaining("Named parameter has been specified multiple times via '--bar, --baz'");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParameterSpecifiedTwiceViaSameKey() throws Exception {
|
||||
Method method = findMethod(Remote.class, "zap", boolean.class, String.class, String.class, String.class);
|
||||
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Parameter for '--baz' has already been specified");
|
||||
|
||||
resolver.resolve(
|
||||
Utils.createMethodParameter(method, 0),
|
||||
asList("--force --name --foo y --baz x --baz z".split(" "))
|
||||
);
|
||||
assertThatThrownBy(() -> {
|
||||
resolver.resolve(
|
||||
Utils.createMethodParameter(method, 0),
|
||||
asList("--force --name --foo y --baz x --baz z".split(" ")));
|
||||
}).isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessageContaining("Parameter for '--baz' has already been specified");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTooMuchInput() throws Exception {
|
||||
Method method = findMethod(Remote.class, "zap", boolean.class, String.class, String.class, String.class);
|
||||
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("the following could not be mapped to parameters: 'leftover'");
|
||||
|
||||
resolver.resolve(
|
||||
Utils.createMethodParameter(method, 0),
|
||||
asList("--foo hello --name bar --force --bar well leftover".split(" "))
|
||||
);
|
||||
assertThatThrownBy(() -> {
|
||||
resolver.resolve(
|
||||
Utils.createMethodParameter(method, 0),
|
||||
asList("--foo hello --name bar --force --bar well leftover".split(" ")));
|
||||
}).isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessageContaining("the following could not be mapped to parameters: 'leftover'");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncompleteCommandResolution() throws Exception {
|
||||
Method method = findMethod(Remote.class, "shutdown", Remote.Delay.class);
|
||||
|
||||
thrown.expect(UnfinishedParameterResolutionException.class);
|
||||
thrown.expectMessage("Error trying to resolve '--delay delay' using [--delay]");
|
||||
|
||||
resolver.resolve(
|
||||
Utils.createMethodParameter(method, 0),
|
||||
asList("--delay".split(" "))
|
||||
);
|
||||
assertThatThrownBy(() -> {
|
||||
resolver.resolve(
|
||||
Utils.createMethodParameter(method, 0),
|
||||
asList("--delay".split(" ")));
|
||||
}).isInstanceOf(UnfinishedParameterResolutionException.class)
|
||||
.hasMessageContaining("Error trying to resolve '--delay delay' using [--delay]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncompleteCommandResolutionBigArity() throws Exception {
|
||||
Method method = findMethod(Remote.class, "add", List.class);
|
||||
|
||||
thrown.expect(UnfinishedParameterResolutionException.class);
|
||||
thrown.expectMessage("Error trying to resolve '--numbers list list list' using [--numbers 1 2]");
|
||||
|
||||
resolver.resolve(
|
||||
Utils.createMethodParameter(method, 0),
|
||||
asList("--numbers 1 2".split(" "))
|
||||
);
|
||||
assertThatThrownBy(() -> {
|
||||
resolver.resolve(
|
||||
Utils.createMethodParameter(method, 0),
|
||||
asList("--numbers 1 2".split(" ")));
|
||||
}).isInstanceOf(UnfinishedParameterResolutionException.class)
|
||||
.hasMessageContaining("Error trying to resolve '--numbers list list list' using [--numbers 1 2]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnresolvableArg() throws Exception {
|
||||
Method method = findMethod(Remote.class, "zap", boolean.class, String.class, String.class, String.class);
|
||||
|
||||
thrown.expect(ParameterMissingResolutionException.class);
|
||||
thrown.expectMessage("Parameter '--name string' should be specified");
|
||||
|
||||
resolver.resolve(
|
||||
Utils.createMethodParameter(method, 1),
|
||||
asList("--foo hello --force --bar well".split(" "))
|
||||
);
|
||||
assertThatThrownBy(() -> {
|
||||
resolver.resolve(
|
||||
Utils.createMethodParameter(method, 1),
|
||||
asList("--foo hello --force --bar well".split(" ")));
|
||||
}).isInstanceOf(ParameterMissingResolutionException.class)
|
||||
.hasMessageContaining("Parameter '--name string' should be specified");
|
||||
}
|
||||
|
||||
// Tests for completion
|
||||
@@ -216,9 +207,9 @@ public class StandardParameterResolverTest {
|
||||
|
||||
@Test
|
||||
public void testValueCompletionWithNonDefaultArity() {
|
||||
|
||||
|
||||
resolver.setValueProviders(singletonList(new Remote.NumberValueProvider("12", "42", "7")));
|
||||
|
||||
|
||||
Method[] methods = {
|
||||
findMethod(org.springframework.shell.standard.Remote.class, "add", List.class),
|
||||
findMethod(org.springframework.shell.standard.Remote.class, "addAsArray", int[].class),
|
||||
|
||||
Reference in New Issue
Block a user