slukyano commented on code in PR #5315: URL: https://github.com/apache/ignite-3/pull/5315#discussion_r1984182169
########## modules/runner/src/test/java/org/apache/ignite/InitParametersBuilderTest.java: ########## @@ -0,0 +1,231 @@ +/* + * 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.ignite; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.util.List; +import org.apache.ignite.internal.testframework.BaseIgniteAbstractTest; +import org.junit.jupiter.api.Test; + +class InitParametersBuilderTest extends BaseIgniteAbstractTest { + + @Test + void build_WithAllParametersSet_ReturnsExpectedInitParameters() { + // Arrange + InitParametersBuilder builder = new InitParametersBuilder(); + String clusterName = "TestCluster"; + List<String> metaStorageNodes = List.of("Node1", "Node2"); + List<String> cmgNodes = List.of("Node3", "Node4"); + String clusterConfiguration = "{config: value}"; + + // Act + InitParameters result = builder + .metaStorageNodeNames(metaStorageNodes) + .cmgNodeNames(cmgNodes) + .clusterName(clusterName) + .clusterConfiguration(clusterConfiguration) + .build(); + + // Assert + assertNotNull(result); + assertEquals(metaStorageNodes, result.metaStorageNodeNames()); + assertEquals(cmgNodes, result.cmgNodeNames()); + assertEquals(clusterName, result.clusterName()); + assertEquals(clusterConfiguration, result.clusterConfiguration()); + } + + @Test + void build_WithoutClusterName_ThrowsIllegalStateException() { + // Arrange + InitParametersBuilder builder = new InitParametersBuilder(); + + // Act & Assert + IllegalStateException exception = assertThrows(IllegalStateException.class, builder::build); + assertEquals("Cluster name is not set.", exception.getMessage()); + } + + @Test + void build_WithNullClusterName_ThrowsIllegalArgumentException() { + // Arrange + InitParametersBuilder builder = new InitParametersBuilder(); + + // Act & Assert + //noinspection DataFlowIssue + IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> builder.clusterName(null)); + assertEquals("Cluster name cannot be null or empty.", exception.getMessage()); + } + + @Test + void build_WithBlankClusterName_ThrowsIllegalArgumentException() { + // Arrange + InitParametersBuilder builder = new InitParametersBuilder(); + + // Act & Assert + IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> builder.clusterName(" ")); + assertEquals("Cluster name cannot be null or empty.", exception.getMessage()); + } + + @Test + void build_WithEmptyMetaStorageNodeNames_SetsEmptyList() { + // Arrange + InitParametersBuilder builder = new InitParametersBuilder(); + + // Act + InitParameters result = builder + .metaStorageNodeNames() + .clusterName("TestCluster") + .build(); + + // Assert + assertNotNull(result); + assertTrue(result.metaStorageNodeNames().isEmpty()); + } + + @Test + void build_WithEmptyCmgNodeNames_SetsEmptyList() { + // Arrange + InitParametersBuilder builder = new InitParametersBuilder(); + + // Act + InitParameters result = builder + .cmgNodeNames() + .clusterName("TestCluster") + .build(); + + // Assert + assertNotNull(result); + assertTrue(result.cmgNodeNames().isEmpty()); + } + + @Test + void build_WithNullMetaStorageNodeCollection_SetsEmptyList() { + // Arrange + InitParametersBuilder builder = new InitParametersBuilder(); + + // Act + InitParameters result = builder + .metaStorageNodeNames((List<String>) null) + .clusterName("TestCluster") + .build(); + + // Assert + assertNotNull(result); + assertTrue(result.metaStorageNodeNames().isEmpty()); + } + + @Test + void build_WithNullCmgNodeCollection_SetsEmptyList() { + // Arrange + InitParametersBuilder builder = new InitParametersBuilder(); + + // Act + InitParameters result = builder + .cmgNodeNames((List<String>) null) Review Comment: Not sure about that. Imagine a library that uses text-based config (say, YAML), reads them in Java, and calls init from Java. Such library can easily initialize cmgNodeNames to null from the config (because it isn't provided in the config) and then pass it as null to the API. I wouldn't require the user to do extra work to avoid passing null as a parameter that's nullable. -- 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: notifications-unsubscr...@ignite.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org