1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.yaml.snakeyaml.issues.issue55;
18
19 import java.util.LinkedList;
20 import java.util.List;
21
22 import junit.framework.TestCase;
23
24 import org.yaml.snakeyaml.Util;
25 import org.yaml.snakeyaml.Yaml;
26 import org.yaml.snakeyaml.introspector.BeanAccess;
27
28 public class JavaBeanListTest extends TestCase {
29
30 public void testYaml() {
31 Yaml beanLoader = new Yaml();
32 beanLoader.setBeanAccess(BeanAccess.FIELD);
33 BlogBean rehydrated = (BlogBean) beanLoader.loadAs(
34 Util.getLocalResource("issues/issue55_2.txt"), BlogBean.class);
35 assertEquals(4, rehydrated.getPosts().size());
36 }
37
38 public void testFailureWithoutFieldAccess() {
39 Yaml beanLoader = new Yaml();
40 try {
41 beanLoader.loadAs(Util.getLocalResource("issues/issue55_2.txt"), BlogBean.class);
42 fail("Private field must not be available");
43 } catch (Exception e) {
44 assertTrue(e.getMessage().contains("Unable to find property 'posts'"));
45 }
46 }
47
48 public static class BlogBean {
49 private List<Integer> posts;
50
51 public BlogBean() {
52 posts = new LinkedList<Integer>();
53 }
54
55 public List<Integer> getPosts() {
56 return posts;
57 }
58 }
59 }