mirror of
https://github.com/Dannecron/spring-boot-demo.git
synced 2025-12-26 08:42:33 +03:00
add tests for ShopController
This commit is contained in:
@@ -14,11 +14,9 @@ import org.springframework.web.bind.annotation.RestController
|
||||
class ShopController (
|
||||
@field:Autowired private val shopProvider: ShopProvider,
|
||||
) {
|
||||
@GetMapping(value = ["/shop/common-info"], produces = ["application/json"] )
|
||||
@GetMapping(value = ["/shop/common-info"], produces = ["application/json"])
|
||||
@ResponseBody
|
||||
fun commonInfo(response: HttpServletResponse): String {
|
||||
response.contentType = "application/json"
|
||||
|
||||
val shop = shopProvider.getRandomShop()
|
||||
|
||||
if (shop == null) {
|
||||
|
||||
@@ -19,7 +19,7 @@ fun renderProductTable(): String {
|
||||
}
|
||||
}
|
||||
|
||||
val products = getProducts()
|
||||
val products = getInnerProducts()
|
||||
for ((i, product) in products.withIndex()) {
|
||||
tr {
|
||||
td (color = getCellColor(0, i+1)) {
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.example.demo.provider.html
|
||||
|
||||
data class InnerProduct(val description: String, val price: Double, val popularity: Int)
|
||||
|
||||
fun getInnerProducts(): Set<InnerProduct> {
|
||||
return setOf(
|
||||
InnerProduct("one", 12.0, 12),
|
||||
InnerProduct("two", 13.0, 20),
|
||||
InnerProduct("three", 14.0, 50)
|
||||
)
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package com.example.demo.provider.html
|
||||
|
||||
data class Product(val description: String, val price: Double, val popularity: Int)
|
||||
|
||||
fun getProducts(): Set<Product> {
|
||||
return setOf(
|
||||
Product("one", 12.0, 12),
|
||||
Product("two", 13.0, 20),
|
||||
Product("three", 14.0, 50)
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user