我有以下类:
public class DaoService {
private Dao dao;
private Map<String, Entity> map;
public DaoService(Dao dao, Map<String, Entity> map){
this.dao = dao;
this.map = map;
}
public create(Entity entity){
Dao.create(entity);
map.put(Entity.getName(), entity);
}
}
我想测试方法调用 realy 是否在映射中放置了一个新元素,当我使用另一个参数调用它时,它将具有等于 2 的大小。但我需要忽略 Dao.create()。
我有以下测试类:
@RunWith(MockitoJUnitRunner.class)
public class DaoServiceTest {
@Mock
Dao dao;
@Mock
Map<String, Entity> map = new HashMap<>();
@InjectMocks
DaoService service;
@Test
public void testCreate(){
Entity entity = new Entity("Alex"); // name
service.create(entity);
assertEquals(map.size(),1); // failNotEquals
}
当我调用它将忽略但不会忽略时,我该怎么办?service.create(entity)dao.create(entity)map.put(entity.getName(), entity)
守着星空守着你
相关分类