### Question:
DwCAUtil { public static Archive archiveFor(URI archiveURI, String tmpDir) throws IOException { Archive archive; Path myArchiveFile = Paths.get(archiveURI); try { if (myArchiveFile.toFile().isFile()) { if (StringUtils.isBlank(tmpDir)) { throw new IllegalArgumentException("cannot read [" + archiveURI + "] without a tmpDir"); } Path extractToFolder = Paths.get(tmpDir); archive = DwcFiles.fromCompressed(myArchiveFile, extractToFolder); } else { archive = DwcFiles.fromLocation(myArchiveFile); } } catch (UnsupportedArchiveException e) { throw new IOException("failed to read [" + archiveURI + "]", e); } return archive; }  static Archive archiveFor(URI archiveURI, String tmpDir);  }### Answer:
@Test public void emitRecords() throws IOException, URISyntaxException { URI archiveURI = getClass().getResource("dwca.zip").toURI(); String tmpDir = "target/tmp/myarchive"; Archive dwcArchive = DwCAUtil.archiveFor(archiveURI, tmpDir); assertHasRecords(dwcArchive); }
@Test(expected = IOException.class) public void throwIOExceptionNotRuntimeExceptionOnBadDwCA() throws IOException, URISyntaxException { URI archiveURI = getClass().getResource("dwcaInvalid.zip").toURI(); String tmpDir = "target/tmp/myarchive"; try { DwCAUtil.archiveFor(archiveURI, tmpDir); } catch(Throwable th) { assertThat(th.getMessage(), containsString("dwcaInvalid.zip")); assertThat(th.getMessage(), containsString("failed to read")); throw th; } }
@Test public void emitRecordsUnpacked() throws IOException, URISyntaxException { URI archiveURI = getClass().getResource("vampire-moth-dwca-main/meta.xml").toURI(); Archive dwcArchive = DwCAUtil.archiveFor(Paths.get(archiveURI).getParent().toUri(), null); assertHasRecords(dwcArchive); }