### Question:
WhitelistEmailController { @RequestMapping(value = "/whitelist/subscribe", method = POST, consumes = APPLICATION_JSON_UTF8_VALUE, produces = APPLICATION_JSON_UTF8_VALUE) public ResponseEntity<?> saveWhiteListEmail(@Valid @RequestBody WhitelistEmailRequest whitelistEmailRequest) throws BaseException { try { WhitelistEmail whitelistEmail = this.whitelistEmailService.saveWhiteListEmail(whitelistEmailRequest.getEmail()); return new ResponseEntity<>(new WhitelistEmailResponse(whitelistEmail.getEmail(), whitelistEmail.getSubscriptionDate()), HttpStatus.OK); } catch (WhitelistEmailNotSavedException e) { throw new UnexpectedException(); } }  @RequestMapping(value = "/whitelist/subscribe", method = POST, consumes = APPLICATION_JSON_UTF8_VALUE, produces = APPLICATION_JSON_UTF8_VALUE) ResponseEntity<?> saveWhiteListEmail(@Valid @RequestBody WhitelistEmailRequest whitelistEmailRequest); @RequestMapping(value = "/whitelist/emails", method = GET, produces = APPLICATION_JSON_UTF8_VALUE) @ResponseStatus(HttpStatus.OK) @ResponseBody List<WhitelistEmail> getEmails();  }### Answer:
@Test public void testSubscribeEmail() throws Exception { when(mockWhitelistEmailService.saveWhiteListEmail(TEST_EMAIL)).thenReturn(new WhitelistEmail(TEST_EMAIL, TEST_DATE)); WhitelistEmailRequest request = new WhitelistEmailRequest(TEST_EMAIL); MvcResult mvcResult1 = this.mockMvc.perform(post(WHITELIST_SUBSCRIBE_ENDPOINT) .contentType(APPLICATION_JSON) .content(jsonWhitelistEmailRequest.write(request).getJson())) .andExpect(status().isOk()) .andDo(print()) .andReturn(); assertThat(mvcResult1.getResponse().getContentAsString()).isEqualTo( jsonWhitelistEmailResponse.write(new WhitelistEmailResponse(TEST_EMAIL, TEST_DATE)).getJson() ); }
@Test public void testSubscribeEmail_Database_Problem() throws Exception { when(mockWhitelistEmailService.saveWhiteListEmail(TEST_EMAIL)).thenThrow(new WhitelistEmailNotSavedException()); WhitelistEmailRequest request = new WhitelistEmailRequest(TEST_EMAIL); this.mockMvc.perform(post(WHITELIST_SUBSCRIBE_ENDPOINT) .contentType(APPLICATION_JSON) .content(jsonWhitelistEmailRequest.write(request).getJson())) .andExpect(status().isInternalServerError()) .andDo(print()); }