### Question:
KnowledgeSearchOrderProvider implements SearchOrderProviderFactory { @Override public SearchOrderProvider build(CompositeControllerContext context) { SearchOrderProvider.Sort sort = new SearchOrderProvider.Sort(FieldSortBuilder.DOC_FIELD_NAME,SortOrder.ASC); SearchType searchType = SearchType.DEFAULT; BoostingTraversalVisitor boostingTraversalVisitor = new BoostingTraversalVisitor(); if (context.getConstraint().isPresent() && boostingTraversalVisitor.visit(context.getConstraint().get().getTraversal())) { sort = SearchOrderProvider.EMPTY; searchType = SearchType.DFS_QUERY_THEN_FETCH; } SearchOrderProvider.Sort finalSort = sort; SearchType finalSearchType = searchType; return new SearchOrderProvider() { @Override public Sort getSort(SearchRequestBuilder builder) { return finalSort; } @Override public SearchType getSearchType(SearchRequestBuilder builder) { return finalSearchType; } }; }  @Override SearchOrderProvider build(CompositeControllerContext context);  }### Answer:
@Test public void testNoBoosting(){ CompositeControllerContext contextMock = Mockito.mock(CompositeControllerContext.class); when(contextMock.getConstraint()).thenAnswer(invocationOnMock -> { return Optional.of(new TraversalConstraint(__.start().has("abc", P.eq(123)))); }); KnowledgeSearchOrderProvider provider = new KnowledgeSearchOrderProvider(); SearchOrderProvider build = provider.build(contextMock); Assert.assertEquals( SearchType.DEFAULT, build.getSearchType(null)); Assert.assertEquals(new SearchOrderProvider.Sort(FieldSortBuilder.DOC_FIELD_NAME, SortOrder.ASC), build.getSort(null)); }
@Test public void testBoostedConstraint(){ CompositeControllerContext contextMock = Mockito.mock(CompositeControllerContext.class); when(contextMock.getConstraint()).thenAnswer(invocationOnMock -> { return Optional.of(new TraversalConstraint(__.start().asAdmin().addStep(new BoostingStepWrapper<>(__.start().has("abc", P.eq(123)).asAdmin().getEndStep(), 100)))); }); KnowledgeSearchOrderProvider provider = new KnowledgeSearchOrderProvider(); SearchOrderProvider build = provider.build(contextMock); Assert.assertEquals( SearchType.DFS_QUERY_THEN_FETCH, build.getSearchType(null)); Assert.assertEquals(SearchOrderProvider.EMPTY, build.getSort(null)); }
@Test public void testBoostedComplexConstraint(){ CompositeControllerContext contextMock = Mockito.mock(CompositeControllerContext.class); when(contextMock.getConstraint()).thenAnswer(invocationOnMock -> { GraphTraversal.Admin<Object, Object> inner = __.start().asAdmin().addStep(new BoostingStepWrapper<>(__.start().has("abc", P.eq(123)).asAdmin().getEndStep(), 100)); return Optional.of(new TraversalConstraint(__.start().and(__.start().has("bla", P.eq("123")), inner))); }); KnowledgeSearchOrderProvider provider = new KnowledgeSearchOrderProvider(); SearchOrderProvider build = provider.build(contextMock); Assert.assertEquals( SearchType.DFS_QUERY_THEN_FETCH, build.getSearchType(null)); Assert.assertEquals(SearchOrderProvider.EMPTY, build.getSort(null)); }