| 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 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (23) |
Complexity: 7 |
Complexity Density: 0.5 |
|
| 14 |
|
public abstract class AbstractSpoolTest extends TestCase |
| 15 |
|
{ |
| 16 |
|
private static int counter = -1; |
| 17 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 18 |
7
|
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 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 26 |
2
|
public void verifySpool(Spool spool, byte[] data) throws IOException... |
| 27 |
|
{ |
| 28 |
2
|
ByteArrayInputStream dataStream = new ByteArrayInputStream(data); |
| 29 |
2
|
verifySpool(spool, dataStream); |
| 30 |
|
} |
| 31 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 32 |
4
|
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 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 39 |
2
|
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 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 49 |
2
|
public File getTestFile()... |
| 50 |
|
{ |
| 51 |
2
|
return generateFile("spool", "test", new File("target")); |
| 52 |
|
} |
| 53 |
|
|
| 54 |
|
} |