This is an automated email from the ASF dual-hosted git repository.
zhaojinchao 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 b7970be468f Add more test case for ShardingSphereYamlConstructorTest
(#19778)
b7970be468f is described below
commit b7970be468fc4a090469d475be7802b09a078f96
Author: Liang Zhang <[email protected]>
AuthorDate: Tue Aug 2 14:03:36 2022 +0800
Add more test case for ShardingSphereYamlConstructorTest (#19778)
---
.../yaml/constructor/ShardingSphereYamlConstructorTest.java | 11 +++++++++--
.../src/test/resources/yaml/accepted-class.yaml | 1 -
2 files changed, 9 insertions(+), 3 deletions(-)
diff --git
a/shardingsphere-infra/shardingsphere-infra-util/src/test/java/org/apache/shardingsphere/infra/util/yaml/constructor/ShardingSphereYamlConstructorTest.java
b/shardingsphere-infra/shardingsphere-infra-util/src/test/java/org/apache/shardingsphere/infra/util/yaml/constructor/ShardingSphereYamlConstructorTest.java
index ce865138d25..91a0cc2aca7 100644
---
a/shardingsphere-infra/shardingsphere-infra-util/src/test/java/org/apache/shardingsphere/infra/util/yaml/constructor/ShardingSphereYamlConstructorTest.java
+++
b/shardingsphere-infra/shardingsphere-infra-util/src/test/java/org/apache/shardingsphere/infra/util/yaml/constructor/ShardingSphereYamlConstructorTest.java
@@ -20,6 +20,7 @@ package org.apache.shardingsphere.infra.util.yaml.constructor;
import
org.apache.shardingsphere.infra.util.yaml.fixture.YamlConfigurationFixture;
import org.junit.Test;
import org.yaml.snakeyaml.Yaml;
+import org.yaml.snakeyaml.constructor.ConstructorException;
import java.io.IOException;
import java.io.InputStream;
@@ -34,8 +35,7 @@ public final class ShardingSphereYamlConstructorTest {
@Test
public void assertToObject() throws IOException {
try (InputStream inputStream =
ShardingSphereYamlConstructorTest.class.getClassLoader().getResourceAsStream("yaml/customized-obj.yaml"))
{
- YamlConfigurationFixture actual = new Yaml(new
ShardingSphereYamlConstructor(YamlConfigurationFixture.class)).loadAs(inputStream,
YamlConfigurationFixture.class);
- assertYamlObject(actual);
+ assertYamlObject(new Yaml(new
ShardingSphereYamlConstructor(YamlConfigurationFixture.class)).loadAs(inputStream,
YamlConfigurationFixture.class));
}
}
@@ -48,4 +48,11 @@ public final class ShardingSphereYamlConstructorTest {
assertThat(actual.getMap().get("key2"), is("value2"));
assertNotNull(actual.getCustomizedClass());
}
+
+ @Test(expected = ConstructorException.class)
+ public void assertToObjectWithNotAcceptClass() throws IOException {
+ try (InputStream inputStream =
ShardingSphereYamlConstructorTest.class.getClassLoader().getResourceAsStream("yaml/accepted-class.yaml"))
{
+ new Yaml(new
ShardingSphereYamlConstructor(Object.class)).loadAs(inputStream, Object.class);
+ }
+ }
}
diff --git
a/shardingsphere-infra/shardingsphere-infra-util/src/test/resources/yaml/accepted-class.yaml
b/shardingsphere-infra/shardingsphere-infra-util/src/test/resources/yaml/accepted-class.yaml
index 7dc1af6efdf..2b75292b07b 100644
---
a/shardingsphere-infra/shardingsphere-infra-util/src/test/resources/yaml/accepted-class.yaml
+++
b/shardingsphere-infra/shardingsphere-infra-util/src/test/resources/yaml/accepted-class.yaml
@@ -18,4 +18,3 @@
props:
normal: normal
url: !!java.net.URLClassLoader [[!!java.net.URL ["http://localhost"]]]
-