package com.atlassian.bitbucket.internal.mirroring.mirror.sync;

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

import java.io.IOException;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

@RunWith(MockitoJUnitRunner.class)
public class MirrorRefChangeCallbackTest {
    @Mock
    private Repository repository;
    @InjectMocks
    private MirrorRefChangeCallback callback;

    @Test
    public void testGetCount() throws IOException {
        assertEquals(0, callback.getCount());

        for (int i = 1; i < 5; ++i) {
            assertTrue(callback.onRefChange(new SimpleRefChange.Builder()
                    .ref(RefTestUtils.minimalBranch("ref" + i))
                    .fromHash("edacf32")
                    .toHash("abcdef12")
                    .type(RefChangeType.UPDATE)
                    .build()));
            assertEquals(i, callback.getCount());
        }
    }
}