@Before public void setUp() throws Exception { // 使用反射将IOC容器注入的service的属性替换指定为mock的对象 ReflectionTestUtils.setField(carService, "basicService", basicService); PowerMockito.when(this.basicService, "getCarType", anyLong()).thenReturn(Optional.empty()); }