Changed return value of ParameterResolver::resolve to use a ValueResult that contains metadata about the value that was resolved
Added new ValueResultAsserts to facilitate testing of ParameterResolvers
This commit is contained in:
27
spring-shell2-core-tests/pom.xml
Normal file
27
spring-shell2-core-tests/pom.xml
Normal file
@@ -0,0 +1,27 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>spring-shell2-core-tests</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.shell</groupId>
|
||||
<artifactId>spring-shell2-parent</artifactId>
|
||||
<version>2.0.0.BUILD-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<description>Core API test classes for Spring Shell 2</description>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.shell</groupId>
|
||||
<artifactId>spring-shell2-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright 2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.shell2;
|
||||
|
||||
import org.assertj.core.api.AbstractAssert;
|
||||
import org.assertj.core.api.Assertions;
|
||||
|
||||
/**
|
||||
* Assertions for {@link ValueResult}.
|
||||
*
|
||||
* @author Camilo Gonzalez
|
||||
*/
|
||||
public class ValueResultAsserts extends AbstractAssert<ValueResultAsserts, ValueResult> {
|
||||
|
||||
public ValueResultAsserts(ValueResult actual) {
|
||||
super(actual, ValueResultAsserts.class);
|
||||
}
|
||||
|
||||
public ValueResultAsserts hasValue(Object expectedValue) {
|
||||
isNotNull();
|
||||
Assertions.assertThat(actual.resolvedValue()).isEqualTo(expectedValue);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ValueResultAsserts usesWords(int... expectedWordsUsed) {
|
||||
isNotNull();
|
||||
|
||||
Assertions.assertThat(actual.wordsUsed().stream().toArray()).containsExactly(expectedWordsUsed);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public ValueResultAsserts notUsesWords() {
|
||||
isNotNull();
|
||||
Assertions.assertThat(actual.wordsUsed().isEmpty());
|
||||
return this;
|
||||
}
|
||||
|
||||
public ValueResultAsserts usesWordsForValue(int... expectedWordsUsedForValue) {
|
||||
isNotNull();
|
||||
|
||||
Assertions.assertThat(actual.wordsUsedForValue().stream().toArray()).containsExactly(expectedWordsUsedForValue);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public ValueResultAsserts notUsesWordsForValue() {
|
||||
isNotNull();
|
||||
Assertions.assertThat(actual.wordsUsedForValue().isEmpty());
|
||||
return this;
|
||||
}
|
||||
|
||||
public static ValueResultAsserts assertThat(ValueResult valueResult) {
|
||||
return new ValueResultAsserts(valueResult);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user