### Question:
AggregationService { public List<AggregatedSegment> aggregateSegments(List<? extends ConnectableSegment> segments) { List<AggregatedSegment> aggregatedSegments = new ArrayList<AggregatedSegment>(); for (Iterator<? extends ConnectableSegment> it = segments.iterator(); it.hasNext();) { ConnectableSegment segment = it.next(); AggregatedSegment newAggregatedSegment = new AggregatedSegment(segment); if (!canConnect(aggregatedSegments, newAggregatedSegment)) aggregatedSegments.add(newAggregatedSegment); } return aggregateMore(aggregatedSegments); }  void aggregate(AnalyzerContext analyzerContext); List<AggregatedSegment> aggregateSegments(List<? extends ConnectableSegment> segments);  }### Answer:
@Test public void testAggregateSegmentsEmpty() throws Exception { List<AggregatedSegment> list = aggregationService.aggregateSegments(Collections.EMPTY_LIST); assertTrue(list.isEmpty()); }
@Test public void testAggregateSegmentsSingle() throws Exception { List<ConnectableSegment> segments = asList(asFixedOrderWay(1)); List<AggregatedSegment> list = aggregationService.aggregateSegments(segments); assertEquals(1, list.size()); }
@Test public void testAggregateSegmentsTwoUnconnected() throws Exception { List<ConnectableSegment> segments = asList(asFixedOrderWay(1, 2), asFixedOrderWay(3, 4)); List<AggregatedSegment> list = aggregationService.aggregateSegments(segments); assertEquals(2, list.size()); }
@Test public void testAggregateSegmentsTwoConnected() throws Exception { List<ConnectableSegment> segments = asList(asFixedOrderWay(1, 2), asFixedOrderWay(2, 3)); List<AggregatedSegment> list = aggregationService.aggregateSegments(segments); assertEquals(1, list.size()); assertEquals(AggregatedSegment.class, list.get(0).getClass()); }