Skip to content

Commit 782acbe

Browse files
committed
Format code
1 parent 6a46bb0 commit 782acbe

File tree

15 files changed

+171
-122
lines changed

15 files changed

+171
-122
lines changed

kafka/src/main/kotlin/com/github/wpanas/spring/kafka/KafkaApplication.kt

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ fun main(args: Array<String>) {
3131

3232
@RestController
3333
@RequestMapping("/order")
34-
class OrderController(private val orderService: OrderService) {
34+
class OrderController(
35+
private val orderService: OrderService,
36+
) {
3537
@PostMapping
3638
fun placeOrder(
3739
@RequestBody orderDto: CreateOrderDto,
@@ -44,21 +46,25 @@ class OrderController(private val orderService: OrderService) {
4446
fun checkOrder(
4547
@PathVariable("id") id: UUID,
4648
): ResponseEntity<ShowOrderDto> =
47-
orderService.findOne(id)
49+
orderService
50+
.findOne(id)
4851
?.let(Order::toDto)
4952
.let { Optional.ofNullable(it) }
5053
.let { ResponseEntity.of(it) }
5154

5255
@GetMapping
5356
fun listOrders(): List<ShowOrderDto> =
54-
orderService.findAll()
57+
orderService
58+
.findAll()
5559
.map(Order::toDto)
5660
}
5761

5862
fun Order.toDto() = ShowOrderDto(id, coffee, isDone)
5963

6064
@Service
61-
class OrderService(private val scheduler: OrderProcessingScheduler) {
65+
class OrderService(
66+
private val scheduler: OrderProcessingScheduler,
67+
) {
6268
private val orders: ConcurrentMap<UUID, Order> = ConcurrentHashMap()
6369

6470
fun placeOrder(orderDetails: OrderDetails): Order {
@@ -83,7 +89,9 @@ class OrderService(private val scheduler: OrderProcessingScheduler) {
8389
}
8490

8591
@Component
86-
class OrderProcessor(private val orderService: OrderService) : MessageListener<String, OrderDetails> {
92+
class OrderProcessor(
93+
private val orderService: OrderService,
94+
) : MessageListener<String, OrderDetails> {
8795
@KafkaListener(
8896
topics = [TOPIC],
8997
groupId = "\${order-processor.group-id}",
@@ -100,9 +108,12 @@ class OrderProcessor(private val orderService: OrderService) : MessageListener<S
100108
}
101109

102110
@Component
103-
class OrderProcessingScheduler(private val kafkaTemplate: KafkaTemplate<String, OrderDetails>) {
111+
class OrderProcessingScheduler(
112+
private val kafkaTemplate: KafkaTemplate<String, OrderDetails>,
113+
) {
104114
fun scheduleProcessing(order: Order) {
105-
kafkaTemplate.send(TOPIC, order.id.toString(), OrderDetails(order.coffee))
115+
kafkaTemplate
116+
.send(TOPIC, order.id.toString(), OrderDetails(order.coffee))
106117
.addCallback(
107118
{
108119
logger.info("Scheduled order ${order.id}")
@@ -118,10 +129,22 @@ class OrderProcessingScheduler(private val kafkaTemplate: KafkaTemplate<String,
118129
}
119130
}
120131

121-
data class OrderDetails(val coffee: String)
122-
123-
data class Order(val id: UUID, val coffee: String, val isDone: Boolean)
124-
125-
data class CreateOrderDto(val coffee: String)
126-
127-
data class ShowOrderDto(val id: UUID, val coffee: String, val isDone: Boolean)
132+
data class OrderDetails(
133+
val coffee: String,
134+
)
135+
136+
data class Order(
137+
val id: UUID,
138+
val coffee: String,
139+
val isDone: Boolean,
140+
)
141+
142+
data class CreateOrderDto(
143+
val coffee: String,
144+
)
145+
146+
data class ShowOrderDto(
147+
val id: UUID,
148+
val coffee: String,
149+
val isDone: Boolean,
150+
)

kafka/src/main/kotlin/com/github/wpanas/spring/kafka/KafkaConfig.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ const val TOPIC = "com.github.wpanas.orders"
1010
@Configuration
1111
class KafkaConfig {
1212
@Bean
13-
fun topic(): NewTopic {
14-
return TopicBuilder.name(TOPIC)
13+
fun topic(): NewTopic =
14+
TopicBuilder
15+
.name(TOPIC)
1516
.build()
16-
}
1717
}

kafka/src/test/kotlin/com/github/wpanas/spring/kafka/KafkaInitializer.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ class KafkaInitializer : ApplicationContextInitializer<ConfigurableApplicationCo
1919

2020
mapOf(
2121
"spring.kafka.bootstrapServers" to kafkaContainer.bootstrapServers,
22-
)
23-
.let(TestPropertyValues::of)
22+
).let(TestPropertyValues::of)
2423
.applyTo(applicationContext)
2524
}
2625
}

kafka/src/test/kotlin/com/github/wpanas/spring/kafka/OrderControllerTest.kt

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,19 @@ internal class OrderControllerTest {
4343
@Test
4444
internal fun `should be able to place order`() {
4545
val order =
46-
mockMvc.post("/order") {
47-
content =
48-
"""{"coffee": "Espresso"}"""
49-
contentType = MediaType.APPLICATION_JSON
50-
accept = MediaType.APPLICATION_JSON
51-
}
52-
.andDo { print() }
46+
mockMvc
47+
.post("/order") {
48+
content =
49+
"""{"coffee": "Espresso"}"""
50+
contentType = MediaType.APPLICATION_JSON
51+
accept = MediaType.APPLICATION_JSON
52+
}.andDo { print() }
5353
.andExpect {
5454
status { isOk() }
5555
jsonPath("$.coffee", `is`("Espresso"))
5656
jsonPath("$.id", `is`(not(emptyString())))
5757
jsonPath("$.isDone", `is`(false))
58-
}
59-
.toOrder()
58+
}.toOrder()
6059

6160
await untilCallTo { orderService.findOne(order.id) } has {
6261
isDone
@@ -67,11 +66,11 @@ internal class OrderControllerTest {
6766
internal fun `should check order details`() {
6867
val order = orderService.placeOrder(OrderDetails("Latte"))
6968

70-
mockMvc.get("/order/${order.id}") {
71-
contentType = MediaType.APPLICATION_JSON
72-
accept = MediaType.APPLICATION_JSON
73-
}
74-
.andDo { print() }
69+
mockMvc
70+
.get("/order/${order.id}") {
71+
contentType = MediaType.APPLICATION_JSON
72+
accept = MediaType.APPLICATION_JSON
73+
}.andDo { print() }
7574
.andExpect {
7675
status { isOk() }
7776
jsonPath("$.coffee", `is`(order.coffee))
@@ -85,11 +84,11 @@ internal class OrderControllerTest {
8584
val firstOrder = orderService.placeOrder(OrderDetails("Latte")).toDto()
8685
val secondOrder = orderService.placeOrder(OrderDetails("Espresso")).toDto()
8786

88-
mockMvc.get("/order") {
89-
contentType = MediaType.APPLICATION_JSON
90-
accept = MediaType.APPLICATION_JSON
91-
}
92-
.andDo { print() }
87+
mockMvc
88+
.get("/order") {
89+
contentType = MediaType.APPLICATION_JSON
90+
accept = MediaType.APPLICATION_JSON
91+
}.andDo { print() }
9392
.andExpect {
9493
status { isOk() }
9594
jsonPath("$[*].coffee", containsInAnyOrder(firstOrder.coffee, secondOrder.coffee))

local-db/src/main/kotlin/com/github/wpanas/spring/local/Application.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,16 @@ data class Cat(
3030
val name: String,
3131
)
3232

33-
data class CreateCatDto(val name: String) {
33+
data class CreateCatDto(
34+
val name: String,
35+
) {
3436
fun toCat() = Cat(id = null, name = name)
3537
}
3638

37-
data class ShowCatDto(val id: Long, val name: String)
39+
data class ShowCatDto(
40+
val id: Long,
41+
val name: String,
42+
)
3843

3944
fun Cat.toDto() = ShowCatDto(id!!, name)
4045

@@ -43,10 +48,13 @@ interface CatRepository : PagingAndSortingRepository<Cat, Long>
4348

4449
@RestController
4550
@RequestMapping("/cats")
46-
class CatController(private val catRepository: CatRepository) {
51+
class CatController(
52+
private val catRepository: CatRepository,
53+
) {
4754
@GetMapping
4855
fun findAll(pageable: Pageable): Page<ShowCatDto> =
49-
catRepository.findAll(pageable)
56+
catRepository
57+
.findAll(pageable)
5058
.map(Cat::toDto)
5159

5260
@PostMapping

local-db/src/test/kotlin/com/github/wpanas/spring/local/CatControllerTest.kt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ internal class CatControllerTest {
2929

3030
@Test
3131
internal fun `should add new cat`() {
32-
mockMvc.post("/cats") {
33-
content =
34-
"""{"name": "Sherry"}"""
35-
contentType = APPLICATION_JSON
36-
accept = APPLICATION_JSON
37-
}
38-
.andDo { print() }
32+
mockMvc
33+
.post("/cats") {
34+
content =
35+
"""{"name": "Sherry"}"""
36+
contentType = APPLICATION_JSON
37+
accept = APPLICATION_JSON
38+
}.andDo { print() }
3939
.andExpect {
4040
status { isOk() }
4141
jsonPath("$.name", `is`("Sherry"))
@@ -47,10 +47,10 @@ internal class CatControllerTest {
4747
val benny = catRepository.save(Cat(id = null, name = "Benny"))
4848
val linda = catRepository.save(Cat(id = null, name = "Linda"))
4949

50-
mockMvc.get("/cats") {
51-
accept = APPLICATION_JSON
52-
}
53-
.andDo { print() }
50+
mockMvc
51+
.get("/cats") {
52+
accept = APPLICATION_JSON
53+
}.andDo { print() }
5454
.andExpect {
5555
status { isOk() }
5656
jsonPath("$.totalElements", `is`(2))

local-db/src/test/kotlin/com/github/wpanas/spring/local/PostgreSQLInitializer.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ class PostgreSQLInitializer : ApplicationContextInitializer<ConfigurableApplicat
2121
"spring.datasource.url" to postgreSQLContainer.jdbcUrl,
2222
"spring.datasource.username" to postgreSQLContainer.username,
2323
"spring.datasource.password" to postgreSQLContainer.password,
24-
)
25-
.let(TestPropertyValues::of)
24+
).let(TestPropertyValues::of)
2625
.applyTo(applicationContext)
2726
}
2827
}

spring-junit5/src/main/kotlin/com/github/wpanas/spring/junit/JunitApplication.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,16 @@ data class Cat(
3131
val name: String,
3232
)
3333

34-
data class CreateCatDto(val name: String) {
34+
data class CreateCatDto(
35+
val name: String,
36+
) {
3537
fun toCat() = Cat(id = null, name = name)
3638
}
3739

38-
data class ShowCatDto(val id: Long, val name: String)
40+
data class ShowCatDto(
41+
val id: Long,
42+
val name: String,
43+
)
3944

4045
fun Cat.toDto() = ShowCatDto(id!!, name)
4146

@@ -44,10 +49,13 @@ interface CatRepository : PagingAndSortingRepository<Cat, Long>
4449

4550
@RestController
4651
@RequestMapping("/cats")
47-
class CatController(private val catRepository: CatRepository) {
52+
class CatController(
53+
private val catRepository: CatRepository,
54+
) {
4855
@GetMapping
4956
fun findAll(pageable: Pageable): Page<ShowCatDto> =
50-
catRepository.findAll(pageable)
57+
catRepository
58+
.findAll(pageable)
5159
.map(Cat::toDto)
5260

5361
@PostMapping

spring-junit5/src/test/kotlin/com/github/wpanas/spring/junit/CatControllerTest.kt

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,11 @@ internal class CatControllerTest {
3939
val postgreSQLContainer =
4040
PostgreSQLContainer(
4141
DockerImageName.parse("postgres:12.4"),
42-
)
43-
.apply {
44-
withLogConsumer(Slf4jLogConsumer(logger))
45-
withDatabaseName("cats_shelter")
46-
withClasspathResourceMapping("init.sql", CONTAINER_PATH, READ_ONLY)
47-
}
42+
).apply {
43+
withLogConsumer(Slf4jLogConsumer(logger))
44+
withDatabaseName("cats_shelter")
45+
withClasspathResourceMapping("init.sql", CONTAINER_PATH, READ_ONLY)
46+
}
4847

4948
@JvmStatic
5049
@DynamicPropertySource
@@ -69,19 +68,18 @@ internal class CatControllerTest {
6968
@Test
7069
internal fun `should add new cat`() {
7170
val cat =
72-
mockMvc.post("/cats") {
73-
content =
74-
"""{"name": "Sherry"}"""
75-
contentType = APPLICATION_JSON
76-
accept = APPLICATION_JSON
77-
}
78-
.andDo { print() }
71+
mockMvc
72+
.post("/cats") {
73+
content =
74+
"""{"name": "Sherry"}"""
75+
contentType = APPLICATION_JSON
76+
accept = APPLICATION_JSON
77+
}.andDo { print() }
7978
.andExpect {
8079
status { isOk() }
8180
jsonPath("$.name", `is`("Sherry"))
8281
jsonPath("$.id", `is`(notNullValue()))
83-
}
84-
.toCat()
82+
}.toCat()
8583

8684
val foundCat = catRepository.findByIdOrNull(cat.id!!)
8785
assertEquals(foundCat, cat)
@@ -92,10 +90,10 @@ internal class CatControllerTest {
9290
val benny = catRepository.save(Cat(id = null, name = "Benny"))
9391
val linda = catRepository.save(Cat(id = null, name = "Linda"))
9492

95-
mockMvc.get("/cats") {
96-
accept = APPLICATION_JSON
97-
}
98-
.andDo { print() }
93+
mockMvc
94+
.get("/cats") {
95+
accept = APPLICATION_JSON
96+
}.andDo { print() }
9997
.andExpect {
10098
status { isOk() }
10199
jsonPath("$.totalElements", `is`(2))

spring-kotest/src/main/kotlin/com/github/wpanas/spring/kotest/KotestApplication.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,16 @@ data class Cat(
3131
val name: String,
3232
)
3333

34-
data class CreateCatDto(val name: String) {
34+
data class CreateCatDto(
35+
val name: String,
36+
) {
3537
fun toCat() = Cat(id = null, name = name)
3638
}
3739

38-
data class ShowCatDto(val id: Long, val name: String)
40+
data class ShowCatDto(
41+
val id: Long,
42+
val name: String,
43+
)
3944

4045
fun Cat.toDto() = ShowCatDto(id!!, name)
4146

@@ -44,10 +49,13 @@ interface CatRepository : PagingAndSortingRepository<Cat, Long>
4449

4550
@RestController
4651
@RequestMapping("/cats")
47-
class CatController(private val catRepository: CatRepository) {
52+
class CatController(
53+
private val catRepository: CatRepository,
54+
) {
4855
@GetMapping
4956
fun findAll(pageable: Pageable): Page<ShowCatDto> =
50-
catRepository.findAll(pageable)
57+
catRepository
58+
.findAll(pageable)
5159
.map(Cat::toDto)
5260

5361
@PostMapping

0 commit comments

Comments
 (0)