From 54935f3e535d0eb2ecccc4144aa872d31eb16c75 Mon Sep 17 00:00:00 2001 From: fwcd Date: Sun, 14 Jan 2024 22:54:54 +0000 Subject: [PATCH 1/3] Add Java 21 CI --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a074ad328..caf113394 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,7 +13,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest, windows-latest] - java: [ '11', '17' ] + java: ['11', '17', '21'] steps: - uses: actions/checkout@v4 - name: Setup JDK From 2a48aab05ef4916c9fe16e856edea4307405c7e3 Mon Sep 17 00:00:00 2001 From: fwcd Date: Wed, 24 Jan 2024 16:54:37 +0100 Subject: [PATCH 2/3] Use hasItems for override JDK member test This should fix the Java 21 CI issues and make the test more robust against new members in Thread. --- .../org/javacs/kt/OverrideMemberTest.kt | 79 ++++++++++--------- 1 file changed, 40 insertions(+), 39 deletions(-) diff --git a/server/src/test/kotlin/org/javacs/kt/OverrideMemberTest.kt b/server/src/test/kotlin/org/javacs/kt/OverrideMemberTest.kt index e2f6c1f18..50f877a3d 100644 --- a/server/src/test/kotlin/org/javacs/kt/OverrideMemberTest.kt +++ b/server/src/test/kotlin/org/javacs/kt/OverrideMemberTest.kt @@ -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 @@ -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() @@ -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)))) } @@ -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)) } @@ -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() @@ -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) { }", - "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) { }", + "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) { }", - 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) { }", + 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)))) } } From 815246256c83d344dabe9634fae174297cab5371 Mon Sep 17 00:00:00 2001 From: fwcd Date: Wed, 24 Jan 2024 17:11:23 +0100 Subject: [PATCH 3/3] Remove setUncaughtExceptionHandler from test Its parameter has been renamed from 'eh' to 'ueh' in Java 21 and matching against both cases would require introducing a more complex matching mechanism (e.g. regex). --- .../org/javacs/kt/OverrideMemberTest.kt | 66 ++++++++++--------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/server/src/test/kotlin/org/javacs/kt/OverrideMemberTest.kt b/server/src/test/kotlin/org/javacs/kt/OverrideMemberTest.kt index 50f877a3d..d60bbb230 100644 --- a/server/src/test/kotlin/org/javacs/kt/OverrideMemberTest.kt +++ b/server/src/test/kotlin/org/javacs/kt/OverrideMemberTest.kt @@ -107,40 +107,42 @@ class OverrideMemberTest : SingleFileTestFixture("overridemember", "OverrideMemb val newTexts = edits.map { it.newText } val ranges = edits.map { it.range } - 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) { }", - "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) { }", + "override fun getId(): Long { }", + "override fun getState(): State { }", + "override fun getUncaughtExceptionHandler(): UncaughtExceptionHandler { }", + )) val padding = System.lineSeparator() + System.lineSeparator() + " " - 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) { }", - 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) { }", + padding + "override fun getId(): Long { }", + padding + "override fun getState(): State { }", + padding + "override fun getUncaughtExceptionHandler(): UncaughtExceptionHandler { }", + )) assertThat(ranges, everyItem(equalTo(range(39, 25, 39, 25)))) }