package com.braintreegateway;

import org.junit.Test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.junit.Assert.*;

public class RequestBuilderTest {

    @Test
    public void toXml() {
        RequestBuilder builder = new RequestBuilder("myparent");
        builder.addElement("name", "value");
        String result = builder.toXML();
        assertEquals("<myparent><name>value</name></myparent>", result);
    }

    // reveal protected methods for test
    private static class Open extends RequestBuilder {
        public Open() {
            super("open");
        }
        public static String publicBuildXmlElement(String name, Object object) {
            return buildXMLElement(name, object);
        }
        public static String formatMap(String name, Map<String,Object> map) {
            return formatAsXML(name, map);
        }
    }

    @Test
    public void list() {
       Open builder = new Open();
       List<String> items = new ArrayList();
       items.add("Chicken");
       items.add("Rabbit");
       String element = builder.publicBuildXmlElement("animals", items);
       assertEquals("<animals type=\"array\"><item>Chicken</item><item>Rabbit</item></animals>", element);
    }

    @Test
    public void map() {
        Open builder = new Open();
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("color", "green");
        map.put("insect", "bee");
        String element = builder.formatMap("examples", map);
        assertEquals("<examples><color>green</color><insect>bee</insect></examples>", element);
    }
}

Add tests to cover upcoming changes on RequestBuilder