package com.maxmind.db;

import static org.junit.Assert.assertEquals;

import java.io.File;
import java.io.IOException;

import org.junit.Test;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.maxmind.db.Reader.FileMode;

public class PointerTest {
    @SuppressWarnings("static-method")
    @Test
    public void testWithPointers() throws IOException {
        File file = ReaderTest.getFile("maps-with-pointers.raw");
        BufferHolder ptf = new BufferHolder(file, FileMode.MEMORY);
        Decoder decoder = new Decoder(NoCache.getInstance(), ptf.get(), 0);

        ObjectMapper om = new ObjectMapper();

        ObjectNode map = om.createObjectNode();
        map.put("long_key", "long_value1");
        assertEquals(map, decoder.decode(0));

        map = om.createObjectNode();
        map.put("long_key", "long_value2");
        assertEquals(map, decoder.decode(22));

        map = om.createObjectNode();
        map.put("long_key2", "long_value1");
        assertEquals(map, decoder.decode(37));

        map = om.createObjectNode();
        map.put("long_key2", "long_value2");
        assertEquals(map, decoder.decode(50));

        map = om.createObjectNode();
        map.put("long_key", "long_value1");
        assertEquals(map, decoder.decode(55));

        map = om.createObjectNode();
        map.put("long_key2", "long_value2");
        assertEquals(map, decoder.decode(57));
    }
}

@@ -117,139 +117,214 @@
 on;%0A
-%0A
 import 
-org.junit.Test;%0A%0Aimport com.fasterxml.jackson.databind.ObjectMapper;%0Aimport com.fasterxml.jackson.databind.node.ObjectNode;
+java.lang.IllegalAccessException;%0Aimport java.lang.InstantiationException;%0Aimport java.lang.reflect.InvocationTargetException;%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0A%0Aimport org.junit.Test;%0A
 %0Aimp
@@ -470,16 +470,28 @@
 inters()
+%0A           
  throws 
@@ -501,16 +501,148 @@
 xception
+,%0A                   InstantiationException,%0A                   IllegalAccessException,%0A                   InvocationTargetException
  %7B%0A     
@@ -859,91 +859,47 @@
     
-ObjectMapper om = new ObjectMapper();%0A%0A        ObjectNode map = om.createObjectNode
+Map%3CString, String%3E map = new HashMap%3C%3E
 ();%0A
@@ -984,16 +984,27 @@
 decode(0
+, Map.class
 ));%0A%0A   
@@ -1014,35 +1014,29 @@
   map = 
-om.createObjectNode
+new HashMap%3C%3E
 ();%0A    
@@ -1118,16 +1118,27 @@
 ecode(22
+, Map.class
 ));%0A%0A   
@@ -1148,35 +1148,29 @@
   map = 
-om.createObjectNode
+new HashMap%3C%3E
 ();%0A    
@@ -1253,16 +1253,27 @@
 ecode(37
+, Map.class
 ));%0A%0A   
@@ -1283,35 +1283,29 @@
   map = 
-om.createObjectNode
+new HashMap%3C%3E
 ();%0A    
@@ -1388,16 +1388,27 @@
 ecode(50
+, Map.class
 ));%0A%0A   
@@ -1418,35 +1418,29 @@
   map = 
-om.createObjectNode
+new HashMap%3C%3E
 ();%0A    
@@ -1522,16 +1522,27 @@
 ecode(55
+, Map.class
 ));%0A%0A   
@@ -1556,27 +1556,21 @@
 p = 
-om.createObjectNode
+new HashMap%3C%3E
 ();%0A
@@ -1657,16 +1657,27 @@
 ecode(57
+, Map.class
 ));%0A    

Fix PointerTest