Skip to content

Commit

Permalink
#3 Output NameSpace format
Browse files Browse the repository at this point in the history
  • Loading branch information
alexhu committed Jun 2, 2016
1 parent 892bf63 commit b7ba2cc
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/test/java/android/content/res/TestAXMLResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@
import org.junit.Test;
import org.junit.experimental.runners.Enclosed;
import org.junit.runner.RunWith;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.*;

import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -53,12 +59,24 @@ public void testPrinting() throws IOException {
}

@Test
public void testToXml() throws IOException {
public void testToXml() throws IOException, ParserConfigurationException {
InputStream testStream = this.getClass().getClassLoader().getResourceAsStream(largeFromMalware);

underTest = new AXMLResource(testStream);

System.out.println(underTest.toXML());;
String xml = underTest.toXML();

try {
Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(xml.getBytes()));
Node manifestNode = document.getFirstChild();
NamedNodeMap manifestNodeAttributes = manifestNode.getAttributes();
assertEquals("http://schemas.android.com/apk/res/android", manifestNodeAttributes.getNamedItem("xmlns:android").getNodeValue());
assertEquals("3133", manifestNodeAttributes.getNamedItem("android:versionCode").getNodeValue());
assertEquals("1.9.3", manifestNodeAttributes.getNamedItem("android:versionName").getNodeValue());
assertEquals("com.faithcomesbyhearing.android.pt.bibleis", manifestNodeAttributes.getNamedItem("package").getNodeValue());
} catch (SAXException e) {
// Is not xml
assertTrue(false);
}
}

@Test
Expand Down

0 comments on commit b7ba2cc

Please sign in to comment.