I want the closeSession() method to closeSession() exception when it is called, so that I can verify that my log has been executed. I mocked the Crypto object as mockCrypto and set it like this:
@Test public void testdecrpyMcpDataExceptions() throws Exception { Crypto mockCrypto = Mockito.mock(Crypto.class); try { mockCrypto = CryptoManager.getCrypto(); logger.info("Cyrpto Initialized"); } finally { logger.info("Finally"); try { logger.info("About to close Crypto!"); Mockito.doThrow(new CryptoException("")).when(mockCrypto).closeSession(); mockCrypto.closeSession(); } catch (CryptoException e) { logger.warn("CryptoException occurred when closing crypto session at decryptMcpData() in CipherUtil : esi"); } } }
However, when I start, I get an error message:
Argument passed to when() is not a mock!
Am I mocking the class or am I just missing something?
source share