Skip to content

Commit 00d409d

Browse files
committed
Switch to Kover for code coverage
1 parent 3ed93e5 commit 00d409d

File tree

11 files changed

+376
-28
lines changed

11 files changed

+376
-28
lines changed

build.gradle.kts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ plugins {
1111
id("com.github.breadmoirai.github-release")
1212
id("org.sonarqube")
1313
id("io.github.gradle-nexus.publish-plugin")
14-
14+
id("org.jetbrains.kotlinx.kover")
1515

1616
kotlin("jvm") apply (false)
1717
id("org.cadixdev.licenser") apply (false)
@@ -47,11 +47,11 @@ allprojects {
4747
configure(moduleNames.map { project(":sunday-$it") }) {
4848

4949
apply(plugin = "java-library")
50-
apply(plugin = "jacoco")
5150
apply(plugin = "maven-publish")
5251
apply(plugin = "signing")
5352

5453
apply(plugin = "org.jetbrains.kotlin.jvm")
54+
apply(plugin = "org.jetbrains.kotlinx.kover")
5555
apply(plugin = "org.jetbrains.dokka")
5656
apply(plugin = "org.cadixdev.licenser")
5757
apply(plugin = "org.jmailen.kotlinter")
@@ -105,10 +105,6 @@ configure(moduleNames.map { project(":sunday-$it") }) {
105105
// TEST
106106
//
107107

108-
configure<JacocoPluginExtension> {
109-
toolVersion = "0.8.12"
110-
}
111-
112108
tasks.named<Test>("test").configure {
113109

114110
useJUnitPlatform()
@@ -120,8 +116,6 @@ configure(moduleNames.map { project(":sunday-$it") }) {
120116
}
121117

122118
reports.junitXml.required.set(true)
123-
124-
finalizedBy("jacocoTestReport")
125119
}
126120

127121

@@ -284,7 +278,7 @@ configure(moduleNames.map { project(":sunday-$it") }) {
284278
property("sonar.jacoco.reportPaths", "")
285279
property(
286280
"sonar.coverage.jacoco.xmlReportPaths",
287-
"$rootDir/code-coverage/build/reports/jacoco/testCoverageReport/testCoverageReport.xml",
281+
"$rootDir/code-coverage/build/reports/kover/report.xml",
288282
)
289283
}
290284
}

code-coverage/build.gradle.kts

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,23 @@
11

22
plugins {
33
base
4-
id("jacoco-report-aggregation")
4+
id("org.jetbrains.kotlinx.kover")
55
}
66

77
repositories {
88
mavenCentral()
99
}
1010

1111
dependencies {
12-
jacocoAggregation(project(":sunday-core"))
13-
jacocoAggregation(project(":sunday-jdk"))
14-
jacocoAggregation(project(":sunday-okhttp"))
15-
}
16-
17-
reporting {
18-
reports {
19-
create<JacocoCoverageReport>("testCoverageReport") {
20-
testType.set(TestSuiteType.UNIT_TEST)
21-
reportTask {
22-
reports.xml.required.set(true)
23-
}
24-
}
25-
}
12+
kover(project(":sunday-core"))
13+
kover(project(":sunday-jdk"))
14+
kover(project(":sunday-okhttp"))
2615
}
2716

2817
tasks {
2918

3019
check {
31-
finalizedBy(named<JacocoReport>("testCoverageReport"))
20+
finalizedBy(named("koverXmlReport"), named("koverHtmlReport"))
3221
}
3322

3423
}

core/src/main/kotlin/io/outfoxx/sunday/RequestFactory.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ abstract class RequestFactory : Closeable {
599599
response.contentType?.let { MediaType.from(it.toString()) }
600600
?: throw SundayError(
601601
SundayError.Reason.InvalidContentType,
602-
response.contentType?.value ?: "",
602+
response.contentType?.value ?: "<none provided>",
603603
)
604604

605605
val contentTypeDecoder =

core/src/main/kotlin/io/outfoxx/sunday/SundayError.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class SundayError(
3434
ResponseDecodingFailed("Response decoding failed"),
3535
EventDecodingFailed("Event decoding failed"),
3636
InvalidBaseUri("Base URL is invalid after expanding template"),
37-
NoSupportedContentTypes("None of the provided Content-Types for the request has a registered decoder"),
37+
NoSupportedContentTypes("None of the provided Content-Types for the request has a registered encoder"),
3838
NoSupportedAcceptTypes("None of the provided Accept types for the request has a registered decoder"),
3939
InvalidHeaderValue("The encoded header value contains one or more invalid characters"),
4040
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright 2020 Outfox, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import io.outfoxx.sunday.MediaType
18+
import io.outfoxx.sunday.http.HeaderParameters
19+
import io.outfoxx.sunday.http.getAll
20+
import io.outfoxx.sunday.http.getFirst
21+
import io.outfoxx.sunday.http.toMultiMap
22+
import org.hamcrest.MatcherAssert.assertThat
23+
import org.hamcrest.Matchers.containsInAnyOrder
24+
import org.hamcrest.Matchers.equalTo
25+
import org.hamcrest.Matchers.`is`
26+
import org.hamcrest.Matchers.oneOf
27+
import org.junit.jupiter.api.Test
28+
29+
class HeaderExtensionsTest {
30+
31+
@Test
32+
fun `test getFirst`() {
33+
val headers = HeaderParameters.encode(mapOf("test" to arrayOf(MediaType.JSON, MediaType.CBOR)))
34+
35+
assertThat(
36+
headers.getFirst("test"),
37+
`is`(oneOf(MediaType.JSON.value, MediaType.CBOR.value)),
38+
)
39+
}
40+
41+
@Test
42+
fun `test getAll`() {
43+
val headers = HeaderParameters.encode(mapOf("test" to arrayOf(MediaType.JSON, MediaType.CBOR)))
44+
45+
assertThat(
46+
headers.getAll("test"),
47+
containsInAnyOrder(MediaType.JSON.value, MediaType.CBOR.value),
48+
)
49+
}
50+
51+
@Test
52+
fun `test toMultiMap`() {
53+
val headers = HeaderParameters.encode(mapOf("test" to arrayOf(MediaType.JSON, MediaType.CBOR)))
54+
55+
assertThat(
56+
headers.toMultiMap(),
57+
equalTo(mapOf("test" to listOf(MediaType.JSON.value, MediaType.CBOR.value))),
58+
)
59+
}
60+
61+
}

core/src/test/kotlin/MediaTypeCodecTest.kt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,13 @@
1414
* limitations under the License.
1515
*/
1616

17+
import com.fasterxml.jackson.databind.json.JsonMapper
18+
import com.fasterxml.jackson.dataformat.cbor.databind.CBORMapper
19+
import io.outfoxx.sunday.MediaType
1720
import io.outfoxx.sunday.mediatypes.codecs.BinaryDecoder
1821
import io.outfoxx.sunday.mediatypes.codecs.BinaryEncoder
22+
import io.outfoxx.sunday.mediatypes.codecs.MediaTypeDecoders
23+
import io.outfoxx.sunday.mediatypes.codecs.MediaTypeEncoders
1924
import io.outfoxx.sunday.mediatypes.codecs.TextDecoder
2025
import io.outfoxx.sunday.mediatypes.codecs.TextEncoder
2126
import io.outfoxx.sunday.mediatypes.codecs.decode
@@ -27,6 +32,9 @@ import okio.Source
2732
import okio.buffer
2833
import org.hamcrest.MatcherAssert.assertThat
2934
import org.hamcrest.Matchers.equalTo
35+
import org.hamcrest.Matchers.`is`
36+
import org.hamcrest.Matchers.not
37+
import org.hamcrest.Matchers.nullValue
3038
import org.junit.jupiter.api.DisplayName
3139
import org.junit.jupiter.api.Nested
3240
import org.junit.jupiter.api.Test
@@ -142,4 +150,29 @@ class MediaTypeCodecTest {
142150
}
143151
}
144152

153+
@Test
154+
fun `test encoders builder registers specific codecs`() {
155+
val encoders =
156+
MediaTypeEncoders
157+
.Builder()
158+
.registerJSON(JsonMapper())
159+
.registerCBOR(CBORMapper())
160+
.build()
161+
162+
assertThat(encoders.find(MediaType.JSON), `is`(not(nullValue())))
163+
assertThat(encoders.find(MediaType.CBOR), `is`(not(nullValue())))
164+
}
165+
166+
@Test
167+
fun `test decoders builder registers specific codecs`() {
168+
val decoders =
169+
MediaTypeDecoders
170+
.Builder()
171+
.registerJSON(JsonMapper())
172+
.registerCBOR(CBORMapper())
173+
.build()
174+
175+
assertThat(decoders.find(MediaType.JSON), `is`(not(nullValue())))
176+
assertThat(decoders.find(MediaType.CBOR), `is`(not(nullValue())))
177+
}
145178
}

core/src/test/kotlin/ProblemsTest.kt

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright 2020 Outfox, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import io.outfoxx.sunday.http.Headers
18+
import io.outfoxx.sunday.http.Request
19+
import io.outfoxx.sunday.http.Response
20+
import io.outfoxx.sunday.utils.Problems
21+
import okio.BufferedSource
22+
import org.hamcrest.MatcherAssert.assertThat
23+
import org.hamcrest.Matchers.equalTo
24+
import org.junit.jupiter.api.Test
25+
import org.zalando.problem.Status
26+
27+
class ProblemsTest {
28+
29+
@Test
30+
fun `test forResponse`() {
31+
val problem = Problems.forResponse(TestResponse(400, "Bad Request", listOf(), null))
32+
33+
assertThat(problem.status, equalTo(Status.BAD_REQUEST))
34+
}
35+
36+
@Test
37+
fun `test forStatus`() {
38+
val problem = Problems.forStatus(400, "Bad Request")
39+
40+
assertThat(problem.status, equalTo(Status.BAD_REQUEST))
41+
}
42+
43+
@Test
44+
fun `test forStatus supports non-standard values`() {
45+
val problem = Problems.forStatus(195, "AI Thinking")
46+
47+
assertThat(problem.status?.statusCode, equalTo(195))
48+
assertThat(problem.status?.reasonPhrase, equalTo("AI Thinking"))
49+
}
50+
51+
data class TestResponse(
52+
override val statusCode: Int,
53+
override val reasonPhrase: String?,
54+
override val headers: Headers,
55+
override val body: BufferedSource?,
56+
) : Response {
57+
58+
override val trailers: Headers?
59+
get() = null
60+
override val request: Request
61+
get() = TODO("Not yet implemented")
62+
}
63+
64+
}

0 commit comments

Comments
 (0)