WebDavRetriever implements RemoteRetriever { static String calculateBaseURL(AtomicBoolean cancelMonitor, String url, List<DavResource> resources) throws IOException { for (Iterator<DavResource> iterator = resources.iterator(); iterator.hasNext(); ) { if (cancelMonitor.get()) { return ""; } DavResource next = iterator.next(); if (url.endsWith(next.getPath())) { iterator.remove(); return url.substring(0, url.length() - next.getPath().length()); } } return url; }  void init(AtomicBoolean cancelMonitor, Logger log, ServiceContext context, WebDavParams params); List<RemoteFile> retrieve(); void destroy();  }
@Test public void testCalculateBaseURL() throws Exception { List<DavResource> resources = new ArrayList<DavResource>(2); final DavResource baseResource = Mockito.mock(DavResource.class); Mockito.when(baseResource.getPath()).thenReturn("/webdav/"); final DavResource otherResource = Mockito.mock(DavResource.class); Mockito.when(otherResource.getPath()).thenReturn("/webdav/metadata.xml"); resources.add(baseResource); resources.add(otherResource); final String baseURL = WebDavRetriever.calculateBaseURL(new AtomicBoolean(), "http: assertEquals("http: assertEquals(1, resources.size()); assertFalse(resources.contains(baseResource)); assertTrue(resources.contains(otherResource)); }