frankvicky commented on code in PR #22196: URL: https://github.com/apache/kafka/pull/22196#discussion_r3579277630
########## streams/src/test/java/org/apache/kafka/streams/state/internals/TimestampedToHeadersStoreAdapterTest.java: ########## @@ -0,0 +1,387 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.kafka.streams.state.internals; + +import org.apache.kafka.common.utils.Bytes; +import org.apache.kafka.streams.KeyValue; +import org.apache.kafka.streams.query.KeyQuery; +import org.apache.kafka.streams.query.PositionBound; +import org.apache.kafka.streams.query.Query; +import org.apache.kafka.streams.query.QueryConfig; +import org.apache.kafka.streams.query.QueryResult; +import org.apache.kafka.streams.query.RangeQuery; +import org.apache.kafka.streams.state.KeyValueIterator; +import org.apache.kafka.streams.state.KeyValueStore; +import org.apache.kafka.streams.state.TimestampedBytesStore; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; + +import java.util.Arrays; + +import static org.apache.kafka.streams.state.HeadersBytesStore.convertToHeaderFormat; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.mockito.Mockito.withSettings; + +@ExtendWith(MockitoExtension.class) +@MockitoSettings(strictness = Strictness.STRICT_STUBS) +public class TimestampedToHeadersStoreAdapterTest { + + @Mock + private KeyValueIterator<Bytes, byte[]> mockIterator; + + @SuppressWarnings("unchecked") + private KeyValueStore<Bytes, byte[]> mockStore; + + private TimestampedToHeadersStoreAdapter adapter; + + @SuppressWarnings("unchecked") + @BeforeEach + public void setUp() { + mockStore = mock(KeyValueStore.class, withSettings().extraInterfaces(TimestampedBytesStore.class)); + when(mockStore.persistent()).thenReturn(true); + adapter = new TimestampedToHeadersStoreAdapter(mockStore); Review Comment: Two tests don't use `@BeforeEach` state `shouldThrowIfStoreIsNotPersistent` and `shouldThrowIfStoreIsNotTimestamped` build their own store and adapter locally, and never touch the adapter / mockStore fields from `setUp` . `setUp` still runs and sets `when(mockStore.persistent()).thenReturn(true)`. Under `STRICT_STUBS`, that stub would trigger `UnnecessaryStubbingException` — it only passes today because `setUp` also constructs the adapter, which happens to call `persistent()` and consumes the stub. If the constructor ever stops calling `persistent()` early, these two unrelated tests will start failing, which is confusing. ########## streams/src/test/java/org/apache/kafka/streams/DslStoreFormatTest.java: ########## @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.kafka.streams; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +public class DslStoreFormatTest { + + @Test + public void shouldResolvePlain() { + assertEquals(DslStoreFormat.PLAIN, DslStoreFormat.of("PLAIN")); + } + + @Test + public void shouldResolveTimestamped() { + assertEquals(DslStoreFormat.TIMESTAMPED, DslStoreFormat.of("TIMESTAMPED")); + } + + @Test + public void shouldResolveHeaders() { + assertEquals(DslStoreFormat.HEADERS, DslStoreFormat.of("HEADERS")); + } + + @Test + public void shouldResolveHeadersCaseInsensitively() { + assertEquals(DslStoreFormat.HEADERS, DslStoreFormat.of("headers")); + assertEquals(DslStoreFormat.HEADERS, DslStoreFormat.of("Headers")); + assertEquals(DslStoreFormat.HEADERS, DslStoreFormat.of("hEaDeRs")); + } + + @Test + public void shouldExposeHeadersNameField() { + assertEquals("HEADERS", DslStoreFormat.HEADERS.name); + } + + @Test + public void shouldThrowOnInvalidInput() { + assertThrows(IllegalArgumentException.class, () -> DslStoreFormat.of("not-a-format")); + } + + @Test + public void shouldThrowOnNullInput() { + assertThrows(NullPointerException.class, () -> DslStoreFormat.of(null)); Review Comment: This test expects NullPointerException from `DslStoreFormat.of(null)`, but the NPE actually comes from `name.toUpperCase()` inside the implementation — it's a side effect, not a documented contract. Consider deleting this test. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
