Skip to content

test: replace deprecated JUnit assertThat calls - #19819

Open
FrankChen021 wants to merge 1 commit into
apache:masterfrom
FrankChen021:agent/replace-deprecated-assert-that
Open

test: replace deprecated JUnit assertThat calls#19819
FrankChen021 wants to merge 1 commit into
apache:masterfrom
FrankChen021:agent/replace-deprecated-assert-that

Conversation

@FrankChen021

Copy link
Copy Markdown
Member

Created by the GPT-5.6-Sol model.

Summary

  • Replace all 79 deprecated org.junit.Assert.assertThat invocations with org.hamcrest.MatcherAssert.assertThat.
  • Add both deprecated JUnit overloads to Druid's Maven Forbidden APIs signatures.
  • Keep assertion behavior unchanged while preventing new uses from compiling.

Why

CodeQL currently reports 79 deprecated-call notes for JUnit's Assert.assertThat. Hamcrest owns these assertions directly, and JUnit 4.13 deprecates its forwarding overloads.

Impact

The source changes are test-only. The Maven Forbidden APIs check now fails if either JUnit assertThat overload is introduced in main or test bytecode.

Root cause

These tests retained JUnit's legacy Hamcrest forwarding API after the assertion implementation moved to Hamcrest.

Checks

  • mvn -ntp -B test-compile -Dweb.console.skip=true -DskipTests -T1C
    • all 78 reactor modules passed
    • Checkstyle, PMD, Enforcer, compilation, and Forbidden APIs checks passed
  • git diff --check

