1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
package info.magnolia.module.cache.util; |
35 |
|
|
36 |
|
import static org.junit.Assert.*; |
37 |
|
|
38 |
|
import java.io.IOException; |
39 |
|
|
40 |
|
import org.junit.Test; |
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
@version |
45 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (32) |
Complexity: 4 |
Complexity Density: 0.14 |
|
46 |
|
public class GZipUtilTest { |
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
47 |
1 |
@Test... |
48 |
|
public void testGzippedEmptyByteArrayShouldBeExactly20BytesLong() throws IOException { |
49 |
1 |
final byte[] gzipped = GZipUtil.gzip(new byte[0]); |
50 |
1 |
assertEquals(20, gzipped.length); |
51 |
1 |
final byte[] unzipped = GZipUtil.ungzip(gzipped); |
52 |
1 |
assertEquals(0, unzipped.length); |
53 |
|
|
54 |
1 |
assertFalse(GZipUtil.isGZipped(unzipped)); |
55 |
1 |
assertTrue(GZipUtil.isGZipped(gzipped)); |
56 |
|
} |
57 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
58 |
1 |
@Test... |
59 |
|
public void testGzipped1ByteArrayShouldNotBe20BytesLong() throws IOException { |
60 |
1 |
final byte[] gzipped = GZipUtil.gzip(new byte[]{'a'}); |
61 |
1 |
assertEquals(21, gzipped.length); |
62 |
1 |
final byte[] unzipped = GZipUtil.ungzip(gzipped); |
63 |
1 |
assertEquals(1, unzipped.length); |
64 |
1 |
assertEquals('a', unzipped[0]); |
65 |
|
|
66 |
1 |
assertFalse(GZipUtil.isGZipped(unzipped)); |
67 |
1 |
assertTrue(GZipUtil.isGZipped(gzipped)); |
68 |
|
} |
69 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
70 |
1 |
@Test... |
71 |
|
public void testGzipIsSymetric() throws IOException { |
72 |
1 |
final byte[] gzipped = GZipUtil.gzip("azerty".getBytes()); |
73 |
1 |
final byte[] unzipped = GZipUtil.ungzip(gzipped); |
74 |
1 |
assertEquals(6, unzipped.length); |
75 |
1 |
assertEquals("azerty", new String(unzipped)); |
76 |
|
|
77 |
1 |
assertFalse(GZipUtil.isGZipped(unzipped)); |
78 |
1 |
assertTrue(GZipUtil.isGZipped(gzipped)); |
79 |
|
} |
80 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
81 |
1 |
@Test... |
82 |
|
public void testGzipActuallyCompressesAtSomePoint() throws IOException { |
83 |
1 |
final String s1 = "qwertzuiopasdfghjklyxcvbnm"; |
84 |
1 |
final String s = s1 + s1; |
85 |
1 |
assertEquals(52, s.length()); |
86 |
1 |
final byte[] gzipped = GZipUtil.gzip(s.getBytes()); |
87 |
1 |
assertTrue(gzipped.length < s.length()); |
88 |
1 |
final byte[] unzipped = GZipUtil.ungzip(gzipped); |
89 |
1 |
assertEquals(s, new String(unzipped)); |
90 |
|
|
91 |
1 |
assertFalse(GZipUtil.isGZipped(unzipped)); |
92 |
1 |
assertTrue(GZipUtil.isGZipped(gzipped)); |
93 |
|
} |
94 |
|
} |