private static void checkCipher_Update_invalidMode_Failure(final int opmode) throws Exception {
        String msg = "update() should throw IllegalStateException [mode=" + opmode + "]";
        final int bs = createAesCipher(opmode).getBlockSize();
        assertEquals(16, bs); // check test is set up correctly
        assertIllegalStateException(msg, () -> createAesCipher(opmode).update(new byte[0]));
        assertIllegalStateException(msg, () -> createAesCipher(opmode).update(new byte[2 * bs]));
        assertIllegalStateException(msg, () -> createAesCipher(opmode).update(
                new byte[2 * bs] /* input */, bs /* inputOffset */, 0 /* inputLen */));
        try {
            createAesCipher(opmode).update(new byte[2*bs] /* input */, 0 /* inputOffset */,
                    2 * bs /* inputLen */, new byte[2 * bs] /* output */, 0 /* outputOffset */);
            fail(msg);
        } catch (IllegalStateException expected) {
        }
    }
Helper for testing that Cipher.update() throws IllegalStateException when
initialized in modes other than DECRYPT or ENCRYPT.
common/src/test/java/org/conscrypt/javax/crypto/CipherTest.java