package com.atlassian.bitbucket.mesh.git.builder.version;

import com.atlassian.bitbucket.mesh.AbstractWiredTest;
import com.atlassian.bitbucket.mesh.git.binary.GitBinaryHelper;
import com.atlassian.bitbucket.mesh.git.builder.GitProcessBuilderFactory;
import com.atlassian.bitbucket.mesh.util.Version;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.concurrent.TimeUnit;

import static org.hamcrest.Matchers.greaterThanOrEqualTo;

public class VersionTest extends AbstractWiredTest {

    @Autowired
    private GitProcessBuilderFactory builderFactory;

    @Test
    public void testRun() {
        Version version = builderFactory.builder().version()
                .build(new VersionStdioHandler())
                .run();
        assertNotNull(version);
        assertThat(version, greaterThanOrEqualTo(GitBinaryHelper.MINIMUM_VERSION));
    }

    @Test
    public void testStart() throws Exception {
        Version version = builderFactory.builder().version()
                .build(new VersionStdioHandler())
                .start()
                .get(2L, TimeUnit.SECONDS);
        assertNotNull(version);
        assertThat(version, greaterThanOrEqualTo(GitBinaryHelper.MINIMUM_VERSION));
    }
}
