// Path: src/main/java/org/dataloader/DataLoaderFactory.java
// public static <K, V> DataLoader<K, V> newDataLoader(BatchLoader<K, V> batchLoadFunction) {
//     return newDataLoader(batchLoadFunction, null);
// }
// 
// Path: src/main/java/org/dataloader/DataLoaderFactory.java
// public static <K, V> DataLoader<K, V> newMappedDataLoader(MappedBatchLoader<K, V> batchLoadFunction) {
//     return newMappedDataLoader(batchLoadFunction, null);
// }


import org.junit.Test;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
import static org.dataloader.DataLoaderFactory.newDataLoader;
import static org.dataloader.DataLoaderFactory.newMappedDataLoader;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
package org.dataloader;




/**
 * Tests related to context.  DataLoaderTest is getting to big and needs refactoring
 */
public class DataLoaderBatchLoaderEnvironmentTest {

    private BatchLoaderWithContext<String, String> contextBatchLoader() {
        return (keys, environment) -> {
            AtomicInteger index = new AtomicInteger(0);
            List<String> list = keys.stream().map(k -> {
                int i = index.getAndIncrement();
                Object context = environment.getContext();
                Object keyContextM = environment.getKeyContexts().get(k);
                Object keyContextL = environment.getKeyContextsList().get(i);
                return k + "-" + context + "-m:" + keyContextM + "-l:" + keyContextL;
            }).collect(Collectors.toList());
            return CompletableFuture.completedFuture(list);
        };
    }


    @Test
    public void context_is_passed_to_batch_loader_function() {
        BatchLoaderWithContext<String, String> batchLoader = (keys, environment) -> {
            List<String> list = keys.stream().map(k -> k + "-" + environment.getContext()).collect(Collectors.toList());
            return CompletableFuture.completedFuture(list);
        };
        DataLoaderOptions options = DataLoaderOptions.newOptions()
                .setBatchLoaderContextProvider(() -> "ctx");
// Path: src/main/java/org/dataloader/DataLoaderFactory.java
// public static <K, V> DataLoader<K, V> newDataLoader(BatchLoader<K, V> batchLoadFunction) {
//     return newDataLoader(batchLoadFunction, null);
// }
// 
// Path: src/main/java/org/dataloader/DataLoaderFactory.java
// public static <K, V> DataLoader<K, V> newMappedDataLoader(MappedBatchLoader<K, V> batchLoadFunction) {
//     return newMappedDataLoader(batchLoadFunction, null);
// }


// Path: src/test/java/org/dataloader/DataLoaderBatchLoaderEnvironmentTest.java
import org.junit.Test;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
import static org.dataloader.DataLoaderFactory.newDataLoader;
import static org.dataloader.DataLoaderFactory.newMappedDataLoader;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;

package org.dataloader;




/**
 * Tests related to context.  DataLoaderTest is getting to big and needs refactoring
 */
public class DataLoaderBatchLoaderEnvironmentTest {

    private BatchLoaderWithContext<String, String> contextBatchLoader() {
        return (keys, environment) -> {
            AtomicInteger index = new AtomicInteger(0);
            List<String> list = keys.stream().map(k -> {
                int i = index.getAndIncrement();
                Object context = environment.getContext();
                Object keyContextM = environment.getKeyContexts().get(k);
                Object keyContextL = environment.getKeyContextsList().get(i);
                return k + "-" + context + "-m:" + keyContextM + "-l:" + keyContextL;
            }).collect(Collectors.toList());
            return CompletableFuture.completedFuture(list);
        };
    }


    @Test
    public void context_is_passed_to_batch_loader_function() {
        BatchLoaderWithContext<String, String> batchLoader = (keys, environment) -> {
            List<String> list = keys.stream().map(k -> k + "-" + environment.getContext()).collect(Collectors.toList());
            return CompletableFuture.completedFuture(list);
        };
        DataLoaderOptions options = DataLoaderOptions.newOptions()
                .setBatchLoaderContextProvider(() -> "ctx");
        DataLoader<String, String> loader = newDataLoader(batchLoader, options);