// 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/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.model.LoginUser;
import com.behase.relumin.model.Role;
import com.behase.relumin.service.UserService;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.internal.util.reflection.Whitebox;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.security.core.Authentication;
import org.springframework.ui.ExtendedModelMap;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;

    @Before
    public void init() {
        Whitebox.setInternalState(controller, "buildNumber", "1");
        Whitebox.setInternalState(controller, "collectStaticsInfoIntervalMillis", "1");
        Whitebox.setInternalState(controller, "authEnabled", true);
        Whitebox.setInternalState(controller, "authAllowAnonymous", true);
    }

    @Test
    public void index_with_auth() throws Exception {
        ExtendedModelMap model = new ExtendedModelMap();
        Authentication authentication = mock(Authentication.class);

        doReturn(new LoginUser("username", "displayName", "rawPassword", Role.VIEWER.getAuthority())).when(userService).getUser(anyString());

        controller.index(authentication, model);
        assertThat(model.get("buildNumber"), is("1"));
        assertThat(model.get("collectStaticsInfoIntervalMillis"), is("1"));
        assertThat(model.get("authEnabled"), is(true));
        assertThat(model.get("authAllowAnonymous"), is(true));
        assertThat(model.get("loginUsername"), is("username"));
        assertThat(model.get("login"), is(true));
    }

    @Test
    public void index() throws Exception {
        ExtendedModelMap model = new ExtendedModelMap();
        Authentication authentication = null;

// 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/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/WebControllerTest.java
import com.behase.relumin.model.LoginUser;
import com.behase.relumin.model.Role;
import com.behase.relumin.service.UserService;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.internal.util.reflection.Whitebox;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.security.core.Authentication;
import org.springframework.ui.ExtendedModelMap;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;


    @Before
    public void init() {
        Whitebox.setInternalState(controller, "buildNumber", "1");
        Whitebox.setInternalState(controller, "collectStaticsInfoIntervalMillis", "1");
        Whitebox.setInternalState(controller, "authEnabled", true);
        Whitebox.setInternalState(controller, "authAllowAnonymous", true);
    }

    @Test
    public void index_with_auth() throws Exception {
        ExtendedModelMap model = new ExtendedModelMap();
        Authentication authentication = mock(Authentication.class);

        doReturn(new LoginUser("username", "displayName", "rawPassword", Role.VIEWER.getAuthority())).when(userService).getUser(anyString());

        controller.index(authentication, model);
        assertThat(model.get("buildNumber"), is("1"));
        assertThat(model.get("collectStaticsInfoIntervalMillis"), is("1"));
        assertThat(model.get("authEnabled"), is(true));
        assertThat(model.get("authAllowAnonymous"), is(true));
        assertThat(model.get("loginUsername"), is("username"));
        assertThat(model.get("login"), is(true));
    }

    @Test
    public void index() throws Exception {
        ExtendedModelMap model = new ExtendedModelMap();
        Authentication authentication = null;

        doReturn(new LoginUser("username", "displayName", "rawPassword", Role.VIEWER.getAuthority())).when(userService).getUser(anyString());