``` org.mockito.exceptions.misusing.UnfinishedVeri...
# test
x
Copy code
org.mockito.exceptions.misusing.UnfinishedVerificationException: 
Missing method call for verify(mock) here:
-> at com.potrero.ph.emr.event.EmrPublisherTest.publish(EmrPublisherTest.kt:43)

Example of correct verification:
    verify(mock).doSomething()

Also, this error might show up because you verify either of: final/private/equals()/hashCode() methods.
Those methods *cannot* be stubbed/verified.
Mocking methods declared on non-public parent classes is not supported.
Copy code
@SpringBootTest
@SpringJUnitConfig
internal open class EmrPublisherTest {
    @MockBean lateinit var repo: EmrRepo
    @SpyBean lateinit var ctrl: EmrPublisher
    @Value(EmrPublisher.PLACEHOLDER) lateinit var duration: String
    private val now = Instant.now()
    private val timeout: Long = 500000

    @BeforeEach
    fun setup() {
        val entity = Emr()
        entity.id = 1
        entity.mrn = "abc123"
        entity.description = "mydesc"
        entity.timestamp = now.minus(Duration.parse(duration)).plusSeconds(2)
        entity.units = "mg"
        entity.value = "25"

        val ret = setOf(entity)

        Mockito.`when`(repo.findByTimestampIsAfter(Mockito.any())).thenReturn(ret, ret, ret)
    }

    @Test
    fun publish() {
        Mockito.verify(ctrl, times(3)).publishCreatedEmr(any()) //43
        ctrl.publish()
    }
}
Copy code
@Service
open class EmrPublisher(private val repo: EmrRepo, @Value(PLACEHOLDER) val duration: Duration) {

    private val log = LogManager.getLogger(this.javaClass)

    @Transactional(readOnly = true)
    @Scheduled(fixedRateString = PLACEHOLDER)
    open fun publish() {
        val lastRun = Instant.now().minus(this.duration)
        log.debug("find emrs after {}", lastRun)
        publishCreatedEmrs(repo.findByTimestampIsAfter(lastRun))
    }


    private fun publishCreatedEmrs(emrs: Collection<Emr>) {
        emrs.forEach { publishCreatedEmr(it) }
    }

    @SendTo(EMR)
    open fun publishCreatedEmr(emr: Emr): EmrCreated {
        log.debug(emr)
        return EmrCreated(emr)
    }

    companion object {
        internal const val EMR = "emr"
        internal const val CREATED_SCHEDULE_PROPERTY = "event.schedule.emr.created"
        const val PLACEHOLDER = "\${$CREATED_SCHEDULE_PROPERTY}"
    }
}