View Javadoc
1   package civitas.crypto.oneoflreencryption;
2   
3   import static org.junit.jupiter.api.Assertions.assertEquals;
4   import static org.junit.jupiter.api.Assertions.assertNull;
5   
6   import org.junit.jupiter.api.DisplayName;
7   import org.junit.jupiter.api.Test;
8   import org.mockito.InjectMocks;
9   
10  import civitas.crypto.ciphertextlist.ElGamalCiphertextListTestData;
11  import civitas.crypto.reencryptfactor.ElGamalReencryptFactorTestData;
12  import io.github.magwas.testing.TestBase;
13  
14  class ConstructElGamal1OfLReencryptionTest extends TestBase
15  		implements ElGamal1OfLReencryptionTestData, ElGamalCiphertextListTestData, ElGamalReencryptFactorTestData {
16  
17  	@InjectMocks
18  	ConstructElGamal1OfLReencryption constructElGamal1OfLReencryption;
19  
20  	@Test
21  	@DisplayName("constructs an encrypted choice," + "containing the reencryption of the choosen vote and its proof ")
22  	void test() {
23  		ElGamal1OfLReencryption encChoice = constructElGamal1OfLReencryption.apply(
24  				EL_GAMAL_PUBLIC_KEY_E, CIPHERTEXT_LIST, MY_CHOICE.ordinal(), ELGAMAL_REENCRYPT_FACTOR_E);
25  		assertEquals(EL_GAMAL_PROOF_1_OF_L, encChoice.proof());
26  		assertEquals(REENCRYPTED_WELL_KNOWN_CHOICE, encChoice.m());
27  	}
28  
29  	@Test
30  	@DisplayName("if choice > number of ciphertexts, a null is returned")
31  	void test1() {
32  		ElGamal1OfLReencryption encChoice = constructElGamal1OfLReencryption.apply(
33  				EL_GAMAL_PUBLIC_KEY_E, CIPHERTEXT_LIST, CIPHERTEXT_LIST.size(), ELGAMAL_REENCRYPT_FACTOR_E);
34  		assertNull(encChoice);
35  	}
36  
37  	@Test
38  	@DisplayName("if ciphertexts is null, a null is returned")
39  	void test2() {
40  		ElGamal1OfLReencryption encChoice = constructElGamal1OfLReencryption.apply(
41  				EL_GAMAL_PUBLIC_KEY_E, null, MY_CHOICE.ordinal(), ELGAMAL_REENCRYPT_FACTOR_E);
42  		assertNull(encChoice);
43  	}
44  }