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