2
2
3
3
import org .dataloader .impl .DefaultCacheMap ;
4
4
import org .dataloader .impl .NoOpValueCache ;
5
+ import org .dataloader .instrumentation .DataLoaderInstrumentation ;
5
6
import org .dataloader .scheduler .BatchLoaderScheduler ;
6
7
import org .dataloader .stats .NoOpStatisticsCollector ;
7
8
import org .dataloader .stats .StatisticsCollector ;
9
+ import org .hamcrest .CoreMatchers ;
8
10
import org .junit .jupiter .api .Test ;
9
11
10
12
import java .util .List ;
@@ -184,4 +186,39 @@ void canBuildViaBuilderOk() {
184
186
assertThat (builtOptions .getStatisticsCollector (),
185
187
equalTo (testStatisticsCollectorSupplier .get ()));
186
188
}
189
+
190
+ @ Test
191
+ void canCopyExistingOptionValuesOnTransform () {
192
+
193
+ DataLoaderInstrumentation instrumentation1 = new DataLoaderInstrumentation () {
194
+ };
195
+ BatchLoaderContextProvider contextProvider1 = () -> null ;
196
+
197
+ DataLoaderOptions startingOptions = DataLoaderOptions .newOptionsBuilder ().setBatchingEnabled (false )
198
+ .setCachingEnabled (false )
199
+ .setInstrumentation (instrumentation1 )
200
+ .setBatchLoaderContextProvider (contextProvider1 )
201
+ .build ();
202
+
203
+ assertThat (startingOptions .batchingEnabled (), equalTo (false ));
204
+ assertThat (startingOptions .cachingEnabled (), equalTo (false ));
205
+ assertThat (startingOptions .getInstrumentation (), equalTo (instrumentation1 ));
206
+ assertThat (startingOptions .getBatchLoaderContextProvider (), equalTo (contextProvider1 ));
207
+
208
+ DataLoaderOptions newOptions = startingOptions .transform (builder -> builder .setBatchingEnabled (true ));
209
+
210
+
211
+ // immutable
212
+ assertThat (newOptions , CoreMatchers .not (startingOptions ));
213
+ assertThat (startingOptions .batchingEnabled (), equalTo (false ));
214
+ assertThat (startingOptions .cachingEnabled (), equalTo (false ));
215
+ assertThat (startingOptions .getInstrumentation (), equalTo (instrumentation1 ));
216
+ assertThat (startingOptions .getBatchLoaderContextProvider (), equalTo (contextProvider1 ));
217
+
218
+ // copied values
219
+ assertThat (newOptions .batchingEnabled (), equalTo (true ));
220
+ assertThat (newOptions .cachingEnabled (), equalTo (false ));
221
+ assertThat (newOptions .getInstrumentation (), equalTo (instrumentation1 ));
222
+ assertThat (newOptions .getBatchLoaderContextProvider (), equalTo (contextProvider1 ));
223
+ }
187
224
}
0 commit comments