3535import com .squareup .moshi .Json ;
3636import java .util .List ;
3737import java .util .Map ;
38+ import kotlin .Pair ;
39+ import kotlin .collections .MapsKt ;
3840import org .http4k .core .Request ;
3941import org .jetbrains .annotations .NotNull ;
4042import org .junit .jupiter .api .Test ;
@@ -57,10 +59,9 @@ class PokemonTest {
5759 @ Test
5860 void pokemon () {
5961 final var newLimit = 1 ;
60- final var dynamicEnvironment1 =
61- Map .of ("offset" , String .valueOf (OFFSET ));
62- final var dynamicEnvironment2 =
63- Map .of ("limit" , String .valueOf (LIMIT ));
62+ final var dynamicEnvironment1 = Map .of ("offset" , String .valueOf (OFFSET ));
63+ final var dynamicEnvironment2 =
64+ MapsKt .mapOf (new Pair <>("limit" , String .valueOf (LIMIT )), new Pair <>("null" , null ));
6465 @ SuppressWarnings ("Convert2Lambda" )
6566 final var preLogHook =
6667 Mockito .spy (
@@ -127,38 +128,40 @@ public void accept(@NotNull StepReport stepReport, @NotNull Rundown rundown) {
127128 assertThat (id .id ()).isEqualTo (rundown .mutableEnv .get ("id" ));
128129 }
129130 });
131+ final var config =
132+ Kick .configure ()
133+ .templatePath (PM_COLLECTION_PATH )
134+ .environmentPath (PM_ENVIRONMENT_PATH )
135+ .responseConfig (unmarshallResponse (afterStepName ("all-pokemon" ), AllPokemon .class ))
136+ .hooks (
137+ pre (beforeStepName ("all-pokemon" ), preStepHookBeforeStepName ),
138+ post (afterStepName ("all-pokemon" ), postStepHookAfterStepName ),
139+ post (afterStepContainingURIPathOfAny ("pokemon-color" ), postStepHookAfterURIPath ),
140+ pre (beforeStepContainingHeader ("preLog" ), preLogHook ),
141+ post (afterStepContainingHeader ("postLog" ), postLogHook ))
142+ .dynamicEnvironment (dynamicEnvironment1 )
143+ .off ();
130144 final var pokeRundown =
131145 ReVoman .revUp (
132- Kick .configure ()
133- .templatePath (PM_COLLECTION_PATH )
134- .environmentPath (PM_ENVIRONMENT_PATH )
135- .responseConfig (unmarshallResponse (afterStepName ("all-pokemon" ), AllPokemon .class ))
136- .hooks (
137- pre (beforeStepName ("all-pokemon" ), preStepHookBeforeStepName ),
138- post (afterStepName ("all-pokemon" ), postStepHookAfterStepName ),
139- post (
140- afterStepContainingURIPathOfAny ("pokemon-color" ), postStepHookAfterURIPath ),
141- pre (beforeStepContainingHeader ("preLog" ), preLogHook ),
142- post (afterStepContainingHeader ("postLog" ), postLogHook ))
143- .dynamicEnvironment (plus (dynamicEnvironment1 , dynamicEnvironment2 ))
144- .off ());
146+ config .overrideDynamicEnvironment (plus (dynamicEnvironment1 , dynamicEnvironment2 )));
145147
146148 final var postHookFailure = pokeRundown .firstUnIgnoredUnsuccessfulStepReport ().failure ;
147149 assertThat (postHookFailure ).containsLeftInstanceOf (PostStepHookFailure .class );
148150 assertThat (postHookFailure .getLeft ().getFailure ()).isEqualTo (RUNTIME_EXCEPTION );
149151 assertThat (pokeRundown .stepReports ).hasSize (5 );
150152 assertThat (pokeRundown .mutableEnv )
151153 .containsExactlyEntriesIn (
152- Map .of (
153- "offset" , String .valueOf (OFFSET ),
154- "limit" , String .valueOf (newLimit ),
155- "baseUrl" , "https://pokeapi.co/api/v2" ,
156- "id" , "1" ,
157- "pokemonName" , "bulbasaur" ,
158- "color" , "black" ,
159- "gender" , "female" ,
160- "ability" , "stench" ,
161- "nature" , "hardy" ));
154+ MapsKt .mapOf (
155+ new Pair <>("offset" , String .valueOf (OFFSET )),
156+ new Pair <>("limit" , String .valueOf (newLimit )),
157+ new Pair <>("baseUrl" , "https://pokeapi.co/api/v2" ),
158+ new Pair <>("id" , "1" ),
159+ new Pair <>("pokemonName" , "bulbasaur" ),
160+ new Pair <>("color" , "black" ),
161+ new Pair <>("gender" , "female" ),
162+ new Pair <>("ability" , "stench" ),
163+ new Pair <>("nature" , "hardy" ),
164+ new Pair <>("null" , null )));
162165 Mockito .verify (preStepHookBeforeStepName , times (1 )).accept (any (), any (), any ());
163166 Mockito .verify (postStepHookAfterStepName , times (1 )).accept (any (), any ());
164167 Mockito .verify (postStepHookAfterURIPath , times (1 )).accept (any (), any ());
0 commit comments