Commit bc77df0f authored by Ricki Hirner's avatar Ricki Hirner

Use JUnit tests instead of instrumentation tests, when possible

parent 04250fef
Pipeline #22375149 passed with stages
in 2 minutes 5 seconds
...@@ -9,8 +9,9 @@ cache: ...@@ -9,8 +9,9 @@ cache:
test: test:
script: script:
- (cd /sdk/emulator; ./emulator @test -no-audio -no-window & wait-for-emulator.sh) #- (cd /sdk/emulator; ./emulator @test -no-audio -no-window & wait-for-emulator.sh)
- ./gradlew check connectedCheck #- ./gradlew check connectedCheck
- ./gradlew check
artifacts: artifacts:
paths: paths:
- build/outputs/lint-results-debug.html - build/outputs/lint-results-debug.html
......
...@@ -66,4 +66,5 @@ dependencies { ...@@ -66,4 +66,5 @@ dependencies {
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version" testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
testImplementation "com.squareup.okhttp3:mockwebserver:$okhttp_version" testImplementation "com.squareup.okhttp3:mockwebserver:$okhttp_version"
testImplementation 'org.ogce:xpp3:1.1.6' // XmlPullParser
} }
...@@ -15,6 +15,7 @@ import okhttp3.* ...@@ -15,6 +15,7 @@ import okhttp3.*
import okhttp3.internal.http.StatusLine import okhttp3.internal.http.StatusLine
import org.xmlpull.v1.XmlPullParser import org.xmlpull.v1.XmlPullParser
import org.xmlpull.v1.XmlPullParserException import org.xmlpull.v1.XmlPullParserException
import java.io.EOFException
import java.io.IOException import java.io.IOException
import java.io.Reader import java.io.Reader
import java.io.StringWriter import java.io.StringWriter
...@@ -287,7 +288,6 @@ open class DavResource @JvmOverloads constructor( ...@@ -287,7 +288,6 @@ open class DavResource @JvmOverloads constructor(
serializer.setPrefix("CAL", XmlUtils.NS_CALDAV) serializer.setPrefix("CAL", XmlUtils.NS_CALDAV)
serializer.setPrefix("CARD", XmlUtils.NS_CARDDAV) serializer.setPrefix("CARD", XmlUtils.NS_CARDDAV)
serializer.startDocument("UTF-8", null) serializer.startDocument("UTF-8", null)
serializer.setPrefix("", XmlUtils.NS_WEBDAV)
serializer.startTag(XmlUtils.NS_WEBDAV, "propfind") serializer.startTag(XmlUtils.NS_WEBDAV, "propfind")
serializer.startTag(XmlUtils.NS_WEBDAV, "prop") serializer.startTag(XmlUtils.NS_WEBDAV, "prop")
for (prop in reqProp) { for (prop in reqProp) {
...@@ -635,6 +635,8 @@ open class DavResource @JvmOverloads constructor( ...@@ -635,6 +635,8 @@ open class DavResource @JvmOverloads constructor(
return response ?: throw DavException("Multi-Status response didn't contain <DAV:multistatus> root element") 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) { } catch (e: XmlPullParserException) {
throw DavException("Couldn't parse Multi-Status XML", e) throw DavException("Couldn't parse Multi-Status XML", e)
} }
......
...@@ -31,7 +31,7 @@ class XmlUtilsTest { ...@@ -31,7 +31,7 @@ class XmlUtilsTest {
fun testProcessTagDepth1() { fun testProcessTagDepth1() {
val parser = XmlUtils.newPullParser() val parser = XmlUtils.newPullParser()
parser.setInput(StringReader("<root><test></test></root>")) 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 var processed = false
XmlUtils.processTag(parser, "", "test", { XmlUtils.processTag(parser, "", "test", {
...@@ -43,8 +43,9 @@ class XmlUtilsTest { ...@@ -43,8 +43,9 @@ class XmlUtilsTest {
@Test @Test
fun testReadText() { fun testReadText() {
val parser = XmlUtils.newPullParser() val parser = XmlUtils.newPullParser()
parser.setInput(StringReader("<test>Test 1</test><test><garbage/>Test 2</test>")) parser.setInput(StringReader("<root><test>Test 1</test><test><garbage/>Test 2</test></root>"))
parser.next() // now on START_TAG <test> [1] parser.next()
parser.next() // now on START_TAG <test>
assertEquals("Test 1", XmlUtils.readText(parser)) assertEquals("Test 1", XmlUtils.readText(parser))
assertEquals(XmlPullParser.END_TAG, parser.eventType) assertEquals(XmlPullParser.END_TAG, parser.eventType)
...@@ -58,7 +59,7 @@ class XmlUtilsTest { ...@@ -58,7 +59,7 @@ class XmlUtilsTest {
fun testReadTextCDATA() { fun testReadTextCDATA() {
val parser = XmlUtils.newPullParser() val parser = XmlUtils.newPullParser()
parser.setInput(StringReader("<test><![CDATA[Test 1</test><test><garbage/>Test 2]]></test>")) 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("Test 1</test><test><garbage/>Test 2", XmlUtils.readText(parser))
assertEquals(XmlPullParser.END_TAG, parser.eventType) assertEquals(XmlPullParser.END_TAG, parser.eventType)
...@@ -67,13 +68,15 @@ class XmlUtilsTest { ...@@ -67,13 +68,15 @@ class XmlUtilsTest {
@Test @Test
fun testReadTextPropertyRoot() { fun testReadTextPropertyRoot() {
val parser = XmlUtils.newPullParser() val parser = XmlUtils.newPullParser()
parser.setInput(StringReader("<entry>Test 1</entry><entry>Test 2</entry>")) parser.setInput(StringReader("<root><entry>Test 1</entry><entry>Test 2</entry></root>"))
// now on START_DOCUMENT [0] parser.next() // now on START_TAG <root>
val entries = mutableListOf<String>() val entries = mutableListOf<String>()
XmlUtils.readTextPropertyList(parser, Property.Name("", "entry"), entries) XmlUtils.readTextPropertyList(parser, Property.Name("", "entry"), entries)
assertEquals("Test 1", entries[0]) assertEquals("Test 1", entries[0])
assertEquals("Test 2", entries[1]) assertEquals("Test 2", entries[1])
parser.next() // END_TAG </root>
assertEquals(XmlPullParser.END_DOCUMENT, parser.eventType) assertEquals(XmlPullParser.END_DOCUMENT, parser.eventType)
} }
......
...@@ -4,10 +4,11 @@ ...@@ -4,10 +4,11 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. * 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.DavResource
import at.bitfire.dav4android.exception.HttpException import at.bitfire.dav4android.Property
import at.bitfire.dav4android.XmlUtils
import at.bitfire.dav4android.property.ResourceType import at.bitfire.dav4android.property.ResourceType
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
import okhttp3.mockwebserver.MockResponse 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