1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.yaml.snakeyaml.immutable.primitives;
18
19 import junit.framework.TestCase;
20
21 import org.yaml.snakeyaml.Yaml;
22 import org.yaml.snakeyaml.error.YAMLException;
23
24 public class ImmutablePrimitivesTest extends TestCase {
25
26 public void testPrimitives() {
27 Yaml yaml = new Yaml(new ImmutablePrimitivesRepresenter());
28 BunchOfPrimitives bunch = new BunchOfPrimitives(10, 40.0, true);
29 String dump = yaml.dump(bunch);
30 assertEquals("!!" + bunch.getClass().getCanonicalName() + " [10, 40.0, true]\n", dump);
31 Object loaded = yaml.load(dump);
32 assertEquals(loaded.toString(), bunch, loaded);
33 }
34
35 public void testPrimitivesLong() {
36 Yaml yaml = new Yaml();
37 String dump = "!!org.yaml.snakeyaml.immutable.primitives.BunchOfPrimitives [10000000000, 40.0, true]";
38 BunchOfPrimitives bunch = (BunchOfPrimitives) yaml.load(dump);
39 assertEquals("Must be truncated.", new Long(10000000000L).intValue(),
40 bunch.getPrimitiveInt());
41 }
42
43 public void testPrimitivesException() {
44 Yaml yaml = new Yaml();
45 String dump = "!!org.yaml.snakeyaml.immutable.primitives.BunchOfPrimitives [10, 40, true]";
46 try {
47 yaml.load(dump);
48 fail();
49 } catch (YAMLException e) {
50 assertEquals(
51 "null; Can't construct a java object for tag:yaml.org,2002:org.yaml.snakeyaml.immutable.primitives.BunchOfPrimitives; exception=No suitable constructor with 3 arguments found for class org.yaml.snakeyaml.immutable.primitives.BunchOfPrimitives",
52 e.getMessage());
53 }
54 }
55 }