leaf-soba commented on code in PR #18816: URL: https://github.com/apache/kafka/pull/18816#discussion_r2036378149
########## streams/src/test/java/org/apache/kafka/streams/state/internals/ChangeLoggingKeyValueBytesStoreTest.java: ########## @@ -89,8 +95,81 @@ public class ChangeLoggingKeyValueBytesStoreTest { public void before() { context = mockContext(); context.setTime(0); + store = new ChangeLoggingKeyValueBytesStore(innerMock); store.init(context, store); } + private void mockPosition() { + when(innerMock.getPosition()).thenReturn(Position.emptyPosition()); + } + private void mockGet(final Map<Bytes, byte[]> mockMap) { + when(innerMock.get(any(Bytes.class))).thenAnswer(invocation -> mockMap.get(invocation.getArgument(0))); + } + private void mockPut(final Map<Bytes, byte[]> mockMap) { + doAnswer(invocation -> { + mockMap.put(invocation.getArgument(0), invocation.getArgument(1)); + StoreQueryUtils.updatePosition(innerMock.getPosition(), context); + return null; + }).when(innerMock).put(any(Bytes.class), any(byte[].class)); Review Comment: Thanks for the question! We use doAnswer(...).when(...) here because put is a void method. Mockito requires this syntax for mocking void methods — when(...).thenAnswer(...) only works for methods that return a value. In contrast, get returns a value, so we can use when(...).thenAnswer(...) there, which I agree is a bit more readable. ``` @Override public synchronized void put(final Bytes key, final byte[] value) { putInternal(key, value); } ``` -- 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-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org