/*
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package com.xpn.xwiki.doc;

import org.jmock.cglib.MockObjectTestCase;

/**
 * Unit tests for {@link XWikiAttachment}.
 *
 * @version $Id$
 */
public class XWikiAttachmentTest extends MockObjectTestCase
{
    public void testGetVersionList() throws Exception
    {
        final XWikiAttachment attach = new XWikiAttachment();
        attach.setVersion("1.1");
        assertEquals("Version list was not one element long for version 1.1", 1,
                     attach.getVersionList().size());
        attach.setVersion("1.2");
        assertEquals("Version list was not two elements long for version 1.2.", 2,
                     attach.getVersionList().size());
        attach.setVersion("1.3");
        assertEquals("Version list was not two elements long for version 1.3.", 3,
                     attach.getVersionList().size());
    }
}

@@ -926,42 +926,199 @@
 ort 
-org.jmock.cglib.MockObjectTestCase
+java.util.Random;%0Aimport java.io.InputStream;%0A%0Aimport com.xpn.xwiki.test.AbstractBridgedComponentTestCase;%0Aimport org.apache.commons.io.IOUtils;%0Aimport org.junit.Test;%0Aimport org.junit.Assert
 ;%0A%0A/
@@ -1232,28 +1232,52 @@
 nds 
-MockObjectTestCase%0A%7B
+AbstractBridgedComponentTestCase%0A%7B%0A    @Test
 %0A   
@@ -1429,32 +1429,39 @@
 %221.1%22);%0A        
+Assert.
 assertEquals(%22Ve
@@ -1517,16 +1517,23 @@
 .1%22, 1,%0A
+       
         
@@ -1612,32 +1612,39 @@
 %221.2%22);%0A        
+Assert.
 assertEquals(%22Ve
@@ -1715,32 +1715,39 @@
                 
+       
 attach.getVersio
@@ -1805,16 +1805,23 @@
         
+Assert.
 assertEq
@@ -1900,32 +1900,39 @@
                 
+       
 attach.getVersio
@@ -1953,11 +1953,1547 @@
 );%0A    %7D
+%0A%0A    /**%0A     * Create an attachment, populate it with enough data to make it flush to disk cache,%0A     * read back data and make sure it's the same.%0A     */%0A    @Test%0A    public void testStoreContentInDiskCache() throws Exception%0A    %7B%0A        int attachLength = 20000;%0A        // Check for data dependent errors.%0A        int seed = (int) System.currentTimeMillis();%0A        final XWikiAttachment attach = new XWikiAttachment();%0A        final InputStream ris = new RandomInputStream(attachLength, seed);%0A        attach.setContent(ris);%0A        Assert.assertEquals(%22Not all of the stream was read%22, 0, ris.available());%0A        Assert.assertTrue(%0A            IOUtils.contentEquals(new RandomInputStream(attachLength, seed),%0A                                  attach.getAttachment_content().getContentInputStream()));%0A    %7D%0A%0A    /** An InputStream which will return a stream of zeros of length given in the constructor. */%0A    private static class RandomInputStream extends InputStream%0A    %7B%0A        private int bytes;%0A%0A        private int state;%0A%0A        public RandomInputStream(final int bytes, final int seed)%0A        %7B%0A            this.bytes = bytes;%0A            this.state = seed;%0A        %7D%0A%0A        public int available()%0A        %7B%0A            return this.bytes;%0A        %7D%0A%0A        public int read()%0A        %7B%0A            if (this.bytes == 0) %7B%0A                return -1;%0A            %7D%0A            this.bytes--;%0A            this.state = this.state %3C%3C 13 %7C this.state %3E%3E%3E 19;%0A            return ++this.state & 0xff;%0A        %7D%0A    %7D
 %0A%7D%0A

Add a nice test to make an attachment and cause it to flush data to the on-disk cache then read it back.