Commit 913b3fe8 authored by Ricki Hirner's avatar Ricki Hirner

Use JUnit tests instead of instrumentation tests, when possible

parent 04250fef
Pipeline #22374961 canceled with stages
in 2 minutes and 24 seconds
......@@ -66,4 +66,5 @@ dependencies {
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
testImplementation 'junit:junit:4.12'
testImplementation "com.squareup.okhttp3:mockwebserver:$okhttp_version"
testImplementation 'org.ogce:xpp3:1.1.6' // XmlPullParser
}
......@@ -15,6 +15,7 @@ import okhttp3.*
import okhttp3.internal.http.StatusLine
import org.xmlpull.v1.XmlPullParser
import org.xmlpull.v1.XmlPullParserException
import java.io.EOFException
import java.io.IOException
import java.io.Reader
import java.io.StringWriter
......@@ -287,7 +288,6 @@ open class DavResource @JvmOverloads constructor(
serializer.setPrefix("CAL", XmlUtils.NS_CALDAV)
serializer.setPrefix("CARD", XmlUtils.NS_CARDDAV)
serializer.startDocument("UTF-8", null)
serializer.setPrefix("", XmlUtils.NS_WEBDAV)
serializer.startTag(XmlUtils.NS_WEBDAV, "propfind")
serializer.startTag(XmlUtils.NS_WEBDAV, "prop")
for (prop in reqProp) {
......@@ -635,6 +635,8 @@ open class DavResource @JvmOverloads constructor(
return response ?: throw DavException("Multi-Status response didn't contain <DAV:multistatus> root element")
} catch (e: EOFException) {
throw DavException("Incomplete Multi-Status XML", e)
} catch (e: XmlPullParserException) {
throw DavException("Couldn't parse Multi-Status XML", e)
}
......
......@@ -31,7 +31,7 @@ class XmlUtilsTest {
fun testProcessTagDepth1() {
val parser = XmlUtils.newPullParser()
parser.setInput(StringReader("<root><test></test></root>"))
parser.next() // now on START_TAG <root> [1]
parser.next() // now on START_TAG <root>
var processed = false
XmlUtils.processTag(parser, "", "test", {
......@@ -43,8 +43,9 @@ class XmlUtilsTest {
@Test
fun testReadText() {
val parser = XmlUtils.newPullParser()
parser.setInput(StringReader("<test>Test 1</test><test><garbage/>Test 2</test>"))
parser.next() // now on START_TAG <test> [1]
parser.setInput(StringReader("<root><test>Test 1</test><test><garbage/>Test 2</test></root>"))
parser.next()
parser.next() // now on START_TAG <test>
assertEquals("Test 1", XmlUtils.readText(parser))
assertEquals(XmlPullParser.END_TAG, parser.eventType)
......@@ -58,7 +59,7 @@ class XmlUtilsTest {
fun testReadTextCDATA() {
val parser = XmlUtils.newPullParser()
parser.setInput(StringReader("<test><![CDATA[Test 1</test><test><garbage/>Test 2]]></test>"))
parser.next() // now on START_TAG <test> [1]
parser.next() // now on START_TAG <test>
assertEquals("Test 1</test><test><garbage/>Test 2", XmlUtils.readText(parser))
assertEquals(XmlPullParser.END_TAG, parser.eventType)
......@@ -67,13 +68,15 @@ class XmlUtilsTest {
@Test
fun testReadTextPropertyRoot() {
val parser = XmlUtils.newPullParser()
parser.setInput(StringReader("<entry>Test 1</entry><entry>Test 2</entry>"))
// now on START_DOCUMENT [0]
parser.setInput(StringReader("<root><entry>Test 1</entry><entry>Test 2</entry></root>"))
parser.next() // now on START_TAG <root>
val entries = mutableListOf<String>()
XmlUtils.readTextPropertyList(parser, Property.Name("", "entry"), entries)
assertEquals("Test 1", entries[0])
assertEquals("Test 2", entries[1])
parser.next() // END_TAG </root>
assertEquals(XmlPullParser.END_DOCUMENT, parser.eventType)
}
......
......@@ -4,10 +4,11 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package at.bitfire.dav4android
package at.bitfire.dav4android.exception
import at.bitfire.dav4android.exception.DavException
import at.bitfire.dav4android.exception.HttpException
import at.bitfire.dav4android.DavResource
import at.bitfire.dav4android.Property
import at.bitfire.dav4android.XmlUtils
import at.bitfire.dav4android.property.ResourceType
import okhttp3.OkHttpClient
import okhttp3.mockwebserver.MockResponse
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment