-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
c795255
commit 579318f
Showing
5 changed files
with
43 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 2 additions & 8 deletions
10
src/test/kotlin/kr/galaxyhub/sc/api/v1/crawler/CrawlerControllerV1Test.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/test/kotlin/kr/galaxyhub/sc/config/spec/ControllerTestSpec.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package kr.galaxyhub.sc.config.spec | ||
|
||
import io.kotest.core.spec.style.DescribeSpec | ||
import io.kotest.core.test.TestCase | ||
import io.kotest.core.test.TestResult | ||
import io.mockk.clearAllMocks | ||
import io.mockk.mockkClass | ||
import org.junit.platform.commons.util.ClassFilter | ||
import org.junit.platform.commons.util.ReflectionUtils | ||
import org.springframework.beans.factory.config.BeanFactoryPostProcessor | ||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory | ||
import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest | ||
import org.springframework.context.annotation.Import | ||
import org.springframework.stereotype.Service | ||
|
||
@Import(MockServiceBeanFactoryPostProcessor::class) | ||
@WebMvcTest | ||
@AutoConfigureRestDocs | ||
abstract class ControllerTestSpec(body: DescribeSpec.() -> Unit = {}) : DescribeSpec(body) { | ||
|
||
override suspend fun afterEach(testCase: TestCase, result: TestResult) { | ||
clearAllMocks() | ||
} | ||
} | ||
|
||
class MockServiceBeanFactoryPostProcessor : BeanFactoryPostProcessor { | ||
|
||
override fun postProcessBeanFactory(beanFactory: ConfigurableListableBeanFactory) { | ||
val classFilter = ClassFilter.of { it.isAnnotationPresent(Service::class.java) } | ||
ReflectionUtils.findAllClassesInPackage("kr.galaxyhub.sc", classFilter).forEach { | ||
beanFactory.registerSingleton(it.simpleName, mockkClass(it.kotlin)) | ||
} | ||
} | ||
} |