1 package civitas.common.mix.voteelementrevelation;
2
3 import static org.junit.jupiter.api.Assertions.assertFalse;
4 import static org.junit.jupiter.api.Assertions.assertThrows;
5 import static org.junit.jupiter.api.Assertions.assertTrue;
6
7 import org.junit.jupiter.api.DisplayName;
8 import org.junit.jupiter.api.Test;
9 import org.mockito.InjectMocks;
10
11 import civitas.common.RandomAwareTestBase;
12 import civitas.common.mix.capabilitymix.CapabilityMixTestData;
13 import civitas.common.mix.votemix.VoteMixTestData;
14 import civitas.crypto.publickey.ElGamalPublicKeyTestData;
15
16 class VerifyMixVoteElementRevelationTest extends RandomAwareTestBase
17 implements MixVoteElementRevelationTestData, ElGamalPublicKeyTestData, VoteMixTestData, CapabilityMixTestData {
18
19 @InjectMocks
20 VerifyMixVoteElementRevelation verifyMixVoteElementRevelation;
21
22 @Test
23 @DisplayName(
24 "checks that the target choice and capability are the reencrytions of the source with the given factors ")
25 void test() {
26 assertTrue(verifyMixVoteElementRevelation.apply(
27 VOTE_ELEMENT_REVELATION, EL_GAMAL_PUBLIC_KEY_E, 0, 1, FROM_MIX, TO_MIX));
28 }
29
30
31
32
33 @Test
34 @DisplayName("if the capability is not reencrypted to target, the verification fails")
35 void test1() {
36 assertFalse(verifyMixVoteElementRevelation.apply(
37 VOTE_ELEMENT_REVELATION, EL_GAMAL_PUBLIC_KEY_E, 0, 0, FROM_MIX, TO_MIX));
38 }
39
40 @Test
41 @DisplayName("if the choice is not reencrypted to target, the verification fails")
42 void test2() {
43 assertFalse(verifyMixVoteElementRevelation.apply(
44 VOTE_ELEMENT_REVELATION, EL_GAMAL_PUBLIC_KEY_EPRIME, 0, 1, FROM_MIX, TO_MIX));
45 }
46
47 @Test
48 @DisplayName("if the fromMix is not a VoteMix, the verification fails")
49 void test3() {
50 assertFalse(verifyMixVoteElementRevelation.apply(
51 VOTE_ELEMENT_REVELATION, EL_GAMAL_PUBLIC_KEY_E, 0, 1, CAPABILITY_MIX_MOCK, TO_MIX));
52 }
53
54 @Test
55 @DisplayName("if the toMix is not a VoteMix, the verification fails")
56 void test4() {
57 assertFalse(verifyMixVoteElementRevelation.apply(
58 VOTE_ELEMENT_REVELATION, EL_GAMAL_PUBLIC_KEY_E, 0, 1, FROM_MIX, CAPABILITY_MIX_MOCK));
59 }
60
61 @Test
62 @DisplayName("if the revelation is null, a NullPointerException is thrown")
63 void test5() {
64 assertThrows(
65 NullPointerException.class,
66 () -> verifyMixVoteElementRevelation.apply(null, EL_GAMAL_PUBLIC_KEY_E, 0, 1, FROM_MIX, TO_MIX));
67 }
68
69 @Test
70 @DisplayName("if the key is null, a NullPointerException is thrown")
71 void test6() {
72 assertThrows(
73 NullPointerException.class,
74 () -> verifyMixVoteElementRevelation.apply(VOTE_ELEMENT_REVELATION, null, 0, 1, FROM_MIX, TO_MIX));
75 }
76
77 @Test
78 @DisplayName("if the fromMix is null, a NullPointerException is thrown")
79 void test7() {
80 assertThrows(
81 NullPointerException.class,
82 () -> verifyMixVoteElementRevelation.apply(
83 VOTE_ELEMENT_REVELATION, EL_GAMAL_PUBLIC_KEY_E, 0, 1, null, TO_MIX));
84 }
85
86 @Test
87 @DisplayName("if the toMix is null, a NullPointerException is thrown")
88 void test8() {
89 assertThrows(
90 NullPointerException.class,
91 () -> verifyMixVoteElementRevelation.apply(
92 VOTE_ELEMENT_REVELATION, EL_GAMAL_PUBLIC_KEY_E, 0, 1, FROM_MIX, null));
93 }
94
95 @Test
96 @DisplayName("if the fromIndex is out of bounds, an IndexOutOfBoundsException is thrown")
97 void test9() {
98 assertThrows(
99 IndexOutOfBoundsException.class,
100 () -> verifyMixVoteElementRevelation.apply(
101 VOTE_ELEMENT_REVELATION, EL_GAMAL_PUBLIC_KEY_E, 2, 1, FROM_MIX, TO_MIX));
102 }
103
104 @Test
105 @DisplayName("if the toIndex is out of bounds, an IndexOutOfBoundsException is thrown")
106 void test10() {
107 assertThrows(
108 IndexOutOfBoundsException.class,
109 () -> verifyMixVoteElementRevelation.apply(
110 VOTE_ELEMENT_REVELATION, EL_GAMAL_PUBLIC_KEY_E, 0, 2, FROM_MIX, TO_MIX));
111 }
112 }