powermockito 常用操作

时间:2022-01-18 20:05:13

1:Mock带参数的静态方法

PowerMockito类

package org.powermock.api.mockito;

CityCodeBean cityCodeBean = CityCodeUtil.getCityCodeBeanByIata(split[4]);
/**********************************/
try {
//PowerMockito.doReturn(cityCodeBean).when(CityCodeUtil.class, "getCityCodeBeanByIata");
PowerMockito.when(CityCodeUtil.class, "getCityCodeBeanByIata", Mockito.anyString()).thenReturn(cityCodeBean);
} catch (Exception e) {
e.printStackTrace();
}