1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.yaml.snakeyaml.constructor;
17
18 import junit.framework.TestCase;
19
20 import org.yaml.snakeyaml.Yaml;
21
22 public class SafeConstructorTest extends TestCase {
23
24 public void testConstructFloat() {
25 Yaml yaml = new Yaml();
26 assertEquals(3.1416, yaml.load("+3.1416"));
27 assertEquals(Double.POSITIVE_INFINITY, yaml.load("+.inf"));
28 assertEquals(Double.POSITIVE_INFINITY, yaml.load(".inf"));
29 assertEquals(Double.NEGATIVE_INFINITY, yaml.load("-.inf"));
30 }
31
32 public void testSafeConstruct() {
33 Yaml yaml = new Yaml(new SafeConstructor());
34 assertEquals(3.1416, yaml.load("+3.1416"));
35 }
36
37 public void testSafeConstructJavaBean() {
38 Yaml yaml = new Yaml(new SafeConstructor());
39 String data = "--- !!org.yaml.snakeyaml.constructor.Person\nfirstName: Andrey\nage: 99";
40 try {
41 yaml.load(data);
42 fail("JavaBeans cannot be created by SafeConstructor.");
43 } catch (ConstructorException e) {
44 assertTrue(e
45 .getMessage()
46 .contains(
47 "could not determine a constructor for the tag tag:yaml.org,2002:org.yaml.snakeyaml.constructor.Person"));
48 }
49 }
50 }