spring启动simplejdbccall junit测试

2ic8powd  于 2021-07-13  发布在  Java
关注(0)|答案(0)|浏览(191)

我正在尝试为我的客户编写junit测试 SimpleJdbcCall 但总是得到 ExceptionsimpleJdbcCall.withProcedureName("MY_PROC").declareParameters(new SqlParameter("ID", Types.VARCHAR)); 如何在此场景中测试SimpleJDBCall?
道类

@Autowired
    JdbcTemplate jdbcTemplate;
    @Autowired
    private SimpleJdbcCall simpleJdbcCall;

    public void call(){

//BREAKS here Exception
     simpleJdbcCall.withProcedureName("MY_PROC").declareParameters(new SqlParameter("ID", Types.VARCHAR));

   SqlParameterSource namedParameters = new MapSqlParameterSource("ID", "123"));
  try {
            result = simpleJdbcCall.execute(namedParameters);
            retry();
        } catch (Exception e) {
            LOGGER.error("ERROR During call : " + CMAConstant.DISPOSITION_CMA + " " + e);
            requestCopyOnWriteArrayList.add(modifyLeadDispositionRequest);
           throw new Exception(e.getMessage());
        }

     }

朱尼特

@InjectMocks
    private static MYDAO dao;
  @Test
    public void update() {

        SimpleJdbcCall mockedCall = Mockito.mock(SimpleJdbcCall.class);

        Mockito.when(mockedCall.withProcedureName(Mockito.any())).thenReturn(mockedCall);

        try {
            final int message = dao.call();
            Assert.assertEquals(0, message);
            LOGGER.info("message = " + message);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

junit的pom

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-launcher</artifactId>
            <scope>test</scope>
        </dependency>

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题