package com.atlassian.stash.internal.scm.git;

import com.atlassian.bitbucket.user.SimplePerson;
import com.atlassian.bitbucket.user.ApplicationUser;
import org.junit.Test;
import org.mockito.Mockito;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.mockito.Mockito.when;

public class AuthorNameTypeTest {

    @Test
    public void testConvertWithPerson() {
        SimplePerson person = new SimplePerson("a", "b");
        assertSame(person, AuthorNameType.USERNAME.convert(person));
        assertSame(person, AuthorNameType.DISPLAYNAME.convert(person));
    }

    @Test
    public void testConvertWithStashUser() {
        ApplicationUser user = Mockito.mock(ApplicationUser.class);
        when(user.getName()).thenReturn("a");
        when(user.getEmailAddress()).thenReturn("b");
        when(user.getDisplayName()).thenReturn("c");
        assertEquals("a", AuthorNameType.USERNAME.convert(user).getName());
        assertEquals("c", AuthorNameType.DISPLAYNAME.convert(user).getName());
    }

    @Test
    public void testParseConfig() {
        assertEquals(AuthorNameType.DISPLAYNAME, AuthorNameType.parseConfig(null));
        assertEquals(AuthorNameType.DISPLAYNAME, AuthorNameType.parseConfig("a"));
        assertEquals(AuthorNameType.DISPLAYNAME, AuthorNameType.parseConfig("displayname"));
        assertEquals(AuthorNameType.USERNAME, AuthorNameType.parseConfig("username"));
    }
}
