BootstrapIndexDownloader { Collection<JarEntry> getIndex() { String index; try { logger.debug("Get bootstrap index..."); index = conn.downloadString("/batch/index"); logger.debug("Get bootstrap completed"); } catch (Exception e) { throw new IllegalStateException("Fail to get bootstrap index from server", e); } return parse(index); } BootstrapIndexDownloader(ServerConnection conn, Logger logger);   }
@Test public void should_download_jar_files() throws Exception { when(connection.downloadString("/batch/index")).thenReturn( "cpd.jar|CA124VADFSDS\n" + "squid.jar|34535FSFSDF\n"); Collection<JarEntry> index = bootstrapIndexDownloader.getIndex(); assertThat(index).hasSize(2); assertThat(index).extracting("filename", "hash") .containsOnly(Tuple.tuple("cpd.jar", "CA124VADFSDS"), Tuple.tuple("squid.jar", "34535FSFSDF")); verify(connection, times(1)).downloadString("/batch/index"); }
@Test public void test_invalid_index() throws Exception { when(connection.downloadString("/batch/index")).thenReturn("cpd.jar\n"); exception.expect(IllegalStateException.class); exception.expectMessage("Fail to parse entry in bootstrap index: cpd.jar"); bootstrapIndexDownloader.getIndex(); }
@Test public void should_fail() throws IOException { when(connection.downloadString("/batch/index")).thenThrow(new IOException("io error")); exception.expect(IllegalStateException.class); exception.expectMessage("Fail to get bootstrap index from server"); bootstrapIndexDownloader.getIndex(); }