1 package civitas.common.encryptedchoice.tests;
2
3 import static org.junit.jupiter.api.Assertions.assertEquals;
4 import static org.mockito.Mockito.verify;
5
6 import org.junit.jupiter.api.DisplayName;
7 import org.junit.jupiter.api.Test;
8 import org.mockito.InjectMocks;
9 import org.mockito.Mock;
10
11 import civitas.common.ballot.tests.BallotTestData;
12 import civitas.common.encryptedchoice.EncryptChoice;
13 import civitas.common.encryptedchoice.EncryptedChoice;
14 import civitas.common.tests.RandomAwareTestBase;
15 import civitas.crypto.ciphertextlist.tests.ElGamalCiphertextListTestData;
16 import civitas.crypto.oneoflreencryption.ConstructElGamal1OfLReencryption;
17 import civitas.crypto.oneoflreencryption.tests.ElGamal1OfLReencryptionTestData;
18 import civitas.crypto.reencryptfactor.GenerateElGamalReencryptFactor;
19
20 class EncryptChoiceTest extends RandomAwareTestBase
21 implements ElGamalCiphertextListTestData, BallotTestData, ElGamal1OfLReencryptionTestData {
22
23 @InjectMocks
24 EncryptChoice encryptChoice;
25
26 @Mock
27 GenerateElGamalReencryptFactor generateElGamalReencryptFactor;
28
29 @Mock
30 ConstructElGamal1OfLReencryption constructElGamal1OfLReencryption;
31
32 @DisplayName(
33 """
34 encrypts the choice for the ballot
35 - generates a random reencryption factor
36 - constructs an 1 of L reeencryption using the choice in the ballot and the factor
37 """)
38 @Test
39 void test() {
40 EncryptedChoice actual = encryptChoice.apply(EL_GAMAL_PUBLIC_KEY_E, CIPHERTEXT_LIST, BALLOT.matrix, 0);
41
42 assertEquals(
43 new EncryptedChoice(
44 ELGAMAL_REENCRYPT_FACTOR_EPRIME, EL_GAMAL_1_OF_L_REENCRYPTION_MAP.get(BALLOT.matrix[0])),
45 actual);
46
47 verify(generateElGamalReencryptFactor).apply(EL_GAMAL_PARAMETERS);
48 verify(constructElGamal1OfLReencryption)
49 .apply(
50 EL_GAMAL_PUBLIC_KEY_E,
51 CIPHERTEXT_LIST,
52 BALLOT.matrix[0].ordinal(),
53 ELGAMAL_REENCRYPT_FACTOR_EPRIME);
54 }
55 }