generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 331
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
76 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,79 @@ | ||
Write unit test for following code. | ||
You MUST return code only, not explain. | ||
You MUST use given-when-then style. | ||
You MUST use should_xx style for test method name. | ||
When testing controller, you MUST use MockMvc and test API only. | ||
Write unit test for following code. You MUST Use English to reply me! | ||
You are working on a project that uses Spring MVC,Spring WebFlux,JDBC to build RESTful APIs. | ||
// class name: BookMeetingRoomRequest | ||
// class fields: meetingRoomId | ||
// class methods: | ||
// super classes: [Object] | ||
// | ||
// class name: BookMeetingRoomResponse | ||
// class fields: bookingId meetingRoomId userId startTime endTime | ||
// class methods: | ||
// super classes: [Object] | ||
// | ||
You MUST use should_xx_xx style for test method name. | ||
You MUST use given-when-then style. | ||
- Test file should be complete and compilable, without need for further actions. | ||
- Ensure that each test focuses on a single use case to maintain clarity and readability. | ||
- Instead of using `@BeforeEach` methods for setup, include all necessary code initialization within each individual test method, do not write parameterized tests. | ||
| This project uses JUnit 5, you should import `org.junit.jupiter.api.Test` and use `@Test` annotation.- You MUST use MockMvc and test API only. | ||
- Use appropriate Spring test annotations such as `@MockBean`, `@Autowired`, `@WebMvcTest`, `@DataJpaTest`, `@AutoConfigureTestDatabase`, `@AutoConfigureMockMvc`, `@SpringBootTest` etc. | ||
|
||
|
||
// here are related classes: | ||
// 'package: cc.unitmesh.untitled.demo.service.BlogService | ||
// class BlogService { | ||
// blogRepository | ||
// + public BlogPost createBlog(BlogPost blogDto) | ||
// + public BlogPost getBlogById(Long id) | ||
// + public BlogPost updateBlog(Long id, BlogPost blogDto) | ||
// + public void deleteBlog(Long id) | ||
// } | ||
// 'package: cc.unitmesh.untitled.demo.service.BlogService | ||
// class BlogService { | ||
// blogRepository | ||
// + public BlogPost createBlog(BlogPost blogDto) | ||
// + public BlogPost getBlogById(Long id) | ||
// + public BlogPost updateBlog(Long id, BlogPost blogDto) | ||
// + public void deleteBlog(Long id) | ||
// } | ||
// 'package: cc.unitmesh.untitled.demo.entity.BlogPost | ||
// class BlogPost { | ||
// id | ||
// title | ||
// content | ||
// author | ||
// + public BlogPost(String title, String content, String author) | ||
// + public BlogPost() | ||
// + public void setId(Long id) | ||
// + public Long getId() | ||
// + public String getTitle() | ||
// + public void setTitle(String title) | ||
// + public String getContent() | ||
// + public void setContent(String content) | ||
// + public String getAuthor() | ||
// + public void setAuthor(String author) | ||
// } | ||
// 'package: cc.unitmesh.untitled.demo.dto.CreateBlogRequest | ||
// class CreateBlogRequest { | ||
// title | ||
// content | ||
// user | ||
// | ||
// } | ||
Code: | ||
```java | ||
@PostMapping("/{meetingRoomId}/book") | ||
public ResponseEntity<BookMeetingRoomResponse> bookMeetingRoom(@PathVariable String meetingRoomId, @RequestBody BookMeetingRoomRequest request) { | ||
// 业务逻辑 | ||
BookMeetingRoomResponse response = new BookMeetingRoomResponse(); | ||
// 设置 response 的属性 | ||
return new ResponseEntity<>(response, HttpStatus.CREATED); | ||
@RestController | ||
@RequestMapping("/blog") | ||
public class BlogController { | ||
BlogService blogService; | ||
|
||
public BlogController(BlogService blogService) { | ||
this.blogService = blogService; | ||
} | ||
|
||
@ApiOperation(value = "Get Blog by id") | ||
@GetMapping("/{id}") | ||
public BlogPost getBlog(@PathVariable Long id) { | ||
return blogService.getBlogById(id); | ||
} | ||
|
||
@ApiOperation(value = "Create a new blog") | ||
@PostMapping("/") | ||
public BlogPost createBlog(@RequestBody CreateBlogRequest request) { | ||
BlogPost blogPost = new BlogPost(); | ||
BeanUtils.copyProperties(request, blogPost); | ||
return blogService.createBlog(blogPost); | ||
} | ||
} | ||
``` | ||
Start with `import` syntax here: | ||
Start with `import` syntax here: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters