// Path: nakadi-producer/src/main/java/org/zalando/nakadiproducer/transmission/MockNakadiPublishingClient.java
// public class MockNakadiPublishingClient implements NakadiPublishingClient {
//     private final ObjectMapper objectMapper;
//     private final MultiValueMap<String, String> sentEvents = new LinkedMultiValueMap<>();
// 
//     public MockNakadiPublishingClient() {
//         this(createDefaultObjectMapper());
//     }
// 
//     public MockNakadiPublishingClient(ObjectMapper objectMapper) {
//         this.objectMapper = objectMapper;
//     }
// 
//     @Override
//     public synchronized void publish(String eventType, List<?> nakadiEvents) throws Exception {
//         nakadiEvents.stream().map(this::transformToJson).forEach(e -> sentEvents.add(eventType, e));
//     }
// 
//     public synchronized List<String> getSentEvents(String eventType) {
//         ArrayList<String> events = new ArrayList<>();
//         List<String> sentEvents = this.sentEvents.get(eventType);
//         if (sentEvents != null) {
//             events.addAll(sentEvents);
//         }
//         return events;
//     }
// 
//     public synchronized void clearSentEvents() {
//         sentEvents.clear();
//     }
// 
//     private String transformToJson(Object value) {
//         try {
//             return objectMapper.writeValueAsString(value);
//         } catch (JsonProcessingException e) {
//             throw new RuntimeException(e);
//         }
//     }
// 
//     private static ObjectMapper createDefaultObjectMapper() {
//         final ObjectMapper objectMapper = new ObjectMapper();
//         objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
//         objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
//         objectMapper.registerModules(new Jdk8Module(), new ParameterNamesModule(), new JavaTimeModule());
//         objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
//         return objectMapper;
//     }
// }
// 
// Path: nakadi-producer/src/main/java/org/zalando/nakadiproducer/transmission/impl/EventTransmitter.java
// public class EventTransmitter {
//     private final EventTransmissionService eventTransmissionService;
// 
//     public EventTransmitter(EventTransmissionService eventTransmissionService) {
//         this.eventTransmissionService = eventTransmissionService;
//     }
// 
//     public void sendEvents() {
//         eventTransmissionService.sendEvents(eventTransmissionService.lockSomeEvents());
//     }
// }


import org.junit.*;
import org.junit.contrib.java.lang.system.EnvironmentVariables;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.autoconfigure.web.server.LocalManagementPort;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.zalando.nakadiproducer.transmission.MockNakadiPublishingClient;
import org.zalando.nakadiproducer.transmission.impl.EventTransmitter;
import java.io.File;
import java.util.List;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.hasSize;
import static org.junit.Assert.assertThat;
package org.zalando.nakadiproducer.tests;




@RunWith(SpringRunner.class)
@SpringBootTest(
        // This line looks like that by intention: We want to test that the MockNakadiPublishingClient will be picked up
        // by our starter *even if* it has been defined *after* the application itself. This has been a problem until
        // this commit.
        classes = { Application.class, MockNakadiConfig.class },
        properties = { "nakadi-producer.transmission-polling-delay=30"},
        webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT
)
public class ApplicationIT {
    @LocalManagementPort
    private int localManagementPort;

    @ClassRule
    public static final EnvironmentVariables environmentVariables
            = new EnvironmentVariables();

    @BeforeClass
    public static void fakeCredentialsDir() {
        environmentVariables.set("CREDENTIALS_DIR", new File("src/main/test/tokens").getAbsolutePath());
    }

    @Autowired
// Path: nakadi-producer/src/main/java/org/zalando/nakadiproducer/transmission/MockNakadiPublishingClient.java
// public class MockNakadiPublishingClient implements NakadiPublishingClient {
//     private final ObjectMapper objectMapper;
//     private final MultiValueMap<String, String> sentEvents = new LinkedMultiValueMap<>();
// 
//     public MockNakadiPublishingClient() {
//         this(createDefaultObjectMapper());
//     }
// 
//     public MockNakadiPublishingClient(ObjectMapper objectMapper) {
//         this.objectMapper = objectMapper;
//     }
// 
//     @Override
//     public synchronized void publish(String eventType, List<?> nakadiEvents) throws Exception {
//         nakadiEvents.stream().map(this::transformToJson).forEach(e -> sentEvents.add(eventType, e));
//     }
// 
//     public synchronized List<String> getSentEvents(String eventType) {
//         ArrayList<String> events = new ArrayList<>();
//         List<String> sentEvents = this.sentEvents.get(eventType);
//         if (sentEvents != null) {
//             events.addAll(sentEvents);
//         }
//         return events;
//     }
// 
//     public synchronized void clearSentEvents() {
//         sentEvents.clear();
//     }
// 
//     private String transformToJson(Object value) {
//         try {
//             return objectMapper.writeValueAsString(value);
//         } catch (JsonProcessingException e) {
//             throw new RuntimeException(e);
//         }
//     }
// 
//     private static ObjectMapper createDefaultObjectMapper() {
//         final ObjectMapper objectMapper = new ObjectMapper();
//         objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
//         objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
//         objectMapper.registerModules(new Jdk8Module(), new ParameterNamesModule(), new JavaTimeModule());
//         objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
//         return objectMapper;
//     }
// }
// 
// Path: nakadi-producer/src/main/java/org/zalando/nakadiproducer/transmission/impl/EventTransmitter.java
// public class EventTransmitter {
//     private final EventTransmissionService eventTransmissionService;
// 
//     public EventTransmitter(EventTransmissionService eventTransmissionService) {
//         this.eventTransmissionService = eventTransmissionService;
//     }
// 
//     public void sendEvents() {
//         eventTransmissionService.sendEvents(eventTransmissionService.lockSomeEvents());
//     }
// }


// Path: nakadi-producer-starter-spring-boot-2-test/src/test/java/org/zalando/nakadiproducer/tests/ApplicationIT.java
import org.junit.*;
import org.junit.contrib.java.lang.system.EnvironmentVariables;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.autoconfigure.web.server.LocalManagementPort;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.zalando.nakadiproducer.transmission.MockNakadiPublishingClient;
import org.zalando.nakadiproducer.transmission.impl.EventTransmitter;
import java.io.File;
import java.util.List;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.hasSize;
import static org.junit.Assert.assertThat;

package org.zalando.nakadiproducer.tests;




@RunWith(SpringRunner.class)
@SpringBootTest(
        // This line looks like that by intention: We want to test that the MockNakadiPublishingClient will be picked up
        // by our starter *even if* it has been defined *after* the application itself. This has been a problem until
        // this commit.
        classes = { Application.class, MockNakadiConfig.class },
        properties = { "nakadi-producer.transmission-polling-delay=30"},
        webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT
)
public class ApplicationIT {
    @LocalManagementPort
    private int localManagementPort;

    @ClassRule
    public static final EnvironmentVariables environmentVariables
            = new EnvironmentVariables();

    @BeforeClass
    public static void fakeCredentialsDir() {
        environmentVariables.set("CREDENTIALS_DIR", new File("src/main/test/tokens").getAbsolutePath());
    }

    @Autowired
    private MockNakadiPublishingClient mockClient;