doThrow(new CertificateExpiredException()).doNothing().when(mRsaCert).checkValidity(); decryptedData = cryptoUtils.decrypt(encrypted, false); assertEquals("anything", decryptedData.getDecryptedData()); doThrow(new CertificateExpiredException()).doNothing().when(mRsaCert).checkValidity(); encrypted = cryptoUtils.encrypt("anything"); assertEquals(CIPHER_RSA + "/" + RSA_KEY_SIZE + ALGORITHM_DATA_SEPARATOR + "anything", encrypted);