Mockito: test method with new Runnable() thread

42 views Asked by At

I have the method:

@Override
public void saveCompetence(/*...*/) throws Exception {
    try {
        operationSupport.mode1(new Runnable() {
            @Override
            public void run() {
                try {
                    // ......
                    
                    }
                } catch (Exception e) {
                    LOG.error("Has errors! ", e);
                    throw new RuntimeException(e);
                }
            }
        });
    } catch (Exception e) {
        LOG.error("Has errors! ", e);
        throw new Exception(Core1.SYSTEM_ERROR);
    }
}

I want to write unit test on method saveCompetence() using Mockito. But when i debugg my unit test, i do not go into inner run() method.

Here is my method mode1():

public void mode1(Runnable callback) {
    final SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
        threadLocalSqlSession.set(sqlSession);
        callback.run();
        sqlSession.commit();
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
        sqlSession.rollback(true);
        throw new RuntimeException(e);
    }
    finally {
        sqlSession.close();
        threadLocalSqlSession.remove();
    }
}

How can I go inside run() method when I debug my unit test ?

0

There are 0 answers