Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

[Enhancement] Allow static imports in test sources so AssertJ is usable

Aperta Adatta ai principianti
#1,267 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@qiaolezi001 ci sta già lavorando.

Dal 29/10/2026.

  • #1282 di @qiaolezi001 — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
69/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
java
Ambito
testing

Direzione di ricerca

Inizia individuando la configurazione di Checkstyle che applica AvoidStaticImport ai sorgenti di test; l’issue non indica il relativo file. Mantieni la regola per i sorgenti principali e configúrala in modo da escludere i sorgenti di test. Poi esegui la convalida Checkstyle pertinente e conferma che gli import statici sono accettati nei test, ma continuano a essere rifiutati nei sorgenti principali.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement

Motivation

assertj-core has been a dependency since #901 (proposed in #717), but no test uses it (yet).
Since #1207, it effectively can't be used in its normal form:

  • Importing the class normally doesn't work in most of our tests, because AssertJ's entry class is also called Assertions and clashes with org.junit.jupiter.api.Assertions.
  • Importing it as static (import static org.assertj.core.api.Assertions.assertThat;) doesn't work either, because AvoidStaticImport rejects it.
  • What's left are workarounds: AssertionsForClassTypes.assertThat(...), which only covers class types (assertThat(list).hasSize(2) doesn't compile; List/Map/Path need AssertionsForInterfaceTypes), or implementing WithAssertions in every test class, which pulls AssertJ's whole entry-point API into the class.

A concrete case: checking that a temp directory is empty. With JUnit it's assertArrayEquals(new String[0], dir.list()) or assertEquals(0, dir.list().length). With AssertJ it's assertThat(dir).isEmptyDirectory(), which also lists the leftover files when it fails.

My research on static imports

#1207 cited seven Apache projects that ban static imports. For test sources they split three ways: Doris and commons-statistics ban them outright, Tomcat and ShardingSphere ban them with whitelists, and Druid, Pinot and Iceberg exempt tests entirely:

Solution

Keep AvoidStaticImport for main sources and skip it for test sources.

Alternatives

  • Exempt only AssertJ: <property name="excludes" value="org.assertj.core.api.Assertions.*"/> on AvoidStaticImport. This is the narrowest fix for AssertJ, but it leaves JUnit and Mockito static imports banned in tests, which would be an odd asymmetry.
  • Whitelist test libraries (as Tomcat and ShardingSphere do, with their own lists): JUnit Assertions/Assumptions, Mockito, AssertJ.
  • Drop assertj-core if we don't want AssertJ at all.

Anything else?

  • Allowing both styles can lead to mixed files. Iceberg hit this and later standardised with a mechanical cleanup (apache/iceberg#10517).
  • This doesn't propose migrating existing tests to AssertJ. It only makes AssertJ usable for new tests where it reads better.
Lingua principale
Java
Stelle
6.3k
Fork
545
Merge medio
2g 22h
PR unite (30g)
41

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di apache/fesod

Tutte le issue di apache/fesod

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.