DefaultInputItem implements InputItem { @Override public InputStream getBody() throws IOException { return fileItem.getInputStream(); } DefaultInputItem(FileItem fileItem, Providers providers); @Override String getName(); @Override String getFilename(); @Override MediaType getMediaType(); @Override MultivaluedMap<String, String> getHeaders(); @Override InputStream getBody(); @Override T getBody(Class<T> type, Type genericType); @Override String getBodyAsString();  }
@Test public void getsBodyAsStream() throws Exception { ByteArrayInputStream in = new ByteArrayInputStream(new byte[0]); when(fileItem.getInputStream()).thenReturn(in); assertSame(in, inputItem.getBody()); }
@SuppressWarnings("unchecked") @Test public void getsBodyAsCustomType() throws Exception { Class<List> type = List.class; ParameterizedType genericType = newParameterizedType(List.class, String.class); Annotation[] annotations = new Annotation[0]; InputStream in = mock(InputStream.class); when(fileItem.getInputStream()).thenReturn(in); when(fileItem.getContentType()).thenReturn(TEXT_PLAIN_TYPE.toString()); MessageBodyReader reader = mock(MessageBodyReader.class); ArrayList<String> bodyAsList = newArrayList("to", "be", "or", "not", "to", "be"); when(reader.readFrom(eq(type), eq(genericType), aryEq(annotations), eq(TEXT_PLAIN_TYPE), any(), eq(in))).thenReturn(bodyAsList); when(providers.getMessageBodyReader(eq(type), eq(genericType), aryEq(annotations), eq(TEXT_PLAIN_TYPE))).thenReturn(reader); assertEquals(bodyAsList, inputItem.getBody(type, genericType)); }
@Test public void failsGetBodyAsCustomTypeWhenMessageBodyReaderForThisTypeIsNotAvailable() throws Exception { Class<List> type = List.class; ParameterizedType genericType = newParameterizedType(List.class, String.class); InputStream in = mock(InputStream.class); when(fileItem.getInputStream()).thenReturn(in); when(fileItem.getContentType()).thenReturn(TEXT_PLAIN_TYPE.toString()); thrown.expect(RuntimeException.class); inputItem.getBody(type, genericType); }