You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by su...@apache.org on 2022/12/06 17:11:36 UTC

[shardingsphere] branch master updated: Add ShardingSphereExternalExceptionTest (#22708)

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

sunnianjun 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 10384585ad0 Add ShardingSphereExternalExceptionTest (#22708)
10384585ad0 is described below

commit 10384585ad081f4d9867224e8e5978143da8b861
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Wed Dec 7 01:11:27 2022 +0800

    Add ShardingSphereExternalExceptionTest (#22708)
    
    * Add test cases for GenericSQLException
    
    * Add ShardingSphereExternalExceptionTest
    
    * Refactor TypedPropertiesTest
    
    * Fix checkstyle
---
 .../infra/metadata/ShardingSphereMetaData.java     |  2 +-
 .../ShardingSphereExternalExceptionTest.java       | 44 ++++++++++++++++++++++
 .../ShardingSphereExternalExceptionFixture.java    | 35 +++++++++++++++++
 .../infra/util/props/TypedPropertiesTest.java      |  4 +-
 4 files changed, 83 insertions(+), 2 deletions(-)

diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaData.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaData.java
index d4e1628f6ec..32c52518512 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaData.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaData.java
@@ -56,7 +56,7 @@ public final class ShardingSphereMetaData {
         databases.forEach((key, value) -> this.databases.put(key.toLowerCase(), value));
         this.globalRuleMetaData = globalRuleMetaData;
         this.props = props;
-        this.internalProps = new InternalConfigurationProperties(props.getProps());
+        internalProps = new InternalConfigurationProperties(props.getProps());
     }
     
     /**
diff --git a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/exception/external/ShardingSphereExternalExceptionTest.java b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/exception/external/ShardingSphereExternalExceptionTest.java
new file mode 100644
index 00000000000..e975579664f
--- /dev/null
+++ b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/exception/external/ShardingSphereExternalExceptionTest.java
@@ -0,0 +1,44 @@
+/*
+ * 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.infra.util.exception.external;
+
+import org.apache.shardingsphere.infra.util.exception.external.fixture.ShardingSphereExternalExceptionFixture;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertNull;
+
+public final class ShardingSphereExternalExceptionTest {
+    
+    @Test
+    public void assertGetMessageWithNoArgsConstructor() {
+        assertNull(new ShardingSphereExternalExceptionFixture().getMessage());
+    }
+    
+    @Test
+    public void assertGetMessage() {
+        assertThat(new ShardingSphereExternalExceptionFixture("Test").getMessage(), is("Test"));
+    }
+    
+    @Test
+    public void assertGetCauseWithMessage() {
+        RuntimeException cause = new RuntimeException("Test");
+        assertThat(new ShardingSphereExternalExceptionFixture("Test", cause).getCause(), is(cause));
+    }
+}
diff --git a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/exception/external/fixture/ShardingSphereExternalExceptionFixture.java b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/exception/external/fixture/ShardingSphereExternalExceptionFixture.java
new file mode 100644
index 00000000000..964dcbeaf96
--- /dev/null
+++ b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/exception/external/fixture/ShardingSphereExternalExceptionFixture.java
@@ -0,0 +1,35 @@
+/*
+ * 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.infra.util.exception.external.fixture;
+
+import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.infra.util.exception.external.ShardingSphereExternalException;
+
+@NoArgsConstructor
+public final class ShardingSphereExternalExceptionFixture extends ShardingSphereExternalException {
+    
+    private static final long serialVersionUID = 4889629532793812626L;
+    
+    public ShardingSphereExternalExceptionFixture(final String reason) {
+        super(reason);
+    }
+    
+    public ShardingSphereExternalExceptionFixture(final String reason, final Exception cause) {
+        super(reason, cause);
+    }
+}
diff --git a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/props/TypedPropertiesTest.java b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/props/TypedPropertiesTest.java
index cb6258c18ba..a104168493a 100644
--- a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/props/TypedPropertiesTest.java
+++ b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/props/TypedPropertiesTest.java
@@ -33,7 +33,8 @@ public final class TypedPropertiesTest {
     
     @Test
     public void assertGetValue() {
-        TypedPropertiesFixture actual = new TypedPropertiesFixture(createProperties());
+        Properties props = createProperties();
+        TypedPropertiesFixture actual = new TypedPropertiesFixture(props);
         assertTrue(actual.getValue(TypedPropertyKeyFixture.BOOLEAN_VALUE));
         assertTrue(actual.getValue(TypedPropertyKeyFixture.BOOLEAN_OBJECT_VALUE));
         assertThat(actual.getValue(TypedPropertyKeyFixture.INT_VALUE), is(100));
@@ -41,6 +42,7 @@ public final class TypedPropertiesTest {
         assertThat(actual.getValue(TypedPropertyKeyFixture.LONG_VALUE), is(10000L));
         assertThat(actual.getValue(TypedPropertyKeyFixture.LONG_OBJECT_VALUE), is(10000L));
         assertThat(actual.getValue(TypedPropertyKeyFixture.STRING_VALUE), is("new_value"));
+        assertThat(actual.getProps(), is(props));
     }
     
     private Properties createProperties() {