// Path: ersatz/src/main/java/io/github/cjstehno/ersatz/server/undertow/ResponseChunker.java
// class ResponseChunker implements IoCallback {
// 
//     private final List<byte[]> chunks;
//     public final int delay;
// 
//     ResponseChunker(final List<byte[]> chunks, final int delay) {
//         this.chunks = chunks;
//         this.delay = delay;
//     }
// 
//     @Override
//     public void onComplete(final HttpServerExchange exchange, final Sender sender) {
//         if (chunks != null && !chunks.isEmpty()) {
//             rest();
//             sender.send(ByteBuffer.wrap(chunks.remove(0)), this);
//         }
//     }
// 
//     private void rest() {
//         if (delay > 0) {
//             try {
//                 Thread.sleep(delay);
//             } catch (InterruptedException e) {
//                 // ignore
//             }
//         }
//     }
// 
//     @Override
//     public void onException(HttpServerExchange exchange, Sender sender, IOException exception) {
//         exception.printStackTrace();
//     }
// 
//     /**
//      * Splits the provided string of content into the specified number of chunks. Any remaining characters will be spread out over the chunks to
//      * keep the sizes as even as possible.
//      *
//      * @param content the content array to be chunked
//      * @param chunks  the number of chunks
//      * @return a List&lt;String&gt; containing the chunk data
//      */
//     public static List<byte[]> prepareChunks(final byte[] content, final int chunks) {
//         int chunklen = content.length / chunks;
//         int remainder = content.length % chunks;
// 
//         final List<byte[]> chunked = new LinkedList<>();
// 
//         int index = 0;
// 
//         for (int n = 0; n < chunks; n++) {
//             int extra = 0;
//             if (remainder > 0) {
//                 extra = 1;
//                 --remainder;
//             }
// 
//             int len = chunklen + extra;
// 
//             final byte[] chunk = new byte[len];
//             System.arraycopy(content, index, chunk, 0, len);
//             chunked.add(chunk);
// 
//             index += len;
//         }
// 
//         return chunked;
//     }
// }


import io.github.cjstehno.ersatz.server.undertow.ResponseChunker;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;

/**
 * Copyright (C) 2022 Christopher J. Stehno
 *
 * 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 io.github.cjstehno.ersatz.server.undertow;



class ResponseChunkerTest {

    private static final byte[] BYTES = "abcdefghijklmnop".getBytes();

    @Test @DisplayName("parsing 3 chunks")
    void parsing_3_chunks(){

// Path: ersatz/src/main/java/io/github/cjstehno/ersatz/server/undertow/ResponseChunker.java
// class ResponseChunker implements IoCallback {
// 
//     private final List<byte[]> chunks;
//     public final int delay;
// 
//     ResponseChunker(final List<byte[]> chunks, final int delay) {
//         this.chunks = chunks;
//         this.delay = delay;
//     }
// 
//     @Override
//     public void onComplete(final HttpServerExchange exchange, final Sender sender) {
//         if (chunks != null && !chunks.isEmpty()) {
//             rest();
//             sender.send(ByteBuffer.wrap(chunks.remove(0)), this);
//         }
//     }
// 
//     private void rest() {
//         if (delay > 0) {
//             try {
//                 Thread.sleep(delay);
//             } catch (InterruptedException e) {
//                 // ignore
//             }
//         }
//     }
// 
//     @Override
//     public void onException(HttpServerExchange exchange, Sender sender, IOException exception) {
//         exception.printStackTrace();
//     }
// 
//     /**
//      * Splits the provided string of content into the specified number of chunks. Any remaining characters will be spread out over the chunks to
//      * keep the sizes as even as possible.
//      *
//      * @param content the content array to be chunked
//      * @param chunks  the number of chunks
//      * @return a List&lt;String&gt; containing the chunk data
//      */
//     public static List<byte[]> prepareChunks(final byte[] content, final int chunks) {
//         int chunklen = content.length / chunks;
//         int remainder = content.length % chunks;
// 
//         final List<byte[]> chunked = new LinkedList<>();
// 
//         int index = 0;
// 
//         for (int n = 0; n < chunks; n++) {
//             int extra = 0;
//             if (remainder > 0) {
//                 extra = 1;
//                 --remainder;
//             }
// 
//             int len = chunklen + extra;
// 
//             final byte[] chunk = new byte[len];
//             System.arraycopy(content, index, chunk, 0, len);
//             chunked.add(chunk);
// 
//             index += len;
//         }
// 
//         return chunked;
//     }
// }


// Path: ersatz/src/test/java/io/github/cjstehno/ersatz/server/undertow/ResponseChunkerTest.java
import io.github.cjstehno.ersatz.server.undertow.ResponseChunker;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;

/**
 * Copyright (C) 2022 Christopher J. Stehno
 *
 * 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 io.github.cjstehno.ersatz.server.undertow;



class ResponseChunkerTest {

    private static final byte[] BYTES = "abcdefghijklmnop".getBytes();

    @Test @DisplayName("parsing 3 chunks")
    void parsing_3_chunks(){

        final var chunks = ResponseChunker.prepareChunks(BYTES, 3);
