ActionResolverUtils { protected static VirtualPath mergeVirtualPaths(List<VirtualPath> virtualPaths) { if ( virtualPaths.isEmpty() ) { VirtualPath virtualPath = new VirtualPathBuilder() .setPathId(new VirtualPathId(UUID.randomUUID().toString())) .setVirtualLink(new ArrayList<VirtualLink>(0)) .setMetric(0L) .setBandwidth(0L) .setDelay(0L) .build(); return virtualPath; } if ( 1 == virtualPaths.size() ) { return virtualPaths.get(0); } List<VirtualLink> virtualLinks = new LinkedList<VirtualLink>(); VirtualLink virtualLink; long metric = 0; long bandwidth = Long.MAX_VALUE; long delay = 0; for ( VirtualPath virtualPath : virtualPaths ) { for ( VirtualLink virtualLink1 : virtualPath.getVirtualLink() ) { virtualLink = new VirtualLinkBuilder(virtualLink1) .setOrder((long)virtualLinks.size()) .build(); virtualLinks.add(virtualLink); } metric += virtualPath.getMetric(); delay += virtualPath.getDelay(); if ( virtualPath.getBandwidth() < bandwidth ) { bandwidth = virtualPath.getBandwidth(); } } VirtualPath virtualPath = new VirtualPathBuilder() .setPathId(new VirtualPathId(UUID.randomUUID().toString())) .setVirtualLink(virtualLinks) .setMetric(metric) .setBandwidth(bandwidth) .setDelay(delay) .build(); return virtualPath; }    }
@Test public void testMergeVirtualPaths() throws Exception { List<VirtualPath> virtualPaths = new ArrayList<VirtualPath>(); VirtualPath virtualPath = mock(VirtualPath.class); VirtualPath virtualPath1 = mock(VirtualPath.class); VirtualLink virtualLink = mock(VirtualLink.class); List<VirtualLink> virtualLinkList = new ArrayList<VirtualLink>(); virtualLinkList.add(virtualLink); Assert.assertTrue(ActionResolverUtils.mergeVirtualPaths(virtualPaths) != null); virtualPaths.add(virtualPath); Assert.assertTrue(ActionResolverUtils.mergeVirtualPaths(virtualPaths) == virtualPath); virtualPaths.add(virtualPath1); when(virtualPath.getVirtualLink()).thenReturn(virtualLinkList); when(virtualPath1.getVirtualLink()).thenReturn(virtualLinkList); when(virtualPath.getMetric()).thenReturn(1L); when(virtualPath.getDelay()).thenReturn(1L); when(virtualPath1.getMetric()).thenReturn(1L); when(virtualPath1.getDelay()).thenReturn(1L); when(virtualPath.getBandwidth()).thenReturn(1L); when(virtualPath1.getBandwidth()).thenReturn(1L); Assert.assertTrue(ActionResolverUtils.mergeVirtualPaths(virtualPaths) != null); verify(virtualPath).getMetric(); verify(virtualPath1).getMetric(); }