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