package de.fred4jupiter.fredbet.service;

import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import de.fred4jupiter.fredbet.AbstractMongoEmbeddedTest;
import de.fred4jupiter.fredbet.FredBetRole;
import de.fred4jupiter.fredbet.domain.AppUser;

public class UserServiceTest extends AbstractMongoEmbeddedTest {

	@Autowired
	private UserService userService;

	@Test
	public void avoidDuplicateUser() {
		userService.save(new AppUser("michael", "michael", FredBetRole.ROLE_USER));
		userService.save(new AppUser("michael", "michael", FredBetRole.ROLE_USER));
	}
}

@@ -122,16 +122,51 @@
 wired;%0A%0A
+import static org.junit.Assert.*;%0A%0A
 import d
@@ -211,24 +211,24 @@
 beddedTest;%0A
-
 import de.fr
@@ -305,16 +305,79 @@
 AppUser;
+%0Aimport de.fred4jupiter.fredbet.web.user.ChangePasswordCommand;
 %0A%0Apublic
@@ -604,16 +604,16 @@
 USER));%0A
-
 %09%09userSe
@@ -684,11 +684,1210 @@
 ER));%0A%09%7D
+%0A%0A%09@Test%0A%09public void changePassword() %7B%0A%09%09final String plainPassword = %22feuerstein%22;%0A%09%09final String plainNewPassword = %22wilma%22;%0A%09%09AppUser appUser = new AppUser(%22fred%22, plainPassword, FredBetRole.ROLE_USER);%0A%09%09userService.save(appUser);%0A%0A%09%09assertNotNull(appUser.getId());%0A%0A%09%09ChangePasswordCommand changePasswordCommand = new ChangePasswordCommand();%0A%09%09changePasswordCommand.setOldPassword(plainPassword);%0A%09%09changePasswordCommand.setNewPassword(plainNewPassword);%0A%09%09userService.changePassword(appUser, changePasswordCommand);%0A%09%7D%0A%0A%09@Test%0A%09public void changePasswordOldPasswordIsNotCorrect() %7B%0A%09%09final String plainPassword = %22hans%22;%0A%09%09final String plainNewPassword = %22mueller%22;%0A%09%09AppUser appUser = new AppUser(%22mini%22, plainPassword, FredBetRole.ROLE_USER);%0A%09%09userService.save(appUser);%0A%0A%09%09assertNotNull(appUser.getId());%0A%0A%09%09ChangePasswordCommand changePasswordCommand = new ChangePasswordCommand();%0A%09%09changePasswordCommand.setOldPassword(%22wrongOldPassword%22);%0A%09%09changePasswordCommand.setNewPassword(plainNewPassword);%0A%0A%09%09try %7B%0A%09%09%09userService.changePassword(appUser, changePasswordCommand);%0A%09%09%09fail(%22OldPasswordWrongException should be thrown%22);%0A%09%09%7D catch (OldPasswordWrongException e) %7B%0A%09%09%09// OK%0A%09%09%7D%0A%0A%09%7D
 %0A%7D%0A

update test