1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.crypto.internal.symmetric.generator; |
21 |
|
|
22 |
|
import org.junit.Before; |
23 |
|
import org.junit.Rule; |
24 |
|
import org.junit.Test; |
25 |
|
import org.xwiki.crypto.KeyGenerator; |
26 |
|
import org.xwiki.crypto.internal.DefaultSecureRandomProvider; |
27 |
|
import org.xwiki.crypto.params.generator.KeyGenerationParameters; |
28 |
|
import org.xwiki.crypto.params.generator.symmetric.GenericKeyGenerationParameters; |
29 |
|
import org.xwiki.test.annotation.ComponentList; |
30 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
31 |
|
|
32 |
|
import static org.hamcrest.CoreMatchers.equalTo; |
33 |
|
import static org.hamcrest.CoreMatchers.not; |
34 |
|
import static org.junit.Assert.assertThat; |
35 |
|
|
36 |
|
@ComponentList({DefaultSecureRandomProvider.class}) |
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 3 |
Complexity Density: 0.33 |
|
37 |
|
public class BcDESedeKeyGeneratorTest |
38 |
|
{ |
39 |
|
@Rule |
40 |
|
public final MockitoComponentMockingRule<KeyGenerator> mocker = |
41 |
|
new MockitoComponentMockingRule<KeyGenerator>(BcDESedeKeyGenerator.class); |
42 |
|
|
43 |
|
private KeyGenerator generator; |
44 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
45 |
2 |
@Before... |
46 |
|
public void configure() throws Exception |
47 |
|
{ |
48 |
2 |
generator = mocker.getComponentUnderTest(); |
49 |
|
} |
50 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
51 |
1 |
@Test... |
52 |
|
public void testGenerateWithoutArgument() throws Exception |
53 |
|
{ |
54 |
1 |
byte[] key = generator.generate(); |
55 |
|
|
56 |
1 |
assertThat(key.length, equalTo(24)); |
57 |
1 |
assertThat(key, not(equalTo(generator.generate()))); |
58 |
|
} |
59 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
60 |
1 |
@Test... |
61 |
|
public void testGenerateWithStrengthParameter() throws Exception |
62 |
|
{ |
63 |
1 |
KeyGenerationParameters params = new GenericKeyGenerationParameters(24); |
64 |
1 |
byte[] key = generator.generate(params); |
65 |
|
|
66 |
1 |
assertThat(key.length, equalTo(24)); |
67 |
1 |
assertThat(key, not(equalTo(generator.generate(params)))); |
68 |
1 |
assertThat(generator.generate(new GenericKeyGenerationParameters(16)).length, equalTo(16)); |
69 |
|
} |
70 |
|
} |