// Path: upload-parser-tests/src/test/java/com/github/elopteryx/upload/util/Servlets.java
// public static HttpServletRequest newRequest() throws Exception {
//     final var request = mock(HttpServletRequest.class);
// 
//     when(request.getMethod()).thenReturn("POST");
//     when(request.getContentType()).thenReturn("multipart/");
//     when(request.getContentLengthLong()).thenReturn(1024 * 1024L);
//     when(request.getInputStream()).thenReturn(new MockServletInputStream());
//     when(request.isAsyncSupported()).thenReturn(true);
// 
//     return request;
// }
// 
// Path: upload-parser-tests/src/test/java/com/github/elopteryx/upload/util/Servlets.java
// public static HttpServletResponse newResponse() {
//     final var response = mock(HttpServletResponse.class);
// 
//     when(response.getStatus()).thenReturn(200);
// 
//     return response;
// }
// 
// Path: upload-parser-core/src/main/java/com/github/elopteryx/upload/util/NullChannel.java
// public class NullChannel implements ReadableByteChannel, WritableByteChannel {
// 
//     /**
//      * Flag to determine whether the channel is closed or not.
//      */
//     private boolean open = true;
// 
//     @Override
//     public int read(final ByteBuffer dst) throws IOException {
//         if (!open) {
//             throw new ClosedChannelException();
//         }
//         return -1;
//     }
// 
//     @Override
//     public int write(final ByteBuffer src) throws IOException {
//         if (!open) {
//             throw new ClosedChannelException();
//         }
//         final var remaining = src.remaining();
//         src.position(src.limit());
//         return remaining;
//     }
// 
//     @Override
//     public boolean isOpen() {
//         return open;
//     }
// 
//     @Override
//     public void close() {
//         open = false;
//     }
// }


import static com.github.elopteryx.upload.util.Servlets.newRequest;
import static com.github.elopteryx.upload.util.Servlets.newResponse;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import com.github.elopteryx.upload.util.NullChannel;
import com.google.common.jimfs.Jimfs;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.nio.ByteBuffer;
import java.nio.file.FileSystem;
import java.nio.file.Files;
import jakarta.servlet.AsyncContext;
import jakarta.servlet.ServletInputStream;
import jakarta.servlet.http.HttpServletResponse;
package com.github.elopteryx.upload;




class UploadParserTest implements OnPartBegin, OnPartEnd, OnRequestComplete, OnError {

    private static FileSystem fileSystem;

    @BeforeAll
    static void setUp() {
        fileSystem = Jimfs.newFileSystem();
    }

    @Test
    void valid_content_type() throws Exception {
        final var request = newRequest();

        when(request.getContentType()).thenReturn("multipart/");
        assertTrue(UploadParser.isMultipart(request));
    }

    @Test
    void invalid_numeric_arguments() {
        assertAll(
                () -> assertThrows(IllegalArgumentException.class, () -> UploadParser.newParser().sizeThreshold(-1)),
                () -> assertThrows(IllegalArgumentException.class, () -> UploadParser.newParser().maxPartSize(-1)),
                () -> assertThrows(IllegalArgumentException.class, () -> UploadParser.newParser().maxRequestSize(-1)),
                () -> assertThrows(IllegalArgumentException.class, () -> UploadParser.newParser().maxBytesUsed(-1))
        );
    }

    @Test
    void invalid_content_type_async() throws Exception {
        final var request = newRequest();

        when(request.getContentType()).thenReturn("text/plain;charset=UTF-8");
        assertFalse(UploadParser.isMultipart(request));
// Path: upload-parser-tests/src/test/java/com/github/elopteryx/upload/util/Servlets.java
// public static HttpServletRequest newRequest() throws Exception {
//     final var request = mock(HttpServletRequest.class);
// 
//     when(request.getMethod()).thenReturn("POST");
//     when(request.getContentType()).thenReturn("multipart/");
//     when(request.getContentLengthLong()).thenReturn(1024 * 1024L);
//     when(request.getInputStream()).thenReturn(new MockServletInputStream());
//     when(request.isAsyncSupported()).thenReturn(true);
// 
//     return request;
// }
// 
// Path: upload-parser-tests/src/test/java/com/github/elopteryx/upload/util/Servlets.java
// public static HttpServletResponse newResponse() {
//     final var response = mock(HttpServletResponse.class);
// 
//     when(response.getStatus()).thenReturn(200);
// 
//     return response;
// }
// 
// Path: upload-parser-core/src/main/java/com/github/elopteryx/upload/util/NullChannel.java
// public class NullChannel implements ReadableByteChannel, WritableByteChannel {
// 
//     /**
//      * Flag to determine whether the channel is closed or not.
//      */
//     private boolean open = true;
// 
//     @Override
//     public int read(final ByteBuffer dst) throws IOException {
//         if (!open) {
//             throw new ClosedChannelException();
//         }
//         return -1;
//     }
// 
//     @Override
//     public int write(final ByteBuffer src) throws IOException {
//         if (!open) {
//             throw new ClosedChannelException();
//         }
//         final var remaining = src.remaining();
//         src.position(src.limit());
//         return remaining;
//     }
// 
//     @Override
//     public boolean isOpen() {
//         return open;
//     }
// 
//     @Override
//     public void close() {
//         open = false;
//     }
// }


// Path: upload-parser-tests/src/test/java/com/github/elopteryx/upload/UploadParserTest.java
import static com.github.elopteryx.upload.util.Servlets.newRequest;
import static com.github.elopteryx.upload.util.Servlets.newResponse;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import com.github.elopteryx.upload.util.NullChannel;
import com.google.common.jimfs.Jimfs;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.nio.ByteBuffer;
import java.nio.file.FileSystem;
import java.nio.file.Files;
import jakarta.servlet.AsyncContext;
import jakarta.servlet.ServletInputStream;
import jakarta.servlet.http.HttpServletResponse;

package com.github.elopteryx.upload;




class UploadParserTest implements OnPartBegin, OnPartEnd, OnRequestComplete, OnError {

    private static FileSystem fileSystem;

    @BeforeAll
    static void setUp() {
        fileSystem = Jimfs.newFileSystem();
    }

    @Test
    void valid_content_type() throws Exception {
        final var request = newRequest();

        when(request.getContentType()).thenReturn("multipart/");
        assertTrue(UploadParser.isMultipart(request));
    }

    @Test
    void invalid_numeric_arguments() {
        assertAll(
                () -> assertThrows(IllegalArgumentException.class, () -> UploadParser.newParser().sizeThreshold(-1)),
                () -> assertThrows(IllegalArgumentException.class, () -> UploadParser.newParser().maxPartSize(-1)),
                () -> assertThrows(IllegalArgumentException.class, () -> UploadParser.newParser().maxRequestSize(-1)),
                () -> assertThrows(IllegalArgumentException.class, () -> UploadParser.newParser().maxBytesUsed(-1))
        );
    }

    @Test
    void invalid_content_type_async() throws Exception {
        final var request = newRequest();

        when(request.getContentType()).thenReturn("text/plain;charset=UTF-8");
        assertFalse(UploadParser.isMultipart(request));
        assertThrows(IllegalArgumentException.class, () -> UploadParser.newParser().userObject(newResponse()).setupAsyncParse(request));