method2testcases stringlengths 118 3.08k |
|---|
### Question:
ContactsServiceImpl implements ContactsService { @Override public Response getAllContacts(HttpHeaders headers) { ArrayList<Contacts> contacts = contactsRepository.findAll(); if (contacts != null && !contacts.isEmpty()) { return new Response<>(1, success, contacts); } else { return new Response<>(0, "No content", null); } } @Override Response findContactsById(UUID id, HttpHeaders headers); @Override Response findContactsByAccountId(UUID accountId, HttpHeaders headers); @Override Response createContacts(Contacts contacts, HttpHeaders headers); @Override Response create(Contacts addContacts, HttpHeaders headers); @Override Response delete(UUID contactsId, HttpHeaders headers); @Override Response modify(Contacts contacts, HttpHeaders headers); @Override Response getAllContacts(HttpHeaders headers); }### Answer:
@Test public void testGetAllContacts1() { ArrayList<Contacts> contacts = new ArrayList<>(); contacts.add(new Contacts()); Mockito.when(contactsRepository.findAll()).thenReturn(contacts); Response result = contactsServiceImpl.getAllContacts(headers); Assert.assertEquals(new Response<>(1, "Success", contacts), result); }
@Test public void testGetAllContacts2() { Mockito.when(contactsRepository.findAll()).thenReturn(null); Response result = contactsServiceImpl.getAllContacts(headers); Assert.assertEquals(new Response<>(0, "No content", null), result); } |
### Question:
ContactsController { @GetMapping(path = "/contacts/welcome") public String home() { return "Welcome to [ Contacts Service ] !"; } @GetMapping(path = "/contacts/welcome") String home(); @CrossOrigin(origins = "*") @GetMapping(path = "/contacts") HttpEntity getAllContacts(@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @PostMapping(path = "/contacts") ResponseEntity<Response> createNewContacts(@RequestBody Contacts aci,
@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @PostMapping(path = "/contacts/admin") HttpEntity<?> createNewContactsAdmin(@RequestBody Contacts aci, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @DeleteMapping(path = "/contacts/{contactsId}") HttpEntity deleteContacts(@PathVariable String contactsId, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @PutMapping(path = "/contacts") HttpEntity modifyContacts(@RequestBody Contacts info, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping(path = "/contacts/account/{accountId}") HttpEntity findContactsByAccountId(@PathVariable String accountId, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping(path = "/contacts/{id}") HttpEntity getContactsByContactsId(@PathVariable String id, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testHome() throws Exception { mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/contactservice/contacts/welcome")) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().string("Welcome to [ Contacts Service ] !")); } |
### Question:
ContactsController { @CrossOrigin(origins = "*") @GetMapping(path = "/contacts") public HttpEntity getAllContacts(@RequestHeader HttpHeaders headers) { ContactsController.LOGGER.info("[Contacts Service][Get All Contacts]"); return ok(contactsService.getAllContacts(headers)); } @GetMapping(path = "/contacts/welcome") String home(); @CrossOrigin(origins = "*") @GetMapping(path = "/contacts") HttpEntity getAllContacts(@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @PostMapping(path = "/contacts") ResponseEntity<Response> createNewContacts(@RequestBody Contacts aci,
@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @PostMapping(path = "/contacts/admin") HttpEntity<?> createNewContactsAdmin(@RequestBody Contacts aci, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @DeleteMapping(path = "/contacts/{contactsId}") HttpEntity deleteContacts(@PathVariable String contactsId, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @PutMapping(path = "/contacts") HttpEntity modifyContacts(@RequestBody Contacts info, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping(path = "/contacts/account/{accountId}") HttpEntity findContactsByAccountId(@PathVariable String accountId, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping(path = "/contacts/{id}") HttpEntity getContactsByContactsId(@PathVariable String id, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testGetAllContacts() throws Exception { Mockito.when(contactsService.getAllContacts(Mockito.any(HttpHeaders.class))).thenReturn(response); String result = mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/contactservice/contacts")) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
InsidePaymentController { @GetMapping(value = "/inside_payment/account") public HttpEntity queryAccount(@RequestHeader HttpHeaders headers) { return ok(service.queryAccount(headers)); } @GetMapping(path = "/welcome") String home(); @PostMapping(value = "/inside_payment") HttpEntity pay(@RequestBody PaymentInfo info, @RequestHeader HttpHeaders headers); @PostMapping(value = "/inside_payment/account") HttpEntity createAccount(@RequestBody AccountInfo info, @RequestHeader HttpHeaders headers); @GetMapping(value = "/inside_payment/{userId}/{money}") HttpEntity addMoney(@PathVariable String userId, @PathVariable
String money, @RequestHeader HttpHeaders headers); @GetMapping(value = "/inside_payment/payment") HttpEntity queryPayment(@RequestHeader HttpHeaders headers); @GetMapping(value = "/inside_payment/account") HttpEntity queryAccount(@RequestHeader HttpHeaders headers); @GetMapping(value = "/inside_payment/drawback/{userId}/{money}") HttpEntity drawBack(@PathVariable String userId, @PathVariable String money, @RequestHeader HttpHeaders headers); @PostMapping(value = "/inside_payment/difference") HttpEntity payDifference(@RequestBody PaymentInfo info, @RequestHeader HttpHeaders headers); @GetMapping(value = "/inside_payment/money") HttpEntity queryAddMoney(@RequestHeader HttpHeaders headers); @Autowired
public InsidePaymentService service; }### Answer:
@Test public void testQueryAccount() throws Exception { Mockito.when(service.queryAccount(Mockito.any(HttpHeaders.class))).thenReturn(response); String result = mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/inside_pay_service/inside_payment/account")) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
RouteServiceImpl implements RouteService { @Override public Response deleteRoute(String routeId, HttpHeaders headers) { routeRepository.removeRouteById(routeId); Route route = routeRepository.findById(routeId); if (route == null) { return new Response<>(1, "Delete Success", routeId); } else { return new Response<>(0, "Delete failed, Reason unKnown with this routeId", routeId); } } @Override Response createAndModify(RouteInfo info, HttpHeaders headers); @Override Response deleteRoute(String routeId, HttpHeaders headers); @Override Response getRouteById(String routeId, HttpHeaders headers); @Override Response getRouteByStartAndTerminal(String startId, String terminalId, HttpHeaders headers); @Override Response getAllRoutes(HttpHeaders headers); }### Answer:
@Test public void testDeleteRoute1() { Mockito.doNothing().doThrow(new RuntimeException()).when(routeRepository).removeRouteById(Mockito.anyString()); Mockito.when(routeRepository.findById(Mockito.anyString())).thenReturn(null); Response result = routeServiceImpl.deleteRoute("route_id", headers); Assert.assertEquals(new Response<>(1, "Delete Success", "route_id"), result); }
@Test public void testDeleteRoute2() { Route route = new Route(); Mockito.doNothing().doThrow(new RuntimeException()).when(routeRepository).removeRouteById(Mockito.anyString()); Mockito.when(routeRepository.findById(Mockito.anyString())).thenReturn(route); Response result = routeServiceImpl.deleteRoute("route_id", headers); Assert.assertEquals(new Response<>(0, "Delete failed, Reason unKnown with this routeId", "route_id"), result); } |
### Question:
InsidePaymentController { @GetMapping(value = "/inside_payment/drawback/{userId}/{money}") public HttpEntity drawBack(@PathVariable String userId, @PathVariable String money, @RequestHeader HttpHeaders headers) { return ok(service.drawBack(userId, money, headers)); } @GetMapping(path = "/welcome") String home(); @PostMapping(value = "/inside_payment") HttpEntity pay(@RequestBody PaymentInfo info, @RequestHeader HttpHeaders headers); @PostMapping(value = "/inside_payment/account") HttpEntity createAccount(@RequestBody AccountInfo info, @RequestHeader HttpHeaders headers); @GetMapping(value = "/inside_payment/{userId}/{money}") HttpEntity addMoney(@PathVariable String userId, @PathVariable
String money, @RequestHeader HttpHeaders headers); @GetMapping(value = "/inside_payment/payment") HttpEntity queryPayment(@RequestHeader HttpHeaders headers); @GetMapping(value = "/inside_payment/account") HttpEntity queryAccount(@RequestHeader HttpHeaders headers); @GetMapping(value = "/inside_payment/drawback/{userId}/{money}") HttpEntity drawBack(@PathVariable String userId, @PathVariable String money, @RequestHeader HttpHeaders headers); @PostMapping(value = "/inside_payment/difference") HttpEntity payDifference(@RequestBody PaymentInfo info, @RequestHeader HttpHeaders headers); @GetMapping(value = "/inside_payment/money") HttpEntity queryAddMoney(@RequestHeader HttpHeaders headers); @Autowired
public InsidePaymentService service; }### Answer:
@Test public void testDrawBack() throws Exception { Mockito.when(service.drawBack(Mockito.anyString(), Mockito.anyString(), Mockito.any(HttpHeaders.class))).thenReturn(response); String result = mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/inside_pay_service/inside_payment/drawback/user_id/money")) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
RouteServiceImpl implements RouteService { @Override public Response getRouteById(String routeId, HttpHeaders headers) { Route route = routeRepository.findById(routeId); if (route == null) { return new Response<>(0, "No content with the routeId", null); } else { return new Response<>(1, success, route); } } @Override Response createAndModify(RouteInfo info, HttpHeaders headers); @Override Response deleteRoute(String routeId, HttpHeaders headers); @Override Response getRouteById(String routeId, HttpHeaders headers); @Override Response getRouteByStartAndTerminal(String startId, String terminalId, HttpHeaders headers); @Override Response getAllRoutes(HttpHeaders headers); }### Answer:
@Test public void testGetRouteById1() { Mockito.when(routeRepository.findById(Mockito.anyString())).thenReturn(null); Response result = routeServiceImpl.getRouteById("route_id", headers); Assert.assertEquals(new Response<>(0, "No content with the routeId", null), result); }
@Test public void testGetRouteById2() { Route route = new Route(); Mockito.when(routeRepository.findById(Mockito.anyString())).thenReturn(route); Response result = routeServiceImpl.getRouteById("route_id", headers); Assert.assertEquals(new Response<>(1, "Success", route), result); } |
### Question:
RouteServiceImpl implements RouteService { @Override public Response getAllRoutes(HttpHeaders headers) { ArrayList<Route> routes = routeRepository.findAll(); if (routes != null && !routes.isEmpty()) { return new Response<>(1, success, routes); } else { return new Response<>(0, "No Content", null); } } @Override Response createAndModify(RouteInfo info, HttpHeaders headers); @Override Response deleteRoute(String routeId, HttpHeaders headers); @Override Response getRouteById(String routeId, HttpHeaders headers); @Override Response getRouteByStartAndTerminal(String startId, String terminalId, HttpHeaders headers); @Override Response getAllRoutes(HttpHeaders headers); }### Answer:
@Test public void testGetAllRoutes1() { ArrayList<Route> routes = new ArrayList<>(); routes.add(new Route()); Mockito.when(routeRepository.findAll()).thenReturn(routes); Response result = routeServiceImpl.getAllRoutes(headers); Assert.assertEquals("Success", result.getMsg()); }
@Test public void testGetAllRoutes2() { Mockito.when(routeRepository.findAll()).thenReturn(null); Response result = routeServiceImpl.getAllRoutes(headers); Assert.assertEquals("No Content", result.getMsg()); } |
### Question:
RouteController { @GetMapping(path = "/welcome") public String home() { return "Welcome to [ Route Service ] !"; } @GetMapping(path = "/welcome") String home(); @PostMapping(path = "/routes") ResponseEntity<Response> createAndModifyRoute(@RequestBody RouteInfo createAndModifyRouteInfo, @RequestHeader HttpHeaders headers); @DeleteMapping(path = "/routes/{routeId}") HttpEntity deleteRoute(@PathVariable String routeId, @RequestHeader HttpHeaders headers); @GetMapping(path = "/routes/{routeId}") HttpEntity queryById(@PathVariable String routeId, @RequestHeader HttpHeaders headers); @GetMapping(path = "/routes") HttpEntity queryAll(@RequestHeader HttpHeaders headers); @GetMapping(path = "/routes/{startId}/{terminalId}") HttpEntity queryByStartAndTerminal(@PathVariable String startId,
@PathVariable String terminalId,
@RequestHeader HttpHeaders headers); }### Answer:
@Test public void testHome() throws Exception { mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/routeservice/welcome")) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().string("Welcome to [ Route Service ] !")); } |
### Question:
RouteController { @PostMapping(path = "/routes") public ResponseEntity<Response> createAndModifyRoute(@RequestBody RouteInfo createAndModifyRouteInfo, @RequestHeader HttpHeaders headers) { RouteController.LOGGER.info("Create Route id: {}", createAndModifyRouteInfo.getId()); return ok(routeService.createAndModify(createAndModifyRouteInfo, headers)); } @GetMapping(path = "/welcome") String home(); @PostMapping(path = "/routes") ResponseEntity<Response> createAndModifyRoute(@RequestBody RouteInfo createAndModifyRouteInfo, @RequestHeader HttpHeaders headers); @DeleteMapping(path = "/routes/{routeId}") HttpEntity deleteRoute(@PathVariable String routeId, @RequestHeader HttpHeaders headers); @GetMapping(path = "/routes/{routeId}") HttpEntity queryById(@PathVariable String routeId, @RequestHeader HttpHeaders headers); @GetMapping(path = "/routes") HttpEntity queryAll(@RequestHeader HttpHeaders headers); @GetMapping(path = "/routes/{startId}/{terminalId}") HttpEntity queryByStartAndTerminal(@PathVariable String startId,
@PathVariable String terminalId,
@RequestHeader HttpHeaders headers); }### Answer:
@Test public void testCreateAndModifyRoute() throws Exception { RouteInfo createAndModifyRouteInfo = new RouteInfo(); Mockito.when(routeService.createAndModify(Mockito.any(RouteInfo.class), Mockito.any(HttpHeaders.class))).thenReturn(response); String requestJson = JSONObject.toJSONString(createAndModifyRouteInfo); String result = mockMvc.perform(MockMvcRequestBuilders.post("/api/v1/routeservice/routes").contentType(MediaType.APPLICATION_JSON).content(requestJson)) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
RouteController { @DeleteMapping(path = "/routes/{routeId}") public HttpEntity deleteRoute(@PathVariable String routeId, @RequestHeader HttpHeaders headers) { RouteController.LOGGER.info("Route id: {}", routeId); return ok(routeService.deleteRoute(routeId, headers)); } @GetMapping(path = "/welcome") String home(); @PostMapping(path = "/routes") ResponseEntity<Response> createAndModifyRoute(@RequestBody RouteInfo createAndModifyRouteInfo, @RequestHeader HttpHeaders headers); @DeleteMapping(path = "/routes/{routeId}") HttpEntity deleteRoute(@PathVariable String routeId, @RequestHeader HttpHeaders headers); @GetMapping(path = "/routes/{routeId}") HttpEntity queryById(@PathVariable String routeId, @RequestHeader HttpHeaders headers); @GetMapping(path = "/routes") HttpEntity queryAll(@RequestHeader HttpHeaders headers); @GetMapping(path = "/routes/{startId}/{terminalId}") HttpEntity queryByStartAndTerminal(@PathVariable String startId,
@PathVariable String terminalId,
@RequestHeader HttpHeaders headers); }### Answer:
@Test public void testDeleteRoute() throws Exception { Mockito.when(routeService.deleteRoute(Mockito.anyString(), Mockito.any(HttpHeaders.class))).thenReturn(response); String result = mockMvc.perform(MockMvcRequestBuilders.delete("/api/v1/routeservice/routes/route_id")) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
RouteController { @GetMapping(path = "/routes/{routeId}") public HttpEntity queryById(@PathVariable String routeId, @RequestHeader HttpHeaders headers) { RouteController.LOGGER.info("Route id: {}", routeId); return ok(routeService.getRouteById(routeId, headers)); } @GetMapping(path = "/welcome") String home(); @PostMapping(path = "/routes") ResponseEntity<Response> createAndModifyRoute(@RequestBody RouteInfo createAndModifyRouteInfo, @RequestHeader HttpHeaders headers); @DeleteMapping(path = "/routes/{routeId}") HttpEntity deleteRoute(@PathVariable String routeId, @RequestHeader HttpHeaders headers); @GetMapping(path = "/routes/{routeId}") HttpEntity queryById(@PathVariable String routeId, @RequestHeader HttpHeaders headers); @GetMapping(path = "/routes") HttpEntity queryAll(@RequestHeader HttpHeaders headers); @GetMapping(path = "/routes/{startId}/{terminalId}") HttpEntity queryByStartAndTerminal(@PathVariable String startId,
@PathVariable String terminalId,
@RequestHeader HttpHeaders headers); }### Answer:
@Test public void testQueryById() throws Exception { Mockito.when(routeService.getRouteById(Mockito.anyString(), Mockito.any(HttpHeaders.class))).thenReturn(response); String result = mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/routeservice/routes/route_id")) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
RouteController { @GetMapping(path = "/routes") public HttpEntity queryAll(@RequestHeader HttpHeaders headers) { return ok(routeService.getAllRoutes(headers)); } @GetMapping(path = "/welcome") String home(); @PostMapping(path = "/routes") ResponseEntity<Response> createAndModifyRoute(@RequestBody RouteInfo createAndModifyRouteInfo, @RequestHeader HttpHeaders headers); @DeleteMapping(path = "/routes/{routeId}") HttpEntity deleteRoute(@PathVariable String routeId, @RequestHeader HttpHeaders headers); @GetMapping(path = "/routes/{routeId}") HttpEntity queryById(@PathVariable String routeId, @RequestHeader HttpHeaders headers); @GetMapping(path = "/routes") HttpEntity queryAll(@RequestHeader HttpHeaders headers); @GetMapping(path = "/routes/{startId}/{terminalId}") HttpEntity queryByStartAndTerminal(@PathVariable String startId,
@PathVariable String terminalId,
@RequestHeader HttpHeaders headers); }### Answer:
@Test public void testQueryAll() throws Exception { Mockito.when(routeService.getAllRoutes(Mockito.any(HttpHeaders.class))).thenReturn(response); String result = mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/routeservice/routes")) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
RouteController { @GetMapping(path = "/routes/{startId}/{terminalId}") public HttpEntity queryByStartAndTerminal(@PathVariable String startId, @PathVariable String terminalId, @RequestHeader HttpHeaders headers) { RouteController.LOGGER.info("startId : {}, terminalId: {}", startId, terminalId); return ok(routeService.getRouteByStartAndTerminal(startId, terminalId, headers)); } @GetMapping(path = "/welcome") String home(); @PostMapping(path = "/routes") ResponseEntity<Response> createAndModifyRoute(@RequestBody RouteInfo createAndModifyRouteInfo, @RequestHeader HttpHeaders headers); @DeleteMapping(path = "/routes/{routeId}") HttpEntity deleteRoute(@PathVariable String routeId, @RequestHeader HttpHeaders headers); @GetMapping(path = "/routes/{routeId}") HttpEntity queryById(@PathVariable String routeId, @RequestHeader HttpHeaders headers); @GetMapping(path = "/routes") HttpEntity queryAll(@RequestHeader HttpHeaders headers); @GetMapping(path = "/routes/{startId}/{terminalId}") HttpEntity queryByStartAndTerminal(@PathVariable String startId,
@PathVariable String terminalId,
@RequestHeader HttpHeaders headers); }### Answer:
@Test public void testQueryByStartAndTerminal() throws Exception { Mockito.when(routeService.getRouteByStartAndTerminal(Mockito.anyString(), Mockito.anyString(), Mockito.any(HttpHeaders.class))).thenReturn(response); String result = mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/routeservice/routes/start_id/terminal_id")) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
UserController { @GetMapping public ResponseEntity<Response> getAllUser(@RequestHeader HttpHeaders headers) { return ok(userService.getAllUsers(headers)); } @GetMapping("/hello") String testHello(); @GetMapping ResponseEntity<Response> getAllUser(@RequestHeader HttpHeaders headers); @GetMapping("/{userName}") ResponseEntity<Response> getUserByUserName(@PathVariable String userName, @RequestHeader HttpHeaders headers); @GetMapping("/id/{userId}") ResponseEntity<Response> getUserByUserId(@PathVariable String userId, @RequestHeader HttpHeaders headers); @PostMapping("/register") ResponseEntity<Response> registerUser(@RequestBody UserDto userDto, @RequestHeader HttpHeaders headers); @DeleteMapping("/{userId}") ResponseEntity<Response> deleteUserById(@PathVariable String userId,
@RequestHeader HttpHeaders headers); @PutMapping ResponseEntity<Response> updateUser(@RequestBody UserDto user,
@RequestHeader HttpHeaders headers); }### Answer:
@Test public void testGetAllUser() throws Exception { Mockito.when(userService.getAllUsers(Mockito.any(HttpHeaders.class))).thenReturn(response); String result = mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/userservice/users")) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
UserController { @GetMapping("/{userName}") public ResponseEntity<Response> getUserByUserName(@PathVariable String userName, @RequestHeader HttpHeaders headers) { return ok(userService.findByUserName(userName, headers)); } @GetMapping("/hello") String testHello(); @GetMapping ResponseEntity<Response> getAllUser(@RequestHeader HttpHeaders headers); @GetMapping("/{userName}") ResponseEntity<Response> getUserByUserName(@PathVariable String userName, @RequestHeader HttpHeaders headers); @GetMapping("/id/{userId}") ResponseEntity<Response> getUserByUserId(@PathVariable String userId, @RequestHeader HttpHeaders headers); @PostMapping("/register") ResponseEntity<Response> registerUser(@RequestBody UserDto userDto, @RequestHeader HttpHeaders headers); @DeleteMapping("/{userId}") ResponseEntity<Response> deleteUserById(@PathVariable String userId,
@RequestHeader HttpHeaders headers); @PutMapping ResponseEntity<Response> updateUser(@RequestBody UserDto user,
@RequestHeader HttpHeaders headers); }### Answer:
@Test public void testGetUserByUserName() throws Exception { Mockito.when(userService.findByUserName(Mockito.anyString(), Mockito.any(HttpHeaders.class))).thenReturn(response); String result = mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/userservice/users/user_name")) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
UserController { @GetMapping("/id/{userId}") public ResponseEntity<Response> getUserByUserId(@PathVariable String userId, @RequestHeader HttpHeaders headers) { return ok(userService.findByUserId(userId, headers)); } @GetMapping("/hello") String testHello(); @GetMapping ResponseEntity<Response> getAllUser(@RequestHeader HttpHeaders headers); @GetMapping("/{userName}") ResponseEntity<Response> getUserByUserName(@PathVariable String userName, @RequestHeader HttpHeaders headers); @GetMapping("/id/{userId}") ResponseEntity<Response> getUserByUserId(@PathVariable String userId, @RequestHeader HttpHeaders headers); @PostMapping("/register") ResponseEntity<Response> registerUser(@RequestBody UserDto userDto, @RequestHeader HttpHeaders headers); @DeleteMapping("/{userId}") ResponseEntity<Response> deleteUserById(@PathVariable String userId,
@RequestHeader HttpHeaders headers); @PutMapping ResponseEntity<Response> updateUser(@RequestBody UserDto user,
@RequestHeader HttpHeaders headers); }### Answer:
@Test public void testGetUserByUserId() throws Exception { Mockito.when(userService.findByUserId(Mockito.anyString(), Mockito.any(HttpHeaders.class))).thenReturn(response); String result = mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/userservice/users/id/user_id")) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
UserController { @PostMapping("/register") public ResponseEntity<Response> registerUser(@RequestBody UserDto userDto, @RequestHeader HttpHeaders headers) { return ResponseEntity.status(HttpStatus.CREATED).body(userService.saveUser(userDto, headers)); } @GetMapping("/hello") String testHello(); @GetMapping ResponseEntity<Response> getAllUser(@RequestHeader HttpHeaders headers); @GetMapping("/{userName}") ResponseEntity<Response> getUserByUserName(@PathVariable String userName, @RequestHeader HttpHeaders headers); @GetMapping("/id/{userId}") ResponseEntity<Response> getUserByUserId(@PathVariable String userId, @RequestHeader HttpHeaders headers); @PostMapping("/register") ResponseEntity<Response> registerUser(@RequestBody UserDto userDto, @RequestHeader HttpHeaders headers); @DeleteMapping("/{userId}") ResponseEntity<Response> deleteUserById(@PathVariable String userId,
@RequestHeader HttpHeaders headers); @PutMapping ResponseEntity<Response> updateUser(@RequestBody UserDto user,
@RequestHeader HttpHeaders headers); }### Answer:
@Test public void testRegisterUser() throws Exception { UserDto userDto = new UserDto(); Mockito.when(userService.saveUser(Mockito.any(UserDto.class), Mockito.any(HttpHeaders.class))).thenReturn(response); String requestJson = JSONObject.toJSONString(userDto); String result = mockMvc.perform(MockMvcRequestBuilders.post("/api/v1/userservice/users/register").contentType(MediaType.APPLICATION_JSON).content(requestJson)) .andExpect(MockMvcResultMatchers.status().isCreated()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
UserController { @DeleteMapping("/{userId}") public ResponseEntity<Response> deleteUserById(@PathVariable String userId, @RequestHeader HttpHeaders headers) { return ok(userService.deleteUser(UUID.fromString(userId), headers)); } @GetMapping("/hello") String testHello(); @GetMapping ResponseEntity<Response> getAllUser(@RequestHeader HttpHeaders headers); @GetMapping("/{userName}") ResponseEntity<Response> getUserByUserName(@PathVariable String userName, @RequestHeader HttpHeaders headers); @GetMapping("/id/{userId}") ResponseEntity<Response> getUserByUserId(@PathVariable String userId, @RequestHeader HttpHeaders headers); @PostMapping("/register") ResponseEntity<Response> registerUser(@RequestBody UserDto userDto, @RequestHeader HttpHeaders headers); @DeleteMapping("/{userId}") ResponseEntity<Response> deleteUserById(@PathVariable String userId,
@RequestHeader HttpHeaders headers); @PutMapping ResponseEntity<Response> updateUser(@RequestBody UserDto user,
@RequestHeader HttpHeaders headers); }### Answer:
@Test public void testDeleteUserById() throws Exception { UUID userId = UUID.randomUUID(); Mockito.when(userService.deleteUser(Mockito.any(UUID.class), Mockito.any(HttpHeaders.class))).thenReturn(response); String result = mockMvc.perform(MockMvcRequestBuilders.delete("/api/v1/userservice/users/" + userId.toString())) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
UserController { @PutMapping public ResponseEntity<Response> updateUser(@RequestBody UserDto user, @RequestHeader HttpHeaders headers) { return ok(userService.updateUser(user, headers)); } @GetMapping("/hello") String testHello(); @GetMapping ResponseEntity<Response> getAllUser(@RequestHeader HttpHeaders headers); @GetMapping("/{userName}") ResponseEntity<Response> getUserByUserName(@PathVariable String userName, @RequestHeader HttpHeaders headers); @GetMapping("/id/{userId}") ResponseEntity<Response> getUserByUserId(@PathVariable String userId, @RequestHeader HttpHeaders headers); @PostMapping("/register") ResponseEntity<Response> registerUser(@RequestBody UserDto userDto, @RequestHeader HttpHeaders headers); @DeleteMapping("/{userId}") ResponseEntity<Response> deleteUserById(@PathVariable String userId,
@RequestHeader HttpHeaders headers); @PutMapping ResponseEntity<Response> updateUser(@RequestBody UserDto user,
@RequestHeader HttpHeaders headers); }### Answer:
@Test public void testUpdateUser() throws Exception { UserDto user = new UserDto(); Mockito.when(userService.updateUser(Mockito.any(UserDto.class), Mockito.any(HttpHeaders.class))).thenReturn(response); String requestJson = JSONObject.toJSONString(user); String result = mockMvc.perform(MockMvcRequestBuilders.put("/api/v1/userservice/users").contentType(MediaType.APPLICATION_JSON).content(requestJson)) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
NotificationServiceImpl implements NotificationService { @Override public boolean preserveSuccess(NotifyInfo info, HttpHeaders headers){ Mail mail = new Mail(); mail.setMailFrom(email); mail.setMailTo(info.getEmail()); mail.setMailSubject("Preserve Success"); Map<String, Object> model = new HashMap<>(); model.put(username, info.getUsername()); model.put(startingPlace,info.getStartingPlace()); model.put(endPlace,info.getEndPlace()); model.put(startingTime,info.getStartingTime()); model.put("date",info.getDate()); model.put(seatClass,info.getSeatClass()); model.put(seatNumber,info.getSeatNumber()); model.put("price",info.getPrice()); mail.setModel(model); try { mailService.sendEmail(mail,"preserve_success.ftl"); return true; } catch (Exception e) { LOGGER.error(e.getMessage()); return false; } } @Override boolean preserveSuccess(NotifyInfo info, HttpHeaders headers); @Override boolean orderCreateSuccess(NotifyInfo info, HttpHeaders headers); @Override boolean orderChangedSuccess(NotifyInfo info, HttpHeaders headers); @Override boolean orderCancelSuccess(NotifyInfo info, HttpHeaders headers); }### Answer:
@Test public void testPreserveSuccess1() throws Exception { NotifyInfo info = new NotifyInfo(); Mockito.doNothing().doThrow(new RuntimeException()).when(mailService).sendEmail(Mockito.any(Mail.class), Mockito.anyString()); boolean result = notificationServiceImpl.preserveSuccess(info, headers); Assert.assertTrue(result); }
@Test public void testPreserveSuccess2() throws Exception { NotifyInfo info = new NotifyInfo(); Mockito.doThrow(new Exception()).when(mailService).sendEmail(Mockito.any(Mail.class), Mockito.anyString()); boolean result = notificationServiceImpl.preserveSuccess(info, headers); Assert.assertFalse(result); } |
### Question:
InsidePaymentController { @GetMapping(value = "/inside_payment/money") public HttpEntity queryAddMoney(@RequestHeader HttpHeaders headers) { return ok(service.queryAddMoney(headers)); } @GetMapping(path = "/welcome") String home(); @PostMapping(value = "/inside_payment") HttpEntity pay(@RequestBody PaymentInfo info, @RequestHeader HttpHeaders headers); @PostMapping(value = "/inside_payment/account") HttpEntity createAccount(@RequestBody AccountInfo info, @RequestHeader HttpHeaders headers); @GetMapping(value = "/inside_payment/{userId}/{money}") HttpEntity addMoney(@PathVariable String userId, @PathVariable
String money, @RequestHeader HttpHeaders headers); @GetMapping(value = "/inside_payment/payment") HttpEntity queryPayment(@RequestHeader HttpHeaders headers); @GetMapping(value = "/inside_payment/account") HttpEntity queryAccount(@RequestHeader HttpHeaders headers); @GetMapping(value = "/inside_payment/drawback/{userId}/{money}") HttpEntity drawBack(@PathVariable String userId, @PathVariable String money, @RequestHeader HttpHeaders headers); @PostMapping(value = "/inside_payment/difference") HttpEntity payDifference(@RequestBody PaymentInfo info, @RequestHeader HttpHeaders headers); @GetMapping(value = "/inside_payment/money") HttpEntity queryAddMoney(@RequestHeader HttpHeaders headers); @Autowired
public InsidePaymentService service; }### Answer:
@Test public void testQueryAddMoney() throws Exception { Mockito.when(service.queryAddMoney(Mockito.any(HttpHeaders.class))).thenReturn(response); String result = mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/inside_pay_service/inside_payment/money")) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
NotificationServiceImpl implements NotificationService { @Override public boolean orderCreateSuccess(NotifyInfo info, HttpHeaders headers){ Mail mail = new Mail(); mail.setMailFrom(email); mail.setMailTo(info.getEmail()); mail.setMailSubject("Order Create Success"); Map<String, Object> model = new HashMap<>(); model.put(username, info.getUsername()); model.put(startingPlace,info.getStartingPlace()); model.put(endPlace,info.getEndPlace()); model.put(startingTime,info.getStartingTime()); model.put("date",info.getDate()); model.put(seatClass,info.getSeatClass()); model.put(seatNumber,info.getSeatNumber()); model.put("orderNumber", info.getOrderNumber()); mail.setModel(model); try { mailService.sendEmail(mail,"order_create_success.ftl"); return true; } catch (Exception e) { LOGGER.error(e.getMessage()); return false; } } @Override boolean preserveSuccess(NotifyInfo info, HttpHeaders headers); @Override boolean orderCreateSuccess(NotifyInfo info, HttpHeaders headers); @Override boolean orderChangedSuccess(NotifyInfo info, HttpHeaders headers); @Override boolean orderCancelSuccess(NotifyInfo info, HttpHeaders headers); }### Answer:
@Test public void testOrderCreateSuccess1() throws Exception { NotifyInfo info = new NotifyInfo(); Mockito.doNothing().doThrow(new RuntimeException()).when(mailService).sendEmail(Mockito.any(Mail.class), Mockito.anyString()); boolean result = notificationServiceImpl.orderCreateSuccess(info, headers); Assert.assertTrue(result); }
@Test public void testOrderCreateSuccess2() throws Exception { NotifyInfo info = new NotifyInfo(); Mockito.doThrow(new Exception()).when(mailService).sendEmail(Mockito.any(Mail.class), Mockito.anyString()); boolean result = notificationServiceImpl.orderCreateSuccess(info, headers); Assert.assertFalse(result); } |
### Question:
NotificationServiceImpl implements NotificationService { @Override public boolean orderChangedSuccess(NotifyInfo info, HttpHeaders headers){ Mail mail = new Mail(); mail.setMailFrom(email); mail.setMailTo(info.getEmail()); mail.setMailSubject("Order Changed Success"); Map<String, Object> model = new HashMap<>(); model.put(username, info.getUsername()); model.put(startingPlace,info.getStartingPlace()); model.put(endPlace,info.getEndPlace()); model.put(startingTime,info.getStartingTime()); model.put("date",info.getDate()); model.put(seatClass,info.getSeatClass()); model.put(seatNumber,info.getSeatNumber()); model.put("orderNumber", info.getOrderNumber()); mail.setModel(model); try { mailService.sendEmail(mail,"order_changed_success.ftl"); return true; } catch (Exception e) { LOGGER.error(e.getMessage()); return false; } } @Override boolean preserveSuccess(NotifyInfo info, HttpHeaders headers); @Override boolean orderCreateSuccess(NotifyInfo info, HttpHeaders headers); @Override boolean orderChangedSuccess(NotifyInfo info, HttpHeaders headers); @Override boolean orderCancelSuccess(NotifyInfo info, HttpHeaders headers); }### Answer:
@Test public void testOrderChangedSuccess1() throws Exception { NotifyInfo info = new NotifyInfo(); Mockito.doNothing().doThrow(new RuntimeException()).when(mailService).sendEmail(Mockito.any(Mail.class), Mockito.anyString()); boolean result = notificationServiceImpl.orderChangedSuccess(info, headers); Assert.assertTrue(result); }
@Test public void testOrderChangedSuccess2() throws Exception { NotifyInfo info = new NotifyInfo(); Mockito.doThrow(new Exception()).when(mailService).sendEmail(Mockito.any(Mail.class), Mockito.anyString()); boolean result = notificationServiceImpl.orderChangedSuccess(info, headers); Assert.assertFalse(result); } |
### Question:
NotificationServiceImpl implements NotificationService { @Override public boolean orderCancelSuccess(NotifyInfo info, HttpHeaders headers){ Mail mail = new Mail(); mail.setMailFrom(email); mail.setMailTo(info.getEmail()); mail.setMailSubject("Order Cancel Success"); Map<String, Object> model = new HashMap<>(); model.put(username, info.getUsername()); model.put("price",info.getPrice()); mail.setModel(model); try { mailService.sendEmail(mail,"order_cancel_success.ftl"); return true; } catch (Exception e) { LOGGER.error(e.getMessage()); return false; } } @Override boolean preserveSuccess(NotifyInfo info, HttpHeaders headers); @Override boolean orderCreateSuccess(NotifyInfo info, HttpHeaders headers); @Override boolean orderChangedSuccess(NotifyInfo info, HttpHeaders headers); @Override boolean orderCancelSuccess(NotifyInfo info, HttpHeaders headers); }### Answer:
@Test public void testOrderCancelSuccess1() throws Exception { NotifyInfo info = new NotifyInfo(); Mockito.doNothing().doThrow(new RuntimeException()).when(mailService).sendEmail(Mockito.any(Mail.class), Mockito.anyString()); boolean result = notificationServiceImpl.orderCancelSuccess(info, headers); Assert.assertTrue(result); }
@Test public void testOrderCancelSuccess2() throws Exception { NotifyInfo info = new NotifyInfo(); Mockito.doThrow(new Exception()).when(mailService).sendEmail(Mockito.any(Mail.class), Mockito.anyString()); boolean result = notificationServiceImpl.orderCancelSuccess(info, headers); Assert.assertFalse(result); } |
### Question:
NotificationController { @GetMapping(path = "/welcome") public String home() { return "Welcome to [ Notification Service ] !"; } @GetMapping(path = "/welcome") String home(); @PostMapping(value = "/notification/preserve_success") boolean preserve_success(@RequestBody NotifyInfo info, @RequestHeader HttpHeaders headers); @PostMapping(value = "/notification/order_create_success") boolean order_create_success(@RequestBody NotifyInfo info, @RequestHeader HttpHeaders headers); @PostMapping(value = "/notification/order_changed_success") boolean order_changed_success(@RequestBody NotifyInfo info, @RequestHeader HttpHeaders headers); @PostMapping(value = "/notification/order_cancel_success") boolean order_cancel_success(@RequestBody NotifyInfo info, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testHome() throws Exception { mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/notifyservice/welcome")) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().string("Welcome to [ Notification Service ] !")); } |
### Question:
ExecuteControlller { @GetMapping(path = "/welcome") public String home(@RequestHeader HttpHeaders headers) { return "Welcome to [ Execute Service ] !"; } @GetMapping(path = "/welcome") String home(@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping(path = "/execute/execute/{orderId}") HttpEntity executeTicket(@PathVariable String orderId, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping(path = "/execute/collected/{orderId}") HttpEntity collectTicket(@PathVariable String orderId, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testHome() throws Exception { mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/executeservice/welcome")) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().string("Welcome to [ Execute Service ] !")); } |
### Question:
ExecuteControlller { @CrossOrigin(origins = "*") @GetMapping(path = "/execute/execute/{orderId}") public HttpEntity executeTicket(@PathVariable String orderId, @RequestHeader HttpHeaders headers) { ExecuteControlller.LOGGER.info("[Execute Service][Execute] Id: {}", orderId); return ok(executeService.ticketExecute(orderId, headers)); } @GetMapping(path = "/welcome") String home(@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping(path = "/execute/execute/{orderId}") HttpEntity executeTicket(@PathVariable String orderId, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping(path = "/execute/collected/{orderId}") HttpEntity collectTicket(@PathVariable String orderId, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testExecuteTicket() throws Exception { Mockito.when(executeService.ticketExecute(Mockito.anyString(), Mockito.any(HttpHeaders.class))).thenReturn(response); String result = mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/executeservice/execute/execute/order_id")) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
ExecuteControlller { @CrossOrigin(origins = "*") @GetMapping(path = "/execute/collected/{orderId}") public HttpEntity collectTicket(@PathVariable String orderId, @RequestHeader HttpHeaders headers) { ExecuteControlller.LOGGER.info("[Execute Service][Collect] Id: {}", orderId); return ok(executeService.ticketCollect(orderId, headers)); } @GetMapping(path = "/welcome") String home(@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping(path = "/execute/execute/{orderId}") HttpEntity executeTicket(@PathVariable String orderId, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping(path = "/execute/collected/{orderId}") HttpEntity collectTicket(@PathVariable String orderId, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testCollectTicket() throws Exception { Mockito.when(executeService.ticketCollect(Mockito.anyString(), Mockito.any(HttpHeaders.class))).thenReturn(response); String result = mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/executeservice/execute/collected/order_id")) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
ConfigServiceImpl implements ConfigService { @Override public Response create(Config info, HttpHeaders headers) { if (repository.findByName(info.getName()) != null) { String result = config0 + info.getName() + " already exists."; return new Response<>(0, result, null); } else { Config config = new Config(info.getName(), info.getValue(), info.getDescription()); repository.save(config); return new Response<>(1, "Create success", config); } } @Override Response create(Config info, HttpHeaders headers); @Override Response update(Config info, HttpHeaders headers); @Override Response query(String name, HttpHeaders headers); @Override Response delete(String name, HttpHeaders headers); @Override Response queryAll(HttpHeaders headers); }### Answer:
@Test public void testCreate1() { Config info = new Config(); Mockito.when(repository.findByName(info.getName())).thenReturn(info); Response result = configServiceImpl.create(info, headers); Assert.assertEquals(new Response<>(0, "Config already exists.", null), result); }
@Test public void testCreate2() { Config info = new Config("", "", ""); Mockito.when(repository.findByName(info.getName())).thenReturn(null); Mockito.when(repository.save(Mockito.any(Config.class))).thenReturn(null); Response result = configServiceImpl.create(info, headers); Assert.assertEquals(new Response<>(1, "Create success", new Config("", "", "")), result); } |
### Question:
ConfigServiceImpl implements ConfigService { @Override public Response update(Config info, HttpHeaders headers) { if (repository.findByName(info.getName()) == null) { String result = config0 + info.getName() + " doesn't exist."; return new Response<>(0, result, null); } else { Config config = new Config(info.getName(), info.getValue(), info.getDescription()); repository.save(config); return new Response<>(1, "Update success", config); } } @Override Response create(Config info, HttpHeaders headers); @Override Response update(Config info, HttpHeaders headers); @Override Response query(String name, HttpHeaders headers); @Override Response delete(String name, HttpHeaders headers); @Override Response queryAll(HttpHeaders headers); }### Answer:
@Test public void testUpdate1() { Config info = new Config(); Mockito.when(repository.findByName(info.getName())).thenReturn(null); Response result = configServiceImpl.update(info, headers); Assert.assertEquals(new Response<>(0, "Config doesn't exist.", null), result); }
@Test public void testUpdate2() { Config info = new Config("", "", ""); Mockito.when(repository.findByName(info.getName())).thenReturn(info); Mockito.when(repository.save(Mockito.any(Config.class))).thenReturn(null); Response result = configServiceImpl.update(info, headers); Assert.assertEquals(new Response<>(1, "Update success", new Config("", "", "")), result); } |
### Question:
ConfigServiceImpl implements ConfigService { @Override public Response query(String name, HttpHeaders headers) { Config config = repository.findByName(name); if (config == null) { return new Response<>(0, "No content", null); } else { return new Response<>(1, "Success", config); } } @Override Response create(Config info, HttpHeaders headers); @Override Response update(Config info, HttpHeaders headers); @Override Response query(String name, HttpHeaders headers); @Override Response delete(String name, HttpHeaders headers); @Override Response queryAll(HttpHeaders headers); }### Answer:
@Test public void testQuery1() { Mockito.when(repository.findByName("name")).thenReturn(null); Response result = configServiceImpl.query("name", headers); Assert.assertEquals(new Response<>(0, "No content", null), result); }
@Test public void testQuery2() { Config info = new Config(); Mockito.when(repository.findByName("name")).thenReturn(info); Response result = configServiceImpl.query("name", headers); Assert.assertEquals(new Response<>(1, "Success", new Config()), result); } |
### Question:
ConfigServiceImpl implements ConfigService { @Override public Response delete(String name, HttpHeaders headers) { Config config = repository.findByName(name); if (config == null) { String result = config0 + name + " doesn't exist."; return new Response<>(0, result, null); } else { repository.deleteByName(name); return new Response<>(1, "Delete success", config); } } @Override Response create(Config info, HttpHeaders headers); @Override Response update(Config info, HttpHeaders headers); @Override Response query(String name, HttpHeaders headers); @Override Response delete(String name, HttpHeaders headers); @Override Response queryAll(HttpHeaders headers); }### Answer:
@Test public void testDelete1() { Mockito.when(repository.findByName("name")).thenReturn(null); Response result = configServiceImpl.delete("name", headers); Assert.assertEquals(new Response<>(0, "Config name doesn't exist.", null), result); }
@Test public void testDelete2() { Config info = new Config(); Mockito.when(repository.findByName("name")).thenReturn(info); Mockito.doNothing().doThrow(new RuntimeException()).when(repository).deleteByName("name"); Response result = configServiceImpl.delete("name", headers); Assert.assertEquals(new Response<>(1, "Delete success", info), result); } |
### Question:
ConfigServiceImpl implements ConfigService { @Override public Response queryAll(HttpHeaders headers) { List<Config> configList = repository.findAll(); if (configList != null && !configList.isEmpty()) { return new Response<>(1, "Find all config success", configList); } else { return new Response<>(0, "No content", null); } } @Override Response create(Config info, HttpHeaders headers); @Override Response update(Config info, HttpHeaders headers); @Override Response query(String name, HttpHeaders headers); @Override Response delete(String name, HttpHeaders headers); @Override Response queryAll(HttpHeaders headers); }### Answer:
@Test public void testQueryAll1() { List<Config> configList = new ArrayList<>(); configList.add(new Config()); Mockito.when(repository.findAll()).thenReturn(configList); Response result = configServiceImpl.queryAll(headers); Assert.assertEquals(new Response<>(1, "Find all config success", configList), result); }
@Test public void testQueryAll2() { Mockito.when(repository.findAll()).thenReturn(null); Response result = configServiceImpl.queryAll(headers); Assert.assertEquals(new Response<>(0, "No content", null), result); } |
### Question:
ConfigController { @GetMapping(path = "/welcome") public String home(@RequestHeader HttpHeaders headers) { return "Welcome to [ Config Service ] !"; } @GetMapping(path = "/welcome") String home(@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping(value = "/configs") HttpEntity queryAll(@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @PostMapping(value = "/configs") HttpEntity<?> createConfig(@RequestBody Config info, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @PutMapping(value = "/configs") HttpEntity updateConfig(@RequestBody Config info, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @DeleteMapping(value = "/configs/{configName}") HttpEntity deleteConfig(@PathVariable String configName, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping(value = "/configs/{configName}") HttpEntity retrieve(@PathVariable String configName, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testHome() throws Exception { mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/configservice/welcome")) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().string("Welcome to [ Config Service ] !")); } |
### Question:
ConfigController { @CrossOrigin(origins = "*") @GetMapping(value = "/configs") public HttpEntity queryAll(@RequestHeader HttpHeaders headers) { return ok(configService.queryAll(headers)); } @GetMapping(path = "/welcome") String home(@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping(value = "/configs") HttpEntity queryAll(@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @PostMapping(value = "/configs") HttpEntity<?> createConfig(@RequestBody Config info, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @PutMapping(value = "/configs") HttpEntity updateConfig(@RequestBody Config info, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @DeleteMapping(value = "/configs/{configName}") HttpEntity deleteConfig(@PathVariable String configName, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping(value = "/configs/{configName}") HttpEntity retrieve(@PathVariable String configName, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testQueryAll() throws Exception { Mockito.when(configService.queryAll(Mockito.any(HttpHeaders.class))).thenReturn(response); String result = mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/configservice/configs")) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
ConfigController { @CrossOrigin(origins = "*") @PostMapping(value = "/configs") public HttpEntity<?> createConfig(@RequestBody Config info, @RequestHeader HttpHeaders headers) { return new ResponseEntity<>(configService.create(info, headers), HttpStatus.CREATED); } @GetMapping(path = "/welcome") String home(@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping(value = "/configs") HttpEntity queryAll(@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @PostMapping(value = "/configs") HttpEntity<?> createConfig(@RequestBody Config info, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @PutMapping(value = "/configs") HttpEntity updateConfig(@RequestBody Config info, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @DeleteMapping(value = "/configs/{configName}") HttpEntity deleteConfig(@PathVariable String configName, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping(value = "/configs/{configName}") HttpEntity retrieve(@PathVariable String configName, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testCreateConfig() throws Exception { Config info = new Config(); Mockito.when(configService.create(Mockito.any(Config.class), Mockito.any(HttpHeaders.class))).thenReturn(response); String requestJson = JSONObject.toJSONString(info); String result = mockMvc.perform(MockMvcRequestBuilders.post("/api/v1/configservice/configs").contentType(MediaType.APPLICATION_JSON).content(requestJson)) .andExpect(MockMvcResultMatchers.status().isCreated()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
ConfigController { @CrossOrigin(origins = "*") @PutMapping(value = "/configs") public HttpEntity updateConfig(@RequestBody Config info, @RequestHeader HttpHeaders headers) { return ok(configService.update(info, headers)); } @GetMapping(path = "/welcome") String home(@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping(value = "/configs") HttpEntity queryAll(@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @PostMapping(value = "/configs") HttpEntity<?> createConfig(@RequestBody Config info, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @PutMapping(value = "/configs") HttpEntity updateConfig(@RequestBody Config info, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @DeleteMapping(value = "/configs/{configName}") HttpEntity deleteConfig(@PathVariable String configName, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping(value = "/configs/{configName}") HttpEntity retrieve(@PathVariable String configName, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testUpdateConfig() throws Exception { Config info = new Config(); Mockito.when(configService.update(Mockito.any(Config.class), Mockito.any(HttpHeaders.class))).thenReturn(response); String requestJson = JSONObject.toJSONString(info); String result = mockMvc.perform(MockMvcRequestBuilders.put("/api/v1/configservice/configs").contentType(MediaType.APPLICATION_JSON).content(requestJson)) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
ConfigController { @CrossOrigin(origins = "*") @DeleteMapping(value = "/configs/{configName}") public HttpEntity deleteConfig(@PathVariable String configName, @RequestHeader HttpHeaders headers) { return ok(configService.delete(configName, headers)); } @GetMapping(path = "/welcome") String home(@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping(value = "/configs") HttpEntity queryAll(@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @PostMapping(value = "/configs") HttpEntity<?> createConfig(@RequestBody Config info, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @PutMapping(value = "/configs") HttpEntity updateConfig(@RequestBody Config info, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @DeleteMapping(value = "/configs/{configName}") HttpEntity deleteConfig(@PathVariable String configName, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping(value = "/configs/{configName}") HttpEntity retrieve(@PathVariable String configName, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testDeleteConfig() throws Exception { Mockito.when(configService.delete(Mockito.anyString(), Mockito.any(HttpHeaders.class))).thenReturn(response); String result = mockMvc.perform(MockMvcRequestBuilders.delete("/api/v1/configservice/configs/config_name")) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
ConfigController { @CrossOrigin(origins = "*") @GetMapping(value = "/configs/{configName}") public HttpEntity retrieve(@PathVariable String configName, @RequestHeader HttpHeaders headers) { return ok(configService.query(configName, headers)); } @GetMapping(path = "/welcome") String home(@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping(value = "/configs") HttpEntity queryAll(@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @PostMapping(value = "/configs") HttpEntity<?> createConfig(@RequestBody Config info, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @PutMapping(value = "/configs") HttpEntity updateConfig(@RequestBody Config info, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @DeleteMapping(value = "/configs/{configName}") HttpEntity deleteConfig(@PathVariable String configName, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping(value = "/configs/{configName}") HttpEntity retrieve(@PathVariable String configName, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testRetrieve() throws Exception { Mockito.when(configService.query(Mockito.anyString(), Mockito.any(HttpHeaders.class))).thenReturn(response); String result = mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/configservice/configs/config_name")) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
AssuranceServiceImpl implements AssuranceService { @Override public Response findAssuranceById(UUID id, HttpHeaders headers) { Assurance assurance = assuranceRepository.findById(id); if (assurance == null) { return new Response<>(0, "No Conotent by this id", null); } else { return new Response<>(1, "Find Assurace Success", assurance); } } @Override Response findAssuranceById(UUID id, HttpHeaders headers); @Override Response findAssuranceByOrderId(UUID orderId, HttpHeaders headers); @Override Response create(int typeIndex, String orderId, HttpHeaders headers); @Override Response deleteById(UUID assuranceId, HttpHeaders headers); @Override Response deleteByOrderId(UUID orderId, HttpHeaders headers); @Override Response modify(String assuranceId, String orderId, int typeIndex, HttpHeaders headers); @Override Response getAllAssurances(HttpHeaders headers); @Override Response getAllAssuranceTypes(HttpHeaders headers); }### Answer:
@Test public void testFindAssuranceById1() { UUID id = UUID.randomUUID(); Mockito.when(assuranceRepository.findById(id)).thenReturn(null); Response result = assuranceServiceImpl.findAssuranceById(id, headers); Assert.assertEquals(new Response<>(0, "No Conotent by this id", null), result); }
@Test public void testFindAssuranceById2() { UUID id = UUID.randomUUID(); Assurance assurance = new Assurance(id, null, null); Mockito.when(assuranceRepository.findById(id)).thenReturn(assurance); Response result = assuranceServiceImpl.findAssuranceById(id, headers); Assert.assertEquals(new Response<>(1, "Find Assurace Success", assurance), result); } |
### Question:
AssuranceServiceImpl implements AssuranceService { @Override public Response findAssuranceByOrderId(UUID orderId, HttpHeaders headers) { Assurance assurance = assuranceRepository.findByOrderId(orderId); if (assurance == null) { return new Response<>(0, "No Content by this orderId", null); } else { return new Response<>(1, "Find Assurace Success", assurance); } } @Override Response findAssuranceById(UUID id, HttpHeaders headers); @Override Response findAssuranceByOrderId(UUID orderId, HttpHeaders headers); @Override Response create(int typeIndex, String orderId, HttpHeaders headers); @Override Response deleteById(UUID assuranceId, HttpHeaders headers); @Override Response deleteByOrderId(UUID orderId, HttpHeaders headers); @Override Response modify(String assuranceId, String orderId, int typeIndex, HttpHeaders headers); @Override Response getAllAssurances(HttpHeaders headers); @Override Response getAllAssuranceTypes(HttpHeaders headers); }### Answer:
@Test public void testFindAssuranceByOrderId1() { UUID orderId = UUID.randomUUID(); Mockito.when(assuranceRepository.findByOrderId(orderId)).thenReturn(null); Response result = assuranceServiceImpl.findAssuranceByOrderId(orderId, headers); Assert.assertEquals(new Response<>(0, "No Content by this orderId", null), result); }
@Test public void testFindAssuranceByOrderId2() { UUID orderId = UUID.randomUUID(); Assurance assurance = new Assurance(null, orderId, null); Mockito.when(assuranceRepository.findByOrderId(orderId)).thenReturn(assurance); Response result = assuranceServiceImpl.findAssuranceByOrderId(orderId, headers); Assert.assertEquals(new Response<>(1, "Find Assurace Success", assurance), result); } |
### Question:
ConsignServiceImpl implements ConsignService { @Override public Response queryByAccountId(UUID accountId, HttpHeaders headers) { List<ConsignRecord> consignRecords = repository.findByAccountId(accountId); if (consignRecords != null && !consignRecords.isEmpty()) { return new Response<>(1, "Find consign by account id success", consignRecords); }else { return new Response<>(0, "No Content according to accountId", null); } } @Override Response insertConsignRecord(Consign consignRequest, HttpHeaders headers); @Override Response updateConsignRecord(Consign consignRequest, HttpHeaders headers); @Override Response queryByAccountId(UUID accountId, HttpHeaders headers); @Override Response queryByOrderId(UUID orderId, HttpHeaders headers); @Override Response queryByConsignee(String consignee, HttpHeaders headers); }### Answer:
@Test public void testQueryByAccountId1() { UUID accountId = UUID.randomUUID(); ArrayList<ConsignRecord> consignRecords = new ArrayList<>(); consignRecords.add(new ConsignRecord()); Mockito.when(repository.findByAccountId(Mockito.any(UUID.class))).thenReturn(consignRecords); Response result = consignServiceImpl.queryByAccountId(accountId, headers); Assert.assertEquals(new Response<>(1, "Find consign by account id success", consignRecords), result); }
@Test public void testQueryByAccountId2() { UUID accountId = UUID.randomUUID(); Mockito.when(repository.findByAccountId(Mockito.any(UUID.class))).thenReturn(null); Response result = consignServiceImpl.queryByAccountId(accountId, headers); Assert.assertEquals(new Response<>(0, "No Content according to accountId", null), result); } |
### Question:
AssuranceServiceImpl implements AssuranceService { @Override public Response getAllAssuranceTypes(HttpHeaders headers) { List<AssuranceTypeBean> atlist = new ArrayList<>(); for (AssuranceType at : AssuranceType.values()) { AssuranceTypeBean atb = new AssuranceTypeBean(); atb.setIndex(at.getIndex()); atb.setName(at.getName()); atb.setPrice(at.getPrice()); atlist.add(atb); } if (!atlist.isEmpty()) { return new Response<>(1, "Find All Assurance", atlist); } else { return new Response<>(0, "Assurance is Empty", null); } } @Override Response findAssuranceById(UUID id, HttpHeaders headers); @Override Response findAssuranceByOrderId(UUID orderId, HttpHeaders headers); @Override Response create(int typeIndex, String orderId, HttpHeaders headers); @Override Response deleteById(UUID assuranceId, HttpHeaders headers); @Override Response deleteByOrderId(UUID orderId, HttpHeaders headers); @Override Response modify(String assuranceId, String orderId, int typeIndex, HttpHeaders headers); @Override Response getAllAssurances(HttpHeaders headers); @Override Response getAllAssuranceTypes(HttpHeaders headers); }### Answer:
@Test public void testGetAllAssuranceTypes() { List<AssuranceTypeBean> assuranceTypeBeanList = new ArrayList<>(); AssuranceTypeBean assuranceTypeBean = new AssuranceTypeBean(1, "Traffic Accident Assurance", 3.0); assuranceTypeBeanList.add(assuranceTypeBean); Response result = assuranceServiceImpl.getAllAssuranceTypes(headers); Assert.assertEquals(new Response<>(1, "Find All Assurance", assuranceTypeBeanList), result); } |
### Question:
SecurityServiceImpl implements SecurityService { @Override public Response findAllSecurityConfig(HttpHeaders headers) { ArrayList<SecurityConfig> securityConfigs = securityRepository.findAll(); if (securityConfigs != null && !securityConfigs.isEmpty()) { return new Response<>(1, success, securityConfigs); } return new Response<>(0, "No Content", null); } @Override Response findAllSecurityConfig(HttpHeaders headers); @Override Response addNewSecurityConfig(SecurityConfig info, HttpHeaders headers); @Override Response modifySecurityConfig(SecurityConfig info, HttpHeaders headers); @Override Response deleteSecurityConfig(String id, HttpHeaders headers); @Override Response check(String accountId, HttpHeaders headers); }### Answer:
@Test public void testFindAllSecurityConfig1() { ArrayList<SecurityConfig> securityConfigs = new ArrayList<>(); securityConfigs.add(new SecurityConfig()); Mockito.when(securityRepository.findAll()).thenReturn(securityConfigs); Response result = securityServiceImpl.findAllSecurityConfig(headers); Assert.assertEquals(new Response<>(1, "Success", securityConfigs), result); }
@Test public void testFindAllSecurityConfig2() { Mockito.when(securityRepository.findAll()).thenReturn(null); Response result = securityServiceImpl.findAllSecurityConfig(headers); Assert.assertEquals(new Response<>(0, "No Content", null), result); } |
### Question:
SecurityServiceImpl implements SecurityService { @Override public Response addNewSecurityConfig(SecurityConfig info, HttpHeaders headers) { SecurityConfig sc = securityRepository.findByName(info.getName()); if (sc != null) { return new Response<>(0, "Security Config Already Exist", null); } else { SecurityConfig config = new SecurityConfig(); config.setId(UUID.randomUUID()); config.setName(info.getName()); config.setValue(info.getValue()); config.setDescription(info.getDescription()); securityRepository.save(config); return new Response<>(1, success, config); } } @Override Response findAllSecurityConfig(HttpHeaders headers); @Override Response addNewSecurityConfig(SecurityConfig info, HttpHeaders headers); @Override Response modifySecurityConfig(SecurityConfig info, HttpHeaders headers); @Override Response deleteSecurityConfig(String id, HttpHeaders headers); @Override Response check(String accountId, HttpHeaders headers); }### Answer:
@Test public void testAddNewSecurityConfig1() { SecurityConfig sc = new SecurityConfig(); Mockito.when(securityRepository.findByName(Mockito.anyString())).thenReturn(sc); Response result = securityServiceImpl.addNewSecurityConfig(sc, headers); Assert.assertEquals(new Response<>(0, "Security Config Already Exist", null), result); }
@Test public void testAddNewSecurityConfig2() { SecurityConfig sc = new SecurityConfig(); Mockito.when(securityRepository.findByName(Mockito.anyString())).thenReturn(null); Mockito.when(securityRepository.save(Mockito.any(SecurityConfig.class))).thenReturn(null); Response result = securityServiceImpl.addNewSecurityConfig(sc, headers); Assert.assertEquals("Success", result.getMsg()); } |
### Question:
SecurityServiceImpl implements SecurityService { @Override public Response modifySecurityConfig(SecurityConfig info, HttpHeaders headers) { SecurityConfig sc = securityRepository.findById(info.getId()); if (sc == null) { return new Response<>(0, "Security Config Not Exist", null); } else { sc.setName(info.getName()); sc.setValue(info.getValue()); sc.setDescription(info.getDescription()); securityRepository.save(sc); return new Response<>(1, success, sc); } } @Override Response findAllSecurityConfig(HttpHeaders headers); @Override Response addNewSecurityConfig(SecurityConfig info, HttpHeaders headers); @Override Response modifySecurityConfig(SecurityConfig info, HttpHeaders headers); @Override Response deleteSecurityConfig(String id, HttpHeaders headers); @Override Response check(String accountId, HttpHeaders headers); }### Answer:
@Test public void testModifySecurityConfig1() { SecurityConfig sc = new SecurityConfig(); Mockito.when(securityRepository.findById(Mockito.any(UUID.class))).thenReturn(null); Response result = securityServiceImpl.modifySecurityConfig(sc, headers); Assert.assertEquals(new Response<>(0, "Security Config Not Exist", null), result); }
@Test public void testModifySecurityConfig2() { SecurityConfig sc = new SecurityConfig(); Mockito.when(securityRepository.findById(Mockito.any(UUID.class))).thenReturn(sc); Mockito.when(securityRepository.save(Mockito.any(SecurityConfig.class))).thenReturn(null); Response result = securityServiceImpl.modifySecurityConfig(sc, headers); Assert.assertEquals(new Response<>(1, "Success", sc), result); } |
### Question:
SecurityServiceImpl implements SecurityService { @Override public Response deleteSecurityConfig(String id, HttpHeaders headers) { securityRepository.deleteById(UUID.fromString(id)); SecurityConfig sc = securityRepository.findById(UUID.fromString(id)); if (sc == null) { return new Response<>(1, success, id); } else { return new Response<>(0, "Reason Not clear", id); } } @Override Response findAllSecurityConfig(HttpHeaders headers); @Override Response addNewSecurityConfig(SecurityConfig info, HttpHeaders headers); @Override Response modifySecurityConfig(SecurityConfig info, HttpHeaders headers); @Override Response deleteSecurityConfig(String id, HttpHeaders headers); @Override Response check(String accountId, HttpHeaders headers); }### Answer:
@Test public void testDeleteSecurityConfig1() { UUID id = UUID.randomUUID(); Mockito.doNothing().doThrow(new RuntimeException()).when(securityRepository).deleteById(Mockito.any(UUID.class)); Mockito.when(securityRepository.findById(Mockito.any(UUID.class))).thenReturn(null); Response result = securityServiceImpl.deleteSecurityConfig(id.toString(), headers); Assert.assertEquals(new Response<>(1, "Success", id.toString()), result); }
@Test public void testDeleteSecurityConfig2() { UUID id = UUID.randomUUID(); SecurityConfig sc = new SecurityConfig(); Mockito.doNothing().doThrow(new RuntimeException()).when(securityRepository).deleteById(Mockito.any(UUID.class)); Mockito.when(securityRepository.findById(Mockito.any(UUID.class))).thenReturn(sc); Response result = securityServiceImpl.deleteSecurityConfig(id.toString(), headers); Assert.assertEquals("Reason Not clear", result.getMsg()); } |
### Question:
ConsignServiceImpl implements ConsignService { @Override public Response queryByOrderId(UUID orderId, HttpHeaders headers) { ConsignRecord consignRecords = repository.findByOrderId(orderId); if (consignRecords != null ) { return new Response<>(1, "Find consign by order id success", consignRecords); }else { return new Response<>(0, "No Content according to order id", null); } } @Override Response insertConsignRecord(Consign consignRequest, HttpHeaders headers); @Override Response updateConsignRecord(Consign consignRequest, HttpHeaders headers); @Override Response queryByAccountId(UUID accountId, HttpHeaders headers); @Override Response queryByOrderId(UUID orderId, HttpHeaders headers); @Override Response queryByConsignee(String consignee, HttpHeaders headers); }### Answer:
@Test public void testQueryByOrderId1() { UUID orderId = UUID.randomUUID(); ConsignRecord consignRecords = new ConsignRecord(); Mockito.when(repository.findByOrderId(Mockito.any(UUID.class))).thenReturn(consignRecords); Response result = consignServiceImpl.queryByOrderId(orderId, headers); Assert.assertEquals(new Response<>(1, "Find consign by order id success", consignRecords), result); }
@Test public void testQueryByOrderId2() { UUID orderId = UUID.randomUUID(); Mockito.when(repository.findByOrderId(Mockito.any(UUID.class))).thenReturn(null); Response result = consignServiceImpl.queryByOrderId(orderId, headers); Assert.assertEquals(new Response<>(0, "No Content according to order id", null), result); } |
### Question:
SecurityController { @GetMapping(value = "/welcome") public String home(@RequestHeader HttpHeaders headers) { return "welcome to [Security Service]"; } @GetMapping(value = "/welcome") String home(@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping(path = "/securityConfigs") HttpEntity findAllSecurityConfig(@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @PostMapping(path = "/securityConfigs") HttpEntity create(@RequestBody SecurityConfig info, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @PutMapping(path = "/securityConfigs") HttpEntity update(@RequestBody SecurityConfig info, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @DeleteMapping(path = "/securityConfigs/{id}") HttpEntity delete(@PathVariable String id, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping(path = "/securityConfigs/{accountId}") HttpEntity check(@PathVariable String accountId, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testHome() throws Exception { mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/securityservice/welcome")) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().string("welcome to [Security Service]")); } |
### Question:
SecurityController { @CrossOrigin(origins = "*") @GetMapping(path = "/securityConfigs") public HttpEntity findAllSecurityConfig(@RequestHeader HttpHeaders headers) { SecurityController.LOGGER.info("[Security Service][Find All]"); return ok(securityService.findAllSecurityConfig(headers)); } @GetMapping(value = "/welcome") String home(@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping(path = "/securityConfigs") HttpEntity findAllSecurityConfig(@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @PostMapping(path = "/securityConfigs") HttpEntity create(@RequestBody SecurityConfig info, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @PutMapping(path = "/securityConfigs") HttpEntity update(@RequestBody SecurityConfig info, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @DeleteMapping(path = "/securityConfigs/{id}") HttpEntity delete(@PathVariable String id, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping(path = "/securityConfigs/{accountId}") HttpEntity check(@PathVariable String accountId, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testFindAllSecurityConfig() throws Exception { Mockito.when(securityService.findAllSecurityConfig(Mockito.any(HttpHeaders.class))).thenReturn(response); String result = mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/securityservice/securityConfigs")) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
SecurityController { @CrossOrigin(origins = "*") @PostMapping(path = "/securityConfigs") public HttpEntity create(@RequestBody SecurityConfig info, @RequestHeader HttpHeaders headers) { SecurityController.LOGGER.info("[Security Service][Create] Name: {}", info.getName()); return ok(securityService.addNewSecurityConfig(info, headers)); } @GetMapping(value = "/welcome") String home(@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping(path = "/securityConfigs") HttpEntity findAllSecurityConfig(@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @PostMapping(path = "/securityConfigs") HttpEntity create(@RequestBody SecurityConfig info, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @PutMapping(path = "/securityConfigs") HttpEntity update(@RequestBody SecurityConfig info, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @DeleteMapping(path = "/securityConfigs/{id}") HttpEntity delete(@PathVariable String id, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping(path = "/securityConfigs/{accountId}") HttpEntity check(@PathVariable String accountId, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testCreate() throws Exception { SecurityConfig info = new SecurityConfig(); Mockito.when(securityService.addNewSecurityConfig(Mockito.any(SecurityConfig.class), Mockito.any(HttpHeaders.class))).thenReturn(response); String requestJson = JSONObject.toJSONString(info); String result = mockMvc.perform(MockMvcRequestBuilders.post("/api/v1/securityservice/securityConfigs").contentType(MediaType.APPLICATION_JSON).content(requestJson)) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
SecurityController { @CrossOrigin(origins = "*") @PutMapping(path = "/securityConfigs") public HttpEntity update(@RequestBody SecurityConfig info, @RequestHeader HttpHeaders headers) { SecurityController.LOGGER.info("[Security Service][Update] Name: {}", info.getName()); return ok(securityService.modifySecurityConfig(info, headers)); } @GetMapping(value = "/welcome") String home(@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping(path = "/securityConfigs") HttpEntity findAllSecurityConfig(@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @PostMapping(path = "/securityConfigs") HttpEntity create(@RequestBody SecurityConfig info, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @PutMapping(path = "/securityConfigs") HttpEntity update(@RequestBody SecurityConfig info, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @DeleteMapping(path = "/securityConfigs/{id}") HttpEntity delete(@PathVariable String id, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping(path = "/securityConfigs/{accountId}") HttpEntity check(@PathVariable String accountId, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testUpdate() throws Exception { SecurityConfig info = new SecurityConfig(); Mockito.when(securityService.modifySecurityConfig(Mockito.any(SecurityConfig.class), Mockito.any(HttpHeaders.class))).thenReturn(response); String requestJson = JSONObject.toJSONString(info); String result = mockMvc.perform(MockMvcRequestBuilders.put("/api/v1/securityservice/securityConfigs").contentType(MediaType.APPLICATION_JSON).content(requestJson)) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
SecurityController { @CrossOrigin(origins = "*") @DeleteMapping(path = "/securityConfigs/{id}") public HttpEntity delete(@PathVariable String id, @RequestHeader HttpHeaders headers) { SecurityController.LOGGER.info("[Security Service][Delete] Id: {}", id); return ok(securityService.deleteSecurityConfig(id, headers)); } @GetMapping(value = "/welcome") String home(@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping(path = "/securityConfigs") HttpEntity findAllSecurityConfig(@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @PostMapping(path = "/securityConfigs") HttpEntity create(@RequestBody SecurityConfig info, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @PutMapping(path = "/securityConfigs") HttpEntity update(@RequestBody SecurityConfig info, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @DeleteMapping(path = "/securityConfigs/{id}") HttpEntity delete(@PathVariable String id, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping(path = "/securityConfigs/{accountId}") HttpEntity check(@PathVariable String accountId, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testDelete() throws Exception { Mockito.when(securityService.deleteSecurityConfig(Mockito.anyString(), Mockito.any(HttpHeaders.class))).thenReturn(response); String result = mockMvc.perform(MockMvcRequestBuilders.delete("/api/v1/securityservice/securityConfigs/id")) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
SecurityController { @CrossOrigin(origins = "*") @GetMapping(path = "/securityConfigs/{accountId}") public HttpEntity check(@PathVariable String accountId, @RequestHeader HttpHeaders headers) { SecurityController.LOGGER.info("[Security Service][Check Security] Check Account Id: {}", accountId); return ok(securityService.check(accountId, headers)); } @GetMapping(value = "/welcome") String home(@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping(path = "/securityConfigs") HttpEntity findAllSecurityConfig(@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @PostMapping(path = "/securityConfigs") HttpEntity create(@RequestBody SecurityConfig info, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @PutMapping(path = "/securityConfigs") HttpEntity update(@RequestBody SecurityConfig info, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @DeleteMapping(path = "/securityConfigs/{id}") HttpEntity delete(@PathVariable String id, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping(path = "/securityConfigs/{accountId}") HttpEntity check(@PathVariable String accountId, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testCheck() throws Exception { Mockito.when(securityService.check(Mockito.anyString(), Mockito.any(HttpHeaders.class))).thenReturn(response); String result = mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/securityservice/securityConfigs/account_id")) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
PaymentServiceImpl implements PaymentService { @Override public Response pay(Payment info, HttpHeaders headers){ if(paymentRepository.findByOrderId(info.getOrderId()) == null){ Payment payment = new Payment(); payment.setOrderId(info.getOrderId()); payment.setPrice(info.getPrice()); payment.setUserId(info.getUserId()); paymentRepository.save(payment); return new Response<>(1, "Pay Success", null); }else{ return new Response<>(0, "Pay Failed, order not found with order id" +info.getOrderId(), null); } } @Override Response pay(Payment info, HttpHeaders headers); @Override Response addMoney(Payment info, HttpHeaders headers); @Override Response query(HttpHeaders headers); @Override void initPayment(Payment payment, HttpHeaders headers); }### Answer:
@Test public void testPay1() { Payment info = new Payment(); Mockito.when(paymentRepository.findByOrderId(Mockito.anyString())).thenReturn(null); Mockito.when(paymentRepository.save(Mockito.any(Payment.class))).thenReturn(null); Response result = paymentServiceImpl.pay(info, headers); Assert.assertEquals(new Response<>(1, "Pay Success", null), result); }
@Test public void testPay2() { Payment info = new Payment(); Mockito.when(paymentRepository.findByOrderId(Mockito.anyString())).thenReturn(info); Response result = paymentServiceImpl.pay(info, headers); Assert.assertEquals(new Response<>(0, "Pay Failed, order not found with order id", null), result); } |
### Question:
PaymentServiceImpl implements PaymentService { @Override public Response addMoney(Payment info, HttpHeaders headers){ Money addMoney = new Money(); addMoney.setUserId(info.getUserId()); addMoney.setMoney(info.getPrice()); addMoneyRepository.save(addMoney); return new Response<>(1,"Add Money Success", addMoney); } @Override Response pay(Payment info, HttpHeaders headers); @Override Response addMoney(Payment info, HttpHeaders headers); @Override Response query(HttpHeaders headers); @Override void initPayment(Payment payment, HttpHeaders headers); }### Answer:
@Test public void testAddMoney() { Payment info = new Payment(); Mockito.when(addMoneyRepository.save(Mockito.any(Money.class))).thenReturn(null); Response result = paymentServiceImpl.addMoney(info, headers); Assert.assertEquals(new Response<>(1,"Add Money Success", new Money("", "")), result); } |
### Question:
PaymentServiceImpl implements PaymentService { @Override public Response query(HttpHeaders headers){ List<Payment> payments = paymentRepository.findAll(); if(payments!= null && !payments.isEmpty()){ return new Response<>(1,"Query Success", payments); }else { return new Response<>(0, "No Content", null); } } @Override Response pay(Payment info, HttpHeaders headers); @Override Response addMoney(Payment info, HttpHeaders headers); @Override Response query(HttpHeaders headers); @Override void initPayment(Payment payment, HttpHeaders headers); }### Answer:
@Test public void testQuery1() { List<Payment> payments = new ArrayList<>(); payments.add(new Payment()); Mockito.when(paymentRepository.findAll()).thenReturn(payments); Response result = paymentServiceImpl.query(headers); Assert.assertEquals(new Response<>(1,"Query Success", payments), result); }
@Test public void testQuery2() { Mockito.when(paymentRepository.findAll()).thenReturn(null); Response result = paymentServiceImpl.query(headers); Assert.assertEquals(new Response<>(0, "No Content", null), result); } |
### Question:
PaymentServiceImpl implements PaymentService { @Override public void initPayment(Payment payment, HttpHeaders headers){ Payment paymentTemp = paymentRepository.findById(payment.getId()); if(paymentTemp == null){ paymentRepository.save(payment); }else{ PaymentServiceImpl.LOGGER.info("[Payment Service][Init Payment] Already Exists: {}", payment.getId()); } } @Override Response pay(Payment info, HttpHeaders headers); @Override Response addMoney(Payment info, HttpHeaders headers); @Override Response query(HttpHeaders headers); @Override void initPayment(Payment payment, HttpHeaders headers); }### Answer:
@Test public void testInitPayment1() { Payment payment = new Payment(); Mockito.when(paymentRepository.findById(Mockito.anyString())).thenReturn(null); Mockito.when(paymentRepository.save(Mockito.any(Payment.class))).thenReturn(null); paymentServiceImpl.initPayment(payment, headers); Mockito.verify(paymentRepository, Mockito.times(1)).save(Mockito.any(Payment.class)); }
@Test public void testInitPayment2() { Payment payment = new Payment(); Mockito.when(paymentRepository.findById(Mockito.anyString())).thenReturn(payment); Mockito.when(paymentRepository.save(Mockito.any(Payment.class))).thenReturn(null); paymentServiceImpl.initPayment(payment, headers); Mockito.verify(paymentRepository, Mockito.times(0)).save(Mockito.any(Payment.class)); } |
### Question:
PaymentController { @GetMapping(path = "/welcome") public String home() { return "Welcome to [ Payment Service ] !"; } @GetMapping(path = "/welcome") String home(); @PostMapping(path = "/payment") HttpEntity pay(@RequestBody Payment info, @RequestHeader HttpHeaders headers); @PostMapping(path = "/payment/money") HttpEntity addMoney(@RequestBody Payment info, @RequestHeader HttpHeaders headers); @GetMapping(path = "/payment") HttpEntity query(@RequestHeader HttpHeaders headers); }### Answer:
@Test public void testHome() throws Exception { mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/paymentservice/welcome")) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().string("Welcome to [ Payment Service ] !")); } |
### Question:
PaymentController { @PostMapping(path = "/payment") public HttpEntity pay(@RequestBody Payment info, @RequestHeader HttpHeaders headers) { return ok(service.pay(info, headers)); } @GetMapping(path = "/welcome") String home(); @PostMapping(path = "/payment") HttpEntity pay(@RequestBody Payment info, @RequestHeader HttpHeaders headers); @PostMapping(path = "/payment/money") HttpEntity addMoney(@RequestBody Payment info, @RequestHeader HttpHeaders headers); @GetMapping(path = "/payment") HttpEntity query(@RequestHeader HttpHeaders headers); }### Answer:
@Test public void testPay() throws Exception { Payment info = new Payment(); Mockito.when(service.pay(Mockito.any(Payment.class), Mockito.any(HttpHeaders.class))).thenReturn(response); String requestJson = JSONObject.toJSONString(info); String result = mockMvc.perform(MockMvcRequestBuilders.post("/api/v1/paymentservice/payment").contentType(MediaType.APPLICATION_JSON).content(requestJson)) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
PaymentController { @PostMapping(path = "/payment/money") public HttpEntity addMoney(@RequestBody Payment info, @RequestHeader HttpHeaders headers) { return ok(service.addMoney(info, headers)); } @GetMapping(path = "/welcome") String home(); @PostMapping(path = "/payment") HttpEntity pay(@RequestBody Payment info, @RequestHeader HttpHeaders headers); @PostMapping(path = "/payment/money") HttpEntity addMoney(@RequestBody Payment info, @RequestHeader HttpHeaders headers); @GetMapping(path = "/payment") HttpEntity query(@RequestHeader HttpHeaders headers); }### Answer:
@Test public void testAddMoney() throws Exception { Payment info = new Payment(); Mockito.when(service.addMoney(Mockito.any(Payment.class), Mockito.any(HttpHeaders.class))).thenReturn(response); String requestJson = JSONObject.toJSONString(info); String result = mockMvc.perform(MockMvcRequestBuilders.post("/api/v1/paymentservice/payment/money").contentType(MediaType.APPLICATION_JSON).content(requestJson)) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
PaymentController { @GetMapping(path = "/payment") public HttpEntity query(@RequestHeader HttpHeaders headers) { return ok(service.query(headers)); } @GetMapping(path = "/welcome") String home(); @PostMapping(path = "/payment") HttpEntity pay(@RequestBody Payment info, @RequestHeader HttpHeaders headers); @PostMapping(path = "/payment/money") HttpEntity addMoney(@RequestBody Payment info, @RequestHeader HttpHeaders headers); @GetMapping(path = "/payment") HttpEntity query(@RequestHeader HttpHeaders headers); }### Answer:
@Test public void testQuery() throws Exception { Mockito.when(service.query(Mockito.any(HttpHeaders.class))).thenReturn(response); String result = mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/paymentservice/payment")) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
TrainServiceImpl implements TrainService { @Override public boolean create(TrainType trainType, HttpHeaders headers) { boolean result = false; if (repository.findById(trainType.getId()) == null) { TrainType type = new TrainType(trainType.getId(), trainType.getEconomyClass(), trainType.getConfortClass()); type.setAverageSpeed(trainType.getAverageSpeed()); repository.save(type); result = true; } return result; } @Override boolean create(TrainType trainType, HttpHeaders headers); @Override TrainType retrieve(String id, HttpHeaders headers); @Override boolean update(TrainType trainType, HttpHeaders headers); @Override boolean delete(String id, HttpHeaders headers); @Override List<TrainType> query(HttpHeaders headers); }### Answer:
@Test public void testCreate1() { TrainType trainType = new TrainType(); Mockito.when(repository.findById(Mockito.anyString())).thenReturn(null); Mockito.when(repository.save(Mockito.any(TrainType.class))).thenReturn(null); boolean result = trainServiceImpl.create(trainType, headers); Assert.assertTrue(result); }
@Test public void testCreate2() { TrainType trainType = new TrainType(); Mockito.when(repository.findById(Mockito.anyString())).thenReturn(trainType); boolean result = trainServiceImpl.create(trainType, headers); Assert.assertFalse(result); } |
### Question:
ConsignServiceImpl implements ConsignService { @Override public Response queryByConsignee(String consignee, HttpHeaders headers) { List<ConsignRecord> consignRecords = repository.findByConsignee(consignee); if (consignRecords != null && !consignRecords.isEmpty()) { return new Response<>(1, "Find consign by consignee success", consignRecords); }else { return new Response<>(0, "No Content according to consignee", null); } } @Override Response insertConsignRecord(Consign consignRequest, HttpHeaders headers); @Override Response updateConsignRecord(Consign consignRequest, HttpHeaders headers); @Override Response queryByAccountId(UUID accountId, HttpHeaders headers); @Override Response queryByOrderId(UUID orderId, HttpHeaders headers); @Override Response queryByConsignee(String consignee, HttpHeaders headers); }### Answer:
@Test public void testQueryByConsignee1() { ArrayList<ConsignRecord> consignRecords = new ArrayList<>(); consignRecords.add(new ConsignRecord()); Mockito.when(repository.findByConsignee(Mockito.anyString())).thenReturn(consignRecords); Response result = consignServiceImpl.queryByConsignee("consignee", headers); Assert.assertEquals(new Response<>(1, "Find consign by consignee success", consignRecords), result); }
@Test public void testQueryByConsignee2() { Mockito.when(repository.findByConsignee(Mockito.anyString())).thenReturn(null); Response result = consignServiceImpl.queryByConsignee("consignee", headers); Assert.assertEquals(new Response<>(0, "No Content according to consignee", null), result); } |
### Question:
TrainServiceImpl implements TrainService { @Override public TrainType retrieve(String id, HttpHeaders headers) { if (repository.findById(id) == null) { return null; } else { return repository.findById(id); } } @Override boolean create(TrainType trainType, HttpHeaders headers); @Override TrainType retrieve(String id, HttpHeaders headers); @Override boolean update(TrainType trainType, HttpHeaders headers); @Override boolean delete(String id, HttpHeaders headers); @Override List<TrainType> query(HttpHeaders headers); }### Answer:
@Test public void testRetrieve1() { Mockito.when(repository.findById(Mockito.anyString())).thenReturn(null); TrainType result = trainServiceImpl.retrieve("id", headers); Assert.assertNull(result); }
@Test public void testRetrieve2() { TrainType trainType = new TrainType(); Mockito.when(repository.findById(Mockito.anyString())).thenReturn(trainType); TrainType result = trainServiceImpl.retrieve("id", headers); Assert.assertNotNull(result); } |
### Question:
TrainServiceImpl implements TrainService { @Override public boolean update(TrainType trainType, HttpHeaders headers) { boolean result = false; if (repository.findById(trainType.getId()) != null) { TrainType type = new TrainType(trainType.getId(), trainType.getEconomyClass(), trainType.getConfortClass()); type.setAverageSpeed(trainType.getAverageSpeed()); repository.save(type); result = true; } return result; } @Override boolean create(TrainType trainType, HttpHeaders headers); @Override TrainType retrieve(String id, HttpHeaders headers); @Override boolean update(TrainType trainType, HttpHeaders headers); @Override boolean delete(String id, HttpHeaders headers); @Override List<TrainType> query(HttpHeaders headers); }### Answer:
@Test public void testUpdate1() { TrainType trainType = new TrainType(); Mockito.when(repository.findById(Mockito.anyString())).thenReturn(trainType); Mockito.when(repository.save(Mockito.any(TrainType.class))).thenReturn(null); boolean result = trainServiceImpl.update(trainType, headers); Assert.assertTrue(result); }
@Test public void testUpdate2() { TrainType trainType = new TrainType(); Mockito.when(repository.findById(Mockito.anyString())).thenReturn(null); boolean result = trainServiceImpl.update(trainType, headers); Assert.assertFalse(result); } |
### Question:
TrainServiceImpl implements TrainService { @Override public boolean delete(String id, HttpHeaders headers) { boolean result = false; if (repository.findById(id) != null) { repository.deleteById(id); result = true; } return result; } @Override boolean create(TrainType trainType, HttpHeaders headers); @Override TrainType retrieve(String id, HttpHeaders headers); @Override boolean update(TrainType trainType, HttpHeaders headers); @Override boolean delete(String id, HttpHeaders headers); @Override List<TrainType> query(HttpHeaders headers); }### Answer:
@Test public void testDelete1() { TrainType trainType = new TrainType(); Mockito.when(repository.findById(Mockito.anyString())).thenReturn(trainType); Mockito.doNothing().doThrow(new RuntimeException()).when(repository).deleteById(Mockito.anyString()); boolean result = trainServiceImpl.delete("id", headers); Assert.assertTrue(result); }
@Test public void testDelete2() { Mockito.when(repository.findById(Mockito.anyString())).thenReturn(null); boolean result = trainServiceImpl.delete("id", headers); Assert.assertFalse(result); } |
### Question:
TrainServiceImpl implements TrainService { @Override public List<TrainType> query(HttpHeaders headers) { return repository.findAll(); } @Override boolean create(TrainType trainType, HttpHeaders headers); @Override TrainType retrieve(String id, HttpHeaders headers); @Override boolean update(TrainType trainType, HttpHeaders headers); @Override boolean delete(String id, HttpHeaders headers); @Override List<TrainType> query(HttpHeaders headers); }### Answer:
@Test public void testQuery() { Mockito.when(repository.findAll()).thenReturn(null); Assert.assertNull(trainServiceImpl.query(headers)); } |
### Question:
TrainController { @GetMapping(path = "/trains/welcome") public String home(@RequestHeader HttpHeaders headers) { return "Welcome to [ Train Service ] !"; } @GetMapping(path = "/trains/welcome") String home(@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @PostMapping(value = "/trains") HttpEntity create(@RequestBody TrainType trainType, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping(value = "/trains/{id}") HttpEntity retrieve(@PathVariable String id, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @PutMapping(value = "/trains") HttpEntity update(@RequestBody TrainType trainType, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @DeleteMapping(value = "/trains/{id}") HttpEntity delete(@PathVariable String id, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping(value = "/trains") HttpEntity query(@RequestHeader HttpHeaders headers); }### Answer:
@Test public void testHome() throws Exception { mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/trainservice/trains/welcome")) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().string("Welcome to [ Train Service ] !")); } |
### Question:
ConsignController { @GetMapping(path = "/welcome") public String home(@RequestHeader HttpHeaders headers) { return "Welcome to [ Consign Service ] !"; } @GetMapping(path = "/welcome") String home(@RequestHeader HttpHeaders headers); @PostMapping(value = "/consigns") HttpEntity insertConsign(@RequestBody Consign request,
@RequestHeader HttpHeaders headers); @PutMapping(value = "/consigns") HttpEntity updateConsign(@RequestBody Consign request, @RequestHeader HttpHeaders headers); @GetMapping(value = "/consigns/account/{id}") HttpEntity findByAccountId(@PathVariable String id, @RequestHeader HttpHeaders headers); @GetMapping(value = "/consigns/order/{id}") HttpEntity findByOrderId(@PathVariable String id, @RequestHeader HttpHeaders headers); @GetMapping(value = "/consigns/{consignee}") HttpEntity findByConsignee(@PathVariable String consignee, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testHome() throws Exception { mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/consignservice/welcome")) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().string("Welcome to [ Consign Service ] !")); } |
### Question:
TravelServiceImpl implements TravelService { @Override public Response getTripByRoute(ArrayList<String> routeIds, HttpHeaders headers) { ArrayList<ArrayList<Trip>> tripList = new ArrayList<>(); for (String routeId : routeIds) { ArrayList<Trip> tempTripList = repository.findByRouteId(routeId); if (tempTripList == null) { tempTripList = new ArrayList<>(); } tripList.add(tempTripList); } if (!tripList.isEmpty()) { return new Response<>(1, success, tripList); } else { return new Response<>(0, noContent, null); } } @Override Response create(TravelInfo info, HttpHeaders headers); @Override Response getRouteByTripId(String tripId, HttpHeaders headers); @Override Response getTrainTypeByTripId(String tripId, HttpHeaders headers); @Override Response getTripByRoute(ArrayList<String> routeIds, HttpHeaders headers); @Override Response retrieve(String tripId, HttpHeaders headers); @Override Response update(TravelInfo info, HttpHeaders headers); @Override Response delete(String tripId, HttpHeaders headers); @Override Response query(TripInfo info, HttpHeaders headers); @Override Response getTripAllDetailInfo(TripAllDetailInfo gtdi, HttpHeaders headers); @Override Response queryAll(HttpHeaders headers); @Override Response adminQueryAll(HttpHeaders headers); }### Answer:
@Test public void testGetTripByRoute1() { ArrayList<String> routeIds = new ArrayList<>(); Response result = travelServiceImpl.getTripByRoute(routeIds, headers); Assert.assertEquals(new Response<>(0, noCnontent, null), result); }
@Test public void testGetTripByRoute2() { ArrayList<String> routeIds = new ArrayList<>(); routeIds.add("route_id_1"); Mockito.when(repository.findByRouteId(Mockito.anyString())).thenReturn(null); Response result = travelServiceImpl.getTripByRoute(routeIds, headers); Assert.assertEquals(success, result.getMsg()); } |
### Question:
TravelServiceImpl implements TravelService { @Override public Response retrieve(String tripId, HttpHeaders headers) { TripId ti = new TripId(tripId); Trip trip = repository.findByTripId(ti); if (trip != null) { return new Response<>(1, "Search Trip Success by Trip Id " + tripId, trip); } else { return new Response<>(0, "No Content according to tripId" + tripId, null); } } @Override Response create(TravelInfo info, HttpHeaders headers); @Override Response getRouteByTripId(String tripId, HttpHeaders headers); @Override Response getTrainTypeByTripId(String tripId, HttpHeaders headers); @Override Response getTripByRoute(ArrayList<String> routeIds, HttpHeaders headers); @Override Response retrieve(String tripId, HttpHeaders headers); @Override Response update(TravelInfo info, HttpHeaders headers); @Override Response delete(String tripId, HttpHeaders headers); @Override Response query(TripInfo info, HttpHeaders headers); @Override Response getTripAllDetailInfo(TripAllDetailInfo gtdi, HttpHeaders headers); @Override Response queryAll(HttpHeaders headers); @Override Response adminQueryAll(HttpHeaders headers); }### Answer:
@Test public void testRetrieve1() { Trip trip = new Trip(); Mockito.when(repository.findByTripId(Mockito.any(TripId.class))).thenReturn(trip); Response result = travelServiceImpl.retrieve("trip_id_1", headers); Assert.assertEquals(new Response<>(1, "Search Trip Success by Trip Id trip_id_1", trip), result); }
@Test public void testRetrieve2() { Trip trip = new Trip(); Mockito.when(repository.findByTripId(Mockito.any(TripId.class))).thenReturn(trip); Response result = travelServiceImpl.retrieve("trip_id_1", headers); Assert.assertEquals(new Response<>(1, "Search Trip Success by Trip Id trip_id_1", trip), result); } |
### Question:
TravelServiceImpl implements TravelService { @Override public Response delete(String tripId, HttpHeaders headers) { TripId ti = new TripId(tripId); if (repository.findByTripId(ti) != null) { repository.deleteByTripId(ti); return new Response<>(1, "Delete trip:" + tripId + ".", tripId); } else { return new Response<>(0, "Trip " + tripId + " doesn't exist.", null); } } @Override Response create(TravelInfo info, HttpHeaders headers); @Override Response getRouteByTripId(String tripId, HttpHeaders headers); @Override Response getTrainTypeByTripId(String tripId, HttpHeaders headers); @Override Response getTripByRoute(ArrayList<String> routeIds, HttpHeaders headers); @Override Response retrieve(String tripId, HttpHeaders headers); @Override Response update(TravelInfo info, HttpHeaders headers); @Override Response delete(String tripId, HttpHeaders headers); @Override Response query(TripInfo info, HttpHeaders headers); @Override Response getTripAllDetailInfo(TripAllDetailInfo gtdi, HttpHeaders headers); @Override Response queryAll(HttpHeaders headers); @Override Response adminQueryAll(HttpHeaders headers); }### Answer:
@Test public void testDelete1() { Trip trip = new Trip(); Mockito.when(repository.findByTripId(Mockito.any(TripId.class))).thenReturn(trip); Mockito.doNothing().doThrow(new RuntimeException()).when(repository).deleteByTripId(Mockito.any(TripId.class)); Response result = travelServiceImpl.delete("trip_id_1", headers); Assert.assertEquals(new Response<>(1, "Delete trip:trip_id_1.", "trip_id_1"), result); }
@Test public void testDelete2() { Mockito.when(repository.findByTripId(Mockito.any(TripId.class))).thenReturn(null); Response result = travelServiceImpl.delete("trip_id_1", headers); Assert.assertEquals(new Response<>(0, "Trip trip_id_1 doesn't exist.", null), result); } |
### Question:
ConsignController { @PostMapping(value = "/consigns") public HttpEntity insertConsign(@RequestBody Consign request, @RequestHeader HttpHeaders headers) { return ok(service.insertConsignRecord(request, headers)); } @GetMapping(path = "/welcome") String home(@RequestHeader HttpHeaders headers); @PostMapping(value = "/consigns") HttpEntity insertConsign(@RequestBody Consign request,
@RequestHeader HttpHeaders headers); @PutMapping(value = "/consigns") HttpEntity updateConsign(@RequestBody Consign request, @RequestHeader HttpHeaders headers); @GetMapping(value = "/consigns/account/{id}") HttpEntity findByAccountId(@PathVariable String id, @RequestHeader HttpHeaders headers); @GetMapping(value = "/consigns/order/{id}") HttpEntity findByOrderId(@PathVariable String id, @RequestHeader HttpHeaders headers); @GetMapping(value = "/consigns/{consignee}") HttpEntity findByConsignee(@PathVariable String consignee, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testInsertConsign() throws Exception { Consign request = new Consign(); Mockito.when(service.insertConsignRecord(Mockito.any(Consign.class), Mockito.any(HttpHeaders.class))).thenReturn(response); String requestJson = JSONObject.toJSONString(request); String result = mockMvc.perform(MockMvcRequestBuilders.post("/api/v1/consignservice/consigns").contentType(MediaType.APPLICATION_JSON).content(requestJson)) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
TravelServiceImpl implements TravelService { @Override public Response queryAll(HttpHeaders headers) { List<Trip> tripList = repository.findAll(); if (tripList != null && !tripList.isEmpty()) { return new Response<>(1, success, tripList); } return new Response<>(0, noContent, null); } @Override Response create(TravelInfo info, HttpHeaders headers); @Override Response getRouteByTripId(String tripId, HttpHeaders headers); @Override Response getTrainTypeByTripId(String tripId, HttpHeaders headers); @Override Response getTripByRoute(ArrayList<String> routeIds, HttpHeaders headers); @Override Response retrieve(String tripId, HttpHeaders headers); @Override Response update(TravelInfo info, HttpHeaders headers); @Override Response delete(String tripId, HttpHeaders headers); @Override Response query(TripInfo info, HttpHeaders headers); @Override Response getTripAllDetailInfo(TripAllDetailInfo gtdi, HttpHeaders headers); @Override Response queryAll(HttpHeaders headers); @Override Response adminQueryAll(HttpHeaders headers); }### Answer:
@Test public void testQueryAll1() { ArrayList<Trip> tripList = new ArrayList<>(); tripList.add(new Trip()); Mockito.when(repository.findAll()).thenReturn(tripList); Response result = travelServiceImpl.queryAll(headers); Assert.assertEquals(new Response<>(1, success, tripList), result); }
@Test public void testQueryAll2() { Mockito.when(repository.findAll()).thenReturn(null); Response result = travelServiceImpl.queryAll(headers); Assert.assertEquals(new Response<>(0, noCnontent, null), result); } |
### Question:
ConsignController { @PutMapping(value = "/consigns") public HttpEntity updateConsign(@RequestBody Consign request, @RequestHeader HttpHeaders headers) { return ok(service.updateConsignRecord(request, headers)); } @GetMapping(path = "/welcome") String home(@RequestHeader HttpHeaders headers); @PostMapping(value = "/consigns") HttpEntity insertConsign(@RequestBody Consign request,
@RequestHeader HttpHeaders headers); @PutMapping(value = "/consigns") HttpEntity updateConsign(@RequestBody Consign request, @RequestHeader HttpHeaders headers); @GetMapping(value = "/consigns/account/{id}") HttpEntity findByAccountId(@PathVariable String id, @RequestHeader HttpHeaders headers); @GetMapping(value = "/consigns/order/{id}") HttpEntity findByOrderId(@PathVariable String id, @RequestHeader HttpHeaders headers); @GetMapping(value = "/consigns/{consignee}") HttpEntity findByConsignee(@PathVariable String consignee, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testUpdateConsign() throws Exception { Consign request = new Consign(); Mockito.when(service.updateConsignRecord(Mockito.any(Consign.class), Mockito.any(HttpHeaders.class))).thenReturn(response); String requestJson = JSONObject.toJSONString(request); String result = mockMvc.perform(MockMvcRequestBuilders.put("/api/v1/consignservice/consigns").contentType(MediaType.APPLICATION_JSON).content(requestJson)) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
FoodMapServiceImpl implements FoodMapService { @Override public Response createFoodStore(FoodStore fs, HttpHeaders headers) { FoodStore fsTemp = foodStoreRepository.findById(fs.getId()); if (fsTemp != null) { FoodMapServiceImpl.LOGGER.info("[Food Map Service][Init FoodStore] Already Exists Id: {}", fs.getId()); return new Response<>(0, "Already Exists Id", null); } else { foodStoreRepository.save(fs); return new Response<>(1, "Save Success", fs); } } @Override Response createFoodStore(FoodStore fs, HttpHeaders headers); @Override TrainFood createTrainFood(TrainFood tf, HttpHeaders headers); @Override Response listFoodStores(HttpHeaders headers); @Override Response listTrainFood(HttpHeaders headers); @Override Response listFoodStoresByStationId(String stationId, HttpHeaders headers); @Override Response listTrainFoodByTripId(String tripId, HttpHeaders headers); @Override Response getFoodStoresByStationIds(List<String> stationIds); }### Answer:
@Test public void testCreateFoodStore1() { FoodStore fs = new FoodStore(); Mockito.when(foodStoreRepository.findById(Mockito.any(UUID.class))).thenReturn(fs); Response result = foodMapServiceImpl.createFoodStore(fs, headers); Assert.assertEquals(new Response<>(0, "Already Exists Id", null), result); }
@Test public void testCreateFoodStore2() { FoodStore fs = new FoodStore(); Mockito.when(foodStoreRepository.findById(Mockito.any(UUID.class))).thenReturn(null); Mockito.when(foodStoreRepository.save(Mockito.any(FoodStore.class))).thenReturn(null); Response result = foodMapServiceImpl.createFoodStore(fs, headers); Assert.assertEquals(new Response<>(1, "Save Success", fs), result); } |
### Question:
ConsignController { @GetMapping(value = "/consigns/account/{id}") public HttpEntity findByAccountId(@PathVariable String id, @RequestHeader HttpHeaders headers) { UUID newid = UUID.fromString(id); return ok(service.queryByAccountId(newid, headers)); } @GetMapping(path = "/welcome") String home(@RequestHeader HttpHeaders headers); @PostMapping(value = "/consigns") HttpEntity insertConsign(@RequestBody Consign request,
@RequestHeader HttpHeaders headers); @PutMapping(value = "/consigns") HttpEntity updateConsign(@RequestBody Consign request, @RequestHeader HttpHeaders headers); @GetMapping(value = "/consigns/account/{id}") HttpEntity findByAccountId(@PathVariable String id, @RequestHeader HttpHeaders headers); @GetMapping(value = "/consigns/order/{id}") HttpEntity findByOrderId(@PathVariable String id, @RequestHeader HttpHeaders headers); @GetMapping(value = "/consigns/{consignee}") HttpEntity findByConsignee(@PathVariable String consignee, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testFindByAccountId() throws Exception { UUID id = UUID.randomUUID(); Mockito.when(service.queryByAccountId(Mockito.any(UUID.class), Mockito.any(HttpHeaders.class))).thenReturn(response); String result = mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/consignservice/consigns/account/" + id.toString())) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
FoodMapServiceImpl implements FoodMapService { @Override public TrainFood createTrainFood(TrainFood tf, HttpHeaders headers) { TrainFood tfTemp = trainFoodRepository.findById(tf.getId()); if (tfTemp != null) { FoodMapServiceImpl.LOGGER.info("[Food Map Service][Init TrainFood] Already Exists Id: {}", tf.getId()); } else { trainFoodRepository.save(tf); } return tf; } @Override Response createFoodStore(FoodStore fs, HttpHeaders headers); @Override TrainFood createTrainFood(TrainFood tf, HttpHeaders headers); @Override Response listFoodStores(HttpHeaders headers); @Override Response listTrainFood(HttpHeaders headers); @Override Response listFoodStoresByStationId(String stationId, HttpHeaders headers); @Override Response listTrainFoodByTripId(String tripId, HttpHeaders headers); @Override Response getFoodStoresByStationIds(List<String> stationIds); }### Answer:
@Test public void testCreateTrainFood1() { TrainFood tf = new TrainFood(); Mockito.when(trainFoodRepository.findById(Mockito.any(UUID.class))).thenReturn(tf); TrainFood result = foodMapServiceImpl.createTrainFood(tf, headers); Assert.assertEquals(tf, result); }
@Test public void testCreateTrainFood2() { TrainFood tf = new TrainFood(); Mockito.when(trainFoodRepository.findById(Mockito.any(UUID.class))).thenReturn(null); Mockito.when(trainFoodRepository.save(Mockito.any(TrainFood.class))).thenReturn(null); TrainFood result = foodMapServiceImpl.createTrainFood(tf, headers); Assert.assertEquals(tf, result); } |
### Question:
FoodMapServiceImpl implements FoodMapService { @Override public Response listFoodStores(HttpHeaders headers) { List<FoodStore> foodStores = foodStoreRepository.findAll(); if (foodStores != null && !foodStores.isEmpty()) { return new Response<>(1, success, foodStores); } else { return new Response<>(0, "Foodstore is empty", null); } } @Override Response createFoodStore(FoodStore fs, HttpHeaders headers); @Override TrainFood createTrainFood(TrainFood tf, HttpHeaders headers); @Override Response listFoodStores(HttpHeaders headers); @Override Response listTrainFood(HttpHeaders headers); @Override Response listFoodStoresByStationId(String stationId, HttpHeaders headers); @Override Response listTrainFoodByTripId(String tripId, HttpHeaders headers); @Override Response getFoodStoresByStationIds(List<String> stationIds); }### Answer:
@Test public void testListFoodStores1() { List<FoodStore> foodStores = new ArrayList<>(); foodStores.add(new FoodStore()); Mockito.when(foodStoreRepository.findAll()).thenReturn(foodStores); Response result = foodMapServiceImpl.listFoodStores(headers); Assert.assertEquals(new Response<>(1, "Success", foodStores), result); }
@Test public void testListFoodStores2() { Mockito.when(foodStoreRepository.findAll()).thenReturn(null); Response result = foodMapServiceImpl.listFoodStores(headers); Assert.assertEquals(new Response<>(0, "Foodstore is empty", null), result); } |
### Question:
FoodMapServiceImpl implements FoodMapService { @Override public Response listTrainFood(HttpHeaders headers) { List<TrainFood> trainFoodList = trainFoodRepository.findAll(); if (trainFoodList != null && !trainFoodList.isEmpty()) { return new Response<>(1, success, trainFoodList); } else { return new Response<>(0, noContent, null); } } @Override Response createFoodStore(FoodStore fs, HttpHeaders headers); @Override TrainFood createTrainFood(TrainFood tf, HttpHeaders headers); @Override Response listFoodStores(HttpHeaders headers); @Override Response listTrainFood(HttpHeaders headers); @Override Response listFoodStoresByStationId(String stationId, HttpHeaders headers); @Override Response listTrainFoodByTripId(String tripId, HttpHeaders headers); @Override Response getFoodStoresByStationIds(List<String> stationIds); }### Answer:
@Test public void testListTrainFood1() { List<TrainFood> trainFoodList = new ArrayList<>(); trainFoodList.add(new TrainFood()); Mockito.when(trainFoodRepository.findAll()).thenReturn(trainFoodList); Response result = foodMapServiceImpl.listTrainFood(headers); Assert.assertEquals(new Response<>(1, "Success", trainFoodList), result); }
@Test public void testListTrainFood2() { Mockito.when(trainFoodRepository.findAll()).thenReturn(null); Response result = foodMapServiceImpl.listTrainFood(headers); Assert.assertEquals(new Response<>(0, "No content", null), result); } |
### Question:
FoodMapServiceImpl implements FoodMapService { @Override public Response listFoodStoresByStationId(String stationId, HttpHeaders headers) { List<FoodStore> foodStoreList = foodStoreRepository.findByStationId(stationId); if (foodStoreList != null && !foodStoreList.isEmpty()) { return new Response<>(1, success, foodStoreList); } else { return new Response<>(0, "FoodStore is empty", null); } } @Override Response createFoodStore(FoodStore fs, HttpHeaders headers); @Override TrainFood createTrainFood(TrainFood tf, HttpHeaders headers); @Override Response listFoodStores(HttpHeaders headers); @Override Response listTrainFood(HttpHeaders headers); @Override Response listFoodStoresByStationId(String stationId, HttpHeaders headers); @Override Response listTrainFoodByTripId(String tripId, HttpHeaders headers); @Override Response getFoodStoresByStationIds(List<String> stationIds); }### Answer:
@Test public void testListFoodStoresByStationId1() { List<FoodStore> foodStoreList = new ArrayList<>(); foodStoreList.add(new FoodStore()); Mockito.when(foodStoreRepository.findByStationId(Mockito.anyString())).thenReturn(foodStoreList); Response result = foodMapServiceImpl.listFoodStoresByStationId("station_id", headers); Assert.assertEquals(new Response<>(1, "Success", foodStoreList), result); }
@Test public void testListFoodStoresByStationId2() { Mockito.when(foodStoreRepository.findByStationId(Mockito.anyString())).thenReturn(null); Response result = foodMapServiceImpl.listFoodStoresByStationId("station_id", headers); Assert.assertEquals(new Response<>(0, "FoodStore is empty", null), result); } |
### Question:
FoodMapServiceImpl implements FoodMapService { @Override public Response listTrainFoodByTripId(String tripId, HttpHeaders headers) { List<TrainFood> trainFoodList = trainFoodRepository.findByTripId(tripId); if (trainFoodList != null) { return new Response<>(1, success, trainFoodList); } else { return new Response<>(0, noContent, null); } } @Override Response createFoodStore(FoodStore fs, HttpHeaders headers); @Override TrainFood createTrainFood(TrainFood tf, HttpHeaders headers); @Override Response listFoodStores(HttpHeaders headers); @Override Response listTrainFood(HttpHeaders headers); @Override Response listFoodStoresByStationId(String stationId, HttpHeaders headers); @Override Response listTrainFoodByTripId(String tripId, HttpHeaders headers); @Override Response getFoodStoresByStationIds(List<String> stationIds); }### Answer:
@Test public void testListTrainFoodByTripId1() { List<TrainFood> trainFoodList = new ArrayList<>(); trainFoodList.add(new TrainFood()); Mockito.when(trainFoodRepository.findByTripId(Mockito.anyString())).thenReturn(trainFoodList); Response result = foodMapServiceImpl.listTrainFoodByTripId("trip_id", headers); Assert.assertEquals(new Response<>(1, "Success", trainFoodList), result); }
@Test public void testListTrainFoodByTripId2() { Mockito.when(trainFoodRepository.findByTripId(Mockito.anyString())).thenReturn(null); Response result = foodMapServiceImpl.listTrainFoodByTripId("trip_id", headers); Assert.assertEquals(new Response<>(0, "No content", null), result); } |
### Question:
ConsignController { @GetMapping(value = "/consigns/order/{id}") public HttpEntity findByOrderId(@PathVariable String id, @RequestHeader HttpHeaders headers) { UUID newid = UUID.fromString(id); return ok(service.queryByOrderId(newid, headers)); } @GetMapping(path = "/welcome") String home(@RequestHeader HttpHeaders headers); @PostMapping(value = "/consigns") HttpEntity insertConsign(@RequestBody Consign request,
@RequestHeader HttpHeaders headers); @PutMapping(value = "/consigns") HttpEntity updateConsign(@RequestBody Consign request, @RequestHeader HttpHeaders headers); @GetMapping(value = "/consigns/account/{id}") HttpEntity findByAccountId(@PathVariable String id, @RequestHeader HttpHeaders headers); @GetMapping(value = "/consigns/order/{id}") HttpEntity findByOrderId(@PathVariable String id, @RequestHeader HttpHeaders headers); @GetMapping(value = "/consigns/{consignee}") HttpEntity findByConsignee(@PathVariable String consignee, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testFindByOrderId() throws Exception { UUID id = UUID.randomUUID(); Mockito.when(service.queryByOrderId(Mockito.any(UUID.class), Mockito.any(HttpHeaders.class))).thenReturn(response); String result = mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/consignservice/consigns/order/" + id.toString())) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
FoodMapServiceImpl implements FoodMapService { @Override public Response getFoodStoresByStationIds(List<String> stationIds) { List<FoodStore> foodStoreList = foodStoreRepository.findByStationIdIn(stationIds); if (foodStoreList != null) { return new Response<>(1, success, foodStoreList); } else { return new Response<>(0, noContent, null); } } @Override Response createFoodStore(FoodStore fs, HttpHeaders headers); @Override TrainFood createTrainFood(TrainFood tf, HttpHeaders headers); @Override Response listFoodStores(HttpHeaders headers); @Override Response listTrainFood(HttpHeaders headers); @Override Response listFoodStoresByStationId(String stationId, HttpHeaders headers); @Override Response listTrainFoodByTripId(String tripId, HttpHeaders headers); @Override Response getFoodStoresByStationIds(List<String> stationIds); }### Answer:
@Test public void testGetFoodStoresByStationIds1() { List<String> stationIds = new ArrayList<>(); List<FoodStore> foodStoreList = new ArrayList<>(); foodStoreList.add(new FoodStore()); Mockito.when(foodStoreRepository.findByStationIdIn(Mockito.anyList())).thenReturn(foodStoreList); Response result = foodMapServiceImpl.getFoodStoresByStationIds(stationIds); Assert.assertEquals(new Response<>(1, "Success", foodStoreList), result); }
@Test public void testGetFoodStoresByStationIds2() { List<String> stationIds = new ArrayList<>(); Mockito.when(foodStoreRepository.findByStationIdIn(Mockito.anyList())).thenReturn(null); Response result = foodMapServiceImpl.getFoodStoresByStationIds(stationIds); Assert.assertEquals(new Response<>(0, "No content", null), result); } |
### Question:
TrainFoodController { @GetMapping(path = "/trainfoods/welcome") public String home() { return "Welcome to [ Train Food Service ] !"; } @GetMapping(path = "/trainfoods/welcome") String home(); @CrossOrigin(origins = "*") @GetMapping("/trainfoods") HttpEntity getAllTrainFood(@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping("/trainfoods/{tripId}") HttpEntity getTrainFoodOfTrip(@PathVariable String tripId, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testHome() throws Exception { mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/foodmapservice/trainfoods/welcome")) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().string("Welcome to [ Train Food Service ] !")); } |
### Question:
TrainFoodController { @CrossOrigin(origins = "*") @GetMapping("/trainfoods") public HttpEntity getAllTrainFood(@RequestHeader HttpHeaders headers) { TrainFoodController.LOGGER.info("[Food Map Service][Get All TrainFoods]"); return ok(foodMapService.listTrainFood(headers)); } @GetMapping(path = "/trainfoods/welcome") String home(); @CrossOrigin(origins = "*") @GetMapping("/trainfoods") HttpEntity getAllTrainFood(@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping("/trainfoods/{tripId}") HttpEntity getTrainFoodOfTrip(@PathVariable String tripId, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testGetAllTrainFood() throws Exception { Mockito.when(foodMapService.listTrainFood(Mockito.any(HttpHeaders.class))).thenReturn(response); String result = mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/foodmapservice/trainfoods")) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
TrainFoodController { @CrossOrigin(origins = "*") @GetMapping("/trainfoods/{tripId}") public HttpEntity getTrainFoodOfTrip(@PathVariable String tripId, @RequestHeader HttpHeaders headers) { TrainFoodController.LOGGER.info("[Food Map Service][Get TrainFoods By TripId]"); return ok(foodMapService.listTrainFoodByTripId(tripId, headers)); } @GetMapping(path = "/trainfoods/welcome") String home(); @CrossOrigin(origins = "*") @GetMapping("/trainfoods") HttpEntity getAllTrainFood(@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping("/trainfoods/{tripId}") HttpEntity getTrainFoodOfTrip(@PathVariable String tripId, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testGetTrainFoodOfTrip() throws Exception { Mockito.when(foodMapService.listTrainFoodByTripId(Mockito.anyString(), Mockito.any(HttpHeaders.class))).thenReturn(response); String result = mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/foodmapservice/trainfoods/trip_id")) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
FoodStoreController { @GetMapping(path = "/foodstores/welcome") public String home() { return "Welcome to [ Food store Service ] !"; } @GetMapping(path = "/foodstores/welcome") String home(); @CrossOrigin(origins = "*") @GetMapping("/foodstores") HttpEntity getAllFoodStores(@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping("/foodstores/{stationId}") HttpEntity getFoodStoresOfStation(@PathVariable String stationId, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @PostMapping("/foodstores") HttpEntity getFoodStoresByStationIds(@RequestBody List<String> stationIdList); }### Answer:
@Test public void testHome() throws Exception { mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/foodmapservice/foodstores/welcome")) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().string("Welcome to [ Food store Service ] !")); } |
### Question:
FoodStoreController { @CrossOrigin(origins = "*") @GetMapping("/foodstores") public HttpEntity getAllFoodStores(@RequestHeader HttpHeaders headers) { FoodStoreController.LOGGER.info("[Food Map Service][Get All FoodStores]"); return ok(foodMapService.listFoodStores(headers)); } @GetMapping(path = "/foodstores/welcome") String home(); @CrossOrigin(origins = "*") @GetMapping("/foodstores") HttpEntity getAllFoodStores(@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping("/foodstores/{stationId}") HttpEntity getFoodStoresOfStation(@PathVariable String stationId, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @PostMapping("/foodstores") HttpEntity getFoodStoresByStationIds(@RequestBody List<String> stationIdList); }### Answer:
@Test public void testGetAllFoodStores() throws Exception { Mockito.when(foodMapService.listFoodStores(Mockito.any(HttpHeaders.class))).thenReturn(response); String result = mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/foodmapservice/foodstores")) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
FoodStoreController { @CrossOrigin(origins = "*") @GetMapping("/foodstores/{stationId}") public HttpEntity getFoodStoresOfStation(@PathVariable String stationId, @RequestHeader HttpHeaders headers) { FoodStoreController.LOGGER.info("[Food Map Service][Get FoodStores By StationId]"); return ok(foodMapService.listFoodStoresByStationId(stationId, headers)); } @GetMapping(path = "/foodstores/welcome") String home(); @CrossOrigin(origins = "*") @GetMapping("/foodstores") HttpEntity getAllFoodStores(@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping("/foodstores/{stationId}") HttpEntity getFoodStoresOfStation(@PathVariable String stationId, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @PostMapping("/foodstores") HttpEntity getFoodStoresByStationIds(@RequestBody List<String> stationIdList); }### Answer:
@Test public void testGetFoodStoresOfStation() throws Exception { Mockito.when(foodMapService.listFoodStoresByStationId(Mockito.anyString(), Mockito.any(HttpHeaders.class))).thenReturn(response); String result = mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/foodmapservice/foodstores/station_id")) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
FoodStoreController { @CrossOrigin(origins = "*") @PostMapping("/foodstores") public HttpEntity getFoodStoresByStationIds(@RequestBody List<String> stationIdList) { return ok(foodMapService.getFoodStoresByStationIds(stationIdList)); } @GetMapping(path = "/foodstores/welcome") String home(); @CrossOrigin(origins = "*") @GetMapping("/foodstores") HttpEntity getAllFoodStores(@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping("/foodstores/{stationId}") HttpEntity getFoodStoresOfStation(@PathVariable String stationId, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @PostMapping("/foodstores") HttpEntity getFoodStoresByStationIds(@RequestBody List<String> stationIdList); }### Answer:
@Test public void testGetFoodStoresByStationIds() throws Exception { List<String> stationIdList = new ArrayList<>(); Mockito.when(foodMapService.getFoodStoresByStationIds(Mockito.anyList())).thenReturn(response); String requestJson = JSONObject.toJSONString(stationIdList); String result = mockMvc.perform(MockMvcRequestBuilders.post("/api/v1/foodmapservice/foodstores").contentType(MediaType.APPLICATION_JSON).content(requestJson)) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
VerifyCodeController { @GetMapping("/generate") public void imageCode(@RequestHeader HttpHeaders headers, HttpServletRequest request, HttpServletResponse response) throws IOException { OutputStream os = response.getOutputStream(); Map<String, Object> map = verifyCodeService.getImageCode(60, 20, os, request, response, headers); String simpleCaptcha = "simpleCaptcha"; request.getSession().setAttribute(simpleCaptcha, map.get("strEnsure").toString().toLowerCase()); request.getSession().setAttribute("codeTime", System.currentTimeMillis()); try { ImageIO.write((BufferedImage) map.get("image"), "JPEG", os); } catch (IOException e) { String error = "Can't generate verification code"; os.write(error.getBytes()); } } @GetMapping("/generate") void imageCode(@RequestHeader HttpHeaders headers,
HttpServletRequest request,
HttpServletResponse response); @GetMapping(value = "/verify/{verifyCode}") boolean verifyCode(@PathVariable String verifyCode, HttpServletRequest request,
HttpServletResponse response, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testImageCode() throws Exception { Map<String, Object> map = new HashMap<>(); BufferedImage image = new BufferedImage(60, 20, BufferedImage.TYPE_INT_RGB); map.put("strEnsure", "XYZ8"); map.put("image", image); Mockito.when(verifyCodeService.getImageCode(Mockito.anyInt(), Mockito.anyInt(), Mockito.any(OutputStream.class), Mockito.any(HttpServletRequest.class), Mockito.any(HttpServletResponse.class), Mockito.any(HttpHeaders.class))).thenReturn(map); mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/verifycode/generate")).andReturn(); Mockito.verify(verifyCodeService, Mockito.times(1)).getImageCode(Mockito.anyInt(), Mockito.anyInt(), Mockito.any(OutputStream.class), Mockito.any(HttpServletRequest.class), Mockito.any(HttpServletResponse.class), Mockito.any(HttpHeaders.class)); } |
### Question:
ConsignController { @GetMapping(value = "/consigns/{consignee}") public HttpEntity findByConsignee(@PathVariable String consignee, @RequestHeader HttpHeaders headers) { return ok(service.queryByConsignee(consignee, headers)); } @GetMapping(path = "/welcome") String home(@RequestHeader HttpHeaders headers); @PostMapping(value = "/consigns") HttpEntity insertConsign(@RequestBody Consign request,
@RequestHeader HttpHeaders headers); @PutMapping(value = "/consigns") HttpEntity updateConsign(@RequestBody Consign request, @RequestHeader HttpHeaders headers); @GetMapping(value = "/consigns/account/{id}") HttpEntity findByAccountId(@PathVariable String id, @RequestHeader HttpHeaders headers); @GetMapping(value = "/consigns/order/{id}") HttpEntity findByOrderId(@PathVariable String id, @RequestHeader HttpHeaders headers); @GetMapping(value = "/consigns/{consignee}") HttpEntity findByConsignee(@PathVariable String consignee, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testFindByConsignee() throws Exception { Mockito.when(service.queryByConsignee(Mockito.anyString(), Mockito.any(HttpHeaders.class))).thenReturn(response); String result = mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/consignservice/consigns/consignee")) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
VerifyCodeController { @GetMapping(value = "/verify/{verifyCode}") public boolean verifyCode(@PathVariable String verifyCode, HttpServletRequest request, HttpServletResponse response, @RequestHeader HttpHeaders headers) { LOGGER.info("receivedCode " + verifyCode); return verifyCodeService.verifyCode(request, response, verifyCode, headers); } @GetMapping("/generate") void imageCode(@RequestHeader HttpHeaders headers,
HttpServletRequest request,
HttpServletResponse response); @GetMapping(value = "/verify/{verifyCode}") boolean verifyCode(@PathVariable String verifyCode, HttpServletRequest request,
HttpServletResponse response, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testVerifyCode() throws Exception { Mockito.when(verifyCodeService.verifyCode(Mockito.any(HttpServletRequest.class), Mockito.any(HttpServletResponse.class), Mockito.anyString(), Mockito.any(HttpHeaders.class))).thenReturn(true); String result = mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/verifycode/verify/verifyCode")) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertTrue(JSONObject.parseObject(result, Boolean.class)); } |
### Question:
Travel2ServiceImpl implements Travel2Service { @Override public Response getTripByRoute(ArrayList<String> routeIds, HttpHeaders headers) { ArrayList<ArrayList<Trip>> tripList = new ArrayList<>(); for (String routeId : routeIds) { ArrayList<Trip> tempTripList = repository.findByRouteId(routeId); if (tempTripList == null) { tempTripList = new ArrayList<>(); } tripList.add(tempTripList); } if (!tripList.isEmpty()) { return new Response<>(1, success, tripList); } else { return new Response<>(0, noCnontent, null); } } @Override Response getRouteByTripId(String tripId, HttpHeaders headers); @Override Response getTrainTypeByTripId(String tripId, HttpHeaders headers); @Override Response getTripByRoute(ArrayList<String> routeIds, HttpHeaders headers); @Override Response create(TravelInfo info, HttpHeaders headers); @Override Response retrieve(String tripId, HttpHeaders headers); @Override Response update(TravelInfo info, HttpHeaders headers); @Override Response delete(String tripId, HttpHeaders headers); @Override Response query(TripInfo info, HttpHeaders headers); @Override Response getTripAllDetailInfo(TripAllDetailInfo gtdi, HttpHeaders headers); @Override Response queryAll(HttpHeaders headers); @Override Response adminQueryAll(HttpHeaders headers); }### Answer:
@Test public void testGetTripByRoute1() { ArrayList<String> routeIds = new ArrayList<>(); Response result = travel2ServiceImpl.getTripByRoute(routeIds, headers); Assert.assertEquals(new Response<>(0, noCnontent, null), result); }
@Test public void testGetTripByRoute2() { ArrayList<String> routeIds = new ArrayList<>(); routeIds.add("route_id_1"); Mockito.when(repository.findByRouteId(Mockito.anyString())).thenReturn(null); Response result = travel2ServiceImpl.getTripByRoute(routeIds, headers); Assert.assertEquals(success, result.getMsg()); } |
### Question:
Travel2ServiceImpl implements Travel2Service { @Override public Response retrieve(String tripId, HttpHeaders headers) { TripId ti = new TripId(tripId); Trip trip = repository.findByTripId(ti); if (trip != null) { return new Response<>(1, "Search Trip Success by Trip Id " + tripId, trip); } else { return new Response<>(0, "No Content according to tripId" + tripId, null); } } @Override Response getRouteByTripId(String tripId, HttpHeaders headers); @Override Response getTrainTypeByTripId(String tripId, HttpHeaders headers); @Override Response getTripByRoute(ArrayList<String> routeIds, HttpHeaders headers); @Override Response create(TravelInfo info, HttpHeaders headers); @Override Response retrieve(String tripId, HttpHeaders headers); @Override Response update(TravelInfo info, HttpHeaders headers); @Override Response delete(String tripId, HttpHeaders headers); @Override Response query(TripInfo info, HttpHeaders headers); @Override Response getTripAllDetailInfo(TripAllDetailInfo gtdi, HttpHeaders headers); @Override Response queryAll(HttpHeaders headers); @Override Response adminQueryAll(HttpHeaders headers); }### Answer:
@Test public void testRetrieve1() { Trip trip = new Trip(); Mockito.when(repository.findByTripId(Mockito.any(TripId.class))).thenReturn(trip); Response result = travel2ServiceImpl.retrieve("trip_id_1", headers); Assert.assertEquals(new Response<>(1, "Search Trip Success by Trip Id trip_id_1", trip), result); }
@Test public void testRetrieve2() { Trip trip = new Trip(); Mockito.when(repository.findByTripId(Mockito.any(TripId.class))).thenReturn(trip); Response result = travel2ServiceImpl.retrieve("trip_id_1", headers); Assert.assertEquals(new Response<>(1, "Search Trip Success by Trip Id trip_id_1", trip), result); } |
### Question:
StationServiceImpl implements StationService { @Override public Response create(Station station, HttpHeaders headers) { if (repository.findById(station.getId()) == null) { station.setStayTime(station.getStayTime()); repository.save(station); return new Response<>(1, "Create success", station); } return new Response<>(0, "Already exists", station); } @Override Response create(Station station, HttpHeaders headers); @Override boolean exist(String stationName, HttpHeaders headers); @Override Response update(Station info, HttpHeaders headers); @Override Response delete(Station info, HttpHeaders headers); @Override Response query(HttpHeaders headers); @Override Response queryForId(String stationName, HttpHeaders headers); @Override Response queryForIdBatch(List<String> nameList, HttpHeaders headers); @Override Response queryById(String stationId, HttpHeaders headers); @Override Response queryByIdBatch(List<String> idList, HttpHeaders headers); }### Answer:
@Test public void testCreate1() { Station station = new Station(); Mockito.when(repository.findById(Mockito.anyString())).thenReturn(null); Mockito.when(repository.save(Mockito.any(Station.class))).thenReturn(null); Response result = stationServiceImpl.create(station, headers); Assert.assertEquals(new Response<>(1, "Create success", station), result); }
@Test public void testCreate2() { Station station = new Station(); Mockito.when(repository.findById(Mockito.anyString())).thenReturn(station); Response result = stationServiceImpl.create(station, headers); Assert.assertEquals(new Response<>(0, "Already exists", station), result); } |
### Question:
InsidePaymentServiceImpl implements InsidePaymentService { @Override public Response addMoney(String userId, String money, HttpHeaders headers) { if (addMoneyRepository.findByUserId(userId) != null) { Money addMoney = new Money(); addMoney.setUserId(userId); addMoney.setMoney(money); addMoney.setType(MoneyType.A); addMoneyRepository.save(addMoney); return new Response<>(1, "Add Money Success", null); } else { return new Response<>(0, "Add Money Failed", null); } } @Override Response pay(PaymentInfo info, HttpHeaders headers); @Override Response createAccount(AccountInfo info, HttpHeaders headers); @Override Response addMoney(String userId, String money, HttpHeaders headers); @Override Response queryAccount(HttpHeaders headers); String queryAccount(String userId, HttpHeaders headers); @Override Response queryPayment(HttpHeaders headers); @Override Response drawBack(String userId, String money, HttpHeaders headers); @Override Response payDifference(PaymentInfo info, HttpHeaders headers); @Override Response queryAddMoney(HttpHeaders headers); @Override void initPayment(Payment payment, HttpHeaders headers); @Autowired
public AddMoneyRepository addMoneyRepository; @Autowired
public PaymentRepository paymentRepository; @Autowired
public RestTemplate restTemplate; }### Answer:
@Test public void testAddMoney1() { List<Money> list = new ArrayList<>(); Mockito.when(addMoneyRepository.findByUserId(Mockito.anyString())).thenReturn(list); Mockito.when(addMoneyRepository.save(Mockito.any(Money.class))).thenReturn(null); Response result = insidePaymentServiceImpl.addMoney("user_id", "money", headers); Assert.assertEquals(new Response<>(1, "Add Money Success", null), result); }
@Test public void testAddMoney2() { Mockito.when(addMoneyRepository.findByUserId(Mockito.anyString())).thenReturn(null); Response result = insidePaymentServiceImpl.addMoney("user_id", "money", headers); Assert.assertEquals(new Response<>(0, "Add Money Failed", null), result); } |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.