package com.atlassian.stash.internal.user;

import com.atlassian.bitbucket.user.*;

import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class UserTestUtils {
    public static <T extends DetailedUser> T createMockDetailedUser(Class<T> userClass) {
        final T user = mock(userClass);
        when(user.getType()).thenReturn(UserType.NORMAL);
        when(user.accept(any(ApplicationUserVisitor.class))).thenAnswer(invocation ->
                ((ApplicationUserVisitor) invocation.getArguments()[0]).visit(user));

        return user;
    }

    public static <T extends ApplicationUser> T createMockNormalUser(Class<T> userClass) {
        final T user = mock(userClass);
        when(user.getType()).thenReturn(UserType.NORMAL);
        when(user.accept(any(ApplicationUserVisitor.class))).thenAnswer(invocation ->
                ((ApplicationUserVisitor) invocation.getArguments()[0]).visit(user));

        return user;
    }

    public static <T extends ServiceUser> T createMockServiceUser(Class<T> userClass) {
        final T user = mock(userClass);
        when(user.getType()).thenReturn(UserType.SERVICE);
        when(user.accept(any(ApplicationUserVisitor.class))).thenAnswer(invocation ->
                ((ApplicationUserVisitor) invocation.getArguments()[0]).visit(user));

        return user;
    }
}
