package com.atlassian.bitbucket.mesh.git.hook;

import com.google.common.io.LineProcessor;
import org.apache.commons.io.IOUtils;
import org.junit.Test;

import java.io.InputStream;
import java.nio.charset.StandardCharsets;

import static com.atlassian.bitbucket.mesh.git.hook.EmptyHookStdin.INSTANCE;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;

public class EmptyHookStdinTest {

    @Test
    public void testOpen() throws Exception {
        try (InputStream stream = INSTANCE.open()) {
            assertNotNull(stream);

            assertEquals("", IOUtils.toString(stream, StandardCharsets.UTF_8));
        }
    }

    @Test
    public void testRead() {
        assertEquals("", INSTANCE.read());
    }

    @Test
    public void testReadLines() {
        LineProcessor<?> processor = mock(LineProcessor.class);
        assertNull(INSTANCE.readLines(processor));

        verify(processor).getResult();
        verifyNoMoreInteractions(processor);
    }

    @Test
    public void testRelease() {
        assertFalse(INSTANCE.isReleased());

        //Even after calling release, isReleased should still return false because this is a singleton
        INSTANCE.release();
        assertFalse(INSTANCE.isReleased());
    }

    @Test
    public void testSize() {
        assertEquals(0L, INSTANCE.size());
    }
}