Skip to content

Commit

Permalink
Fix collection generation not throw exception (#999)
Browse files Browse the repository at this point in the history
  • Loading branch information
seongahjo committed Jul 8, 2024
1 parent 2eaa787 commit 87b15b3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,17 @@ public ArbitraryIntrospectorResult introspect(ArbitraryGeneratorContext context)
List<CombinableArbitrary<?>> elementCombinableArbitraryList = context.getElementCombinableArbitraryList();

Class<?> type = Types.getActualType(context.getResolvedType());
Constructor<?> declaredConstructor = TypeCache.getDeclaredConstructor(type, Collection.class);
Constructor<?> declaredConstructor;
try {
declaredConstructor = TypeCache.getDeclaredConstructor(type, Collection.class);
} catch (Exception ex) {
LOGGER.warn(
"The collection interface is not resolved by the ConcretePropertyCandidateResolver. Generated as null.",
ex
);
return ArbitraryIntrospectorResult.NOT_INTROSPECTED;
}

return new ArbitraryIntrospectorResult(
CombinableArbitrary.containerBuilder()
.elements(elementCombinableArbitraryList)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.lang.reflect.Modifier;
import java.time.Instant;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -1232,4 +1233,12 @@ void constant() {
() -> SUT.giveMeOne(ConstantObject.class)
);
}

@Test
void collectionNotThrows() {
thenNoException().isThrownBy(
() -> SUT.giveMeOne(new TypeReference<Collection<String>>() {
})
);
}
}

0 comments on commit 87b15b3

Please sign in to comment.