private void test_Cipher_aborted_doFinal(Cipher c, String algorithm, String provider,
            Key encryptKey, Key decryptKey) throws Exception {
        byte[] text = getActualPlainText(algorithm);
        AlgorithmParameterSpec encryptSpec = getEncryptAlgorithmParameterSpec(algorithm);
        c.init(Cipher.ENCRYPT_MODE, encryptKey, encryptSpec);
        if (isAEAD(algorithm)) {
            c.updateAAD(new byte[24]);
        }
        try {
            c.doFinal(text, 0, text.length, new byte[0]);
            fail("Short buffer should have thrown ShortBufferException");
        } catch (ShortBufferException expected) {
            // Ignored
        }
        byte[] cipherText = c.doFinal(text);
        c.init(Cipher.DECRYPT_MODE, decryptKey, getDecryptAlgorithmParameterSpec(encryptSpec, c));
        if (isAEAD(algorithm)) {
            c.updateAAD(new byte[24]);
        }
        byte[] plainText = c.doFinal(cipherText);
        byte[] expectedPlainText = getExpectedPlainText(algorithm, provider);
        assertArrayEquals("Expected " + Arrays.toString(expectedPlainText) + " but was "
                + Arrays.toString(plainText)
                , expectedPlainText, plainText);
    }
Try various .init(...) calls with null parameters to make sure it is
handled.
common/src/test/java/org/conscrypt/javax/crypto/CipherTest.java