some refactoring

This commit is contained in:
Denis Savosin
2024-10-02 12:18:55 +07:00
parent 16f43c6172
commit 9b00237657
33 changed files with 109 additions and 82 deletions

View File

@@ -1,9 +1,8 @@
package com.example.demo.http.controllers
import com.example.demo.http.controllers.ProductController
import com.example.demo.models.Product
import com.example.demo.http.responses.ResponseStatus
import com.example.demo.services.ProductService
import com.example.demo.models.Product
import com.example.demo.services.database.product.ProductService
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import org.hamcrest.Matchers.contains
import org.hamcrest.Matchers.nullValue

View File

@@ -1,8 +1,7 @@
package com.example.demo.http.controllers
import com.example.demo.http.controllers.ShopController
import com.example.demo.models.*
import com.example.demo.provider.ShopProvider
import com.example.demo.providers.ShopProvider
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.whenever
import org.springframework.beans.factory.annotation.Autowired

View File

@@ -1,10 +1,14 @@
package com.example.demo.services
package com.example.demo.services.database.city
import com.example.demo.BaseFeatureTest
import com.example.demo.models.City
import com.example.demo.provider.CityRepository
import com.example.demo.providers.CityRepository
import com.example.demo.services.database.exceptions.AlreadyDeletedException
import com.example.demo.services.database.city.exceptions.CityNotFoundException
import org.junit.jupiter.api.assertThrows
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.test.context.ContextConfiguration
import java.util.*
import kotlin.test.*
@ContextConfiguration(classes = [CityRepository::class, CityServiceImpl::class])
@@ -35,6 +39,14 @@ class CityServiceImplTest: BaseFeatureTest() {
assertEquals(city.id, deletedCity.id)
assertNotNull(deletedCity.deletedAt)
assertTrue(deletedCity.isDeleted())
assertThrows<AlreadyDeletedException> {
cityServiceImpl.delete(city.guid)
}
assertThrows<CityNotFoundException> {
cityServiceImpl.delete(UUID.randomUUID())
}
} finally {
val id = city?.id
if (id != null) {

View File

@@ -1,10 +1,10 @@
package com.example.demo.services
package com.example.demo.services.database.product
import com.example.demo.BaseFeatureTest
import com.example.demo.http.exceptions.NotFoundException
import com.example.demo.http.exceptions.UnprocessableException
import com.example.demo.models.Product
import com.example.demo.provider.ProductRepository
import com.example.demo.providers.ProductRepository
import com.example.demo.services.database.exceptions.AlreadyDeletedException
import com.example.demo.services.database.product.exceptions.ProductNotFoundException
import org.junit.jupiter.api.assertThrows
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.test.context.ContextConfiguration
@@ -52,11 +52,11 @@ class ProductServiceImplFeatureTest: BaseFeatureTest() {
assertTrue(deletedProduct.isDeleted())
// try to delete already deleted product
assertThrows<UnprocessableException> {
assertThrows<AlreadyDeletedException> {
productService.delete(product.guid)
}
assertThrows<NotFoundException> {
assertThrows<ProductNotFoundException> {
productService.delete(UUID.randomUUID())
}
} finally {

View File

@@ -1,10 +1,10 @@
package com.example.demo.services
package com.example.demo.services.database.product
import com.example.demo.http.exceptions.NotFoundException
import com.example.demo.models.Product
import com.example.demo.provider.ProductRepository
import com.example.demo.providers.ProductRepository
import com.example.demo.services.kafka.Producer
import com.example.demo.services.kafka.exceptions.InvalidArgumentException
import com.example.demo.services.database.product.exceptions.ProductNotFoundException
import org.junit.jupiter.api.assertThrows
import org.junit.runner.RunWith
import org.mockito.kotlin.*
@@ -67,7 +67,7 @@ class ProductServiceImplTest {
whenever(productRepository.findByGuid(eq(guid)))
.thenReturn(null)
assertThrows<NotFoundException> {
assertThrows<ProductNotFoundException> {
productService.syncToKafka(guid, specificTopic)
}