Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

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

Abierto Apto para principiantes
#1,267 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@qiaolezi001 ya está trabajando en esto.

Desde el 29/10/2026.

  • #1282 de @qiaolezi001 — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
69/100
Tipo de issue
Nueva funcionalidad
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
java
Área
testing

Línea de trabajo

Empieza por localizar la configuración de Checkstyle que aplica AvoidStaticImport a las fuentes de prueba; el issue no indica su archivo. Mantén la regla para las fuentes principales y configúrala para que omita las fuentes de prueba. Después, ejecuta la validación de Checkstyle pertinente y confirma que las importaciones estáticas se aceptan en las pruebas, pero se siguen rechazando en las fuentes principales.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.
Lenguaje dominante
Java
Estrellas
6.3k
Forks
545
Merge medio
2 d 22 h
PR fusionados (30 d)
41

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de apache/fesod

Todos los issues de apache/fesod

Issues similares

Más issues de Java

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.