/**
 * Copyright (c) 2008-2011, http://www.snakeyaml.org
 *
 * 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 org.yaml.snakeyaml.issues.issue112;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.io.IOException;

import org.junit.Test;
import org.yaml.snakeyaml.JavaBeanDumper;
import org.yaml.snakeyaml.Util;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor;

public class ParameterisedTypeLoadingTestCase {

    @Test
    public void testParameterisedTypeLoading() throws IOException {
        Yaml yamlParser = new Yaml(new Constructor(MyCompositeObject.class));

        MyCompositeObject obj = (MyCompositeObject) yamlParser.load(this.getClass()
                .getClassLoader().getResource("issues/issue112-1.yaml").openStream());

        assertNotNull(obj);

        for (Object thing : obj.getThings()) {
            assertEquals(MyClass.class, thing.getClass());
            @SuppressWarnings("unchecked")
            MyClass<Object> mclass = (MyClass<Object>) thing;
            assertNotNull("The 'name' property must be set.", mclass.getName());
            assertTrue("'name' must not be empty.", mclass.getName().toString().length() > 0);
        }

        // dump the object
        JavaBeanDumper dumper = new JavaBeanDumper();
        String output = dumper.dump(obj);
        assertEquals(Util.getLocalResource("issues/issue112-2.yaml"), output);
    }
}

@@ -753,78 +753,63 @@
 ll;%0A
-import static org.junit.Assert.assertTrue;%0A%0Aimport java.io.IOException
+%0Aimport java.io.IOException;%0Aimport java.io.InputStream
 ;%0A%0Ai
@@ -872,16 +872,58 @@
 Dumper;%0A
+import org.yaml.snakeyaml.JavaBeanLoader;%0A
 import o
@@ -1308,61 +1308,200 @@
 oad(
-this.getClass()%0A                .getClassLoader().get
+getInput());%0A%0A        check(obj);%0A%0A        // dump the object%0A        JavaBeanDumper dumper = new JavaBeanDumper();%0A        String output = dumper.dump(obj);%0A        assertEquals(Util.getLocal
 Reso
@@ -1526,271 +1526,653 @@
 112-
-1
+2
 .yaml%22)
-.openStream());%0A%0A        assertNotNull
+, output);%0A    %7D%0A%0A    @Test%0A    public void testJavaBeanLoader() throws IOException %7B%0A        JavaBeanLoader%3CMyCompositeObject%3E yamlParser = new JavaBeanLoader%3CMyCompositeObject%3E(%0A                MyCompositeObject.class);%0A%0A        MyCompositeObject obj = yamlParser.load(getInput());%0A%0A        check
 (obj);%0A
-%0A
     
+%7D%0A%0A
     
-for (Object thing : obj.getThings()) %7B%0A            assertEquals(MyClass.class, thing.getClass());%0A            @SuppressWarnings(%22unchecked%22)%0A            MyClass%3CObject%3E mclass = (MyClass%3CObject%3E) thing
+private void check(MyCompositeObject obj) %7B%0A        Object%5B%5D values = %7B 1, %22two%22, 3, %22four%22, %22!!!%22 %7D;%0A        assertNotNull(obj);%0A        assertEquals(5, obj.getThings().size());%0A        int i = 0;%0A        for (MyClass%3C? extends Object%3E thing : obj.getThings()) %7B%0A            assertEquals(MyClass.class, thing.getClass())
 ;%0A  
@@ -2227,30 +2227,29 @@
 t be set.%22, 
-mclass
+thing
 .getName());
@@ -2271,82 +2271,43 @@
 sert
-True(%22'name' must not be empty.%22, mclass.getName().toString().length() %3E 0
+Equals(values%5Bi++%5D, thing.getName()
 );%0A 
@@ -2319,166 +2319,122 @@
   %7D%0A
-%0A
     
-    // dump the object%0A        JavaBeanDumper dumper = new JavaBeanDumper();%0A        String output = dumper.dump(obj);%0A        assertEquals(Util.getLocal
+%7D%0A%0A    private InputStream getInput() throws IOException %7B%0A        return this.getClass().getClassLoader().get
 Reso
@@ -2455,32 +2455,36 @@
 ssue112-
-2
+1
 .yaml%22)
-, output
+.openStream(
 );%0A    %7D

Fix issue 112: improve tests