title: Error mocking Cipher in java
body: <p>In order to do the test, I mock a Cipher object, but when I run the test, its fails because it's run the cipher code instead of the mock.</p>
  
  <p>So, I write a very simple test and when I run it, fails always.</p>
  
  <p>My test code is:</p>
  
  <pre><code>import javax.crypto.Cipher;
  
  import org.junit.Test;
  import org.mockito.Mockito;
  
  public class SimpleTest {
      @Test
      public void simpleTest() throws Exception {
          Cipher cipher = Mockito.mock(Cipher.class);
          cipher.doFinal(null);
          assertTrue(true);
      }
  }
  </code></pre>
  
  <p>And the exception who produces:</p>
  
  <pre><code>java.lang.IllegalStateException: Cipher not initialized
      at javax.crypto.Cipher.checkCipherState(Cipher.java:1750)
      at javax.crypto.Cipher.doFinal(Cipher.java:2157)
      at SimpleTest.simpleTest(SimpleTest.java:12)
      ...
  </code></pre>
  
  <p>Why is doFinal executed?</p>