clolov commented on code in PR #23830:
URL: https://github.com/apache/kafka/pull/23830#discussion_r4315675728


##########
server-common/src/test/java/org/apache/kafka/server/mirror/MirrorPartitionStateTest.java:
##########
@@ -0,0 +1,108 @@
+/*
+ * 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.server.mirror;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.EnumSource;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import java.util.EnumSet;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import org.junit.jupiter.params.provider.Arguments;

Review Comment:
   I think this ordering of imports breaks spotlessJavaCheck. Try gradlew 
spotlessApply and it ought to fix things 😊



##########
server-common/src/test/java/org/apache/kafka/server/mirror/MirrorPartitionStateTest.java:
##########
@@ -0,0 +1,108 @@
+/*
+ * 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.server.mirror;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.EnumSource;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import java.util.EnumSet;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import org.junit.jupiter.params.provider.Arguments;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+class MirrorPartitionStateTest {
+    @ParameterizedTest
+    @MethodSource("expectedStateValues")
+    void testValue(MirrorPartitionState state, byte expectedValue) {
+        assertEquals(expectedValue, state.value());
+    }
+
+    @ParameterizedTest
+    @MethodSource("expectedStateValues")
+    void testFromValue(MirrorPartitionState expectedState, byte value) {
+        assertEquals(expectedState, MirrorPartitionState.fromValue(value));
+    }
+
+    @Test
+    void testFromValueInvalidPositive() {

Review Comment:
   I think a similar `@ValueSource(bytes = {9, -2, 100})` would collapse these 
tests into one!



##########
server-common/src/test/java/org/apache/kafka/server/mirror/MirrorPartitionStateTest.java:
##########
@@ -0,0 +1,108 @@
+/*
+ * 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.server.mirror;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.EnumSource;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import java.util.EnumSet;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import org.junit.jupiter.params.provider.Arguments;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+class MirrorPartitionStateTest {
+    @ParameterizedTest
+    @MethodSource("expectedStateValues")
+    void testValue(MirrorPartitionState state, byte expectedValue) {
+        assertEquals(expectedValue, state.value());
+    }
+
+    @ParameterizedTest
+    @MethodSource("expectedStateValues")
+    void testFromValue(MirrorPartitionState expectedState, byte value) {
+        assertEquals(expectedState, MirrorPartitionState.fromValue(value));
+    }
+
+    @Test
+    void testFromValueInvalidPositive() {
+        assertThrows(
+            IllegalArgumentException.class,
+            () -> MirrorPartitionState.fromValue((byte) 9),
+            "Should throw IllegalArgumentException for invalid positive value"
+        );
+    }
+
+    @Test
+    void testFromValueInvalidNegative() {
+        assertThrows(
+            IllegalArgumentException.class,
+            () -> MirrorPartitionState.fromValue((byte) -2),
+            "Should throw IllegalArgumentException for invalid negative value"
+        );
+    }
+
+    @Test
+    void testFromValueInvalidRange() {
+        assertThrows(
+            IllegalArgumentException.class,
+            () -> MirrorPartitionState.fromValue((byte) 100),
+            "Should throw IllegalArgumentException for out-of-range value"
+        );
+    }
+
+    @Test
+    void testAllStatesAreCoveredByTable() {
+        Set<MirrorPartitionState> tested = expectedStateValues()
+                .map(args -> (MirrorPartitionState) args.get()[0])

Review Comment:
   I think both this test and the one below changed indentation from 4 to 8 and 
I have a slight suspicion one of the formatting tools will complain 😞 



##########
server-common/src/test/java/org/apache/kafka/server/mirror/MirrorPartitionStateTest.java:
##########
@@ -0,0 +1,108 @@
+/*
+ * 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.server.mirror;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.EnumSource;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import java.util.EnumSet;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import org.junit.jupiter.params.provider.Arguments;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+class MirrorPartitionStateTest {
+    @ParameterizedTest
+    @MethodSource("expectedStateValues")
+    void testValue(MirrorPartitionState state, byte expectedValue) {
+        assertEquals(expectedValue, state.value());
+    }
+
+    @ParameterizedTest
+    @MethodSource("expectedStateValues")
+    void testFromValue(MirrorPartitionState expectedState, byte value) {
+        assertEquals(expectedState, MirrorPartitionState.fromValue(value));
+    }
+
+    @Test
+    void testFromValueInvalidPositive() {
+        assertThrows(
+            IllegalArgumentException.class,
+            () -> MirrorPartitionState.fromValue((byte) 9),
+            "Should throw IllegalArgumentException for invalid positive value"
+        );
+    }
+
+    @Test
+    void testFromValueInvalidNegative() {
+        assertThrows(
+            IllegalArgumentException.class,
+            () -> MirrorPartitionState.fromValue((byte) -2),
+            "Should throw IllegalArgumentException for invalid negative value"
+        );
+    }
+
+    @Test
+    void testFromValueInvalidRange() {
+        assertThrows(
+            IllegalArgumentException.class,
+            () -> MirrorPartitionState.fromValue((byte) 100),
+            "Should throw IllegalArgumentException for out-of-range value"
+        );
+    }
+
+    @Test
+    void testAllStatesAreCoveredByTable() {
+        Set<MirrorPartitionState> tested = expectedStateValues()
+                .map(args -> (MirrorPartitionState) args.get()[0])
+                .collect(Collectors.toCollection(() ->
+                        EnumSet.noneOf(MirrorPartitionState.class)));
+
+        assertEquals(EnumSet.allOf(MirrorPartitionState.class), tested,
+                "Every MirrorPartitionState must have an entry in 
stateValues() with its expected byte value");

Review Comment:
   stateValues -> expectedStateValues



-- 
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]

Reply via email to