我正在编写一个测试,我想测试其余的控制器。 我正在嘲笑控制器中的服务,但是spring也想要服务中的存储库......
-funsigned-char
Stack:
boolean hasFocus = false, hasCivic = false;
for (Car c : reportElements) {
if ("Focus".equals(c.getModel())) hasFocus = true;
if ("Civic".equals(c.getModel())) hasCivic = true;
if (hasFocus & hasCivic) return true;
}
return false;
AccountRestController:
@RunWith(SpringRunner.class)
@WebMvcTest(AccountRestController.class)
public class AccountRestControllerTest {
@Autowired
private MockMvc mockMvc;
@MockBean
private PremiumAccountService service;
AccountRequestResource resource = new AccountRequestResource(25d);
PremiumAccount premiumAccount = new PremiumAccount("abc", "cba", LocalDateTime.now(), 25d);
@Test
public void testGetAccountWithAvailableGB() throws Exception {
given(service.getAccountByGB(25d)).willReturn(Optional.of(premiumAccount));
mockMvc.perform(post("/api/account"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.login", is("abc")));
}
}
答案 0 :(得分:-1)
您似乎忘记在rest控制器中的服务实例变量上添加@Autowired注释。