You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by GitBox <gi...@apache.org> on 2022/08/16 08:26:06 UTC
[GitHub] [kafka] clolov commented on a diff in pull request #12492: KAFKA-14133: Replace EasyMock with Mockito in streams tests
clolov commented on code in PR #12492:
URL: https://github.com/apache/kafka/pull/12492#discussion_r946480290
##########
streams/src/test/java/org/apache/kafka/streams/kstream/internals/KStreamFlatTransformValuesTest.java:
##########
@@ -68,69 +72,60 @@ public void shouldTransformInputRecordToMultipleOutputValues() {
"Hello",
"Blue",
"Planet");
+
processor.init(context);
- EasyMock.reset(valueTransformer);
- EasyMock.expect(valueTransformer.transform(inputKey, inputValue)).andReturn(outputValues);
- for (final String outputValue : outputValues) {
- context.forward(new Record<>(inputKey, outputValue, 0L));
- }
- replayAll();
+ when(valueTransformer.transform(inputKey, inputValue)).thenReturn(outputValues);
processor.process(new Record<>(inputKey, inputValue, 0L));
- verifyAll();
+ for (final String outputValue : outputValues) {
+ verify(context).forward(new Record<>(inputKey, outputValue, 0L));
+ }
}
@Test
public void shouldEmitNoRecordIfTransformReturnsEmptyList() {
processor.init(context);
- EasyMock.reset(valueTransformer);
- EasyMock.expect(valueTransformer.transform(inputKey, inputValue)).andReturn(Collections.emptyList());
- replayAll();
+ when(valueTransformer.transform(inputKey, inputValue)).thenReturn(Collections.emptyList());
processor.process(new Record<>(inputKey, inputValue, 0L));
- verifyAll();
+ verify(context, never()).forward(ArgumentMatchers.<Record<Integer, String>>any());
}
@Test
public void shouldEmitNoRecordIfTransformReturnsNull() {
processor.init(context);
- EasyMock.reset(valueTransformer);
- EasyMock.expect(valueTransformer.transform(inputKey, inputValue)).andReturn(null);
- replayAll();
+ when(valueTransformer.transform(inputKey, inputValue)).thenReturn(null);
processor.process(new Record<>(inputKey, inputValue, 0L));
- verifyAll();
+ verify(context, never()).forward(ArgumentMatchers.<Record<Integer, String>>any());
}
@Test
public void shouldCloseFlatTransformValuesProcessor() {
- valueTransformer.close();
- replayAll();
-
processor.close();
- verifyAll();
+ verify(valueTransformer).close();
}
@Test
public void shouldGetFlatTransformValuesProcessor() {
+ @SuppressWarnings("unchecked")
final ValueTransformerWithKeySupplier<Integer, Integer, Iterable<String>> valueTransformerSupplier =
mock(ValueTransformerWithKeySupplier.class);
final KStreamFlatTransformValues<Integer, Integer, String> processorSupplier =
new KStreamFlatTransformValues<>(valueTransformerSupplier);
- EasyMock.expect(valueTransformerSupplier.get()).andReturn(valueTransformer);
- replayAll();
+ when(valueTransformerSupplier.get()).thenReturn(valueTransformer);
final Processor<Integer, Integer, Integer, String> processor = processorSupplier.get();
- verifyAll();
+ verify(valueTransformerSupplier).get();
Review Comment:
I have a slight preference for not verifying something which has been explicitly stubbed. My rule of thumb is to only verify behaviour of mocks which would call important logic that we otherwise have no way of confirming purely by the return value(s). For example, verify that a `close()` method on some resource has been called. What is your opinion on this @cadonna? How would you like it approached?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org