### Question:
AccountController { @RequestMapping(path = "/account/{id}", method = RequestMethod.GET) public ResponseEntity<Account> getAccountById(@PathVariable Long id) { if (!service.isAccountPresent(id)) { return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null); } return ResponseEntity.ok(service.getAccountById(id)); }  @RequestMapping(path = "/account/{id}", method = RequestMethod.GET) ResponseEntity<Account> getAccountById(@PathVariable Long id); @RequestMapping(path = "/accounts", method = RequestMethod.GET) ResponseEntity<List<Account>> getAccounts(); @RequestMapping(path = "/account", method = RequestMethod.POST) ResponseEntity<Account> addAccount(@RequestBody Account account); @RequestMapping(path = "/account/{id}", method = RequestMethod.PUT) ResponseEntity<Account> updateAccount(@PathVariable Long id, @RequestBody Account account); @RequestMapping(path = "/account/{id}", method = RequestMethod.DELETE) ResponseEntity<String> deleteAccount(@PathVariable Long id);  }### Answer:
@Test public void whenIdGivenIsPresentThenItShouldReturnAccount() { Account mockAccount = mock(Account.class); Long id = new Long(1); when(mockAccount.getId()).thenReturn(id); when(mockAccount.getName()).thenReturn("Sagar Jadhav"); when(service.getAccountById(id)).thenReturn(mockAccount); when(service.isAccountPresent(id)).thenReturn(true); ResponseEntity<Account> responseEntity = controller.getAccountById(id); assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); assertEquals(mockAccount, responseEntity.getBody()); }
@Test public void whenIdGivenIsNotPresentThenItShouldReturnResponseWithNotFoundStatusCode() { Long id = new Long(1); when(service.isAccountPresent(id)).thenReturn(false); ResponseEntity<Account> responseEntity = controller.getAccountById(id); assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode()); assertEquals(null, responseEntity.getBody()); }