1 /**
2 * Copyright (c) 2008-2012, http://www.snakeyaml.org
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.yaml.snakeyaml.issues.issue73;
17
18 import java.util.ArrayList;
19
20 import junit.framework.TestCase;
21
22 import org.yaml.snakeyaml.Yaml;
23
24 /**
25 * Test bean when the implementation is defined: ArrayList instead of just the
26 * interface List
27 */
28 public class ArrayListTest extends TestCase {
29 public void testListImplementation() {
30 Bean1 bean = new Bean1();
31 bean.setId("ID123");
32 ArrayList<String> list = new ArrayList<String>(3);
33 list.add("zzz");
34 list.add("xxx");
35 list.add("ccc");
36 bean.setList(list);
37 Yaml yaml = new Yaml();
38 String doc = yaml.dump(bean);
39 // System.out.println(doc);
40 Bean1 loaded = (Bean1) yaml.load(doc);
41 assertEquals(3, loaded.getList().size());
42 assertEquals(ArrayList.class, loaded.getList().getClass());
43 }
44
45 public static class Bean1 {
46 private ArrayList<String> list;
47 private String id;
48
49 public ArrayList<String> getList() {
50 return list;
51 }
52
53 public void setList(ArrayList<String> list) {
54 this.list = list;
55 }
56
57 public String getId() {
58 return id;
59 }
60
61 public void setId(String id) {
62 this.id = id;
63 }
64 }
65 }