Skip to content

Commit

Permalink
Include more kinds of lists in test parameter converter support
Browse files Browse the repository at this point in the history
Fixes: quarkusio#28677
(cherry picked from commit f4fd3cf)
  • Loading branch information
geoand authored and gsmet committed Oct 28, 2022
1 parent 475da0d commit 1913971
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 7 deletions.
11 changes: 11 additions & 0 deletions integration-tests/test-extension/tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.checkerframework</groupId>
<artifactId>checker-qual</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- Minimal test dependencies to *-deployment artifacts for consistent build order -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.ValueSource;

import com.google.common.collect.Lists;

import io.quarkus.test.junit.QuarkusTest;

/**
Expand Down Expand Up @@ -138,6 +140,27 @@ static Stream<Map.Entry<String, String>> testStreamOfMapEntryArguments() {
return Map.of("a", "b").entrySet().stream();
}

@ParameterizedTest
@MethodSource("testSublistArgumentsList")
public void sublistArgumentsList(List<Integer> ignore) {
}

static Stream<Arguments> testSublistArgumentsList() {
return Stream.of(
Arguments.of(List.of(1, 2).subList(0, 1)));
}

@ParameterizedTest
@MethodSource("testReverseArgumentsList")
public void reverseArgumentsList(List<Integer> ignore) {
}

static Stream<Arguments> testReverseArgumentsList() {
return Stream.of(
Arguments.of(
Lists.reverse(List.of(1, 2, 3))));
}

@SuppressWarnings("unused")
static class TestData {
final List<String> foo = Arrays.asList("one", "two", "three");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.function.Predicate;

import com.thoughtworks.xstream.converters.collections.CollectionConverter;
import com.thoughtworks.xstream.mapper.Mapper;
Expand All @@ -21,20 +22,38 @@ public class CustomListConverter extends CollectionConverter {

// if we wanted to be 100% sure, we'd list all the List.of methods, but I think it's pretty safe to say
// that the JDK won't add custom implementations for the other classes
private final Set<String> SUPPORTED_CLASS_NAMES = Set.of(
List.of().getClass().getName(),
List.of(Integer.MAX_VALUE).getClass().getName(),
Arrays.asList(Integer.MAX_VALUE).getClass().getName(),
Collections.unmodifiableList(List.of()).getClass().getName(),
Collections.emptyList().getClass().getName());

private final Predicate<String> supported = new Predicate<String>() {

private final Set<String> JDK_LIST_CLASS_NAMES = Set.of(
List.of().getClass().getName(),
List.of(Integer.MAX_VALUE).getClass().getName(),
Arrays.asList(Integer.MAX_VALUE).getClass().getName(),
Collections.unmodifiableList(List.of()).getClass().getName(),
Collections.emptyList().getClass().getName(),
List.of(Integer.MIN_VALUE, Integer.MAX_VALUE).subList(0, 1).getClass().getName());

@Override
public boolean test(String className) {
return JDK_LIST_CLASS_NAMES.contains(className);
}
}.or(new Predicate<>() {

private static final String GUAVA_LISTS_PACKAGE = "com.google.common.collect.Lists";

@Override
public boolean test(String className) {
return className.startsWith(GUAVA_LISTS_PACKAGE);
}
});

public CustomListConverter(Mapper mapper) {
super(mapper);
}

@Override
public boolean canConvert(Class type) {
return (type != null) && SUPPORTED_CLASS_NAMES.contains(type.getName());
return (type != null) && supported.test(type.getName());
}

@Override
Expand Down

0 comments on commit 1913971

Please sign in to comment.