### Question:
JAXBHandler { public static XmlFormatType determineXmlType(InputStream is) throws IOException { is.mark(1024); byte[] buffer = new byte[1024]; int bytesRead = is.read(buffer); if (bytesRead < 0) { return new XmlFormatType(XmlFormatType.INVALID); } String str = new String(buffer, 0, bytesRead); Pattern addisPattern = Pattern.compile("^(<\\?xml[^\\?]*\\?>[\\s]*)?<addis-data[^>]*>"); Matcher addisMatcher = addisPattern.matcher(str); if (!addisMatcher.find()) { return new XmlFormatType(XmlFormatType.INVALID); } Pattern versionPattern = Pattern.compile("http: Matcher versionMatcher = versionPattern.matcher(str); XmlFormatType type = null; if (versionMatcher.find()) { type = new XmlFormatType(Integer.parseInt(versionMatcher.group(1))); } else { type = new XmlFormatType(XmlFormatType.LEGACY_VERSION); } is.reset(); return type; }  static int currentSchemaVersion(); static void marshallAddisData(AddisData data, OutputStream os); static AddisData unmarshallAddisData(InputStream is); static XmlFormatType determineXmlType(InputStream is);  }### Answer:
@Test public void determineXmlVersionTest() throws IOException { ByteArrayInputStream emptyInput = new ByteArrayInputStream("".getBytes()); XmlFormatType emptyVersion = JAXBHandler.determineXmlType(emptyInput); assertFalse(emptyVersion.isValid()); assertFalse(emptyVersion.isLegacy()); ByteArrayInputStream v3input = new ByteArrayInputStream(V3_XML.getBytes()); XmlFormatType v3version = JAXBHandler.determineXmlType(v3input); assertTrue(v3version.isValid()); assertFalse(v3version.isLegacy()); assertEquals(3, v3version.getVersion()); ByteArrayInputStream v2input = new ByteArrayInputStream(V2_XML.getBytes()); XmlFormatType v2version = JAXBHandler.determineXmlType(v2input); assertTrue(v2version.isValid()); assertFalse(v2version.isLegacy()); assertEquals(2, v2version.getVersion()); ByteArrayInputStream v0input = new ByteArrayInputStream(LEGACY_XML.getBytes()); XmlFormatType v0version = JAXBHandler.determineXmlType(v0input); assertTrue(v0version.isValid()); assertTrue(v0version.isLegacy()); ByteArrayInputStream otherInput = new ByteArrayInputStream(OTHER_XML.getBytes()); XmlFormatType otherVersion = JAXBHandler.determineXmlType(otherInput); assertFalse(otherVersion.isValid()); }