@Test
  public void testCreateCustomer() throws Exception {

    long now = System.currentTimeMillis();
    String f = "Joe", l = "Doe";

    String jsonOfJoeDoe =
        "{ \"signupDate\":" + now + ",\"firstName\":\"" + f + "\",\"lastName\":\"" + l + "\"}";

    MvcResult mvcResult =
        mockMvc
            .perform(
                post("/users/{userId}/customers", userId)
                    .accept(applicationJsonMediaType)
                    .content(jsonOfJoeDoe)
                    .contentType(this.applicationJsonMediaType))
            .andExpect(status().isCreated())
            .andExpect(content().contentType(this.applicationJsonMediaType))
            .andReturn();

    mockServer.verify();

    String locationUri = mvcResult.getResponse().getHeader("Location");
    Assert.assertTrue(locationUri.contains("/users/" + userId + "/customers/"));
  }
  @Test
  public void testWhenTheCodeIsDenied() throws Exception {
    mockUaaServer
        .expect(requestTo("http://uaa.example.com/uaa/password_resets"))
        .andExpect(method(POST))
        .andRespond(withBadRequest());

    emailResetPasswordService.forgotPassword(uriComponentsBuilder, "*****@*****.**");

    mockUaaServer.verify();

    Assert.assertEquals(0, smtpServer.getReceivedEmailSize());
  }
  @Test
  public void testChangingAPassword() throws Exception {
    mockUaaServer
        .expect(requestTo("http://uaa.example.com/uaa/password_change"))
        .andExpect(method(POST))
        .andExpect(jsonPath("$.code").value("secret_code"))
        .andExpect(jsonPath("$.new_password").value("new_secret"))
        .andRespond(withSuccess("userman", APPLICATION_JSON));

    String username = emailResetPasswordService.resetPassword("secret_code", "new_secret");

    mockUaaServer.verify();

    Assert.assertEquals("userman", username);
  }
  @Test
  public void testWhenAResetCodeIsReturnedByTheUaa() throws Exception {
    mockUaaServer
        .expect(requestTo("http://uaa.example.com/uaa/password_resets"))
        .andExpect(method(POST))
        .andRespond(withSuccess("the_secret_code", APPLICATION_JSON));

    emailResetPasswordService.forgotPassword(uriComponentsBuilder, "*****@*****.**");

    mockUaaServer.verify();

    Assert.assertEquals(1, smtpServer.getReceivedEmailSize());
    SmtpMessage message = (SmtpMessage) smtpServer.getReceivedEmail().next();
    Assert.assertEquals("*****@*****.**", message.getHeaderValue("To"));
    Assert.assertEquals(
        "Click the link to reset your password <a href=\"http://login.example.com/login/reset_password?code=the_secret_code&[email protected]\">Reset Password</a>",
        message.getBody());
  }