/* Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.camunda.spin.impl.util;

import static org.assertj.core.api.Assertions.assertThat;

import java.io.InputStream;

import org.junit.Test;

public class IoUtilTest {

  private static final int INPUT_STREAM_BYTE_LIMIT = 16;
  
  @Test
  public void testReadFirstBytes() {
    String input = "a string with some content";
    InputStream inputStream = IoUtil.stringAsInputStream(input);
    
    byte[] firstBytes = IoUtil.readFirstBytes(inputStream, INPUT_STREAM_BYTE_LIMIT);
    assertThat(new String(firstBytes, IoUtil.ENCODING_CHARSET)).isEqualTo(input.substring(0, INPUT_STREAM_BYTE_LIMIT));
  }
  
  @Test
  public void testReadFirstBytesUtf8() {
    String input = "ä string with some content";
    InputStream inputStream = IoUtil.stringAsInputStream(input);
    
    byte[] firstBytes = IoUtil.readFirstBytes(inputStream, INPUT_STREAM_BYTE_LIMIT);
    
    // ä is two bytes in utf-8
    assertThat(new String(firstBytes, IoUtil.ENCODING_CHARSET)).isEqualTo(input.substring(0, INPUT_STREAM_BYTE_LIMIT - 1));
  }
  
}

@@ -601,109 +601,108 @@
 ort 
-static org.assertj.core.api.Assertions.assertThat;%0A%0Aimport java.io.InputStream;%0A%0Aimport org.junit.Tes
+java.io.InputStream;%0Aimport org.junit.Test;%0A%0Aimport static org.assertj.core.api.Assertions.assertTha
 t;%0A%0A
@@ -1033,24 +1033,25 @@
 YTE_LIMIT);%0A
+%0A
     assertTh
@@ -1154,24 +1154,85 @@
 TE_LIMIT));%0A
+    assertThat(firstBytes).hasSize(INPUT_STREAM_BYTE_LIMIT);%0A
   %7D%0A  %0A  @Te
@@ -1639,16 +1639,590 @@
  - 1));%0A
+    assertThat(firstBytes).hasSize(INPUT_STREAM_BYTE_LIMIT);%0A  %7D%0A%0A  @Test%0A  public void testReadFirstBytesOfEmptyInputStream() %7B%0A    InputStream inputStream = IoUtil.stringAsInputStream(%22%22);%0A%0A    byte%5B%5D firstBytes = IoUtil.readFirstBytes(inputStream, INPUT_STREAM_BYTE_LIMIT);%0A%0A    assertThat(firstBytes).hasSize(0);%0A  %7D%0A%0A  @Test%0A  public void testReadFirstBytesOfSmallInputStream() %7B%0A    InputStream inputStream = IoUtil.stringAsInputStream(%22a%22);%0A%0A    byte%5B%5D firstBytes = IoUtil.readFirstBytes(inputStream, INPUT_STREAM_BYTE_LIMIT);%0A%0A    assertThat(firstBytes).hasSize(1);%0A
   %7D%0A  %0A%7D

add IoUtil tests