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