// Path: src/main/java/com/behase/relumin/exception/InvalidParameterException.java
// public class InvalidParameterException extends ApiException {
//     private static final long serialVersionUID = -6416726302671334601L;
// 
//     public InvalidParameterException(String message) {
//         super(Constants.ERR_CODE_INVALID_PARAMETER, String.format("Invalid parameter. %s", message), HttpStatus.BAD_REQUEST);
//     }
// }
// 
// Path: src/main/java/com/behase/relumin/model/LoginUser.java
// @Data
// @Builder
// @NoArgsConstructor
// public class LoginUser {
//     private String username;
//     private String displayName;
//     private String password;
//     private String role;
// 
//     public LoginUser(String username, String displayName, String rawPassword, String role) {
//         this.username = username;
//         this.displayName = displayName;
//         this.password = new StandardPasswordEncoder().encode(rawPassword);
//         this.role = Role.get(role).getAuthority();
//     }
// 
//     @JsonIgnore
//     public User getSpringUser() {
//         return new User(username, password, Lists.newArrayList(Role.get(role)));
//     }
// 
//     public void setRawPassword(String rawPassword) {
//         this.password = new StandardPasswordEncoder().encode(rawPassword);
//     }
// }
// 
// Path: src/main/java/com/behase/relumin/model/Role.java
// public class Role implements GrantedAuthority {
//     private static final long serialVersionUID = -4168971547041673977L;
// 
//     private String authority;
// 
//     private Role(String authority) {
//         this.authority = authority;
//     }
// 
//     @Override
//     public String getAuthority() {
//         return authority;
//     }
// 
//     public static final Role VIEWER = new Role("VIEWER");
//     public static final Role RELUMIN_ADMIN = new Role("RELUMIN_ADMIN");
// 
//     public static Role get(String role) {
//         switch (role) {
//             case "VIEWER":
//                 return VIEWER;
//             case "RELUMIN_ADMIN":
//                 return RELUMIN_ADMIN;
//             default:
//         }
//         throw new InvalidParameterException(String.format("'%s' is invalid role.", role));
//     }
// }
// 
// Path: src/main/java/com/behase/relumin/service/LoggingOperationService.java
// public interface LoggingOperationService {
//     void log(String operationName, Authentication authentication);
// 
//     void log(String operationName, Authentication authentication, String msg);
// 
//     void log(String operationName, Authentication authentication, String msg, Object... objects);
// }
// 
// Path: src/main/java/com/behase/relumin/service/UserService.java
// public interface UserService extends UserDetailsService {
//     LoginUser getUser(String username) throws Exception;
// 
//     List<LoginUser> getUsers() throws Exception;
// 
//     void addUser(String username, String displayName, String password, String role) throws Exception;
// 
//     void changePassword(String username, String oldPassword, String password) throws Exception;
// 
//     void updateUser(String username, String displayName, String role) throws Exception;
// 
//     void deleteUser(String username) throws Exception;
// }


import com.behase.relumin.exception.InvalidParameterException;
import com.behase.relumin.model.LoginUser;
import com.behase.relumin.model.Role;
import com.behase.relumin.service.LoggingOperationService;
import com.behase.relumin.service.UserService;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.security.core.Authentication;
import java.util.List;
import java.util.Map;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
        controller.updateMe(null, "");
    }

    @Test
    public void updateMe() throws Exception {
        doReturn(new LoginUser("username", "displayName", "rawPassword", Role.VIEWER.getAuthority())).when(userService).getUser(anyString());

        LoginUser result = controller.updateMe(mock(Authentication.class), "");
        log.info("result={}", result);
        assertThat(result.getUsername(), is("username"));
    }

    @Test
    public void changePassword_authentication_is_null_throw_exception() throws Exception {
        expectedEx.expect(InvalidParameterException.class);
        expectedEx.expectMessage(containsString("You are not loggedin."));

        controller.changePassword(null, "", "");
    }

    @Test
    public void changePassword() throws Exception {
        doReturn(new LoginUser("username", "displayName", "rawPassword", Role.VIEWER.getAuthority())).when(userService).getUser(anyString());

        LoginUser result = controller.changePassword(mock(Authentication.class), "", "");
        log.info("result={}", result);
        assertThat(result.getUsername(), is("username"));
    }

    @Test
