I am getting the following error using Hamcrest Matcher library.
我使用Hamcrest Matcher库得到以下错误。
"The method assertThat(T, Matcher) in the type Assert is not applicable for the arguments (List, AnyOf)"
“类型Assert中的方法assertThat(T,Matcher)不适用于参数(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.
我需要检查一个url是否有效,并且null值也可以接受。我是这个库的新手并且被这个错误困扰了。
1 个解决方案
#1
0
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.
看起来poster_path_image2的类型为List。但Matcher startWith可以在String上工作。检查变量的类型以及匹配器能够处理的内容。
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"
.
我更改了第二个匹配器,因为我认为你想要检查你的String是否为null,而不是它包含字符串值“null”。
#1
0
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.
看起来poster_path_image2的类型为List。但Matcher startWith可以在String上工作。检查变量的类型以及匹配器能够处理的内容。
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"
.
我更改了第二个匹配器,因为我认为你想要检查你的String是否为null,而不是它包含字符串值“null”。