### Question:
XmlFile { public static XmlElement parseElements(ByteSource source, ToIntFunction<String> filterFn) { ArgChecker.notNull(source, "source"); ArgChecker.notNull(filterFn, "filterFn"); ToIntFunction<String> safeFilterFn = name -> Math.max(filterFn.applyAsInt(name), 0); return Unchecked.wrap(() -> { try (InputStream in = source.openBufferedStream()) { XMLStreamReader xmlReader = XML_FACTORY.createXMLStreamReader(in); try { return parseElements(xmlReader, safeFilterFn, Integer.MAX_VALUE); } finally { xmlReader.close(); } } }); } private  XmlFile(XmlElement root, Map<String, XmlElement> refs); static XmlFile of(ByteSource source); static XmlFile of(ByteSource source, String refAttrName); static XmlElement parseElements(ByteSource source, ToIntFunction<String> filterFn); XmlElement getRoot(); ImmutableMap<String, XmlElement> getReferences(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString();  }### Answer:
@Test public void test_parseElements_ByteSource_Fn_mismatchedTags() { ByteSource source = ByteSource.wrap(SAMPLE_MISMATCHED_TAGS.getBytes(StandardCharsets.UTF_8)); assertThatIllegalArgumentException().isThrownBy(() -> XmlFile.parseElements(source, name -> Integer.MAX_VALUE)); }
@Test public void test_parseElements_ByteSource_Fn_badEnd() { ByteSource source = ByteSource.wrap(SAMPLE_BAD_END.getBytes(StandardCharsets.UTF_8)); assertThatIllegalArgumentException().isThrownBy(() -> XmlFile.parseElements(source, name -> Integer.MAX_VALUE)); }
@Test public void test_parseElements_ByteSource_Fn_ioException() { ByteSource source = Files.asByteSource(new File("/oh-dear-no-such-file")); assertThatExceptionOfType(UncheckedIOException.class) .isThrownBy(() -> XmlFile.parseElements(source, name -> Integer.MAX_VALUE)); }