我想在 中测试我的休息端点BookRestController。我用 编写一个测试@WebMvcTest。
@RunWith(SpringRunner.class)
@WebMvcTest(BookRestController.class)
public class BookRestControllerTest {
@Autowired
private MockMvc mockMvc;
@MockBean
private CategoryService categoryService;
private ObjectMapper objectMapper = new ObjectMapper();
@Test
public void should_create_new_category_when_try_to_update() throws Exception {
given(categoryService.getCategoryById(20L)).willReturn(null);
Category category = new Category("Fantastyka");
ResultActions resultActions = mockMvc.perform(put("/api/category/10")
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(category)));
resultActions.andExpect(status().isNoContent());
}
}
Run Code Online (Sandbox Code Playgroud)
在存储库包中,我有 4 个存储库,但在我的测试端点中,我只使用其中之一。

这是我的方法BookRestController
@RestController
public class BookRestController {
@Autowired
private CategoryService categoryService;
@RequestMapping(value = "/api/category/{id}", method = RequestMethod.PUT)
public ResponseEntity<Category> updateCategory(@PathVariable Long id, @RequestBody Category category){
return ResponseEntity
.status(HttpStatus.NO_CONTENT) …Run Code Online (Sandbox Code Playgroud) 我正在使用 spring 并用 定义了 bean ArrayList。invites它是一个包含对象的列表Invite。
@Getter
public class Invite {
private String invitee;
private String email;
private boolean confirm;
private String token;
}
Run Code Online (Sandbox Code Playgroud)
这是我的数据提供者类别:
@Getter
public class InvitationsData {
private List<Invite> invites = new ArrayList<>();
@PostConstruct
private void initInvites(){
invites.add(new Invite("John", "john@john.com", false, "6456453"));
invites.add(new Invite("John", "john@john.com", false, "3252352"));
}
}
Run Code Online (Sandbox Code Playgroud)
@Bean在我创建的配置类中InvitationsData- 它有效。
在服务中,我想修改列表中与令牌字符串匹配并已设置为 的一个confirm对象false。
invitationsData.getInvites()
.stream()
.filter(i -> token.equals(i.getToken()))
.filter(i -> !i.isConfirm())
.forEach(i -> {
i.setConfirm(true); …Run Code Online (Sandbox Code Playgroud) 如何使用diff脚本中的命令显示目录中所有相同内容的文件?也许我应该提供更多细节。
该脚本应该在指定的目录和子目录中找到相同的文件,并将它们按文件大小的降序排列显示在终端中。