/*
 * Modified by
 * @author  Data Virtuality GmbH
 * @date    $Date$
 *
 */
// https://issues.jboss.org/browse/TEIID-2441
package org.teiid.core.util;

import static org.junit.jupiter.api.Assertions.*;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.charset.Charset;

import org.junit.jupiter.api.Test;

@SuppressWarnings("nls")
public class TestInputStreamReader {

	@Test public void testMultiByte() throws Exception {
		InputStreamReader isr = new InputStreamReader(new ByteArrayInputStream(new byte[] {(byte)80, (byte)-61, (byte)-70}), Charset.forName("UTF-8").newDecoder(), 2);
		assertEquals(80, isr.read());
		assertEquals(250, isr.read());
	}

	@Test public void testError() throws Exception {
		assertThrows(IOException.class, () -> {
			InputStreamReader isr = new InputStreamReader(new ByteArrayInputStream(new byte[] {(byte)80, (byte)-61, (byte)-70, (byte)-61, (byte)-70, (byte)80, (byte)-61, (byte)-70}), Charset.forName("ASCII").newDecoder(), 4);
			while (isr.read() != -1) {
			}
		});
	}
}
