我有以下使用查询dsl绑定的存储库
public interface StatusRepository extends
PagingAndSortingRepository<Status, Long>,
QuerydslPredicateExecutor<Status>,
QuerydslBinderCustomizer<QStatus> {
@Override
default void customize(QuerydslBindings bindings, @NotNull QStatus root) {
bindings.bind(String.class).first((StringPath path, String value) ->
path.likeIgnoreCase(value.replace("_", "[_]")));
}
我正在为customize
方法编写单元测试,遇到了困难
@Test
public void customize() {
QuerydslBindings bindings = mock(QuerydslBindings.class);
QStatus qstatus = mock(QStatus.class);
QuerydslBindings.TypeBinder mock =
PowerMockito.mock(QuerydslBindings.TypeBinder.class);
when(bindings.bind(String.class)).thenReturn(mock);
statusRepository.customize(bindings, qstatusGroup);
}
Cannot mock/spy class org.springframework.data.querydsl.binding.QuerydslBindings$TypeBinder
Mockito cannot mock/spy because :
- final class
我正在使用powermockito来模拟QuerydslBindings.TypeBinder,但它仍然说它不能被模拟
1条答案
按热度按时间7kqas0il1#
检查QuerydslPredicateArgumentResolver Spring如何使用绑定器。
其思想是直接使用绑定器并检查生成的 predicate