Skip to content
This repository was archived by the owner on Dec 10, 2025. It is now read-only.

Commit f63d2d5

Browse files
committed
test: add unit tests for QueueEntryImpl comparison logic
1 parent 76efd4c commit f63d2d5

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

build.gradle.kts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ allprojects {
4141

4242
compileOnly("org.springframework.boot:spring-boot-configuration-processor:3.5.3")
4343
// "kapt"("org.springframework.boot:spring-boot-configuration-processor:3.4.3")
44+
45+
testImplementation(kotlin("test"))
4446
}
4547

4648

@@ -53,6 +55,10 @@ allprojects {
5355
options.use()
5456
options.tags("implNote:a:Implementation Note:")
5557
}
58+
59+
test {
60+
useJUnitPlatform()
61+
}
5662
}
5763
}
5864

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package dev.slne.surf.cloud.standalone.server.queue.entry
2+
3+
import org.junit.jupiter.api.Assertions.assertEquals
4+
import org.junit.jupiter.api.Test
5+
import java.util.*
6+
7+
class QueueEntryImplTest {
8+
9+
private fun newEntry(priority: Int, preferredServer: Long? = null) =
10+
QueueEntryImpl(
11+
PlayerQueueHandle(UUID.randomUUID()),
12+
priority,
13+
bypassFull = false,
14+
bypassQueue = false,
15+
preferredServerUid = preferredServer
16+
)
17+
18+
@Test
19+
fun `compareTo honors priority`() {
20+
val high = newEntry(priority = 10)
21+
val low = newEntry(priority = 5)
22+
23+
assertEquals(-1, high.compareTo(low), "Higher priority should come first")
24+
assertEquals(1, low.compareTo(high), "Lower priority should come after")
25+
}
26+
27+
@Test
28+
fun `compareTo prioritizes preferred server`() {
29+
val a = newEntry(priority = 5, preferredServer = 1)
30+
val b = newEntry(priority = 5, preferredServer = null)
31+
32+
assertEquals(-1, a.compareTo(b))
33+
assertEquals(1, b.compareTo(a))
34+
}
35+
36+
@Test
37+
fun `compareTo equality when all fields equal`() {
38+
val a = newEntry(priority = 5, preferredServer = 1)
39+
val b = a.copy()
40+
41+
assertEquals(0, a.compareTo(b))
42+
assertEquals(0, b.compareTo(a))
43+
}
44+
}

0 commit comments

Comments
 (0)