NioMultipartParser extends OutputStream implements Disposable { @Override public void write(final int data) throws IOException { write(new byte[]{(byte) data}, 0, 1); } NioMultipartParser(final MultipartContext multipartContext, final NioMultipartParserListener nioMultipartParserListener);  NioMultipartParser(final MultipartContext multipartContext, final NioMultipartParserListener nioMultipartParserListener, final PartBodyStreamStorageFactory partBodyStreamStorageFactory);  NioMultipartParser(final MultipartContext multipartContext, final NioMultipartParserListener nioMultipartParserListener, final int bufferSize);  NioMultipartParser(final MultipartContext multipartContext,
                              final NioMultipartParserListener nioMultipartParserListener,
                              final PartBodyStreamStorageFactory partBodyStreamStorageFactory,
                              final int bufferSize,
                              final int maxHeadersSectionSize,
                              final int maxLevelOfNestedMultipart); @Override void close(); @Override boolean dispose(); @Override void flush(); @Override void write(final int data); @Override void write(byte[] data); @Override void write(byte[] data, int indexStart, int indexEnd); List<String> geFsmTransitions(); static final int DEFAULT_BUFFER_SIZE; static final int DEFAULT_HEADERS_SECTION_SIZE; static final int DEFAULT_MAX_LEVEL_OF_NESTED_MULTIPART; }
@Test public void testWrite_emptyData() throws IOException { MultipartContext context = mock(MultipartContext.class); when(context.getContentType()).thenReturn("multipart/form-data;boundary=MUEYT2qJT0_ZzYUvVQLy_DlrLeADyxzmsA"); NioMultipartParserListener listener = mock(NioMultipartParserListener.class); NioMultipartParser parser = new NioMultipartParser(context, listener); parser.write(new byte[]{}); }
@Test public void testWrite_error1(){ MultipartContext context = mock(MultipartContext.class); when(context.getContentType()).thenReturn("multipart/form-data;boundary=MUEYT2qJT0_ZzYUvVQLy_DlrLeADyxzmsA"); NioMultipartParserListener listener = mock(NioMultipartParserListener.class); NioMultipartParser parser = new NioMultipartParser(context, listener); Exception expected = null; try { parser.write(null, 0, 10); }catch (Exception e){ expected = e; } Assert.assertNotNull(expected); expected = null; try { parser.write(new byte[]{0x01, 0x02, 0x03}, 0, 2); }catch (Exception e){ expected = e; } Assert.assertNotNull(expected); }
@Test public void testWrite_error2(){ MultipartContext context = mock(MultipartContext.class); when(context.getContentType()).thenReturn("multipart/form-data;boundary=MUEYT2qJT0_ZzYUvVQLy_DlrLeADyxzmsA"); NioMultipartParserListener listener = mock(NioMultipartParserListener.class); NioMultipartParser parser = new NioMultipartParser(context, listener); Exception expected = null; try { parser.write(new byte[]{0x01, 0x02, 0x03}, 9, 10); }catch (Exception e){ expected = e; } Assert.assertNotNull(expected); expected = null; try { parser.write(new byte[]{0x01, 0x02, 0x03}, 0, 2); }catch (Exception e){ expected = e; } Assert.assertNotNull(expected); }
@Test public void testWrite_error3(){ MultipartContext context = mock(MultipartContext.class); when(context.getContentType()).thenReturn("multipart/form-data;boundary=MUEYT2qJT0_ZzYUvVQLy_DlrLeADyxzmsA"); NioMultipartParserListener listener = mock(NioMultipartParserListener.class); NioMultipartParser parser = new NioMultipartParser(context, listener); Exception expected = null; try { parser.write(new byte[]{0x01, 0x02, 0x03}, 3, 2); }catch (Exception e){ expected = e; } Assert.assertNotNull(expected); expected = null; try { parser.write(new byte[]{0x01, 0x02, 0x03}, 0, 2); }catch (Exception e){ expected = e; } Assert.assertNotNull(expected); }
@Test public void testWrite_error4(){ MultipartContext context = mock(MultipartContext.class); when(context.getContentType()).thenReturn("multipart/form-data;boundary=MUEYT2qJT0_ZzYUvVQLy_DlrLeADyxzmsA"); NioMultipartParserListener listener = mock(NioMultipartParserListener.class); NioMultipartParser parser = new NioMultipartParser(context, listener); Exception expected = null; try { parser.write(new byte[]{0x01, 0x02, 0x03}, 0, 15); }catch (Exception e){ expected = e; } Assert.assertNotNull(expected); expected = null; try { parser.write(new byte[]{0x01, 0x02, 0x03}, 0, 2); }catch (Exception e){ expected = e; } Assert.assertNotNull(expected); }