[Enhancement] Allow static imports in test sources so AssertJ is usable
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 69/100
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
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
Assertionsand clashes withorg.junit.jupiter.api.Assertions. - Importing it as static (
import static org.assertj.core.api.Assertions.assertThat;) doesn't work either, becauseAvoidStaticImportrejects it. - What's left are workarounds:
AssertionsForClassTypes.assertThat(...), which only covers class types (assertThat(list).hasSize(2)doesn't compile;List/Map/PathneedAssertionsForInterfaceTypes), or implementingWithAssertionsin 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:
- Iceberg has suppressed
AvoidStaticImportfor all test sources since it first added checkstyle (apache/iceberg#143, 2019):checkstyle-suppressions.xml#L29. In its tests, AssertJ is in fact required to be statically imported (apache/iceberg#10517). - Pinot (
suppressions.xml#L47) and Druid (checkstyle-suppressions.xml#L49) also suppress it forsrc/test. - JUnit's own repository uses static imports and AssertJ side by side in its tests (
UniqueIdTests.java#L13-L19), and so do Flink (MdcUtilsNullContextTest.java#L33-L35), Camel (DefaultExchangeTest.java#L36-L43) and Hadoop (TestLists.java#L28-L29).
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.*"/>onAvoidStaticImport. 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-coreif 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
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de apache/fesod
-
[Task] mvnw.cmd always shows as modified after cloningPosiblemente ocupada @yebuguntang la tomó hace 4 días. Abiertodiscussion welcome help wanted
Dificultad 1/5 Menos de una hora Aptitud para principiantes 91/100
Los mantenedores suelen responder en 1 día
-
discussion welcome security waiting for feedback
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
apache/fesod#1184 · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
[Bug] xlsx stream write leaves temp filePosiblemente ocupada @nkuprins la tomó hace 22 días. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
apache/fesod#1137 · 1 comentario · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
[Bug] A cell read into a ReadCellData field loses its row and column indexPosiblemente ocupada @CodeMan-cmd la tomó hace 36 días. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
apache/fesod#1131 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
[bug]Custom converters with supportExcelTypeKey() == null are silently ignored when writing CSVPosiblemente ocupada @Mikkey-f la tomó hace 52 días. Abierto
Dificultad 2/5 Medio día Aptitud para principiantes 84/100
Los mantenedores suelen responder en 1 día
Todos los issues de apache/fesod
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 67/100
quarkiverse/quarkus-google-cloud-services#1188 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 78/100
opendataloader-project/opendataloader-pdf#851 ·
Los mantenedores suelen responder en 1 día
-
Component: Frontend Component: Web Component Type: Maintenance
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
it-at-m/refarch-templates#1944 ·
Los mantenedores suelen responder en 2 días
-
3.0.0-M*: every channel stays reachable from its session's KEX listeners, so a long-lived session leaks all closed channelsPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día