Skip to content

Commit 6c9d464

Browse files
committed
code formatting: format source code for Flexible coroutine context #2328
1 parent 5bdfc8a commit 6c9d464

2 files changed

Lines changed: 40 additions & 20 deletions

File tree

jooby/src/main/kotlin/io/jooby/CoroutineRouter.kt

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,19 @@
55
*/
66
package io.jooby
77

8-
import io.jooby.Router.*
9-
import kotlinx.coroutines.*
8+
import io.jooby.Router.DELETE
9+
import io.jooby.Router.GET
10+
import io.jooby.Router.HEAD
11+
import io.jooby.Router.OPTIONS
12+
import io.jooby.Router.PATCH
13+
import io.jooby.Router.POST
14+
import io.jooby.Router.PUT
15+
import io.jooby.Router.TRACE
16+
import kotlinx.coroutines.CoroutineExceptionHandler
17+
import kotlinx.coroutines.CoroutineScope
18+
import kotlinx.coroutines.CoroutineStart
19+
import kotlinx.coroutines.asCoroutineDispatcher
20+
import kotlinx.coroutines.launch
1021
import kotlin.coroutines.CoroutineContext
1122

1223
internal class RouterCoroutineScope(override val coroutineContext: CoroutineContext) : CoroutineScope
@@ -24,45 +35,45 @@ class CoroutineRouter(val coroutineStart: CoroutineStart, val router: Router) {
2435

2536
@RouterDsl
2637
fun get(pattern: String, handler: suspend HandlerContext.() -> Any) =
27-
route(GET, pattern, handler)
38+
route(GET, pattern, handler)
2839

2940
@RouterDsl
3041
fun post(pattern: String, handler: suspend HandlerContext.() -> Any) =
31-
route(POST, pattern, handler)
42+
route(POST, pattern, handler)
3243

3344
@RouterDsl
3445
fun put(pattern: String, handler: suspend HandlerContext.() -> Any) =
35-
route(PUT, pattern, handler)
46+
route(PUT, pattern, handler)
3647

3748
@RouterDsl
3849
fun delete(pattern: String, handler: suspend HandlerContext.() -> Any) =
39-
route(DELETE, pattern, handler)
50+
route(DELETE, pattern, handler)
4051

4152
@RouterDsl
4253
fun patch(pattern: String, handler: suspend HandlerContext.() -> Any) =
43-
route(PATCH, pattern, handler)
54+
route(PATCH, pattern, handler)
4455

4556
@RouterDsl
4657
fun head(pattern: String, handler: suspend HandlerContext.() -> Any) =
47-
route(HEAD, pattern, handler)
58+
route(HEAD, pattern, handler)
4859

4960
@RouterDsl
5061
fun trace(pattern: String, handler: suspend HandlerContext.() -> Any) =
51-
route(TRACE, pattern, handler)
62+
route(TRACE, pattern, handler)
5263

5364
@RouterDsl
5465
fun options(pattern: String, handler: suspend HandlerContext.() -> Any) =
55-
route(OPTIONS, pattern, handler)
66+
route(OPTIONS, pattern, handler)
5667

5768
fun route(method: String, pattern: String, handler: suspend HandlerContext.() -> Any): Route =
58-
router.route(method, pattern) { ctx ->
59-
launch(ctx) {
60-
val result = handler(HandlerContext(ctx))
61-
if (result != ctx) {
62-
ctx.render(result)
69+
router.route(method, pattern) { ctx ->
70+
launch(ctx) {
71+
val result = handler(HandlerContext(ctx))
72+
if (result != ctx) {
73+
ctx.render(result)
74+
}
6375
}
64-
}
65-
}.setHandle(handler).attribute("coroutine", true)
76+
}.setHandle(handler).attribute("coroutine", true)
6677

6778
internal fun launch(ctx: Context, block: suspend CoroutineScope.() -> Unit) {
6879
val exceptionHandler = CoroutineExceptionHandler { _, x -> ctx.sendError(x) }

jooby/src/test/kotlin/io/jooby/CoroutineRouterTest.kt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@ import kotlinx.coroutines.CoroutineExceptionHandler
55
import kotlinx.coroutines.CoroutineStart
66
import org.junit.jupiter.api.Test
77
import org.mockito.ArgumentCaptor
8-
import org.mockito.Mockito.*
8+
import org.mockito.Mockito.RETURNS_DEEP_STUBS
9+
import org.mockito.Mockito.`when`
10+
import org.mockito.Mockito.any
11+
import org.mockito.Mockito.argThat
12+
import org.mockito.Mockito.eq
13+
import org.mockito.Mockito.mock
14+
import org.mockito.Mockito.verify
15+
import org.mockito.Mockito.verifyNoInteractions
916
import kotlin.coroutines.AbstractCoroutineContextElement
1017
import kotlin.coroutines.CoroutineContext
1118

@@ -29,7 +36,8 @@ class CoroutineRouterTest {
2936
@Test
3037
fun launchContext_isRunEveryTime() {
3138
val mockCoroutineContext = mock(CoroutineContext::class.java)
32-
`when`(mockCoroutineContext.plus(any() ?: mockCoroutineContext)).thenReturn(mockCoroutineContext, ExtraContext())
39+
`when`(mockCoroutineContext.plus(any()
40+
?: mockCoroutineContext)).thenReturn(mockCoroutineContext, ExtraContext())
3341

3442
CoroutineRouter(CoroutineStart.DEFAULT, router).apply {
3543
launchContext { mockCoroutineContext + it + ExtraContext() }
@@ -41,7 +49,8 @@ class CoroutineRouterTest {
4149
verifyNoInteractions(mockCoroutineContext)
4250

4351
handlerCaptor.value.apply(ctx)
44-
verify(mockCoroutineContext).plus(argThat { it is CoroutineExceptionHandler } ?: mockCoroutineContext)
52+
verify(mockCoroutineContext).plus(argThat { it is CoroutineExceptionHandler }
53+
?: mockCoroutineContext)
4554
verify(mockCoroutineContext).plus(argThat { it is ExtraContext } ?: mockCoroutineContext)
4655
}
4756

0 commit comments

Comments
 (0)