package juglr;

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static org.testng.Assert.*;

import java.util.Iterator;
import java.util.List;
import java.util.ArrayList;

/**
 *
 */
public class BoxParserTest {

    @DataProvider(name="json")
    public Iterator<Object[]> flatJSon() {
        List<Object[]> data = new ArrayList<Object[]>();

        data.add(new Object[]{
                "{}",
                Box.newMap()
        });
        data.add(new Object[]{
                "{\"One\":1}",
                Box.newMap().put("One", new Box(1))
        });
        data.add(new Object[]{
                "{\"One\":1, \"bad\":false}",
                Box.newMap()
                        .put("One", new Box(1))
                        .put("bad", new Box(false))
        });
        data.add(new Object[]{
                "{\"bad\":false, \"list\":[27,68,true]}",
                Box.newMap()
                        .put("bad", new Box(false))
                        .put("list", Box.newList()
                                              .add(new Box(27))
                                              .add(new Box(68))
                                              .add(new Box(true)))
        });
        data.add(new Object[]{
                "{\"__store__\": [{\"__index__\": [\"firstname\"], \"__base__\": \"mybase\", \"__id__\": \"mke\", \"firstname\": \"Mikkel\", \"lastname\": \"kamstrup\"}]}",
                Box.newMap()
                    .put("__store__", Box.newList()
                        .add(Box.newMap()
                            .put("__index__", Box.newList().add("firstname"))
                            .put("__base__", "mybase")
                            .put("__id__", "mke")
                            .put("firstname", "Mikkel")
                            .put("lastname", "kamstrup"))
                     )
        });

        return data.iterator();
    }

    @Test(dataProvider="json")
    public void parseJSon(String json, Message expected) {
        BoxParser parser = new JSonBoxParser();

        Box result = parser.parse(json);
        assertEquals(result,expected);

    }
}

@@ -146,67 +146,9 @@
 til.
-Iterator;%0Aimport java.util.List;%0Aimport java.util.ArrayList
+*
 ;%0A%0A/
@@ -2109,11 +2109,1232 @@
 ;%0A%0A    %7D
+%0A%0A    @Test%0A    public void threadSafety() throws Exception %7B%0A        final String json = %22%7B%5C%22__store__%5C%22: %5B%7B%5C%22__index__%5C%22: %5B%5C%22firstname%5C%22%5D, %5C%22__base__%5C%22: %5C%22mybase%5C%22, %5C%22__id__%5C%22: %5C%22mke%5C%22, %5C%22firstname%5C%22: %5C%22Mikkel%5C%22, %5C%22lastname%5C%22: %5C%22kamstrup%5C%22%7D%5D%7D%22;%0A        final BoxParser parser = new JSonBoxParser();%0A        final List%3CThrowable%3E errors =%0A                Collections.synchronizedList(new LinkedList%3CThrowable%3E());%0A        Thread%5B%5D threads = new Thread%5B20%5D;%0A        for (int i = 0; i %3C threads.length; i++) %7B%0A            threads%5Bi%5D = new Thread(new Runnable() %7B%0A                public void run() %7B%0A                    try %7B%0A                        for (int i = 0; i %3C 10; i++) %7B%0A                            parser.parse(json);%0A                        %7D%0A                    %7D catch (Throwable t) %7B%0A                        errors.add(t);%0A                    %7D%0A                %7D%0A            %7D);%0A        %7D%0A%0A        for (Thread thread : threads) %7B%0A            thread.start();%0A        %7D%0A%0A        for (Thread thread : threads) %7B%0A            thread.join();%0A        %7D%0A%0A        if (errors.size() != 0) %7B%0A            for (Throwable t : errors) %7B%0A                t.printStackTrace();%0A            %7D%0A            fail();%0A        %7D%0A    %7D
 %0A%7D%0A

Add a heavily multithreaded test case for JSonBoxParser since I am seeing some spooky behaviour in Higgla