@Test
public void testSortDoesNotAddExtraRootPaths() throws Exception {

  // create a sort request against the entity directly
  List<SortRequestProperty> sortRequestProperties = new ArrayList<>();
  sortRequestProperties.add(
      new SortRequestProperty(AlertHistoryResourceProvider.ALERT_HISTORY_TIMESTAMP,
          org.apache.ambari.server.controller.spi.SortRequest.Order.ASC));
  SortRequest sortRequest = new SortRequestImpl(sortRequestProperties);
  // create a complex, cross-entity predicate
  Predicate predicate = new PredicateBuilder().property(
          AlertHistoryResourceProvider.ALERT_HISTORY_DEFINITION_NAME).equals("foo").toPredicate();
  MockAlertHistoryredicateVisitor visitor = new MockAlertHistoryredicateVisitor();
  PredicateHelper.visit(predicate, visitor);
  JpaSortBuilder<AlertHistoryEntity> sortBuilder = new JpaSortBuilder<AlertHistoryEntity>();
  List<Order> sortOrders = sortBuilder.buildSortOrders(sortRequest, visitor);
  Assert.assertEquals(sortOrders.size(), 1);
  // verify the CriteriaQuery has the correct roots
  // it should have one for the main query predicate
  CriteriaQuery<AlertHistoryEntity> query = visitor.getCriteriaQuery();
  Set<Root<?>> roots = query.getRoots();
  Assert.assertEquals(1, roots.size());
}