1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.yaml.snakeyaml.issues.issue72;
17
18 import java.util.ArrayList;
19 import java.util.Collection;
20 import java.util.HashSet;
21
22 import junit.framework.TestCase;
23
24 import org.yaml.snakeyaml.Yaml;
25
26 public class CollectionTest extends TestCase {
27
28 public void testCollectionList() {
29 CollectionList bean = new CollectionList();
30 Yaml yaml = new Yaml();
31 String doc = yaml.dumpAsMap(bean);
32
33 Yaml beanLoader = new Yaml();
34 CollectionList parsed = beanLoader.loadAs(doc, CollectionList.class);
35 assertTrue(parsed.getNames().contains("aaa"));
36 assertTrue(parsed.getNames().contains("bbb"));
37 assertEquals(2, parsed.getNames().size());
38 }
39
40 public static class CollectionList {
41 private Collection<String> names;
42
43 public CollectionList() {
44 names = new ArrayList<String>();
45 names.add("aaa");
46 names.add("bbb");
47 }
48
49 public Collection<String> getNames() {
50 return names;
51 }
52
53 public void setNames(Collection<String> names) {
54 this.names = names;
55 }
56 }
57
58 public void testCollectionSet() {
59 CollectionSet bean = new CollectionSet();
60 Yaml yaml = new Yaml();
61 String doc = yaml.dumpAsMap(bean);
62
63 Yaml beanLoader = new Yaml();
64 CollectionSet parsed = beanLoader.loadAs(doc, CollectionSet.class);
65 assertTrue(parsed.getRoles().contains(11));
66 assertTrue(parsed.getRoles().contains(13));
67 assertEquals(2, parsed.getRoles().size());
68 }
69
70 public static class CollectionSet {
71 private Collection<Integer> roles;
72
73 public CollectionSet() {
74 roles = new HashSet<Integer>();
75 roles.add(11);
76 roles.add(13);
77 }
78
79 public Collection<Integer> getRoles() {
80 return roles;
81 }
82
83 public void setRoles(Collection<Integer> roles) {
84 this.roles = roles;
85 }
86 }
87 }