package com.atlassian.bitbucket.mesh.git;

import com.atlassian.bitbucket.mesh.repository.Repository;
import com.atlassian.bitbucket.mesh.repository.RepositoryManager;
import com.google.common.collect.ImmutableList;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
public class DefaultRpcArgumentDecoderTest {

    private final Path repositoryPath = Paths.get("repository", "path", "123");

    @Mock
    private Repository repository;
    @Mock
    private RepositoryManager repositoryManager;
    @InjectMocks
    private DefaultRpcArgumentDecoder argumentDecoder;

    @Before
    public void setup() {
        when(repositoryManager.getById("123")).thenReturn(repository);
        when(repository.getPath()).thenReturn(Paths.get("repository", "path", "123"));
    }

    @Test
    public void testDecodeArguments() {
        ImmutableList<String> args = ImmutableList.of("argumentOne", "argumentTwo", "$repository_path('123')",
                "argumentFour");

        List<String> result = argumentDecoder.decode(args);

        assertThat(result, contains("argumentOne", "argumentTwo", repositoryPath.toString(), "argumentFour"));
    }
}
