/*
 * Copyright (c) 2006-2014 DMDirc Developers
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package com.dmdirc.util.io;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;

@RunWith(MockitoJUnitRunner.class)
public class StreamReaderTest {

    @Test
    public void testGetListDiscarding() throws Exception {
        final InputStream inputStream = spy(getClass().getResource("test5.txt").openStream());
        final StreamIgnorer streamReader = new StreamIgnorer(inputStream);
        assertNull(streamReader.getList());
        streamReader.run();
        assertNull(streamReader.getList());
        verify(inputStream, atLeastOnce()).read(any(byte[].class), anyInt(), anyInt());
    }

    @Test
    public void testGetListBuffer() throws Exception {
        final StringBuffer stringBuffer = new StringBuffer();
        final StreamIgnorer streamReader = new StreamIgnorer(getClass().getResource("test5.txt")
                .openStream(),
                stringBuffer);
        assertNull(streamReader.getList());
        streamReader.run();
        assertNull(streamReader.getList());
        assertEquals("Line 1\nLine 2\nLine 3", stringBuffer.toString());
    }

    @Test
    public void testGetListList() throws Exception {
        final List<String> list = new ArrayList<>();
        final StreamIgnorer streamReader = new StreamIgnorer(getClass().getResource("test5.txt")
                .openStream(), list);
        assertTrue(streamReader.getList().isEmpty());
        streamReader.run();
        assertEquals(4, list.size());
        assertEquals("", list.get(0));
        assertEquals("Line 1", list.get(1));
        assertEquals("Line 2", list.get(2));
        assertEquals("Line 3", list.get(3));
    }
}
@@ -1181,59 +1181,8 @@
 eam;
-%0Aimport java.util.ArrayList;%0Aimport java.util.List;
 %0A%0Aim
@@ -1287,139 +1287,8 @@
 r;%0A%0A
-import static org.junit.Assert.assertEquals;%0Aimport static org.junit.Assert.assertNull;%0Aimport static org.junit.Assert.assertTrue;%0A
 impo
@@ -1814,1234 +1814,112 @@
     
-assertNull(streamReader.getList());%0A        streamReader.run();%0A        assertNull(streamReader.getList());%0A        verify(inputStream, atLeastOnce()).read(any(byte%5B%5D.class), anyInt(), anyInt());%0A    %7D%0A%0A    @Test%0A    public void testGetListBuffer() throws Exception %7B%0A        final StringBuffer stringBuffer = new StringBuffer();%0A        final StreamIgnorer streamReader = new StreamIgnorer(getClass().getResource(%22test5.txt%22)%0A                .openStream(),%0A                stringBuffer);%0A        assertNull(streamReader.getList());%0A        streamReader.run();%0A        assertNull(streamReader.getList());%0A        assertEquals(%22Line 1%5CnLine 2%5CnLine 3%22, stringBuffer.toString());%0A    %7D%0A%0A    @Test%0A    public void testGetListList() throws Exception %7B%0A        final List%3CString%3E list = new ArrayList%3C%3E();%0A        final StreamIgnorer streamReader = new StreamIgnorer(getClass().getResource(%22test5.txt%22)%0A                .openStream(), list);%0A        assertTrue(streamReader.getList().isEmpty());%0A        streamReader.run();%0A        assertEquals(4, list.size());%0A        assertEquals(%22%22, list.get(0));%0A        assertEquals(%22Line 1%22, list.get(1));%0A        assertEquals(%22Line 2%22, list.get(2));%0A        assertEquals(%22Line 3%22, list.get(3
+streamReader.run();%0A        verify(inputStream, atLeastOnce()).read(any(byte%5B%5D.class), anyInt(), anyInt(
 ));%0A

Fix test.