import org.springframework.util.MultiValueMap;
import java.time.Duration;
+import java.util.stream.Stream;
import static de.juplo.kafka.wordcount.counter.CounterApplicationIT.TOPIC_IN;
import static de.juplo.kafka.wordcount.counter.CounterApplicationIT.TOPIC_OUT;
@Test
void testSendMessage()
{
- TestData.injectInputMessages((key, value) -> kafkaTemplate.send(TOPIC_IN, key, value));
+ Stream
+ .of(TestData.INPUT_MESSAGES)
+ .forEach(word -> kafkaTemplate.send(TOPIC_IN, word.getUser(), word));
await("Expected messages")
.atMost(Duration.ofSeconds(10))
import java.util.Map;
import java.util.Properties;
+import java.util.stream.Stream;
import static de.juplo.kafka.wordcount.counter.TestData.convertToMap;
import static de.juplo.kafka.wordcount.counter.TestData.parseHeader;
@Test
public void test()
{
- TestData.injectInputMessages((key, value) -> in.pipeInput(key, value));
+ Stream
+ .of(TestData.INPUT_MESSAGES)
+ .forEach(word -> in.pipeInput(word.getUser(), word));
MultiValueMap<Word, WordCounter> receivedMessages = new LinkedMultiValueMap<>();
out
import java.util.Map;
import java.util.Properties;
-import java.util.function.BiConsumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;
class TestData
{
- static void injectInputMessages(BiConsumer<String, Word> consumer)
- {
- Stream
- .of(INPUT_MESSAGES)
- .forEach(word -> consumer.accept(word.getUser(), word));
- }
-
static final Word[] INPUT_MESSAGES = new Word[]
{
Word.of("peter","Hallo"),
static void assertExpectedMessages(MultiValueMap<Word, WordCounter> receivedMessages)
{
- expectedMessages.forEach(
+ expectedMessages().forEach(
(word, counter) ->
assertThat(receivedMessages.get(word))
.containsExactlyElementsOf(counter));
WordCounter.of("klaus","s",3)),
};
- static MultiValueMap<Word, WordCounter> expectedMessages;
- static
+ static MultiValueMap<Word, WordCounter> expectedMessages()
{
- expectedMessages = new LinkedMultiValueMap<>();
+ MultiValueMap<Word, WordCounter> expectedMessages = new LinkedMultiValueMap<>();
Stream
.of(EXPECTED_MESSAGES)
.forEach(keyValue -> expectedMessages.add(keyValue.key, keyValue.value));
+ return expectedMessages;
}
static Map<String, Object> convertToMap(Properties properties)