-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
297 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 36 additions & 20 deletions
56
common-api/src/test/kotlin/com/itangcent/common/constant/HttpMethodTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,48 @@ | ||
package com.itangcent.common.constant | ||
|
||
import org.junit.jupiter.api.Assertions | ||
import org.junit.jupiter.api.Test | ||
import kotlin.test.assertEquals | ||
|
||
/** | ||
* Test case for [HttpMethod] | ||
*/ | ||
internal class HttpMethodTest { | ||
|
||
@Test | ||
fun preferMethod() { | ||
|
||
Assertions.assertEquals("ALL", HttpMethod.preferMethod("")) | ||
|
||
Assertions.assertEquals("GET", HttpMethod.preferMethod("GET")) | ||
Assertions.assertEquals("POST", HttpMethod.preferMethod("POST")) | ||
|
||
Assertions.assertEquals("GET", HttpMethod.preferMethod("XXX.GET")) | ||
Assertions.assertEquals("POST", HttpMethod.preferMethod("XXX.POST")) | ||
Assertions.assertEquals("GET", HttpMethod.preferMethod("POST.GET")) | ||
Assertions.assertEquals("POST", HttpMethod.preferMethod("GET.POST")) | ||
|
||
Assertions.assertEquals("GET", HttpMethod.preferMethod("POST_GET")) | ||
Assertions.assertEquals("GET", HttpMethod.preferMethod("GET_POST")) | ||
|
||
Assertions.assertEquals("GET", HttpMethod.preferMethod("[GET]")) | ||
Assertions.assertEquals("POST", HttpMethod.preferMethod("[POST]")) | ||
Assertions.assertEquals("GET", HttpMethod.preferMethod("[GET][POST]")) | ||
Assertions.assertEquals("GET", HttpMethod.preferMethod("[POST][GET]")) | ||
fun `test preferMethod function`() { | ||
|
||
assertEquals("ALL", HttpMethod.preferMethod("")) | ||
assertEquals("ALL", HttpMethod.preferMethod("foo")) | ||
|
||
assertEquals("GET", HttpMethod.preferMethod("GET")) | ||
assertEquals("POST", HttpMethod.preferMethod("POST")) | ||
assertEquals("DELETE", HttpMethod.preferMethod("DELETE")) | ||
assertEquals("PUT", HttpMethod.preferMethod("PUT")) | ||
assertEquals("PATCH", HttpMethod.preferMethod("PATCH")) | ||
assertEquals("OPTIONS", HttpMethod.preferMethod("OPTIONS")) | ||
assertEquals("TRACE", HttpMethod.preferMethod("TRACE")) | ||
assertEquals("HEAD", HttpMethod.preferMethod("HEAD")) | ||
|
||
assertEquals("GET", HttpMethod.preferMethod("get")) | ||
assertEquals("POST", HttpMethod.preferMethod("post")) | ||
assertEquals("DELETE", HttpMethod.preferMethod("delete")) | ||
assertEquals("PUT", HttpMethod.preferMethod("put")) | ||
assertEquals("PATCH", HttpMethod.preferMethod("patch")) | ||
assertEquals("OPTIONS", HttpMethod.preferMethod("options")) | ||
assertEquals("TRACE", HttpMethod.preferMethod("trace")) | ||
assertEquals("HEAD", HttpMethod.preferMethod("head")) | ||
|
||
assertEquals("GET", HttpMethod.preferMethod("XXX.GET")) | ||
assertEquals("POST", HttpMethod.preferMethod("XXX.POST")) | ||
assertEquals("GET", HttpMethod.preferMethod("POST.GET")) | ||
assertEquals("POST", HttpMethod.preferMethod("GET.POST")) | ||
|
||
assertEquals("GET", HttpMethod.preferMethod("POST_GET")) | ||
assertEquals("GET", HttpMethod.preferMethod("GET_POST")) | ||
|
||
assertEquals("GET", HttpMethod.preferMethod("[GET]")) | ||
assertEquals("POST", HttpMethod.preferMethod("[POST]")) | ||
assertEquals("GET", HttpMethod.preferMethod("[GET][POST]")) | ||
assertEquals("GET", HttpMethod.preferMethod("[POST][GET]")) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
common-api/src/test/kotlin/com/itangcent/utils/FuncKitKtTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.itangcent.utils | ||
|
||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.Test | ||
|
||
class FuncKitKtTest { | ||
|
||
@Test | ||
fun `test and function`() { | ||
val isEven = { num: Int -> num % 2 == 0 } | ||
val isPositive = { num: Int -> num > 0 } | ||
|
||
val isEvenAndPositive = isEven.and(isPositive) | ||
|
||
assertEquals(true, isEvenAndPositive(4)) | ||
assertEquals(false, isEvenAndPositive(3)) | ||
assertEquals(false, isEvenAndPositive(-4)) | ||
assertEquals(false, isEvenAndPositive(0)) | ||
} | ||
|
||
@Test | ||
fun `test then function with one parameter`() { | ||
var result = "" | ||
|
||
val addHello = { str: String -> result = "$result $str Hello" } | ||
val addWorld = { str: String -> result = "$result $str World" } | ||
|
||
val addHelloThenWorld = addHello.then(addWorld) | ||
|
||
result = "" | ||
addHelloThenWorld("Hi") | ||
assertEquals(" Hi Hello Hi World", result) | ||
|
||
result = "" | ||
addHelloThenWorld("") | ||
assertEquals(" Hello World", result) | ||
} | ||
|
||
@Test | ||
fun `test then function with three parameters`() { | ||
var result = "" | ||
|
||
val addHello = { str: String, num: Int, flag: Boolean -> result = "$result $str Hello $num $flag" } | ||
val addWorld = { str: String, num: Int, flag: Boolean -> result = "$result $str World $num $flag" } | ||
|
||
val addHelloThenWorld = addHello.then(addWorld) | ||
|
||
result = "" | ||
addHelloThenWorld("Hi", 42, true) | ||
assertEquals(" Hi Hello 42 true Hi World 42 true", result) | ||
|
||
result = "" | ||
addHelloThenWorld("", 0, false) | ||
assertEquals(" Hello 0 false World 0 false", result) | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
common-api/src/test/kotlin/org/apache/http/util/EntityKitsKtTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package org.apache.http.util | ||
|
||
import org.apache.http.HttpEntity | ||
import org.apache.http.entity.ContentType | ||
import org.apache.http.entity.StringEntity | ||
import org.junit.jupiter.api.Test | ||
import kotlin.test.assertContentEquals | ||
import kotlin.test.assertEquals | ||
|
||
class EntityKitsKtTest { | ||
|
||
@Test | ||
fun `test HttpEntity toByteArray`() { | ||
val content = "Hello, world!" | ||
val entity = StringEntity(content, ContentType.TEXT_PLAIN) | ||
val bytes = entity.toByteArray() | ||
assertContentEquals(content.toByteArray(), bytes) | ||
} | ||
|
||
@Test | ||
fun `test HttpEntity consume`() { | ||
object : HttpEntity { | ||
override fun getContent() = null | ||
override fun getContentLength() = 0L | ||
override fun getContentType() = null | ||
override fun isChunked() = false | ||
override fun isRepeatable() = false | ||
override fun isStreaming() = false | ||
override fun writeTo(output: java.io.OutputStream?) {} | ||
override fun getContentEncoding() = null | ||
override fun consumeContent() {} | ||
}.consume() | ||
object : HttpEntity { | ||
override fun getContent() = "content".byteInputStream(Charsets.UTF_8) | ||
override fun getContentLength() = 0L | ||
override fun getContentType() = null | ||
override fun isChunked() = false | ||
override fun isRepeatable() = false | ||
override fun isStreaming() = true | ||
override fun writeTo(output: java.io.OutputStream?) {} | ||
override fun getContentEncoding() = null | ||
override fun consumeContent() {} | ||
}.consume() | ||
} | ||
|
||
@Test | ||
fun `test HttpEntity getContentCharSet`() { | ||
val contentType = ContentType.create("text/plain", "UTF-8") | ||
val entity = StringEntity("Hello, world!", contentType) | ||
val charset = entity.getContentCharSet() | ||
assertEquals("UTF-8", charset) | ||
} | ||
|
||
@Test | ||
fun `test HttpEntity getContentMimeType`() { | ||
val contentType = ContentType.create("text/plain", "UTF-8") | ||
val entity = StringEntity("Hello, world!", contentType) | ||
val mimeType = entity.getContentMimeType() | ||
assertEquals("text/plain", mimeType) | ||
} | ||
|
||
@Test | ||
fun `test HttpEntity readString`() { | ||
val content = "Hello, world!" | ||
val entity = StringEntity(content, ContentType.TEXT_PLAIN) | ||
assertEquals(content, entity.readString()) | ||
|
||
val wildcardEntity = StringEntity(content, ContentType.WILDCARD) | ||
assertEquals(content, wildcardEntity.readString()) | ||
assertEquals(content, wildcardEntity.readString(Charsets.ISO_8859_1)) | ||
} | ||
|
||
@Test | ||
fun `test HttpEntity readString with default charset`() { | ||
val content = "Hello, world!" | ||
val entity = StringEntity(content, ContentType.TEXT_PLAIN.withCharset("ISO-8859-1")) | ||
assertEquals(content, entity.readString()) | ||
} | ||
|
||
@Test | ||
fun `test HttpEntity readString with specified charset`() { | ||
val content = "Hello, world!" | ||
val entity = StringEntity(content, ContentType.TEXT_PLAIN.withCharset("ISO-8859-1")) | ||
val result = entity.readString("ISO-8859-1") | ||
assertEquals(content, result) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 0 additions & 9 deletions
9
idea-plugin/src/main/kotlin/com/itangcent/idea/utils/ExtensibleKit.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 0 additions & 26 deletions
26
idea-plugin/src/test/kotlin/com/itangcent/idea/utils/ExtensibleKitKtTest.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.