Skip to content

Commit

Permalink
object @component
Browse files Browse the repository at this point in the history
  • Loading branch information
jesperancinha committed Jan 21, 2025
1 parent f50c347 commit e96f240
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
10 changes: 10 additions & 0 deletions jeorg-spring-kotlin/mix-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@
<artifactId>kotlin-test-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.ninja-squad</groupId>
<artifactId>springmockk</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.kotest</groupId>
<artifactId>kotest-assertions-core-jvm</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class MixServiceApplication(
inventoryProcessor.performAll()

mySingletonComponent.sayHello()
MySingletonComponent.sayHello()
}

private fun process(notificationEmail: Notification) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ sealed class Notification {

@Component
object MySingletonComponent {
fun sayHello() {
fun sayHello(): Boolean {
println("Hello from MySingletonComponent!")
return true
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.jesperancinha.smtd.mixservice.configuration

import com.ninjasquad.springmockk.MockkBean
import io.mockk.every
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.context.annotation.Primary
import org.springframework.stereotype.Component
import kotlin.test.Test

@Component
@Primary
object MySingletonComponent {
fun sayHello(): Boolean {
println("AHA!")
return true
}
}
@SpringBootTest
class MySingletonComponentTest {


@Test
fun `should be able to mock singleton object bean`() {
}
}

0 comments on commit e96f240

Please sign in to comment.