You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2022/07/24 02:31:58 UTC

[shardingsphere] branch master updated: Add more unit test for ClassBasedShardingAlgorithmFactory (#19491)

This is an automated email from the ASF dual-hosted git repository.

zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 7826f9a08cc Add more unit test for ClassBasedShardingAlgorithmFactory (#19491)
7826f9a08cc is described below

commit 7826f9a08cc20f7067b43d3ea12f6a04314302f5
Author: lushaorong <ww...@163.com>
AuthorDate: Sun Jul 24 10:31:52 2022 +0800

    Add more unit test for ClassBasedShardingAlgorithmFactory (#19491)
    
    * Add more unit test for ClassBasedShardingAlgorithmFactory
    
    * remove unless line
    
    * refactor
---
 .../ClassBasedShardingAlgorithmFactoryTest.java    | 45 ++++++++++++++++++++++
 1 file changed, 45 insertions(+)

diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/classbased/ClassBasedShardingAlgorithmFactoryTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/classbased/ClassBasedShardingAlgorithmFactoryTest.java
new file mode 100644
index 00000000000..570cad289a2
--- /dev/null
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/classbased/ClassBasedShardingAlgorithmFactoryTest.java
@@ -0,0 +1,45 @@
+/*
+ * 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.sharding.algorithm.sharding.classbased;
+
+import org.apache.shardingsphere.infra.exception.ShardingSphereException;
+import org.apache.shardingsphere.sharding.api.sharding.standard.StandardShardingAlgorithm;
+import org.apache.shardingsphere.sharding.fixture.ClassBasedHintShardingAlgorithmFixture;
+import org.apache.shardingsphere.sharding.fixture.ClassBasedStandardShardingAlgorithmFixture;
+import org.junit.Test;
+
+import java.util.Properties;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.junit.Assert.assertThat;
+
+public final class ClassBasedShardingAlgorithmFactoryTest {
+    
+    @Test(expected = ShardingSphereException.class)
+    public void assertNewInstanceWithUnAssignableFrom() {
+        ClassBasedShardingAlgorithmFactory.newInstance(ClassBasedHintShardingAlgorithmFixture.class.getName(), StandardShardingAlgorithm.class, new Properties());
+    }
+    
+    @SuppressWarnings("rawtypes")
+    @Test
+    public void assertNewInstance() {
+        StandardShardingAlgorithm algorithm =
+                ClassBasedShardingAlgorithmFactory.newInstance(ClassBasedStandardShardingAlgorithmFixture.class.getName(), StandardShardingAlgorithm.class, new Properties());
+        assertThat(algorithm, instanceOf(ClassBasedStandardShardingAlgorithmFixture.class));
+    }
+}