我到处搜索,但是找不到答案。
请提供任何帮助。
这是我的课程
@Component
public class Lookup {
protected String getDesc(String item, Map<String,String> map) {
String desc = null;
for(Map.Entry<String,String> entry: map.entrySet()){
if(entry.getKey().equalsIgnoreCase(item) {
desc = entry.getValue();
}
}
return desc;
}
}
这是我的考试班 如果我删除EntrySet上的支票,则可以使用,但不能覆盖if语句
@RunWith(MockitoJUnitRunner.class)
public class LookupTest {
@InjectMocks Lookup lookup;
@Test
public void testLookup_Item() {
String item = "item_1";
Map<String,String> map = new HashMap<String,String>();
map.put("item_1", "Description");
when(map.entrySet().contains(item)).thenReturn(true); //this doesn't work
String desc = lookup.getDesc(item, map);
assertEquals("Description", desc);
}
}