Skip to content

Commit

Permalink
Add test for inheritance in frameworks context
Browse files Browse the repository at this point in the history
  • Loading branch information
osoykan committed Oct 28, 2024
1 parent 8686ad0 commit 1880fc6
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,11 @@ abstract class MediatorUseCases : MediatorDIConvention {
val result = testMediator.send(TestQuery(1))
result shouldBe "hello 1"
}

@Test
fun inheritance_for_command_handler() = runTest {
val command = TestCommandForInheritance()
testMediator.send(command)
command.invocationCount() shouldBe 1
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,13 @@ class TestQueryHandler(
return "hello " + query.id
}
}

class TestCommandForInheritance : Command, EnrichedWithMetadata()

abstract class MyCommandHandlerBaseForSpecificCommand : CommandHandler<TestCommandForInheritance>

class TestInheritedCommandHandlerForSpecificCommand : MyCommandHandlerBaseForSpecificCommand() {
override suspend fun handle(command: TestCommandForInheritance) {
command.incrementInvocationCount()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package com.trendyol.kediatr.koin
import com.trendyol.kediatr.*
import com.trendyol.kediatr.framewokUseCases.*
import org.junit.jupiter.api.extension.RegisterExtension
import org.koin.dsl.*
import org.koin.test.*
import org.koin.dsl.bind
import org.koin.dsl.module
import org.koin.test.KoinTest
import org.koin.test.inject
import org.koin.test.junit5.KoinTestExtension

class MediatorTests : KoinTest, MediatorUseCases() {
Expand All @@ -22,6 +24,7 @@ class MediatorTests : KoinTest, MediatorUseCases() {
single { TestNotificationHandler(get()) } bind NotificationHandler::class
single { TestBrokenCommandHandler(get()) } bind CommandHandler::class
single { TestPipelineCommandHandler(get()) } bind CommandHandler::class
single { TestInheritedCommandHandlerForSpecificCommand() } bind CommandHandler::class
}
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ class MediatorTests : MediatorUseCases() {
@Produces
fun handler4(mediator: Mediator): TestPipelineCommandHandler = TestPipelineCommandHandler(mediator)

@Produces
fun handler5(): TestInheritedCommandHandlerForSpecificCommand =
TestInheritedCommandHandlerForSpecificCommand()

@Produces
fun notificationHandler(mediator: Mediator) = TestNotificationHandler(mediator)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import org.springframework.boot.test.context.SpringBootTest
TestNotificationHandler::class,
TestBrokenCommandHandler::class,
TestPipelineCommandHandler::class,
TestCommandWithResultCommandHandler::class
TestCommandWithResultCommandHandler::class,
TestInheritedCommandHandlerForSpecificCommand::class
]
)
class MediatorTests : MediatorUseCases() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import org.springframework.boot.test.context.SpringBootTest
TestNotificationHandler::class,
TestBrokenCommandHandler::class,
TestPipelineCommandHandler::class,
TestCommandWithResultCommandHandler::class
TestCommandWithResultCommandHandler::class,
TestInheritedCommandHandlerForSpecificCommand::class
]
)
class MediatorTests : MediatorUseCases() {
Expand Down

0 comments on commit 1880fc6

Please sign in to comment.