Skip to content

Commit cb6065b

Browse files
authored
Improve tests / KDoc (#79)
* Add test for decoding quoted string and fix content type in test * Add method to get all values of a header that is defined as a list
1 parent e22831f commit cb6065b

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

src/main/kotlin/at/bitfire/dav4jvm/HttpUtils.kt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,30 @@ object HttpUtils {
4949
return pathSegments.lastOrNull() ?: ""
5050
}
5151

52+
/**
53+
* Gets all values of a header that is defined as a list [RFC 9110 5.6.1],
54+
* regardless of they're sent as one line or as multiple lines.
55+
*
56+
* For instance, regardless of whether a server sends:
57+
*
58+
* ```
59+
* DAV: 1
60+
* DAV: 2
61+
* ```
62+
*
63+
* or
64+
*
65+
* ```
66+
* DAV: 1, 2
67+
* ```
68+
*
69+
* this method would return `arrayOf("1","2")` for the `DAV` header.
70+
*
71+
* @param response the HTTP response to evaluate
72+
* @param name header name (for instance: `DAV`)
73+
*
74+
* @return all values for the given header name
75+
*/
5276
fun listHeader(response: Response, name: String): Array<String> {
5377
val value = response.headers(name).joinToString(",")
5478
return value.split(',').filter { it.isNotEmpty() }.toTypedArray()

src/test/kotlin/at/bitfire/dav4jvm/DavResourceTest.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,15 +1116,14 @@ class DavResourceTest {
11161116
.build())
11171117
}
11181118

1119-
@Test
1119+
@Test(expected = DavException::class)
11201120
fun testAssertMultiStatus_NonXML_ReallyNotXML() {
11211121
val dav = DavResource(httpClient, "https://from.com".toHttpUrl())
11221122
dav.assertMultiStatus(okhttp3.Response.Builder()
11231123
.request(Request.Builder().url(dav.location).build())
11241124
.protocol(Protocol.HTTP_1_1)
11251125
.code(207).message("Multi-Status")
1126-
.addHeader("Content-Type", "text/plain")
1127-
.body("Some error occurred".toResponseBody())
1126+
.body("Some error occurred".toResponseBody("text/plain".toMediaType()))
11281127
.build())
11291128
}
11301129

src/test/kotlin/at/bitfire/dav4jvm/QuotedStringUtilsTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class QuotedStringUtilsTest {
2222
assertEquals("\"\\\\\"", QuotedStringUtils.asQuotedString("\\"))
2323
}
2424

25+
@Test
2526
fun testDecodeQuotedString() {
2627
assertEquals("\"", QuotedStringUtils.decodeQuotedString("\""))
2728
assertEquals("\\", QuotedStringUtils.decodeQuotedString("\"\\\""))

0 commit comments

Comments
 (0)