@FrankChen021 FrankChen021 changed the title Replace deprecated JUnit assertThat calls test: replace deprecated JUnit assertThat calls Jul 30, 2026
for (StringTuple value : values) {
if (start != null) {
Assert.assertThat(value.compareTo(start), Matchers.greaterThanOrEqualTo(0));
MatcherAssert.assertThat(value.compareTo(start), Matchers.greaterThanOrEqualTo(0));
@FrankChen021
FrankChen021 marked this pull request as ready for review July 30, 2026 18:00
Copilot AI review requested due to automatic review settings July 30, 2026 18:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates Apache Druid’s test code to stop using JUnit 4’s deprecated Hamcrest forwarding API (org.junit.Assert.assertThat) by switching assertions to Hamcrest’s owned API (org.hamcrest.MatcherAssert.assertThat). It also hardens the build by forbidding the deprecated JUnit overloads via the Forbidden APIs signature file.

Changes:

  • Replace deprecated Assert.assertThat usages with MatcherAssert.assertThat (or static Hamcrest assertThat) in tests.
  • Add Forbidden APIs signatures to prevent new bytecode references to the deprecated JUnit assertThat overloads.

Reviewed changes

Copilot reviewed 33 out of 33 changed files in this pull request and generated no comments.

Show a summary per file
File Description
server/src/test/java/org/apache/druid/server/log/RequestLoggerProviderTest.java Switch assertion to MatcherAssert.assertThat.
server/src/test/java/org/apache/druid/server/log/LoggingRequestLoggerProviderTest.java Switch assertion to MatcherAssert.assertThat.
server/src/test/java/org/apache/druid/server/emitter/EmitterModuleTest.java Switch assertions to MatcherAssert.assertThat.
server/src/test/java/org/apache/druid/segment/LookupSegmentWranglerTest.java Switch assertion to MatcherAssert.assertThat.
server/src/test/java/org/apache/druid/segment/join/LookupJoinableFactoryTest.java Switch assertion to MatcherAssert.assertThat.
server/src/test/java/org/apache/druid/segment/InlineSegmentWranglerTest.java Switch assertion to MatcherAssert.assertThat.
server/src/test/java/org/apache/druid/curator/CuratorModuleTest.java Switch assertion to MatcherAssert.assertThat.
processing/src/test/java/org/apache/druid/utils/CloseableUtilsTest.java Replace multiple deprecated assertThat calls with Hamcrest MatcherAssert.
processing/src/test/java/org/apache/druid/segment/join/HashJoinSegmentTest.java Switch assertion to MatcherAssert.assertThat.
indexing-service/src/test/java/org/apache/druid/indexing/overlord/SingleTaskBackgroundRunnerTest.java Switch assertion to MatcherAssert.assertThat.
indexing-service/src/test/java/org/apache/druid/indexing/input/DruidInputSourceTest.java Switch assertions to MatcherAssert.assertThat.
indexing-service/src/test/java/org/apache/druid/indexing/common/task/batch/parallel/RangePartitionMultiPhaseParallelIndexingTest.java Switch range assertions to MatcherAssert.assertThat.
indexing-service/src/test/java/org/apache/druid/indexing/common/task/batch/parallel/PartialHashSegmentGenerateTaskTest.java Switch assertion to MatcherAssert.assertThat.
indexing-service/src/test/java/org/apache/druid/indexing/common/task/batch/parallel/ParallelIndexSupervisorTaskTest.java Switch assertion to MatcherAssert.assertThat.
indexing-service/src/test/java/org/apache/druid/indexing/common/task/batch/parallel/iterator/RangePartitionIndexTaskInputRowIteratorBuilderTest.java Switch assertion to MatcherAssert.assertThat.
indexing-service/src/test/java/org/apache/druid/indexing/common/task/batch/parallel/distribution/StringSketchTest.java Switch assertions to MatcherAssert.assertThat.
extensions-core/histogram/src/test/java/org/apache/druid/query/aggregation/histogram/QuantilesTest.java Switch assertion to MatcherAssert.assertThat.
extensions-core/datasketches/src/test/java/org/apache/druid/query/aggregation/datasketches/util/ToObjectVectorColumnProcessorFactoryTest.java Switch assertion to MatcherAssert.assertThat.
extensions-contrib/moving-average-query/src/test/java/org/apache/druid/query/movingaverage/MovingAverageQueryTest.java Switch assertions to MatcherAssert.assertThat.
extensions-contrib/moving-average-query/src/test/java/org/apache/druid/query/movingaverage/MovingAverageIterableTest.java Switch assertion to MatcherAssert.assertThat.
extensions-contrib/moving-average-query/src/test/java/org/apache/druid/query/movingaverage/averagers/LongSumAveragerFactoryTest.java Switch assertion to MatcherAssert.assertThat.
extensions-contrib/moving-average-query/src/test/java/org/apache/druid/query/movingaverage/averagers/LongMinAveragerFactoryTest.java Switch assertion to MatcherAssert.assertThat.
extensions-contrib/moving-average-query/src/test/java/org/apache/druid/query/movingaverage/averagers/LongMeanNoNullAveragerFactoryTest.java Switch assertion to MatcherAssert.assertThat.
extensions-contrib/moving-average-query/src/test/java/org/apache/druid/query/movingaverage/averagers/LongMeanAveragerFactoryTest.java Switch assertion to MatcherAssert.assertThat.
extensions-contrib/moving-average-query/src/test/java/org/apache/druid/query/movingaverage/averagers/LongMaxAveragerFactoryTest.java Switch assertion to MatcherAssert.assertThat.
extensions-contrib/moving-average-query/src/test/java/org/apache/druid/query/movingaverage/averagers/DoubleSumAveragerFactoryTest.java Switch assertion to MatcherAssert.assertThat.
extensions-contrib/moving-average-query/src/test/java/org/apache/druid/query/movingaverage/averagers/DoubleMinAveragerFactoryTest.java Switch assertion to MatcherAssert.assertThat.
extensions-contrib/moving-average-query/src/test/java/org/apache/druid/query/movingaverage/averagers/DoubleMeanNoNullAveragerFactoryTest.java Switch assertion to MatcherAssert.assertThat.
extensions-contrib/moving-average-query/src/test/java/org/apache/druid/query/movingaverage/averagers/DoubleMeanAveragerFactoryTest.java Switch assertion to MatcherAssert.assertThat.
extensions-contrib/moving-average-query/src/test/java/org/apache/druid/query/movingaverage/averagers/DoubleMaxAveragerFactoryTest.java Switch assertion to MatcherAssert.assertThat.
extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/CompressedBigDecimalAggregatorTimeseriesTestBase.java Replace static assertThat import to Hamcrest-owned assertThat.
extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/CompressedBigDecimalAggregatorGroupByTestBase.java Switch assertions to MatcherAssert.assertThat.
codestyle/druid-forbidden-apis.txt Add forbidden signatures for deprecated JUnit Assert.assertThat overloads.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@FrankChen021 FrankChen021 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have reviewed the code for correctness, edge cases, concurrency, and integration risks; no issues found.

Reviewed 33 of 33 changed files.


This is an automated review by Codex GPT-5.6-Sol

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants