use of com.intellij.util.download.FileDownloader in project android by JetBrains.
the class DistributionServiceTest method testAsync2.
/**
* Test that if we get another call to refresh while one is in progress, it's callbacks will be queued.
*/
public void testAsync2() throws Exception {
final FileDownloader downloader = Mockito.mock(FileDownloader.class);
final Semaphore s = new Semaphore();
s.down();
final Semaphore s2 = new Semaphore();
s2.down();
Mockito.when(downloader.download(Matchers.any(File.class))).thenAnswer(new Answer<List<Pair<File, DownloadableFileDescription>>>() {
@Override
public List<Pair<File, DownloadableFileDescription>> answer(InvocationOnMock invocation) throws Throwable {
assertTrue(s.waitFor(5000));
return ImmutableList.of(Pair.create(myDistributionFile, myDescription));
}
});
DistributionService service = new DistributionService(downloader, CACHE_PATH, myDistributionFileUrl);
final AtomicBoolean check = new AtomicBoolean(false);
service.refresh(() -> check.set(true), null);
service.refresh(() -> {
assertTrue(check.get());
s2.up();
}, null);
s.up();
assertTrue(s2.waitFor(5000));
service.getSupportedDistributionForApiLevel(19);
try {
Mockito.verify(downloader).download(Matchers.any(File.class));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of com.intellij.util.download.FileDownloader in project android by JetBrains.
the class DistributionServiceTest method testCache.
/**
* Test that we don't download on every request
*
* @throws Exception
*/
public void testCache() throws Exception {
FileDownloader downloader = Mockito.mock(FileDownloader.class);
Mockito.when(downloader.download(Matchers.any(File.class))).thenReturn(ImmutableList.of(Pair.create(myDistributionFile, myDescription)));
DistributionService service = new DistributionService(downloader, CACHE_PATH, myDistributionFileUrl);
service.getSupportedDistributionForApiLevel(19);
service.getDistributionForApiLevel(21);
Mockito.verify(downloader).download(Matchers.any(File.class));
}
use of com.intellij.util.download.FileDownloader in project android by JetBrains.
the class DistributionServiceTest method testFailure.
/**
* Test that the failure callback will be called if the download fails, and then the fallback data will be used.
*/
public void testFailure() throws Exception {
FileDownloader downloader = Mockito.mock(FileDownloader.class);
Mockito.when(downloader.download(Matchers.any(File.class))).thenThrow(new RuntimeException("expected exception"));
DistributionService service = new DistributionService(downloader, CACHE_PATH, myDistributionFileUrl);
final FutureResult<Boolean> result = new FutureResult<>();
service.refresh(() -> {
assert false;
}, () -> result.set(true));
assertTrue(result.get(5, TimeUnit.SECONDS));
assertEquals(0.4, service.getSupportedDistributionForApiLevel(17), 0.001);
}
Aggregations