File tree Expand file tree Collapse file tree
androidTest/java/com/owncloud/android
main/java/com/owncloud/android/lib/common/utils/responseFormat Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -13,7 +13,6 @@ import junit.framework.TestCase.assertEquals
1313import org.junit.Test
1414
1515class ResponseFormatDetectorTests {
16-
1716 @Test
1817 fun testJsonDetection () {
1918 val json = """ { "name": "Alice", "age": 30 }"""
Original file line number Diff line number Diff line change 88package com.owncloud.android.lib.common.utils.responseFormat
99
1010enum class ResponseFormat {
11- JSON , XML , UNKNOWN
11+ JSON ,
12+ XML ,
13+ UNKNOWN
1214}
Original file line number Diff line number Diff line change @@ -18,14 +18,14 @@ object ResponseFormatDetector {
1818 private const val JSON_OBJECT_PREFIX = " {"
1919 private const val JSON_ARRAY_PREFIX = " ["
2020
21- fun detectFormat (input : String ): ResponseFormat {
22- return when {
21+ fun detectFormat (input : String ): ResponseFormat =
22+ when {
2323 isJson(input) -> ResponseFormat .JSON
2424 isXml(input) -> ResponseFormat .XML
2525 else -> ResponseFormat .UNKNOWN
2626 }
27- }
2827
28+ @Suppress(" TooGenericExceptionCaught" )
2929 private fun isJson (input : String ): Boolean {
3030 return try {
3131 val trimmed = input.trim()
@@ -43,8 +43,9 @@ object ResponseFormatDetector {
4343 }
4444 }
4545
46- private fun isXml (input : String ): Boolean {
47- return try {
46+ @Suppress(" TooGenericExceptionCaught" )
47+ private fun isXml (input : String ): Boolean =
48+ try {
4849 val factory = DocumentBuilderFactory .newInstance()
4950 val builder = factory.newDocumentBuilder()
5051 val stream = ByteArrayInputStream (input.toByteArray())
@@ -54,5 +55,4 @@ object ResponseFormatDetector {
5455 Log_OC .e(TAG , " Exception isXml: $e " )
5556 false
5657 }
57- }
5858}
You can’t perform that action at this time.
0 commit comments