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

import com.atlassian.bitbucket.mesh.process.ProcessSummary;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
public class GetConfigCompletionHandlerTest {

    private GetConfigCompletionHandler handler;
    @Mock
    private ProcessSummary processSummary;

    @Before
    public void setup() {
        handler = new GetConfigCompletionHandler();
    }

    @Test
    public void testIsError() {
        Throwable thrown = mock(Throwable.class);
        when(processSummary.getExitCode()).thenReturn(1);
        when(processSummary.getThrown()).thenReturn(thrown);

        assertTrue(handler.isError(processSummary));
    }

    @Test
    public void testIsErrorWithInvalidKey() {
        when(processSummary.getExitCode()).thenReturn(1);

        assertFalse(handler.isError(processSummary));
    }
}
