### Question:
DeferredFileBody implements RawDataBody, SizeAware { @Override public InputStream getInputStream() throws MessagingException { try { if (file != null) { Timber.d("Decrypted data is file-backed."); return new BufferedInputStream(new FileInputStream(file)); } if (data != null) { Timber.d("Decrypted data is memory-backed."); return new ByteArrayInputStream(data); } throw new IllegalStateException("Data must be fully written before it can be read!"); } catch (IOException ioe) { throw new MessagingException("Unable to open body", ioe); } } DeferredFileBody(FileFactory fileFactory, String transferEncoding); @VisibleForTesting  DeferredFileBody(int memoryBackedThreshold, FileFactory fileFactory,
            String transferEncoding); OutputStream getOutputStream(); @Override InputStream getInputStream(); @Override long getSize(); File getFile(); @Override void setEncoding(String encoding); @Override void writeTo(OutputStream out); @Override String getEncoding(); static final int DEFAULT_MEMORY_BACKED_THRESHOLD; }### Answer:
@Test public void withShortData__shouldReturnData() throws Exception { writeShortTestData(); InputStream inputStream = deferredFileBody.getInputStream(); byte[] data = IOUtils.toByteArray(inputStream); assertNull(createdFile); assertArrayEquals(TEST_DATA_SHORT, data); }
@Test public void withLongData__shouldReturnData() throws Exception { writeLongTestData(); InputStream inputStream = deferredFileBody.getInputStream(); byte[] data = IOUtils.toByteArray(inputStream); InputStream fileInputStream = new FileInputStream(createdFile); byte[] dataFromFile = IOUtils.toByteArray(fileInputStream); assertArrayEquals(TEST_DATA_LONG, data); assertArrayEquals(TEST_DATA_LONG, dataFromFile); }