From aaa58934c75cdf29af7fd6270ace00a9baddf852 Mon Sep 17 00:00:00 2001 From: leoweigl Date: Fri, 16 Oct 2026 17:50:59 +0200 Subject: [PATCH 1/2] Add unit tests for Listener and fix the test runtime --- CHANGELOG.md | 10 +++++ build.gradle.kts | 3 ++ .../entities/enums/ListenerTest.java | 44 +++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 src/test/java/org/overengineer/inlineproblems/entities/enums/ListenerTest.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 04691a8..0368959 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,9 +3,19 @@ # InlineProblems Changelog ## [Unreleased] + +### Added + +- Unit tests for the different problem detection strategies, making sure there are no duplicate IDs and that every ID maps back to its listener + ### Changed + - The GitHub release draft is created when a release is merged into the release branch, no longer on every push to main, so it cannot be published before the code is on the release branch +### Fixed + +- JUnit 4 class could not be found when running tests due to a missing dependency in build.gradle.kts, JUnit 5 refers to JUnit 4 in IntelliJ + ## [0.6.1] - 2026-10-13 ### Fixed diff --git a/build.gradle.kts b/build.gradle.kts index 56d7c3d..346487b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -43,6 +43,9 @@ dependencies { testImplementation(platform("org.junit:junit-bom:${properties("junitVersion").get()}")) testImplementation("org.junit.jupiter:junit-jupiter") testRuntimeOnly("org.junit.platform:junit-platform-launcher") + // JUnit 5 Test Framework refers to JUnit 4 - see IntelliJ Platform Gradle Plugin FAQ + // https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-faq.html + testRuntimeOnly("junit:junit:4.13.2") } // Configure the IntelliJ Platform Gradle Plugin diff --git a/src/test/java/org/overengineer/inlineproblems/entities/enums/ListenerTest.java b/src/test/java/org/overengineer/inlineproblems/entities/enums/ListenerTest.java new file mode 100644 index 0000000..93585eb --- /dev/null +++ b/src/test/java/org/overengineer/inlineproblems/entities/enums/ListenerTest.java @@ -0,0 +1,44 @@ +package org.overengineer.inlineproblems.entities.enums; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +import java.util.*; + +import static org.junit.jupiter.api.Assertions.*; + +class ListenerTest { + @Test + void idsAreUnique() { + Set knownIds = new HashSet<>(); + List duplicateIds = new ArrayList<>(); + + for (Listener listener : Listener.values()) { + if (!knownIds.add(listener.getId())) { + duplicateIds.add(listener.getId()); + } + } + + assertEquals(List.of(), duplicateIds); + } + + @Test + void fromIdReturnsCorrectListener() { + List mismatchedListeners = new ArrayList<>(); + + for (Listener listener : Listener.values()) { + if (listener != Listener.fromId(listener.getId())) { + mismatchedListeners.add(listener); + } + } + + assertEquals(List.of(), mismatchedListeners); + } + + @ParameterizedTest + @ValueSource(ints = {Integer.MIN_VALUE, -1, 99, Integer.MAX_VALUE}) + void fromIdReturnsDefaultForUnknownId(int unknownId) { + assertEquals(Listener.DEFAULT, Listener.fromId(unknownId)); + } +} From d4fbc91f6ccf13084f33f213e8f917cc1d31ff30 Mon Sep 17 00:00:00 2001 From: leoweigl Date: Thu, 22 Oct 2026 17:14:19 +0200 Subject: [PATCH 2/2] Update outdated comments about the test setup --- .github/workflows/run-ui-tests.yml | 3 +-- build.gradle.kts | 7 +++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/run-ui-tests.yml b/.github/workflows/run-ui-tests.yml index 0291ffa..d98bf6e 100644 --- a/.github/workflows/run-ui-tests.yml +++ b/.github/workflows/run-ui-tests.yml @@ -5,8 +5,7 @@ # the old runIdeForUiTests setup there is no separate "start the IDE and wait for the robot server" # dance - the task is all that has to run. # -# Note: there are no UI tests in the project yet, so the task currently runs an empty suite. The -# workflow exists so that adding the first test under src/test is enough to get it covered here. +# Tests are under src/test and require the JUnit 4 runtime dependency. # # Please check https://plugins.jetbrains.com/docs/intellij/testing-plugins.html for information # about testing plugins. diff --git a/build.gradle.kts b/build.gradle.kts index 346487b..cc7a7c7 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -151,8 +151,7 @@ qodana { * Replaces the runIdeForUiTests task of the old gradle-intellij-plugin, which drove the IDE * through the robot-server plugin - the 2.x plugin uses the IntelliJ Starter framework. * - * There are no UI tests yet, so the task currently runs an empty suite. The plumbing is here so - * that adding the first test under src/test/java is all it takes. */ + * Tests are under src/test and require the JUnit 4 runtime dependency. */ intellijPlatformTesting.testIdeUi.register("testIdeUi") { task { useJUnitPlatform() @@ -167,8 +166,8 @@ tasks { useJUnitPlatform() } - // Pointless without test sources, and running both instrumentation tasks in one build - // crashes InstrumentCodeTask ("1 >= 1"). instrumentCode still covers the shipped code. + // Running both instrumentation tasks in one build crashes InstrumentCodeTask ("1 >= 1"). + // instrumentCode still covers the shipped code. named("instrumentTestCode") { enabled = false }