Skip to content

Commit

Permalink
Use hasItems for override JDK member test
Browse files Browse the repository at this point in the history
This should fix the Java 21 CI issues and make the test more robust
against new members in Thread.
  • Loading branch information
fwcd committed Jan 24, 2024
1 parent 54935f3 commit 2a48aab
Showing 1 changed file with 40 additions and 39 deletions.
79 changes: 40 additions & 39 deletions server/src/test/kotlin/org/javacs/kt/OverrideMemberTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.eclipse.lsp4j.TextDocumentPositionParams
import org.junit.Test
import org.hamcrest.core.Every.everyItem
import org.hamcrest.Matchers.containsInAnyOrder
import org.hamcrest.Matchers.hasItems
import org.hamcrest.Matchers.equalTo
import org.hamcrest.Matchers.hasSize
import org.junit.Assert.assertThat
Expand All @@ -17,7 +18,7 @@ class OverrideMemberTest : SingleFileTestFixture("overridemember", "OverrideMemb

val root = testResourcesRoot().resolve(workspaceRoot)
val fileUri = root.resolve(file).toUri().toString()

@Test
fun `should show all overrides for class`() {
val result = languageServer.getProtocolExtensionService().overrideMember(TextDocumentPositionParams(TextDocumentIdentifier(fileUri), position(9, 8))).get()
Expand All @@ -39,7 +40,7 @@ class OverrideMemberTest : SingleFileTestFixture("overridemember", "OverrideMemb
padding + "override fun equals(other: Any?): Boolean { }",
padding + "override fun hashCode(): Int { }",
padding + "override fun toString(): String { }"))


assertThat(ranges, everyItem(equalTo(range(9, 31, 9, 31))))
}
Expand All @@ -63,14 +64,14 @@ class OverrideMemberTest : SingleFileTestFixture("overridemember", "OverrideMemb
padding + "override fun equals(other: Any?): Boolean { }",
padding + "override fun hashCode(): Int { }",
padding + "override fun toString(): String { }"))

assertThat(ranges, everyItem(equalTo(range(12, 56, 12, 56))))
}

@Test
fun `should show NO overrides for class where all other alternatives are already implemented`() {
val result = languageServer.getProtocolExtensionService().overrideMember(TextDocumentPositionParams(TextDocumentIdentifier(fileUri), position(15, 8))).get()

assertThat(result, hasSize(0))
}

Expand All @@ -93,10 +94,10 @@ class OverrideMemberTest : SingleFileTestFixture("overridemember", "OverrideMemb
padding + "override fun equals(other: Any?): Boolean { }",
padding + "override fun hashCode(): Int { }",
padding + "override fun toString(): String { }"))

assertThat(ranges, everyItem(equalTo(range(37, 25, 37, 25))))
}

@Test
fun `should find members in jdk object`() {
val result = languageServer.getProtocolExtensionService().overrideMember(TextDocumentPositionParams(TextDocumentIdentifier(fileUri), position(39, 9))).get()
Expand All @@ -106,41 +107,41 @@ class OverrideMemberTest : SingleFileTestFixture("overridemember", "OverrideMemb
val newTexts = edits.map { it.newText }
val ranges = edits.map { it.range }

assertThat(titles, containsInAnyOrder("override fun equals(other: Any?): Boolean { }",
"override fun hashCode(): Int { }",
"override fun toString(): String { }",
"override fun run() { }",
"override fun clone(): Any { }",
"override fun start() { }",
"override fun interrupt() { }",
"override fun isInterrupted(): Boolean { }",
"override fun countStackFrames(): Int { }",
"override fun getContextClassLoader(): ClassLoader { }",
"override fun setContextClassLoader(cl: ClassLoader) { }",
"override fun getStackTrace(): (Array<(StackTraceElement..StackTraceElement?)>..Array<out (StackTraceElement..StackTraceElement?)>) { }",
"override fun getId(): Long { }",
"override fun getState(): State { }",
"override fun getUncaughtExceptionHandler(): UncaughtExceptionHandler { }",
"override fun setUncaughtExceptionHandler(eh: UncaughtExceptionHandler) { }"))
assertThat(titles, hasItems("override fun equals(other: Any?): Boolean { }",
"override fun hashCode(): Int { }",
"override fun toString(): String { }",
"override fun run() { }",
"override fun clone(): Any { }",
"override fun start() { }",
"override fun interrupt() { }",
"override fun isInterrupted(): Boolean { }",
"override fun countStackFrames(): Int { }",
"override fun getContextClassLoader(): ClassLoader { }",
"override fun setContextClassLoader(cl: ClassLoader) { }",
"override fun getStackTrace(): (Array<(StackTraceElement..StackTraceElement?)>..Array<out (StackTraceElement..StackTraceElement?)>) { }",
"override fun getId(): Long { }",
"override fun getState(): State { }",
"override fun getUncaughtExceptionHandler(): UncaughtExceptionHandler { }",
"override fun setUncaughtExceptionHandler(eh: UncaughtExceptionHandler) { }"))

val padding = System.lineSeparator() + System.lineSeparator() + " "
assertThat(newTexts, containsInAnyOrder(padding + "override fun equals(other: Any?): Boolean { }",
padding + "override fun hashCode(): Int { }",
padding + "override fun toString(): String { }",
padding + "override fun run() { }",
padding + "override fun clone(): Any { }",
padding + "override fun start() { }",
padding + "override fun interrupt() { }",
padding + "override fun isInterrupted(): Boolean { }",
padding + "override fun countStackFrames(): Int { }",
padding + "override fun getContextClassLoader(): ClassLoader { }",
padding + "override fun setContextClassLoader(cl: ClassLoader) { }",
padding + "override fun getStackTrace(): (Array<(StackTraceElement..StackTraceElement?)>..Array<out (StackTraceElement..StackTraceElement?)>) { }",
padding + "override fun getId(): Long { }",
padding + "override fun getState(): State { }",
padding + "override fun getUncaughtExceptionHandler(): UncaughtExceptionHandler { }",
padding + "override fun setUncaughtExceptionHandler(eh: UncaughtExceptionHandler) { }"))
assertThat(newTexts, hasItems(padding + "override fun equals(other: Any?): Boolean { }",
padding + "override fun hashCode(): Int { }",
padding + "override fun toString(): String { }",
padding + "override fun run() { }",
padding + "override fun clone(): Any { }",
padding + "override fun start() { }",
padding + "override fun interrupt() { }",
padding + "override fun isInterrupted(): Boolean { }",
padding + "override fun countStackFrames(): Int { }",
padding + "override fun getContextClassLoader(): ClassLoader { }",
padding + "override fun setContextClassLoader(cl: ClassLoader) { }",
padding + "override fun getStackTrace(): (Array<(StackTraceElement..StackTraceElement?)>..Array<out (StackTraceElement..StackTraceElement?)>) { }",
padding + "override fun getId(): Long { }",
padding + "override fun getState(): State { }",
padding + "override fun getUncaughtExceptionHandler(): UncaughtExceptionHandler { }",
padding + "override fun setUncaughtExceptionHandler(eh: UncaughtExceptionHandler) { }"))

assertThat(ranges, everyItem(equalTo(range(39, 25, 39, 25))))
}
}

0 comments on commit 2a48aab

Please sign in to comment.