NJN
NJN

Reputation: 79

How do I handle this error for Hamcrest matcher

I am getting the following error using Hamcrest Matcher library.

"The method assertThat(T, Matcher) in the type Assert is not applicable for the arguments (List, AnyOf)"

What I am trying is Sample code

List<String> poster_path_image2;         
assertThat(poster_path_image2, anyOf(startsWith("https:"), startsWith("null")));

I need to check if a url is valid and null value is acceptable as well. I am new to this library and stumped by this error.

Upvotes: 1

Views: 384

Answers (1)

Simulant
Simulant

Reputation: 20112

It looks like poster_path_image2 is of type List. but the Matcher startsWith can just work on String. Check the types of your variables and what the matcher is able to process.

Maybe you want to get the first element of your List or repeat the assertion for every item in the list.

String path = "your test String";       
assertThat(path, anyOf(startsWith("https:"), is(nullValue())));

I changed the second matcher as I think you want the check if your String is null and not if it contains the String value "null".

Upvotes: 0

Related Questions