package com.marcospassos.phpserializer.adapter;

import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;

import com.marcospassos.phpserializer.Context;
import com.marcospassos.phpserializer.Writer;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import org.mockito.InOrder;

/**
 * @author Marcos Passos
 * @since 1.0
 */
public class MapAdapterTest
{
    @Test
    public void write() throws Exception
    {
        MapAdapter<Object, Object> adapter = new MapAdapter<>();
        Writer writer = mock(Writer.class);
        Context context = mock(Context.class);
        Map<Object, Object> map = new HashMap<>();
        map.put(1, "a");
        map.put("2", "b");
        map.put(3, "c");

        adapter.write(map, writer, context);

        InOrder order = inOrder(writer, context);

        order.verify(writer).writeArrayStart(3);
        order.verify(writer).writeKey(1);
        order.verify(context).write("a", writer);
        order.verify(writer).writeKey("2");
        order.verify(context).write("b", writer);
        order.verify(writer).writeKey(3);
        order.verify(context).write("c", writer);
        order.verify(writer).writeArrayEnd();
    }
}
@@ -734,24 +734,106 @@
 t(3, %22c%22);%0A%0A
+        // The verify check is split by entries once HashMap is an unordered map%0A%0A
         adap
@@ -962,32 +962,33 @@
 ayStart(3);%0A
+%0A
         
 order.verify
@@ -967,37 +967,88 @@
 rt(3);%0A%0A        
-order
+InOrder first = inOrder(writer, context);%0A%0A        first
 .verify(writer).
@@ -1060,37 +1060,37 @@
 Key(1);%0A        
-order
+first
 .verify(context)
@@ -1106,32 +1106,33 @@
 %22, writer);%0A
+%0A
         
 order.verify
@@ -1111,37 +1111,90 @@
 iter);%0A%0A        
-order
+InOrder second = inOrder(writer, context);%0A%0A        second
 .verify(writer).
@@ -1208,37 +1208,38 @@
 y(%222%22);%0A        
-order
+second
 .verify(context)
@@ -1255,32 +1255,33 @@
 %22, writer);%0A
+%0A
         
 order.verify
@@ -1260,37 +1260,88 @@
 iter);%0A%0A        
-o
+InO
 rder
+ third = inOrder(writer, context);%0A%0A        third
 .verify(writer).
@@ -1353,37 +1353,37 @@
 Key(3);%0A        
-order
+third
 .verify(context)
@@ -1403,16 +1403,17 @@
 riter);%0A
+%0A
         
@@ -1449,16 +1449,59 @@
 ayEnd();
+%0A%0A        order.verifyNoMoreInteractions();
 %0A    %7D%0A%7D

Fix test for unordered map making it order-insensitive