@Test
public void filterSegmentsByNodesTest() throws ReaperException {

  Map<List<String>, List<String>> rangeToEndpoint = Maps.newHashMap();
  rangeToEndpoint.put(Arrays.asList("1", "2"), Arrays.asList("node1", "node2", "node3"));
  rangeToEndpoint.put(Arrays.asList("2", "4"), Arrays.asList("node1", "node2", "node3"));
  rangeToEndpoint.put(Arrays.asList("4", "6"), Arrays.asList("node1"));
  rangeToEndpoint.put(Arrays.asList("6", "8"), Arrays.asList("node1", "node2"));
  List<Segment> segments = Arrays.asList(
          Segment.builder().withTokenRange(new RingRange("1", "2")).build(),
          Segment.builder().withTokenRange(new RingRange("2", "3")).build(),
          Segment.builder().withTokenRange(new RingRange("3", "4")).build(),
          Segment.builder().withTokenRange(new RingRange("4", "5")).build(),
          Segment.builder().withTokenRange(new RingRange("5", "6")).build(),
          Segment.builder().withTokenRange(new RingRange("6", "8")).build());
  final RepairUnit repairUnit1 = mock(RepairUnit.class);
  when(repairUnit1.getNodes()).thenReturn(new HashSet<String>(Arrays.asList("node3", "node2")));
  final RepairUnit repairUnit2 = mock(RepairUnit.class);
  when(repairUnit2.getNodes()).thenReturn(new HashSet<String>(Arrays.asList("node1")));
  final RepairUnit repairUnit3 = mock(RepairUnit.class);
  when(repairUnit3.getNodes()).thenReturn(new HashSet<String>(Arrays.asList("node3")));
  List<Segment> filtered = RepairRunService.filterSegmentsByNodes(
          segments, repairUnit1, RepairRunService.buildEndpointToRangeMap(rangeToEndpoint));
  assertEquals(filtered.size(), 4);
  filtered = RepairRunService.filterSegmentsByNodes(segments, repairUnit2,
      RepairRunService.buildEndpointToRangeMap(rangeToEndpoint));
  assertEquals(filtered.size(), 6);
  filtered = RepairRunService.filterSegmentsByNodes(segments, repairUnit3,
      RepairRunService.buildEndpointToRangeMap(rangeToEndpoint));
  assertEquals(filtered.size(), 3);
  final RepairUnit repairUnitWithNoNodes = mock(RepairUnit.class);
  when(repairUnitWithNoNodes.getNodes()).thenReturn(new HashSet<String>());
  filtered = RepairRunService.filterSegmentsByNodes(segments, repairUnitWithNoNodes,
      RepairRunService.buildEndpointToRangeMap(rangeToEndpoint));
  assertEquals(filtered.size(), 6);
}