-
Notifications
You must be signed in to change notification settings - Fork 96
Expand file tree
/
Copy pathResponseFormatDetectorTests.kt
More file actions
45 lines (38 loc) · 1.34 KB
/
ResponseFormatDetectorTests.kt
File metadata and controls
45 lines (38 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
* Nextcloud Android Library
*
* SPDX-FileCopyrightText: 2025 Alper Ozturk <alper.ozturk@nextcloud.com>
* SPDX-License-Identifier: MIT
*/
package com.owncloud.android
import com.owncloud.android.lib.common.utils.responseFormat.ResponseFormat
import com.owncloud.android.lib.common.utils.responseFormat.ResponseFormatDetector
import junit.framework.TestCase.assertEquals
import org.junit.Test
class ResponseFormatDetectorTests {
@Test
fun testJsonDetection() {
val json = """{ "name": "Alice", "age": 30 }"""
assertEquals(ResponseFormat.JSON, ResponseFormatDetector.detectFormat(json))
}
@Test
fun testJsonArrayDetection() {
val jsonArray = """[{"name": "Alice"}, {"name": "Bob"}]"""
assertEquals(ResponseFormat.JSON, ResponseFormatDetector.detectFormat(jsonArray))
}
@Test
fun testXmlDetection() {
val xml = """<person><name>Alice</name><age>30</age></person>"""
assertEquals(ResponseFormat.XML, ResponseFormatDetector.detectFormat(xml))
}
@Test
fun testInvalidFormat() {
val invalid = "Just a plain string"
assertEquals(ResponseFormat.UNKNOWN, ResponseFormatDetector.detectFormat(invalid))
}
@Test
fun testEmptyString() {
val empty = ""
assertEquals(ResponseFormat.UNKNOWN, ResponseFormatDetector.detectFormat(empty))
}
}