1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.yaml.snakeyaml.issues.issue8;
18
19 import java.io.IOException;
20
21 import junit.framework.TestCase;
22
23 import org.yaml.snakeyaml.DumperOptions;
24 import org.yaml.snakeyaml.Yaml;
25
26
27
28
29 public class PrattleRepresenterTest extends TestCase {
30 public void test() throws IOException {
31 Yaml yaml = new Yaml();
32 Person person = new Person("Alan", "Gutierrez", 9);
33 String etalon = "!!org.yaml.snakeyaml.issues.issue8.Person {firstName: Alan, hatSize: 9, lastName: Gutierrez}\n";
34 assertEquals(etalon, yaml.dump(person));
35 assertEquals(etalon, yaml.dump(person));
36 }
37
38 public void test2beans() throws IOException {
39 DumperOptions options = new DumperOptions();
40 options.setAllowReadOnlyProperties(true);
41 Yaml yaml = new Yaml(options);
42 Person person = new Person("Alan", "Gutierrez", 9);
43 String etalon = "!!org.yaml.snakeyaml.issues.issue8.Person {firstName: Alan, hatSize: 9, lastName: Gutierrez}\n";
44 assertEquals(etalon, yaml.dump(person));
45 Horse horse = new Horse("Tom", person);
46 String etalon2 = "!!org.yaml.snakeyaml.issues.issue8.PrattleRepresenterTest$Horse\nname: Tom\nowner: {firstName: Alan, hatSize: 9, lastName: Gutierrez}\n";
47 assertEquals(etalon2, yaml.dump(horse));
48 }
49
50 public static class Horse {
51 private String name;
52 private Person owner;
53
54 public Horse(String name, Person owner) {
55 super();
56 this.name = name;
57 this.owner = owner;
58 }
59
60 public String getName() {
61 return name;
62 }
63
64 public Person getOwner() {
65 return owner;
66 }
67
68 }
69 }