Clover Coverage Report - Atlassian Core
Coverage timestamp: Sun Nov 30 2008 18:33:35 CST
14   54   7   2.8
4   44   0.5   5
5     1.4  
1    
 
 
  AbstractSpoolTest       Line # 14 14 7 100% 1.0
 
  (7)
 
1    package test.atlassian.core.spool;
2   
3    import junit.framework.TestCase;
4    import com.atlassian.core.spool.Spool;
5   
6    import java.io.InputStream;
7    import java.io.ByteArrayInputStream;
8    import java.io.IOException;
9    import java.io.File;
10    import java.util.Random;
11   
12    import org.apache.commons.io.IOUtils;
13   
 
14    public abstract class AbstractSpoolTest extends TestCase
15    {
16    private static int counter = -1;
17   
 
18  7 toggle public byte[] getTestData(int size)
19    {
20  7 byte[] data = new byte[size];
21  20487 for (int x = 0; x < size; x++)
22  20480 data[x] = (byte) (Math.random() * Byte.MAX_VALUE);
23  7 return data;
24    }
25   
 
26  2 toggle public void verifySpool(Spool spool, byte[] data) throws IOException
27    {
28  2 ByteArrayInputStream dataStream = new ByteArrayInputStream(data);
29  2 verifySpool(spool, dataStream);
30    }
31   
 
32  4 toggle public void verifySpool(Spool spool, InputStream dataStream) throws IOException
33    {
34  4 InputStream spoolStream = spool.spool(dataStream);
35  4 dataStream.reset();
36  4 assertTrue("Stream duplicated exactly", IOUtils.contentEquals(dataStream, spoolStream));
37    }
38   
 
39  2 toggle private static File generateFile(String prefix, String suffix, File dir)
40    {
41  2 if (counter == -1)
42    {
43  1 counter = new Random().nextInt() & 0xffff;
44    }
45  2 counter++;
46  2 return new File(dir, prefix + Integer.toString(counter) + suffix);
47    }
48   
 
49  2 toggle public File getTestFile()
50    {
51  2 return generateFile("spool", "test", new File("target"));
52    }
53   
54    }