package com.atlassian.bitbucket.mesh.git;

import com.atlassian.bitbucket.mesh.repository.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;

import java.util.function.Function;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;

@RunWith(MockitoJUnitRunner.class)
public class DarkRefMapperTest {

    @Test
    public void testMapDarkRefsToStashRefsForBitbucketServerRepository() {
        Function<String, String> mapper = DarkRefMapper.INSTANCE.visit(mock(BitbucketServerRepository.class));

        assertEquals("stash-refs/pull-requests/1/from", mapper.apply("dark-refs/pull-requests/1/from"));
        assertEquals("stash-refs/pull-requests/1/from", mapper.apply("stash-refs/pull-requests/1/from"));
    }

    @Test
    public void testMapStashRefsToDarkRefsForManagedRepository() {
        Function<String, String> mapper = DarkRefMapper.INSTANCE.visit(mock(ManagedRepository.class));

        assertEquals("dark-refs/pull-requests/1/from", mapper.apply("stash-refs/pull-requests/1/from"));
        assertEquals("dark-refs/pull-requests/1/from", mapper.apply("dark-refs/pull-requests/1/from"));
    }

    @Test
    public void testRefsNotMappedForSharedObjectsRepository() {
        Function<String, String> mapper = DarkRefMapper.INSTANCE.visit(mock(SharedObjectsRepository.class));

        assertEquals("stash-refs/pull-requests/1/from", mapper.apply("stash-refs/pull-requests/1/from"));
        assertEquals("dark-refs/pull-requests/1/from", mapper.apply("dark-refs/pull-requests/1/from"));
    }

    @Test
    public void testRefsNotMappedForPathRepository() {
        Function<String, String> mapper = DarkRefMapper.INSTANCE.visit(mock(PathRepository.class));

        assertEquals("stash-refs/pull-requests/1/from", mapper.apply("stash-refs/pull-requests/1/from"));
        assertEquals("dark-refs/pull-requests/1/from", mapper.apply("dark-refs/pull-requests/1/from"));
    }

    @Test
    public void testRefsNotMappedForWorkTree() {
        Function<String, String> mapper = DarkRefMapper.INSTANCE.visit(mock(WorkTree.class));

        assertEquals("stash-refs/pull-requests/1/from", mapper.apply("stash-refs/pull-requests/1/from"));
        assertEquals("dark-refs/pull-requests/1/from", mapper.apply("dark-refs/pull-requests/1/from"));
    }
}