1616
1717import org .eclipse .edc .plugins .edcbuild .Versions ;
1818import org .gradle .api .Project ;
19+ import org .jetbrains .annotations .NotNull ;
20+
21+ import java .util .List ;
22+ import java .util .Map ;
23+ import java .util .stream .Stream ;
1924
2025import static java .lang .String .format ;
21- import static org .gradle .api .plugins .JavaPlugin .TEST_IMPLEMENTATION_CONFIGURATION_NAME ;
22- import static org .gradle .api .plugins .JavaPlugin .TEST_RUNTIME_ONLY_CONFIGURATION_NAME ;
26+ import static java .util .Map .entry ;
2327
2428/**
2529 * Applies default test dependencies to all "java-library" projects: JUnit, Mockito and AssertJ in their respective
@@ -30,16 +34,35 @@ class DefaultTestDependencyConvention implements EdcConvention {
3034 @ Override
3135 public void apply (Project target ) {
3236 target .getPluginManager ().withPlugin ("java-library" , plugin -> {
33- var d = target .getDependencies ();
34-
35- d .add (TEST_IMPLEMENTATION_CONFIGURATION_NAME , d .platform (format ("org.junit:junit-bom:%s" , Versions .JUPITER )));
36- d .add (TEST_RUNTIME_ONLY_CONFIGURATION_NAME , "org.junit.platform:junit-platform-launcher" );
37- d .add (TEST_RUNTIME_ONLY_CONFIGURATION_NAME , "org.junit.jupiter:junit-jupiter-engine" );
38- d .add (TEST_IMPLEMENTATION_CONFIGURATION_NAME , "org.junit.jupiter:junit-jupiter-api" );
39- d .add (TEST_IMPLEMENTATION_CONFIGURATION_NAME , "org.junit.jupiter:junit-jupiter-params" );
40- d .add (TEST_IMPLEMENTATION_CONFIGURATION_NAME , format ("org.mockito:mockito-core:%s" , Versions .MOCKITO ));
41- d .add (TEST_IMPLEMENTATION_CONFIGURATION_NAME , format ("org.assertj:assertj-core:%s" , Versions .ASSERTJ ));
37+ var dependencyHandler = target .getDependencies ();
38+
39+ var dependencies = Map .of (
40+ "Implementation" , List .of (
41+ dependencyHandler .platform (format ("org.junit:junit-bom:%s" , Versions .JUPITER )),
42+ "org.junit.jupiter:junit-jupiter-api" ,
43+ "org.junit.jupiter:junit-jupiter-params" ,
44+ "org.mockito:mockito-core:%s" .formatted (Versions .MOCKITO ),
45+ "org.assertj:assertj-core:%s" .formatted (Versions .ASSERTJ )
46+ ),
47+ "RuntimeOnly" , List .of (
48+ "org.junit.platform:junit-platform-launcher" ,
49+ "org.junit.jupiter:junit-jupiter-engine"
50+ )
51+ );
52+
53+ prepareDependenciesFor (dependencies , "test" )
54+ .forEach (dependency -> dependencyHandler .add (dependency .getKey (), dependency .getValue ()));
55+
56+ if (target .getPluginManager ().hasPlugin ("java-test-fixtures" )) {
57+ prepareDependenciesFor (dependencies , "testFixtures" )
58+ .forEach (dependency -> dependencyHandler .add (dependency .getKey (), dependency .getValue ()));
59+ }
4260 });
4361 }
4462
63+ private @ NotNull Stream <? extends Map .Entry <String , ?>> prepareDependenciesFor (Map <@ NotNull String , @ NotNull List <?>> dependencies , String configurationContext ) {
64+ return dependencies .entrySet ().stream ()
65+ .flatMap (entry -> entry .getValue ().stream ().map (it -> entry (configurationContext + entry .getKey (), it )));
66+ }
67+
4568}
0 commit comments