-
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.
added kotest, improved tests, small code improvements
- Loading branch information
1 parent
9668927
commit 3298ac1
Showing
4 changed files
with
32 additions
and
65 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
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
11 changes: 4 additions & 7 deletions
11
...lin/de/envite/greenbpm/camunda_process_carbon_pricing/fibonacci_worker/FibonacciKtTest.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
70 changes: 16 additions & 54 deletions
70
...envite/greenbpm/camunda_process_carbon_pricing/fibonacci_worker/JobExporterServiceTest.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 |
---|---|---|
@@ -1,75 +1,37 @@ | ||
package de.envite.greenbpm.camunda_process_carbon_pricing.fibonacci_worker | ||
|
||
import io.micrometer.core.instrument.Counter | ||
import io.micrometer.core.instrument.MeterRegistry | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
import io.mockk.verify | ||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.BeforeEach | ||
import io.kotest.assertions.assertSoftly | ||
import io.kotest.matchers.shouldBe | ||
import io.micrometer.core.instrument.simple.SimpleMeterRegistry | ||
import org.junit.jupiter.api.Test | ||
import org.springframework.boot.test.context.SpringBootTest | ||
|
||
@SpringBootTest | ||
class JobExporterServiceTest { | ||
private lateinit var meterRegistry: MeterRegistry | ||
private lateinit var classUnderTest: JobExporterService | ||
private lateinit var jobsStartedCounter: Counter | ||
private lateinit var jobsFinishedCounter: Counter | ||
|
||
@BeforeEach | ||
fun setup(){ | ||
meterRegistry = mockk(relaxed = true) | ||
jobsStartedCounter = mockk(relaxed = true) | ||
jobsFinishedCounter = mockk(relaxed = true) | ||
|
||
every { Counter.builder("fibonacciworker_jobs_started") | ||
.tag("jobKey","testId") | ||
.register(meterRegistry) | ||
} returns jobsStartedCounter | ||
|
||
every { Counter.builder("fibonacciworker_jobs_finished") | ||
.tag("jobKey","testId") | ||
.register(meterRegistry) | ||
} returns jobsFinishedCounter | ||
class JobExporterServiceTest { | ||
|
||
classUnderTest = JobExporterService(meterRegistry) | ||
} | ||
private val meterRegistry: SimpleMeterRegistry = SimpleMeterRegistry() | ||
private val classUnderTest: JobExporterService = JobExporterService(meterRegistry) | ||
|
||
@Test | ||
fun `reportJobStarted should increase jobsStartedCounter`() { | ||
fun `reportJobStarted should increase jobsStartedCounter and update gauge`() { | ||
val id = "testId" | ||
|
||
classUnderTest.reportJobStarted(id) | ||
|
||
verify { jobsStartedCounter.increment() } | ||
|
||
assertEquals(1, classUnderTest.getJobsInExecution()) | ||
assertSoftly { | ||
meterRegistry.get("${BASE_NAME}_started").counter().count() shouldBe 1.0 | ||
meterRegistry.get("${BASE_NAME}_in_execution").gauge().value() shouldBe 1.0 | ||
} | ||
} | ||
|
||
@Test | ||
fun `reportJobFinished should increase jobsFinishedCounter`() { | ||
fun `reportJobStarted should decrease jobsStartedCounter and update gauge`() { | ||
val id = "testId" | ||
|
||
classUnderTest.reportJobFinished(id) | ||
|
||
verify { jobsFinishedCounter.increment() } | ||
|
||
assertEquals(-1, classUnderTest.getJobsInExecution()) | ||
|
||
} | ||
|
||
@Test | ||
fun `increase and decrease jobsInExecution`() { | ||
val id = "testId" | ||
|
||
classUnderTest.reportJobStarted(id) | ||
|
||
assertEquals(1, classUnderTest.getJobsInExecution()) | ||
|
||
classUnderTest.reportJobFinished(id) | ||
|
||
assertEquals(0, classUnderTest.getJobsInExecution()) | ||
|
||
assertSoftly { | ||
meterRegistry.get("${BASE_NAME}_finished").counter().count() shouldBe 1.0 | ||
meterRegistry.get("${BASE_NAME}_in_execution").gauge().value() shouldBe -1.0 | ||
} | ||
} | ||
} |