package org.folio.util;

import static org.junit.Assert.*;

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

import org.folio.rest.testing.UtilityClassTester;
import org.junit.Test;

public class IoUtilTest {
  @Test
  public void utilityClass() {
    UtilityClassTester.assertUtilityClass(IoUtil.class);
  }

  @Test(expected = NullPointerException.class)
  public void nullFilename() throws IOException {
    IoUtil.toStringUtf8((InputStream)null);
  }

  private InputStream inputStream(String s) {
    return new ByteArrayInputStream(s.getBytes(StandardCharsets.UTF_8));
  }

  @Test
  public void readEmptyStream() throws IOException {
    assertEquals("", IoUtil.toStringUtf8(inputStream("")));
  }

  @Test
  public void readUmlauts() throws IOException {
    String s = "first line\numlauts: äöü\n";
    assertEquals(s, IoUtil.toStringUtf8(inputStream(s)));
  }

  @Test
  public void readUmlautsEncoding() throws IOException {
    String s = "first line\numlauts: äöü\n";
    assertEquals(s, IoUtil.toString(inputStream(s), StandardCharsets.UTF_8));
    assertNotEquals(s, IoUtil.toString(inputStream(s), StandardCharsets.ISO_8859_1));
  }

  @Test
  public void read3000() throws IOException {
    char [] expected = new char [3000];
    for (int i = 0; i < expected.length; i++) {
      expected[i] = 'a';
    }
    String s = new String(expected);
    assertEquals(s, IoUtil.toStringUtf8(inputStream(s)));
  }
}

@@ -53,9 +53,68 @@
 ert.
-*
+assertEquals;%0Aimport static org.junit.Assert.assertNotEquals
 ;%0A%0Ai
@@ -348,16 +348,87 @@
 lTest %7B%0A
+  private static final String example = %22first line%5Cnumlauts: %C3%A4%C3%B6%C3%BC%5Cn%22;%0A%0A
   @Test%0A
@@ -977,53 +977,8 @@
 n %7B%0A
-    String s = %22first line%5Cnumlauts: %C3%A4%C3%B6%C3%BC%5Cn%22;%0A
     
@@ -982,33 +982,39 @@
    assertEquals(
-s
+example
 , IoUtil.toStrin
@@ -1023,33 +1023,39 @@
 tf8(inputStream(
-s
+example
 )));%0A  %7D%0A%0A  @Tes
@@ -1117,53 +1117,8 @@
 n %7B%0A
-    String s = %22first line%5Cnumlauts: %C3%A4%C3%B6%C3%BC%5Cn%22;%0A
     
@@ -1122,33 +1122,39 @@
    assertEquals(
-s
+example
 , IoUtil.toStrin
@@ -1159,33 +1159,39 @@
 ing(inputStream(
-s
+example
 ), StandardChars
@@ -1215,33 +1215,39 @@
 assertNotEquals(
-s
+example
 , IoUtil.toStrin
@@ -1260,17 +1260,23 @@
 tStream(
-s
+example
 ), Stand
@@ -1577,11 +1577,222 @@
 )));%0A  %7D
+%0A%0A  @Test%0A  public void readFile() throws IOException %7B%0A    String path = System.getProperty(%22user.dir%22) + %22/src/test/resources/ResourceUtilExample.bin%22;%0A    assertEquals(example, IoUtil.toStringUtf8(path));%0A  %7D
 %0A%7D%0A

add unit tests