package org.folio.util;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

import org.folio.rest.testing.UtilityClassTester;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;

class PercentCodecTest {
  @Test
  void isUtilityClass() {
    UtilityClassTester.assertUtilityClass(PercentCodec.class);
  }

  @ParameterizedTest
  @CsvSource({
    "              , ''",  // null -> empty
    "''            , ''",  // empty -> empty
    "abc           , abc",
    "status == open, status%20%3D%3D%20open",
    "key=a-umlaut-ä, key%3Da-umlaut-%C3%A4",
    "ääääääääää    , %C3%A4%C3%A4%C3%A4%C3%A4%C3%A4%C3%A4%C3%A4%C3%A4%C3%A4%C3%A4",
    "a b c         , a%20b%20c",
  })
  void uriEncode(String s, String expected) {
    assertThat(PercentCodec.encode(s).toString(), is(expected));
    StringBuffer stringBuffer = new StringBuffer("foo = ");
    PercentCodec.encode(stringBuffer, s);
    assertThat(stringBuffer.toString(), is("foo = " + expected));
  }
}

@@ -115,16 +115,142 @@
 rtThat;%0A
+import static org.junit.jupiter.api.Assertions.assertThrows;%0A%0Aimport java.io.IOException;%0Aimport java.io.UncheckedIOException;
 %0Aimport 
@@ -934,12 +934,9 @@
 oid 
-uriE
+e
 ncod
@@ -1004,21 +1004,18 @@
 code
-(s).to
+As
 String(
+s
 ), i
@@ -1199,11 +1199,646 @@
 d));%0A  %7D
+%0A%0A  @Test%0A  void encodeThrowsUncheckedIOException() throws IOException %7B%0A    var out = new Appendable() %7B%0A      @Override%0A      public Appendable append(CharSequence csq) throws IOException %7B%0A        throw new IOException(%22failing mock%22);%0A      %7D%0A      @Override%0A      public Appendable append(CharSequence csq, int start, int end) throws IOException %7B%0A        throw new IOException(%22failing mock%22);%0A      %7D%0A      @Override%0A      public Appendable append(char c) throws IOException %7B%0A        throw new IOException(%22failing mock%22);%0A      %7D%0A    %7D;%0A%0A    assertThrows(UncheckedIOException.class, () -%3E PercentCodec.encode(out, %22foo%22));%0A  %7D
 %0A%7D%0A

Add test coverage