package org.yaml.snakeyaml.constructor;

import java.util.HashMap;
import java.util.Map;

import junit.framework.TestCase;

import org.yaml.snakeyaml.composer.Composer;
import org.yaml.snakeyaml.composer.ComposerImpl;
import org.yaml.snakeyaml.parser.Parser;
import org.yaml.snakeyaml.parser.ParserImpl;
import org.yaml.snakeyaml.reader.Reader;
import org.yaml.snakeyaml.resolver.Resolver;
import org.yaml.snakeyaml.resolver.ResolverImpl;
import org.yaml.snakeyaml.scanner.Scanner;
import org.yaml.snakeyaml.scanner.ScannerImpl;

public class ConstructorTest extends TestCase {

    public void testGetSingleData() {
        String data = "american:\n  - Boston Red Sox";
        Object map = construct(data);
        assertNotNull(map);
        assertTrue(map.getClass().toString(), map instanceof Map);
        assertTrue(map.getClass().toString(), map instanceof HashMap);
        // TODO assertTrue(map.getClass().toString(), map instanceof
        // LinkedHashMap);
    }

    public void testGetBean() {
        String data = "--- !java/object:org.yaml.snakeyaml.constructor.Person\nfirstName: Andrey\nage: 99";
        Object obj = construct(data);
        assertNotNull(obj);
        assertTrue(obj.getClass().toString(), obj instanceof Person);
        Person person = (Person) obj;
        assertEquals("Andrey", person.getFirstName());
        assertNull(person.getLastName());
        assertEquals(99, person.getAge());
    }

    private Object construct(String data) {
        Reader reader = new Reader(data);
        Scanner scanner = new ScannerImpl(reader);
        Parser parser = new ParserImpl(scanner);
        Resolver resolver = new ResolverImpl();
        Composer composer = new ComposerImpl(parser, resolver);
        Constructor constructor = new ConstructorImpl(composer);
        Object result = constructor.getSingleData();
        return result;
    }
}

@@ -1469,24 +1469,1194 @@
 ;%0D%0A    %7D%0D%0A%0D%0A
+    /**%0D%0A     * TODO Deviation from PyYAML. Assume the tag is the class name%0D%0A     */%0D%0A    public void qtestGetBeanAssumeClass() %7B%0D%0A        String data = %22--- !org.yaml.snakeyaml.constructor.Person%5CnfirstName: Andrey%5Cnage: 99%22;%0D%0A        Object obj = construct(data);%0D%0A        assertNotNull(obj);%0D%0A        assertTrue(%22Unexpected: %22 + obj.getClass().toString(), obj instanceof Person);%0D%0A        Person person = (Person) obj;%0D%0A        assertEquals(%22Andrey%22, person.getFirstName());%0D%0A        assertNull(person.getLastName());%0D%0A        assertEquals(99, person.getAge());%0D%0A    %7D%0D%0A%0D%0A    // TODO sequence constructor is not yet implemented%0D%0A    /**%0D%0A     * create instance from constructor%0D%0A     */%0D%0A    public void qtestGetConstructorBean() %7B%0D%0A        String data = %22--- !java/object:org.yaml.snakeyaml.constructor.Person %5B Andrey, Somov, 99 %5D%22;%0D%0A        Object obj = construct(data);%0D%0A        assertNotNull(obj);%0D%0A        assertTrue(obj.getClass().toString(), obj instanceof Person);%0D%0A        Person person = (Person) obj;%0D%0A        assertEquals(%22Andrey%22, person.getFirstName());%0D%0A        assertNull(person.getLastName());%0D%0A        assertEquals(99, person.getAge());%0D%0A    %7D%0D%0A%0D%0A
     private 

update tests