@@ -0,0 +1,1217 @@
+package com.github.davidcarboni.encryptedfileupload;%0A%0Aimport com.github.davidcarboni.cryptolite.Random;%0Aimport org.apache.commons.fileupload.FileItem;%0Aimport org.apache.commons.io.FileUtils;%0Aimport org.apache.commons.lang.ArrayUtils;%0Aimport org.junit.Test;%0A%0Aimport static org.junit.Assert.assertFalse;%0A%0A%0A/**%0A * Test to confirm that data are written to disk encrpted when the threshold is reached in %7B@link EncryptedFileItemFactory%7D.%0A */%0Apublic class EncryptedFileItemFactoryTest %7B%0A%0A    @Test%0A    public void shouldEncryptUpload() throws Exception %7B%0A%0A        // Given%0A        EncryptedFileItemFactory fileItemFactory = new EncryptedFileItemFactory();%0A        byte%5B%5D data = Random.bytes(fileItemFactory.getSizeThreshold() + 1);%0A%0A        // When%0A        FileItem item = fileItemFactory.createItem(%22test%22, %22text/plain%22, true, %22test.txt%22);%0A        item.getOutputStream().write(data);%0A        item.getOutputStream().close();%0A%0A        // Then%0A        // Confirm we wrote to disk%0A        assertFalse(item.isInMemory());%0A        // Confirm the file is not in cleartext:%0A        byte%5B%5D read = FileUtils.readFileToByteArray(((EncryptedFileItem) item).getTempFile());%0A        assertFalse(ArrayUtils.isEquals(data, read));%0A    %7D%0A%7D

Test to verify that data are encrypted if written to disk.