@Override
  public void enableCaching() {
    CACHING_ENABLED.set(Boolean.TRUE);
  }
@Test
  void openSession_with_caching_returns_wrapper_of_MyBatis_DbSession_which_delegates_all_methods_but_close() {
    boolean batchOrRegular = random.nextBoolean();

    underTest.enableCaching();

    verifyFirstDelegation(batchOrRegular, (myBatisDbSession, dbSession) -> {
      dbSession.rollback();
      verify(myBatisDbSession).rollback();
    });
    verifyDelegation(batchOrRegular, (myBatisDbSession, dbSession) -> {
      boolean flag = random.nextBoolean();
      dbSession.rollback(flag);
      verify(myBatisDbSession).rollback(flag);
    });

    verifyDelegation(batchOrRegular, (myBatisDbSession, dbSession) -> {
      dbSession.commit();
      verify(myBatisDbSession).commit();
    });
    verifyDelegation(batchOrRegular, (myBatisDbSession, dbSession) -> {
      boolean flag = random.nextBoolean();
      dbSession.commit(flag);
      verify(myBatisDbSession).commit(flag);
    });

    verifyDelegation(batchOrRegular, (myBatisDbSession, dbSession) -> {
      String str = randomAlphabetic(10);
      dbSession.selectOne(str);
      verify(myBatisDbSession).selectOne(str);
    });
    verifyDelegation(batchOrRegular, (myBatisDbSession, dbSession) -> {
      String str = randomAlphabetic(10);
      Object object = new Object();
      dbSession.selectOne(str, object);
      verify(myBatisDbSession).selectOne(str, object);
    });

    verifyDelegation(batchOrRegular, (myBatisDbSession, dbSession) -> {
      String str = randomAlphabetic(10);
      dbSession.selectList(str);
      verify(myBatisDbSession).selectList(str);
    });
    verifyDelegation(batchOrRegular, (myBatisDbSession, dbSession) -> {
      String str = randomAlphabetic(10);
      Object object = new Object();
      dbSession.selectList(str, object);
      verify(myBatisDbSession).selectList(str, object);
    });
    verifyDelegation(batchOrRegular, (myBatisDbSession, dbSession) -> {
      String str = randomAlphabetic(10);
      Object parameter = new Object();
      RowBounds rowBounds = new RowBounds();
      dbSession.selectList(str, parameter, rowBounds);
      verify(myBatisDbSession).selectList(str, parameter, rowBounds);
    });

    verifyDelegation(batchOrRegular, (myBatisDbSession, dbSession) -> {
      String str = randomAlphabetic(10);
      String mapKey = randomAlphabetic(10);
      dbSession.selectMap(str, mapKey);
      verify(myBatisDbSession).selectMap(str, mapKey);
    });
    verifyDelegation(batchOrRegular, (myBatisDbSession, dbSession) -> {
      String str = randomAlphabetic(10);
      Object parameter = new Object();
      String mapKey = randomAlphabetic(10);
      dbSession.selectMap(str, parameter, mapKey);
      verify(myBatisDbSession).selectMap(str, parameter, mapKey);
    });
    verifyDelegation(batchOrRegular, (myBatisDbSession, dbSession) -> {
      String str = randomAlphabetic(10);
      Object parameter = new Object();
      String mapKey = randomAlphabetic(10);
      RowBounds rowBounds = new RowBounds();
      dbSession.selectMap(str, parameter, mapKey, rowBounds);
      verify(myBatisDbSession).selectMap(str, parameter, mapKey, rowBounds);
    });

    verifyDelegation(batchOrRegular, (myBatisDbSession, dbSession) -> {
      String str = randomAlphabetic(10);
      ResultHandler handler = mock(ResultHandler.class);
      dbSession.select(str, handler);
      verify(myBatisDbSession).select(str, handler);
    });
    verifyDelegation(batchOrRegular, (myBatisDbSession, dbSession) -> {
      String str = randomAlphabetic(10);
      Object parameter = new Object();
      ResultHandler handler = mock(ResultHandler.class);
      dbSession.select(str, parameter, handler);
      verify(myBatisDbSession).select(str, parameter, handler);
    });
    verifyDelegation(batchOrRegular, (myBatisDbSession, dbSession) -> {
      String str = randomAlphabetic(10);
      Object parameter = new Object();
      ResultHandler handler = mock(ResultHandler.class);
      RowBounds rowBounds = new RowBounds();
      dbSession.select(str, parameter, rowBounds, handler);
      verify(myBatisDbSession).select(str, parameter, rowBounds, handler);
    });

    verifyDelegation(batchOrRegular, (myBatisDbSession, dbSession) -> {
      String str = randomAlphabetic(10);
      dbSession.insert(str);
      verify(myBatisDbSession).insert(str);
    });
    verifyDelegation(batchOrRegular, (myBatisDbSession, dbSession) -> {
      String str = randomAlphabetic(10);
      Object object = new Object();
      dbSession.insert(str, object);
      verify(myBatisDbSession).insert(str, object);
    });

    verifyDelegation(batchOrRegular, (myBatisDbSession, dbSession) -> {
      String str = randomAlphabetic(10);
      dbSession.update(str);
      verify(myBatisDbSession).update(str);
    });
    verifyDelegation(batchOrRegular, (myBatisDbSession, dbSession) -> {
      String str = randomAlphabetic(10);
      Object object = new Object();
      dbSession.update(str, object);
      verify(myBatisDbSession).update(str, object);
    });

    verifyDelegation(batchOrRegular, (myBatisDbSession, dbSession) -> {
      String str = randomAlphabetic(10);
      dbSession.delete(str);
      verify(myBatisDbSession).delete(str);
    });
    verifyDelegation(batchOrRegular, (myBatisDbSession, dbSession) -> {
      String str = randomAlphabetic(10);
      Object object = new Object();
      dbSession.delete(str, object);
      verify(myBatisDbSession).delete(str, object);
    });

    verifyDelegation(batchOrRegular, (myBatisDbSession, dbSession) -> {
      dbSession.flushStatements();
      verify(myBatisDbSession).flushStatements();
    });

    verifyDelegation(batchOrRegular, (myBatisDbSession, dbSession) -> {
      dbSession.clearCache();
      verify(myBatisDbSession).clearCache();
    });

    verifyDelegation(batchOrRegular, (myBatisDbSession, dbSession) -> {
      Configuration expected = mock(Configuration.class);
      when(myBatisDbSession.getConfiguration()).thenReturn(expected);
      assertThat(dbSession.getConfiguration()).isSameAs(expected);
      verify(myBatisDbSession).getConfiguration();
    });

    verifyDelegation(batchOrRegular, (myBatisDbSession, dbSession) -> {
      Class<Object> clazz = Object.class;
      Object expected = new Object();
      when(myBatisDbSession.getMapper(clazz)).thenReturn(expected);
      assertThat(dbSession.getMapper(clazz)).isSameAs(expected);
      verify(myBatisDbSession).getMapper(clazz);
    });

    verifyDelegation(batchOrRegular, (myBatisDbSession, dbSession) -> {
      Connection connection = mock(Connection.class);
      when(myBatisDbSession.getConnection()).thenReturn(connection);
      assertThat(dbSession.getConnection()).isSameAs(connection);
      verify(myBatisDbSession).getConnection();
    });
  }