Custom subjects: Add wildcards for generic types
Prior to I9a3b7a877, we had those wildcards in OptionalSubject. As the new approach applied in that change tied us even more to the generic type bounds of Subject and of factories for standard Subject types, we had to remove those wildcards. With the generic types of Subject gone (I75f3d1510), we can now add the wildcards again and even do so for the similarly structured ListSubject. The used wildcards follow the PECS principle. Change-Id: I4500e702520d24a8cfde54d26c8760772d3ec22e
This commit is contained in:
committed by
David Pursehouse
parent
5f040fb432
commit
d2b61e2e09
@@ -30,10 +30,10 @@ import java.util.function.BiFunction;
|
||||
public class ListSubject<S extends Subject, E> extends IterableSubject {
|
||||
|
||||
private final List<E> list;
|
||||
private final BiFunction<StandardSubjectBuilder, E, S> elementSubjectCreator;
|
||||
private final BiFunction<StandardSubjectBuilder, ? super E, ? extends S> elementSubjectCreator;
|
||||
|
||||
public static <S extends Subject, E> ListSubject<S, E> assertThat(
|
||||
List<E> list, Subject.Factory<S, E> subjectFactory) {
|
||||
List<E> list, Subject.Factory<? extends S, ? super E> subjectFactory) {
|
||||
return assertAbout(elements()).thatCustom(list, subjectFactory);
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ public class ListSubject<S extends Subject, E> extends IterableSubject {
|
||||
private ListSubject(
|
||||
FailureMetadata failureMetadata,
|
||||
List<E> list,
|
||||
BiFunction<StandardSubjectBuilder, E, S> elementSubjectCreator) {
|
||||
BiFunction<StandardSubjectBuilder, ? super E, ? extends S> elementSubjectCreator) {
|
||||
super(failureMetadata, list);
|
||||
this.list = list;
|
||||
this.elementSubjectCreator = elementSubjectCreator;
|
||||
@@ -78,12 +78,13 @@ public class ListSubject<S extends Subject, E> extends IterableSubject {
|
||||
}
|
||||
|
||||
public <S extends Subject, E> ListSubject<S, E> thatCustom(
|
||||
List<E> list, Subject.Factory<S, E> subjectFactory) {
|
||||
List<E> list, Subject.Factory<? extends S, ? super E> subjectFactory) {
|
||||
return that(list, (builder, element) -> builder.about(subjectFactory).that(element));
|
||||
}
|
||||
|
||||
public <S extends Subject, E> ListSubject<S, E> that(
|
||||
List<E> list, BiFunction<StandardSubjectBuilder, E, S> elementSubjectCreator) {
|
||||
List<E> list,
|
||||
BiFunction<StandardSubjectBuilder, ? super E, ? extends S> elementSubjectCreator) {
|
||||
return new ListSubject<>(metadata(), list, elementSubjectCreator);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ public class OptionalSubject<S extends Subject, T> extends Subject {
|
||||
}
|
||||
|
||||
public static <S extends Subject, T> OptionalSubject<S, T> assertThat(
|
||||
Optional<T> optional, Subject.Factory<S, T> valueSubjectFactory) {
|
||||
Optional<T> optional, Subject.Factory<? extends S, ? super T> valueSubjectFactory) {
|
||||
return assertAbout(optionals()).thatCustom(optional, valueSubjectFactory);
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ public class OptionalSubject<S extends Subject, T> extends Subject {
|
||||
}
|
||||
|
||||
public <S extends Subject, T> OptionalSubject<S, T> thatCustom(
|
||||
Optional<T> optional, Subject.Factory<S, T> valueSubjectFactory) {
|
||||
Optional<T> optional, Subject.Factory<? extends S, ? super T> valueSubjectFactory) {
|
||||
return that(optional, (builder, value) -> builder.about(valueSubjectFactory).that(value));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user