package com.atlassian.bitbucket.web.conditions;

import com.atlassian.bitbucket.repository.Repository;
import com.atlassian.bitbucket.repository.RepositoryService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import java.util.Collections;

import static com.atlassian.bitbucket.web.conditions.RepositoryNotEmptyCondition.REPOSITORY;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.isA;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
public class RepositoryNotEmptyConditionTest {

    @Mock
    private Repository repository;
    @Mock
    private RepositoryService repositoryService;

    @InjectMocks
    private RepositoryNotEmptyCondition condition;

    @Test
    public void testNonEmptyRepository() throws Exception {
        when(repositoryService.isEmpty(isA(Repository.class))).thenReturn(false);
        assertTrue(condition.shouldDisplay(Collections.<String, Object>singletonMap(REPOSITORY, repository)));
    }

    @Test
    public void testEmptyRepository() throws Exception {
        when(repositoryService.isEmpty(isA(Repository.class))).thenReturn(true);
        assertFalse(condition.shouldDisplay(Collections.<String, Object>singletonMap(REPOSITORY, repository)));
    }

    @Test
    public void testNoRepository() throws Exception {
        assertTrue(condition.shouldDisplay(Collections.singletonMap(REPOSITORY, null)));
    }
}
