Pregunta

I have a customer matcher that I've created as follows:

private static class FromResidualAllocationMatcher extends BaseMatcher<FromResidualAllocation> {....}

In my test class I create a list of these matchers:

List<FromResidualAllocationMatcher> matchers = Lists.newArrayList();
// create list elements

I them try to create a matcher as follows:

Matchers.allOf(matchers)

I am hoping to call the following overloaded method avalialbe on org.hamcrest.Matchers:

public static <T> org.hamcrest.Matcher<T> allOf(org.hamcrest.Matcher<? super T>... param1) {
return org.hamcrest.core.AllOf.<T>allOf(param1);
}

The compiler gives me the following error:

The method allOf(Matcher<? super T>...) in the type Matchers is not applicable for the arguments (List<ResidualAllocationServiceImplTest.FromResidualAllocationMatcher>)

How do I need to define my BaseMatcher implementation to get this to work?

¿Fue útil?

Solución

Your Matcher is fine. The allOf wants an array of Matchers, while you supply a List. Convert the List to an array with List.toArray(T[]).

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top