Skip to content

Commit 5eace4d

Browse files
committed
reformat
1 parent f22fb9e commit 5eace4d

File tree

5 files changed

+19
-11
lines changed

5 files changed

+19
-11
lines changed

src/main/kotlin/org/learning/by/example/reactive/kotlin/microservices/KotlinReactiveMS/extensions/UtilExtensions.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.learning.by.example.reactive.kotlin.microservices.KotlinReactiveMS.extensions
22

3+
import org.slf4j.LoggerFactory
34
import org.springframework.http.MediaType.APPLICATION_JSON_UTF8
45
import org.springframework.web.reactive.function.server.ServerRequest
56
import org.springframework.web.reactive.function.server.ServerResponse.BodyBuilder
@@ -10,4 +11,4 @@ internal fun <T : Any> T.toMono() = Mono.just(this)!!
1011
internal infix fun <T : Any> BodyBuilder.withBody(value: T) = this.contentType(APPLICATION_JSON_UTF8).toBody(value)
1112
internal fun <T : Any> BodyBuilder.toBody(value: T) = this.body(value.toMono(), value.javaClass)!!
1213
inline internal fun <reified T : Any> ServerRequest.extract() = this.bodyToMono(T::class.java)
13-
14+
inline internal fun <reified T : Any> getLogger() = LoggerFactory.getLogger(T::class.java)

src/main/kotlin/org/learning/by/example/reactive/kotlin/microservices/KotlinReactiveMS/handlers/ErrorHandler.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package org.learning.by.example.reactive.kotlin.microservices.KotlinReactiveMS.handlers
22

33
import org.learning.by.example.reactive.kotlin.microservices.KotlinReactiveMS.exceptions.PathNotFoundException
4+
import org.learning.by.example.reactive.kotlin.microservices.KotlinReactiveMS.extensions.getLogger
45
import org.learning.by.example.reactive.kotlin.microservices.KotlinReactiveMS.extensions.toMono
56
import org.learning.by.example.reactive.kotlin.microservices.KotlinReactiveMS.extensions.withBody
67
import org.learning.by.example.reactive.kotlin.microservices.KotlinReactiveMS.handlers.ThrowableTranslator.Translate
78
import org.learning.by.example.reactive.kotlin.microservices.KotlinReactiveMS.model.ErrorResponse
8-
import org.slf4j.LoggerFactory
99
import org.springframework.web.reactive.function.server.ServerRequest
1010
import org.springframework.web.reactive.function.server.ServerResponse
1111
import org.springframework.web.reactive.function.server.ServerResponse.status
@@ -14,13 +14,14 @@ import reactor.core.publisher.Mono
1414
internal class ErrorHandler {
1515

1616
companion object {
17-
private val logger = LoggerFactory.getLogger(ErrorHandler::class.java)
17+
private val logger = getLogger<ErrorHandler>()
1818
private val NOT_FOUND = "not found"
1919
private val ERROR_RAISED = "error raised"
2020
}
2121

22-
fun notFound(request: ServerRequest) = PathNotFoundException(NOT_FOUND).toMono<Throwable>()
23-
.transform(this::getResponse)!!
22+
@Suppress("UNUSED_PARAMETER")
23+
fun notFound(request: ServerRequest) =
24+
PathNotFoundException(NOT_FOUND).toMono<Throwable>().transform(this::getResponse)!!
2425

2526
fun throwableError(throwable: Throwable): Mono<ServerResponse> {
2627
logger.error(ERROR_RAISED, throwable)

src/main/kotlin/org/learning/by/example/reactive/kotlin/microservices/KotlinReactiveMS/handlers/ThrowableTranslator.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ internal class ThrowableTranslator private constructor(throwable: Throwable) {
3131
}
3232

3333
companion object Translate {
34-
fun <T : Throwable> throwable(throwable: Mono<T>): Mono<ThrowableTranslator> {
35-
return throwable.map(::ThrowableTranslator)
36-
}
34+
fun <T : Throwable> throwable(throwable: Mono<T>) = throwable.map(::ThrowableTranslator)!!
3735
}
3836
}

src/main/kotlin/org/learning/by/example/reactive/kotlin/microservices/KotlinReactiveMS/routers/ApiRouter.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ internal class ApiRouter(val handler: ApiHandler, val errorHandler: ErrorHandler
1818

1919
fun doRoute() = router {
2020
(accept(MediaType.APPLICATION_JSON_UTF8) and API_PATH).nest {
21-
GET(LOCATION_WITH_ADDRESS_PATH).invoke(handler::getLocation)
22-
POST(LOCATION_PATH).invoke(handler::postLocation)
23-
path(ANY_PATH).invoke(errorHandler::notFound)
21+
GET(LOCATION_WITH_ADDRESS_PATH)(handler::getLocation)
22+
POST(LOCATION_PATH)(handler::postLocation)
23+
path(ANY_PATH)(errorHandler::notFound)
2424
}
2525
}
2626
}

src/test/kotlin/org/learning/by/example/reactive/kotlin/microservices/KotlinReactiveMS/extensions/UtilsExtensionsTests.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,12 @@ private class UtilsExtensionsTests : BasicIntegrationTest() {
9595
assert.that(throwable, isA<ClassCastException>())
9696
}
9797
}
98+
99+
@Test
100+
fun getLoggerTest(){
101+
val logger = getLogger<UtilsExtensionsTests>()
102+
assert.that(logger, !isNull())
103+
assert.that(logger, isA<org.slf4j.Logger>())
104+
assert.that(logger.name, equalTo(UtilsExtensionsTests::class.qualifiedName))
105+
}
98106
}

0 commit comments

Comments
 (0)