terrymanu commented on code in PR #19350:
URL: https://github.com/apache/shardingsphere/pull/19350#discussion_r924200234
##########
shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/test/java/org/apache/shardingsphere/infra/federation/optimizer/context/OptimizerContextTest.java:
##########
@@ -38,14 +38,14 @@
import static org.mockito.Mockito.mock;
public final class OptimizerContextTest {
-
+
Review Comment:
Please do not change the original indent
##########
shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/metadata/persist/service/MetaDataVersionPersistServiceTest.java:
##########
@@ -0,0 +1,76 @@
+/*
+ * 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.shardingsphere.mode.metadata.persist.service;
+
+import
org.apache.shardingsphere.mode.metadata.persist.node.DatabaseMetaDataNode;
+import org.apache.shardingsphere.mode.persist.PersistRepository;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.contains;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+public class MetaDataVersionPersistServiceTest {
+
+ private PersistRepository repository;
+
+ private MetaDataVersionPersistService metaDataVersionPersistService;
+
+ @Before
+ public void setUp() {
+ repository = mock(PersistRepository.class);
+ when(repository.get(contains("foo_db"))).thenReturn("1");
+ metaDataVersionPersistService = new
MetaDataVersionPersistService(repository);
+ }
+
+ @Test
+ public void assertGetActiveVersion() {
+
assertTrue(metaDataVersionPersistService.getActiveVersion("foo_db").isPresent());
+ verify(repository,
times(1)).get(DatabaseMetaDataNode.getActiveVersionPath("foo_db"));
+ }
+
+ @Test
+ public void assertIsActiveVersion() {
+ assertTrue(metaDataVersionPersistService.isActiveVersion("foo_db",
"1"));
+ }
+
+ @Test
+ public void assertCreateNewVersion() {
+
assertTrue(!metaDataVersionPersistService.createNewVersion("new_db").isPresent());
+
assertEquals(metaDataVersionPersistService.createNewVersion("foo_db").get(),
"2");
Review Comment:
Please use assertThat to instead of assertEquals
##########
shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/metadata/persist/service/MetaDataVersionPersistServiceTest.java:
##########
@@ -0,0 +1,76 @@
+/*
+ * 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.shardingsphere.mode.metadata.persist.service;
+
+import
org.apache.shardingsphere.mode.metadata.persist.node.DatabaseMetaDataNode;
+import org.apache.shardingsphere.mode.persist.PersistRepository;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.contains;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+public class MetaDataVersionPersistServiceTest {
+
+ private PersistRepository repository;
+
+ private MetaDataVersionPersistService metaDataVersionPersistService;
+
+ @Before
+ public void setUp() {
+ repository = mock(PersistRepository.class);
+ when(repository.get(contains("foo_db"))).thenReturn("1");
+ metaDataVersionPersistService = new
MetaDataVersionPersistService(repository);
+ }
+
+ @Test
+ public void assertGetActiveVersion() {
+
assertTrue(metaDataVersionPersistService.getActiveVersion("foo_db").isPresent());
+ verify(repository,
times(1)).get(DatabaseMetaDataNode.getActiveVersionPath("foo_db"));
Review Comment:
times(1) is the default value, it is better to remove it
##########
shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/metadata/persist/service/MetaDataVersionPersistServiceTest.java:
##########
@@ -0,0 +1,76 @@
+/*
+ * 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.shardingsphere.mode.metadata.persist.service;
+
+import
org.apache.shardingsphere.mode.metadata.persist.node.DatabaseMetaDataNode;
+import org.apache.shardingsphere.mode.persist.PersistRepository;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.contains;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+public class MetaDataVersionPersistServiceTest {
+
+ private PersistRepository repository;
+
+ private MetaDataVersionPersistService metaDataVersionPersistService;
+
+ @Before
+ public void setUp() {
+ repository = mock(PersistRepository.class);
+ when(repository.get(contains("foo_db"))).thenReturn("1");
+ metaDataVersionPersistService = new
MetaDataVersionPersistService(repository);
+ }
+
+ @Test
+ public void assertGetActiveVersion() {
+
assertTrue(metaDataVersionPersistService.getActiveVersion("foo_db").isPresent());
+ verify(repository,
times(1)).get(DatabaseMetaDataNode.getActiveVersionPath("foo_db"));
+ }
+
+ @Test
+ public void assertIsActiveVersion() {
+ assertTrue(metaDataVersionPersistService.isActiveVersion("foo_db",
"1"));
+ }
+
+ @Test
+ public void assertCreateNewVersion() {
+
assertTrue(!metaDataVersionPersistService.createNewVersion("new_db").isPresent());
Review Comment:
Please use assertFalse to instead of double negative.
##########
shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/metadata/persist/service/MetaDataVersionPersistServiceTest.java:
##########
@@ -0,0 +1,76 @@
+/*
+ * 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.shardingsphere.mode.metadata.persist.service;
+
+import
org.apache.shardingsphere.mode.metadata.persist.node.DatabaseMetaDataNode;
+import org.apache.shardingsphere.mode.persist.PersistRepository;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.contains;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+public class MetaDataVersionPersistServiceTest {
Review Comment:
Please add final if the class does not design for extension
--
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]