[Daemon] Add unit tests for LimitedLinkedList
This commit is contained in:
committed by
Space Team
parent
f7b139466d
commit
3ca1249926
@@ -19,6 +19,7 @@ val nativePlatformVariants = listOf(
|
||||
)
|
||||
|
||||
dependencies {
|
||||
api(kotlinStdlib())
|
||||
compileOnly(project(":daemon-common"))
|
||||
compileOnly(commonDependency("net.rubygrapefruit", "native-platform"))
|
||||
|
||||
@@ -27,6 +28,13 @@ dependencies {
|
||||
nativePlatformVariants.forEach {
|
||||
embedded(commonDependency("net.rubygrapefruit", "native-platform", "-$it"))
|
||||
}
|
||||
testImplementation(platform(libs.junit.bom))
|
||||
testImplementation(libs.junit.jupiter.api)
|
||||
testRuntimeOnly(libs.junit.jupiter.engine)
|
||||
}
|
||||
|
||||
projectTest(jUnitMode = JUnitMode.JUnit5) {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
configureKotlinCompileTasksGradleCompatibility()
|
||||
|
||||
@@ -9,6 +9,12 @@ import java.util.*
|
||||
|
||||
|
||||
internal class LimitedLinkedList<E>(private val limit: Int) : LinkedList<E>() {
|
||||
init {
|
||||
require(limit > 0) {
|
||||
"The limit shall be > 0. Other values does not make any sense"
|
||||
}
|
||||
}
|
||||
|
||||
override fun add(element: E): Boolean {
|
||||
val added = super.add(element)
|
||||
while (added && size > limit) {
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.daemon.client
|
||||
|
||||
import org.junit.jupiter.api.Assertions.*
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class LimitedLinkedListTest {
|
||||
@Test
|
||||
@DisplayName("adding elements within limit")
|
||||
fun withinLimit() {
|
||||
val limitedList = LimitedLinkedList<Int>(5)
|
||||
assertTrue(limitedList.add(1))
|
||||
assertTrue(limitedList.add(2))
|
||||
assertTrue(limitedList.add(3))
|
||||
assertEquals(listOf(1, 2, 3), limitedList)
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("adding elements beyond limit")
|
||||
fun beyondLimit() {
|
||||
val limitedList = LimitedLinkedList<Int>(3)
|
||||
assertTrue(limitedList.add(1))
|
||||
assertTrue(limitedList.add(2))
|
||||
assertTrue(limitedList.add(3))
|
||||
assertTrue(limitedList.add(4))
|
||||
assertEquals(listOf(2, 3, 4), limitedList)
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("incorrect limit values lead to exception")
|
||||
fun incorrectLimitValues() {
|
||||
assertThrows(IllegalArgumentException::class.java) {
|
||||
LimitedLinkedList<String>(0)
|
||||
}
|
||||
assertThrows(IllegalArgumentException::class.java) {
|
||||
LimitedLinkedList<String>(-50)
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
@@ -25,4 +25,12 @@
|
||||
<developerConnection>scm:git:https://github.com/JetBrains/kotlin.git</developerConnection>
|
||||
<url>https://github.com/JetBrains/kotlin</url>
|
||||
</scm>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib</artifactId>
|
||||
<version>ArtifactsTest.version</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
Reference in New Issue
Block a user