package com.atlassian.bitbucket.internal.branch;

import com.atlassian.bitbucket.commit.MinimalCommit;
import com.atlassian.bitbucket.repository.Ref;
import com.atlassian.bitbucket.repository.RefMetadataContext;
import com.atlassian.bitbucket.repository.Repository;

import java.util.Set;

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

public final class MetadataProviderTestUtils {

    private MetadataProviderTestUtils() {
    }

    public static MinimalCommit mockCommit(String hash) {
        MinimalCommit commit = mock(MinimalCommit.class);
        when(commit.getId()).thenReturn(hash);
        return commit;
    }

    public static RefMetadataContext mockContext(Ref baseRef, Set<Ref> refs) {
        Repository repository = mock(Repository.class);
        RefMetadataContext context = mock(RefMetadataContext.class);
        when(context.getBaseRef()).thenReturn(baseRef);
        when(context.getRefs()).thenReturn(refs);
        when(context.getRepository()).thenReturn(repository);
        return context;
    }

    public static Ref mockRef(String refId) {
        return mockRef(refId, "commit-id-" + refId);
    }

    public static Ref mockRef(String refId, String hash) {
        Ref ref = mock(Ref.class);
        when(ref.getId()).thenReturn(refId);
        when(ref.getLatestCommit()).thenReturn(hash);
        return ref;
    }
}
