JDBI测试自定义注释以生成sql语句

时间:2019-05-07 10:31:30

标签: java jdbi

我正在测试jdbi包中的自定义SqlStatementCustomizingAnnotation批注。

http://jdbi.org/#_statement_customizing_annotations

我有以下单元测试,但我看到返回的“ customizer”对象是lambda。我如何断言我想在自定义批注中生成的SQL是我所期望的。如何将“定制程序”对象转换为sql语句,或检查并声明“定制程序”对象中的sql。

SourceEventTimeCustomizerTest

 @Test
 public void testSourceModifiedQuery(){
        SourceModifiedQuery.SourceEventDateTimeCustomizer srcModifiedQuery = new SourceModifiedQuery.SourceEventDateTimeCustomizer();

        Annotation annotation = buildSourceModifiedQueryAnnotation();

        List<Query> queries = new ArrayList<Query>();
        queries.add(QueryHelper.createQuery("source_modified_date_time" , Query.Operator.EQ, "2018-01-01"));

        SqlStatementCustomizer customizer = srcModifiedQuery.createForParameter(annotation, DealDao.class, null, queries );
        assertNotNull(customizer);

    }

SourceEventTimeCustomizer

  @Override
        public SqlStatementCustomizer createForParameter(final Annotation annotation, final Class sqlObjectType,
                final Method method, final Object arg) {
            final List<Query> queries = (List<Query>) arg;
            final SourceModifiedQuery sourceModifiedQuery = (SourceModifiedQuery) annotation;

            final String actualQuery = genQuery(queries, sourceModifiedQuery);
            return sqlStatement -> sqlStatement.define(sourceModifiedQuery.value(), actualQuery);
        }

0 个答案:

没有答案