/** Test for clear statement caches. */ @Test public void testClearStatementCaches() { testClass.statementCachingEnabled = true; mockPreparedStatementCache.clear(); expectLastCall().once(); mockCallableStatementCache.clear(); expectLastCall().once(); replay(mockPreparedStatementCache, mockCallableStatementCache); testClass.clearStatementCaches(true); verify(mockPreparedStatementCache, mockCallableStatementCache); reset(mockPreparedStatementCache, mockCallableStatementCache); mockPool.closeConnectionWatch = true; mockPreparedStatementCache.checkForProperClosure(); expectLastCall().once(); mockCallableStatementCache.checkForProperClosure(); expectLastCall().once(); replay(mockPreparedStatementCache, mockCallableStatementCache); testClass.clearStatementCaches(false); verify(mockPreparedStatementCache, mockCallableStatementCache); }
/** * Mock setup. * * @throws Exception */ @BeforeClass public static void setUp() throws Exception { config = CommonTestUtils.getConfigClone(); mockConnection = createNiceMock(ConnectionHandle.class); mockPreparedStatementCache = createNiceMock(IStatementCache.class); mockCallableStatementCache = createNiceMock(IStatementCache.class); mockLogger = createNiceMock(Logger.class); makeThreadSafe(mockLogger, true); mockPool = createNiceMock(BoneCP.class); mockPool.closeConnectionWatch = true; expect(mockPool.getConfig()).andReturn(config).anyTimes(); config.setTransactionRecoveryEnabled(false); config.setStatementsCacheSize(1); replay(mockPool); testClass = new ConnectionHandle( mockConnection, mockPreparedStatementCache, mockCallableStatementCache, mockPool); testStatementCache = new StatementCache(100); Field field = testClass.getClass().getDeclaredField("logger"); field.setAccessible(true); field.set(null, mockLogger); config.setReleaseHelperThreads(0); }