[Enhancement] Allow static imports in test sources so AssertJ is usable
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 69/100
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
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.
- Lingua principale
- Java
- Stelle
- 6.3k
- Fork
- 545
- Merge medio
- 2g 22h
- PR unite (30g)
- 41
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di apache/fesod
-
[Task] mvnw.cmd always shows as modified after cloningForse già presa @yebuguntang l’ha presa 5 giorni fa. Apertadiscussion welcome help wanted
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 91/100
I maintainer di solito rispondono entro 1 giorno
-
discussion welcome security waiting for feedback
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
apache/fesod#1184 · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug] xlsx stream write leaves temp fileForse già presa @nkuprins l’ha presa 23 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
apache/fesod#1137 · 1 commento · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug] A cell read into a ReadCellData field loses its row and column indexForse già presa @CodeMan-cmd l’ha presa 38 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
apache/fesod#1131 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
[bug]Custom converters with supportExcelTypeKey() == null are silently ignored when writing CSVForse già presa @Mikkey-f l’ha presa 53 giorni fa. Aperta
Difficoltà 2/5 Mezza giornata Idoneità per principianti 84/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di apache/fesod
Issue simili
-
status: waiting-for-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
spring-projects/spring-framework#37614 ·
I maintainer di solito rispondono entro 1 giorno
-
azure-spring azure-spring-aad Client
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
Azure/azure-sdk-for-java#51046 · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
helm-knative-apply.sh fails with Helm 4Forse già presa Una pull request collegata a questa issue è aperta o già unita. Apertaarea: triage theme: undefined
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
jhipster/generator-jhipster#35895 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
oracle/graalvm-reachability-metadata#11659 ·
I maintainer di solito rispondono entro 1 giorno