@@ -119,7 +119,7 @@ public class CryptoUtilTest {
119119 public void setUp () throws Exception {
120120 PowerMockito .mockStatic (Log .class );
121121 PowerMockito .mockStatic (TextUtils .class );
122- PowerMockito .when (TextUtils .isEmpty (anyString ( ))).then ((Answer <Boolean >) invocation -> {
122+ PowerMockito .when (TextUtils .isEmpty (nullable ( String . class ))).then ((Answer <Boolean >) invocation -> {
123123 String input = invocation .getArgument (0 , String .class );
124124 return input == null || input .isEmpty ();
125125 });
@@ -1781,14 +1781,14 @@ public void shouldHandleKeyStoreErrorDuringMigration() throws Exception {
17811781 when (keyGenerator .generateKey ()).thenReturn (mockSecretKey );
17821782
17831783 byte [] encryptedNewKey = new byte []{30 , 31 , 32 , 33 };
1784- doReturn (encryptedNewKey ).when (cryptoUtil ).RSAEncrypt (newAESKey );
1784+ doReturn (encryptedNewKey ).when (cryptoUtil ).RSAEncrypt (any ( byte []. class ) );
17851785 String encodedNewKey = "new_generated_key" ;
17861786 PowerMockito .when (Base64 .encode (encryptedNewKey , Base64 .DEFAULT ))
17871787 .thenReturn (encodedNewKey .getBytes (StandardCharsets .UTF_8 ));
17881788
17891789 byte [] result = cryptoUtil .getAESKey ();
17901790
1791- Mockito .verify (storage , times (2 )).remove (KEY_ALIAS );
1791+ Mockito .verify (storage , times (1 )).remove (KEY_ALIAS );
17921792
17931793 assertThat (result , is (newAESKey ));
17941794 Mockito .verify (storage ).store (KEY_ALIAS , encodedNewKey );
@@ -1930,14 +1930,15 @@ public void shouldGenerateNewKeyWhenMigrationFails() throws Exception {
19301930 when (keyGenerator .generateKey ()).thenReturn (mockSecretKey );
19311931
19321932 byte [] encryptedNewKey = new byte []{40 , 41 , 42 };
1933- doReturn (encryptedNewKey ).when (cryptoUtil ).RSAEncrypt (newAESKey );
1933+ doReturn (encryptedNewKey ).when (cryptoUtil ).RSAEncrypt (any ( byte []. class ) );
19341934 String encodedNewKey = "fresh_key" ;
19351935 PowerMockito .when (Base64 .encode (encryptedNewKey , Base64 .DEFAULT ))
19361936 .thenReturn (encodedNewKey .getBytes (StandardCharsets .UTF_8 ));
19371937 byte [] result = cryptoUtil .getAESKey ();
19381938 assertThat (result , is (newAESKey ));
19391939 Mockito .verify (storage ).store (KEY_ALIAS , encodedNewKey );
1940- Mockito .verify (storage , times (2 )).remove (KEY_ALIAS );
1941- Mockito .verify (storage , times (2 )).remove (OLD_KEY_ALIAS );
1940+ // deleteAESKeys() is called once in tryMigrateLegacyAESKey when getRSAKeyEntry throws
1941+ Mockito .verify (storage , times (1 )).remove (KEY_ALIAS );
1942+ Mockito .verify (storage , times (1 )).remove (OLD_KEY_ALIAS );
19421943 }
19431944}
0 commit comments