In my UT code, extract below, I see warning :
Unchecked generic array creation for varargs parameter of
type Matcher <? extends String> []
I have read in another stackoverflow answer about the problems using a generic parameter to a varargs method.
But is there a neat way to slightly restructure this test to get rid of the ugly warning and avoid @SuppressWarnings
?
package stackoverflow;
import org.hamcrest.CoreMatchers;
import org.junit.Assert;
import org.junit.Test;
import static org.junit.matchers.JUnitMatchers.containsString;
import static org.hamcrest.CoreMatchers.not;
public class FooTest {
@SuppressWarnings({"unchecked"})
@Test
public void sampleTest() {
Assert.assertThat("foo bar",
CoreMatchers.allOf(
containsString("foo"),
containsString("bar"),
not(containsString("baz"))));
}
}