Skip to content

Commit

Permalink
Rename ObjectArrayArguments.create() to arguments()
Browse files Browse the repository at this point in the history
Issue: #765
  • Loading branch information
sbrannen committed Apr 3, 2017
1 parent 762f8c2 commit 30438b4
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 20 deletions.
3 changes: 2 additions & 1 deletion documentation/src/docs/asciidoc/release-notes-5.0.0-M5.adoc
Expand Up @@ -35,7 +35,8 @@ on GitHub.

===== Deprecations and Breaking Changes

* ❓
* The `create()` factory method in `ObjectArrayArguments` in the `junit-jupiter-params`
module has been renamed to `arguments()`.

===== New Features and Improvements

Expand Down
2 changes: 2 additions & 0 deletions documentation/src/docs/asciidoc/writing-tests.adoc
Expand Up @@ -605,6 +605,8 @@ include::{testDir}/example/ParameterizedTestDemo.java[tags=simple_MethodSource_e
----

In case you need multiple parameters, you need to return `Argument` instances as shown below.
Note that `arguments(Object...)` is a static factory method defined in
`org.junit.jupiter.params.provider.ObjectArrayArguments`.

[source,java,indent=0]
[subs="verbatim"]
Expand Down
Expand Up @@ -13,6 +13,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.params.provider.ObjectArrayArguments.arguments;

import java.time.LocalDate;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -82,7 +83,7 @@ void testWithMultiArgMethodSource(String first, int second) {
}

static Stream<Arguments> stringAndIntProvider() {
return Stream.of(ObjectArrayArguments.create("foo", 1), ObjectArrayArguments.create("bar", 2));
return Stream.of(arguments("foo", 1), arguments("bar", 2));
}
// end::multi_arg_MethodSource_example[]

Expand Down Expand Up @@ -112,9 +113,10 @@ void testWithArgumentsSource(String argument) {
}

static class MyArgumentsProvider implements ArgumentsProvider {

@Override
public Stream<? extends Arguments> arguments(ContainerExtensionContext context) {
return Stream.of("foo", "bar").map(ObjectArrayArguments::create);
return Stream.of("foo", "bar").map(ObjectArrayArguments::arguments);
}
}
// end::ArgumentsSource_example[]
Expand Down Expand Up @@ -143,6 +145,7 @@ void testWithExplicitArgumentConversion(@ConvertWith(ToStringArgumentConverter.c
}

static class ToStringArgumentConverter extends SimpleArgumentConverter {

@Override
protected Object convert(Object source, Class<?> targetType) {
assertEquals(String.class, targetType, "Can only convert to String");
Expand Down
2 changes: 2 additions & 0 deletions documentation/src/test/java/example/TestInfoDemo.java
Expand Up @@ -22,6 +22,8 @@

class TestInfoDemo {

// TODO Add example with constructor injection.

@BeforeEach
void init(TestInfo testInfo) {
String displayName = testInfo.getDisplayName();
Expand Down
Expand Up @@ -41,7 +41,7 @@ public Stream<? extends Arguments> arguments(ContainerExtensionContext context)
settings.getFormat().setQuoteEscape('\'');
settings.setAutoConfigurationEnabled(false);
CsvParser csvParser = new CsvParser(settings);
return Arrays.stream(lines).map(csvParser::parseLine).map(ObjectArrayArguments::create);
return Arrays.stream(lines).map(csvParser::parseLine).map(ObjectArrayArguments::arguments);
}

}
Expand Up @@ -104,7 +104,7 @@ public boolean hasNext() {

@Override
public Arguments next() {
Arguments result = ObjectArrayArguments.create(nextArguments);
Arguments result = ObjectArrayArguments.arguments(nextArguments);
advance();
return result;
}
Expand Down
Expand Up @@ -48,7 +48,7 @@ public void accept(EnumSource enumSource) {

@Override
public Stream<? extends Arguments> arguments(ContainerExtensionContext context) {
return stream(enumClass.getEnumConstants()).filter(this::select).map(ObjectArrayArguments::create);
return stream(enumClass.getEnumConstants()).filter(this::select).map(ObjectArrayArguments::arguments);
}

private boolean select(Enum<?> constant) {
Expand Down
Expand Up @@ -50,9 +50,9 @@ private static Arguments toArguments(Object item) {
return (Arguments) item;
}
if (item instanceof Object[]) {
return ObjectArrayArguments.create((Object[]) item);
return ObjectArrayArguments.arguments((Object[]) item);
}
return ObjectArrayArguments.create(item);
return ObjectArrayArguments.arguments(item);
}

}
Expand Up @@ -15,10 +15,8 @@
import org.junit.platform.commons.meta.API;

/**
* Concrete implementation of the {@code Arguments} abstraction.
*
* <p>It provides access to an array of objects to be used for invoking a
* {@code @ParameterizedTest} method.
* Concrete implementation of the {@code Arguments} API that provides access to
* an array of objects to be used for invoking a {@code @ParameterizedTest} method.
*
* <p>A {@link java.util.stream.Stream} of such {@code Arguments} will
* typically be accessed via {@linkplain ArgumentsProvider providers}.
Expand All @@ -33,7 +31,11 @@ public class ObjectArrayArguments implements Arguments {

private final Object[] arguments;

public static ObjectArrayArguments create(Object... arguments) {
/**
* Factory method for creating an {@code ObjectArrayArguments} based on the
* supplied arguments
*/
public static ObjectArrayArguments arguments(Object... arguments) {
return new ObjectArrayArguments(arguments);
}

Expand All @@ -43,7 +45,7 @@ private ObjectArrayArguments(Object... arguments) {

@Override
public Object[] get() {
return arguments;
return this.arguments;
}

}
Expand Up @@ -44,6 +44,6 @@ public void accept(ValueSource source) {

@Override
public Stream<? extends Arguments> arguments(ContainerExtensionContext context) {
return Arrays.stream(arguments).map(ObjectArrayArguments::create);
return Arrays.stream(arguments).map(ObjectArrayArguments::arguments);
}
}
Expand Up @@ -169,7 +169,7 @@ static class ArgumentsProviderWithCloseHandler implements ArgumentsProvider {

@Override
public Stream<? extends Arguments> arguments(ContainerExtensionContext context) {
Stream<ObjectArrayArguments> argumentsStream = Stream.of("foo", "bar").map(ObjectArrayArguments::create);
Stream<ObjectArrayArguments> argumentsStream = Stream.of("foo", "bar").map(ObjectArrayArguments::arguments);

return argumentsStream.onClose(() -> streamWasClosed = true);
}
Expand Down
Expand Up @@ -116,7 +116,7 @@ private static class TwoSingleStringArgumentsProvider implements ArgumentsProvid

@Override
public Stream<? extends Arguments> arguments(ContainerExtensionContext context) throws Exception {
return Stream.of(ObjectArrayArguments.create("foo"), ObjectArrayArguments.create("bar"));
return Stream.of(ObjectArrayArguments.arguments("foo"), ObjectArrayArguments.arguments("bar"));
}
}

Expand Down
Expand Up @@ -119,7 +119,7 @@ static Object providerWithIllegalReturnType() {
}

static Stream<ObjectArrayArguments> argumentsStreamProvider() {
return Stream.of("foo", "bar").map(ObjectArrayArguments::create);
return Stream.of("foo", "bar").map(ObjectArrayArguments::arguments);
}

static Iterable<Object[]> objectArrayProvider() {
Expand Down
Expand Up @@ -12,6 +12,7 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.params.provider.ObjectArrayArguments.arguments;

import org.junit.jupiter.api.Test;

Expand All @@ -22,7 +23,7 @@ class ObjectArrayArgumentsTests {

@Test
void supportsVarargs() {
ObjectArrayArguments arguments = ObjectArrayArguments.create(1, "2", 3.0);
ObjectArrayArguments arguments = arguments(1, "2", 3.0);

assertArrayEquals(new Object[] { 1, "2", 3.0 }, arguments.get());
}
Expand All @@ -31,7 +32,7 @@ void supportsVarargs() {
void returnsSameArrayUsedForCreating() {
Object[] input = { 1, "2", 3.0 };

ObjectArrayArguments arguments = ObjectArrayArguments.create(input);
ObjectArrayArguments arguments = arguments(input);

assertThat(arguments.get()).isSameAs(input);
}
Expand Down

0 comments on commit 30438b4

Please sign in to comment.