/**
* Copyright (c) 2008, SnakeYAML
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package examples.collections;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import junit.framework.TestCase;
import org.yaml.snakeyaml.Util;
import org.yaml.snakeyaml.Yaml;
/**
* Test ListBean->List developers
* Developer class cannot be properly recognised
*/
public class TypeSafeListNoGerericsTest extends TestCase {
public void testDumpList() {
ListBean bean = new ListBean();
List list = new ArrayList();
list.add("aaa");
list.add("bbb");
bean.setChildren(list);
List developers = new ArrayList();
developers.add(new Developer("Fred", "creator"));
developers.add(new Developer("John", "committer"));
bean.setDevelopers(developers);
Yaml yaml = new Yaml();
String output = yaml.dumpAsMap(bean);
// System.out.println(output);
String etalon = Util.getLocalResource("examples/list-bean-4.yaml");
assertEquals(etalon, output);
}
@SuppressWarnings("unchecked")
public void testLoadList() {
String output = Util.getLocalResource("examples/list-bean-1.yaml");
// System.out.println(output);
Yaml beanLoader = new Yaml();
ListBean parsed = beanLoader.loadAs(output, ListBean.class);
assertNotNull(parsed);
List list2 = parsed.getChildren();
assertEquals(2, list2.size());
assertEquals("aaa", list2.get(0));
assertEquals("bbb", list2.get(1));
List