Skip to content

Commit

Permalink
refactor: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolaiSviridov committed Jan 22, 2024
1 parent e561689 commit 6c87bbc
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions core/src/test/kotlin/TestJsonObjectBuffer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,25 @@ import java.io.File
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.atomic.AtomicInteger
import kotlin.random.Random
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue
import kotlin.test.*

class TestJsonObjectBuffer {
private val tmpFolder = File("src/test/tmp/")
private val numberOfCoroutines = 100
private val numberOfActions = 50

@BeforeTest
fun prepare() {
tmpFolder.mkdirs()
}

@AfterTest
fun cleanup() {
tmpFolder.deleteRecursively()
}

@Test
fun testJsonObjectBufferChanges() {
tmpFolder.mkdirs()
val map = massGeneration { generateChange(it) }
assertEquals(numberOfActions * numberOfCoroutines, map.size)

Expand All @@ -36,12 +43,10 @@ class TestJsonObjectBuffer {
assertEquals(generatedChange, savedChange)
}
assertTrue(map.isEmpty())
cleanup()
}

@Test
fun testJsonObjectBufferComments() {
tmpFolder.mkdirs()
val map = massGeneration { generateComments(it) }
assertEquals(numberOfActions * numberOfCoroutines, map.size)

Expand All @@ -55,7 +60,6 @@ class TestJsonObjectBuffer {
}
}
assertTrue(map.isEmpty())
cleanup()
}

private inline fun <reified T> massGeneration(
Expand Down Expand Up @@ -111,8 +115,6 @@ class TestJsonObjectBuffer {
}
}

private fun cleanup() = tmpFolder.deleteRecursively()

private fun generateFileCommentREST() = FileCommentREST(
UserAccountGerrit(Random.nextInt(0, 10)),
randomField("updated"),
Expand Down

0 comments on commit 6c87bbc

Please sign in to comment.