// Path: src/main/java/com/behase/relumin/exception/InvalidParameterException.java
// public class InvalidParameterException extends ApiException {
//     private static final long serialVersionUID = -6416726302671334601L;
// 
//     public InvalidParameterException(String message) {
//         super(Constants.ERR_CODE_INVALID_PARAMETER, String.format("Invalid parameter. %s", message), HttpStatus.BAD_REQUEST);
//     }
// }
// 
// Path: src/main/java/com/behase/relumin/model/LoginUser.java
// @Data
// @Builder
// @NoArgsConstructor
// public class LoginUser {
//     private String username;
//     private String displayName;
//     private String password;
//     private String role;
// 
//     public LoginUser(String username, String displayName, String rawPassword, String role) {
//         this.username = username;
//         this.displayName = displayName;
//         this.password = new StandardPasswordEncoder().encode(rawPassword);
//         this.role = Role.get(role).getAuthority();
//     }
// 
//     @JsonIgnore
//     public User getSpringUser() {
//         return new User(username, password, Lists.newArrayList(Role.get(role)));
//     }
// 
//     public void setRawPassword(String rawPassword) {
//         this.password = new StandardPasswordEncoder().encode(rawPassword);
//     }
// }
// 
// Path: src/main/java/com/behase/relumin/model/Role.java
// public class Role implements GrantedAuthority {
//     private static final long serialVersionUID = -4168971547041673977L;
// 
//     private String authority;
// 
//     private Role(String authority) {
//         this.authority = authority;
//     }
// 
//     @Override
//     public String getAuthority() {
//         return authority;
//     }
// 
//     public static final Role VIEWER = new Role("VIEWER");
//     public static final Role RELUMIN_ADMIN = new Role("RELUMIN_ADMIN");
// 
//     public static Role get(String role) {
//         switch (role) {
//             case "VIEWER":
//                 return VIEWER;
//             case "RELUMIN_ADMIN":
//                 return RELUMIN_ADMIN;
//             default:
//         }
//         throw new InvalidParameterException(String.format("'%s' is invalid role.", role));
//     }
// }
// 
// Path: src/main/java/com/behase/relumin/service/LoggingOperationService.java
// public interface LoggingOperationService {
//     void log(String operationName, Authentication authentication);
// 
//     void log(String operationName, Authentication authentication, String msg);
// 
//     void log(String operationName, Authentication authentication, String msg, Object... objects);
// }
// 
// Path: src/main/java/com/behase/relumin/service/UserService.java
// public interface UserService extends UserDetailsService {
//     LoginUser getUser(String username) throws Exception;
// 
//     List<LoginUser> getUsers() throws Exception;
// 
//     void addUser(String username, String displayName, String password, String role) throws Exception;
// 
//     void changePassword(String username, String oldPassword, String password) throws Exception;
// 
//     void updateUser(String username, String displayName, String role) throws Exception;
// 
//     void deleteUser(String username) throws Exception;
// }


// Path: src/test/java/com/behase/relumin/controller/UserApiControllerTest.java
import com.behase.relumin.exception.InvalidParameterException;
import com.behase.relumin.model.LoginUser;
import com.behase.relumin.model.Role;
import com.behase.relumin.service.LoggingOperationService;
import com.behase.relumin.service.UserService;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.security.core.Authentication;
import java.util.List;
import java.util.Map;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;

        controller.updateMe(null, "");
    }

    @Test
    public void updateMe() throws Exception {
        doReturn(new LoginUser("username", "displayName", "rawPassword", Role.VIEWER.getAuthority())).when(userService).getUser(anyString());

        LoginUser result = controller.updateMe(mock(Authentication.class), "");
        log.info("result={}", result);
        assertThat(result.getUsername(), is("username"));
    }

    @Test
    public void changePassword_authentication_is_null_throw_exception() throws Exception {
        expectedEx.expect(InvalidParameterException.class);
        expectedEx.expectMessage(containsString("You are not loggedin."));

        controller.changePassword(null, "", "");
    }

    @Test
    public void changePassword() throws Exception {
        doReturn(new LoginUser("username", "displayName", "rawPassword", Role.VIEWER.getAuthority())).when(userService).getUser(anyString());

        LoginUser result = controller.changePassword(mock(Authentication.class), "", "");
        log.info("result={}", result);
        assertThat(result.getUsername(), is("username"));
    }

    @Test
    public void delete() throws Exception {