private static LuceneQuery mockLuceneQuery(int limit, int pageSize) { LuceneQuery mockLuceneQuery = mock(LuceneQuery.class); when(mockLuceneQuery.getLimit()).thenReturn(limit); when(mockLuceneQuery.getPageSize()).thenReturn(pageSize); ObjectUtils.doOperationSafely(() -> when(mockLuceneQuery.findKeys()) .thenReturn(Collections.emptySet()), Collections.emptySet()); rethrowAsRuntimeException(() -> when(mockLuceneQuery.findPages()) .thenThrow(newUnsupportedOperationException("Operation Not Supported!"))); ObjectUtils.doOperationSafely(() -> when(mockLuceneQuery.findResults()) .thenReturn(Collections.emptyList()), Collections.emptyList()); ObjectUtils.doOperationSafely(() -> when(mockLuceneQuery.findValues()) .thenReturn(Collections.emptyList()), Collections.emptyList()); return mockLuceneQuery; }