package com.github.jsonldjava.utils;


import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.util.Map;

import org.junit.Test;

import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.ObjectMapper;

public class JsonUtilsTest {
    @Test
    public void resolveTest() {
        final String baseUri = "http://mysite.net";
        final String pathToResolve = "picture.jpg";
        String resolve = "";

        try {
            resolve = JsonLdUrl.resolve(baseUri, pathToResolve);
        } catch (final Exception e) {
            assertTrue(false);
        }
        assertEquals(baseUri + "/" + pathToResolve, resolve);
    }

    @SuppressWarnings("unchecked")
    @Test
    public void fromStringTest() {
        final String testString = "{\"seq\":3,\"id\":\"e48dfa735d9fad88db6b7cd696002df7\",\"changes\":[{\"rev\":\"2-6aebf275bc3f29b67695c727d448df8e\"}]}";
        final String testFailure = "{{{{{{{{{{{";
        Object obj = null;

        try {
            obj = JsonUtils.fromString(testString);
        } catch (final Exception e) {
            assertTrue(false);
        }

        assertTrue(((Map<String, Object>) obj).containsKey("seq"));
        assertTrue(((Map<String, Object>) obj).get("seq") instanceof Number);

        try {
            obj = JsonUtils.fromString(testFailure);
            assertTrue(false);
        } catch (final Exception e) {
            assertTrue(true);
        }
    }

    @Test
    public void testFromJsonParser() throws Exception {
        final ObjectMapper jsonMapper = new ObjectMapper();
        final JsonFactory jsonFactory = new JsonFactory(jsonMapper);
        final Reader testInputString = new StringReader("{}");
        final JsonParser jp = jsonFactory.createParser(testInputString);
        JsonUtils.fromJsonParser(jp);
    }

    @Test
    public void trailingContent_1() throws JsonParseException, IOException {
        trailingContent("{}");
    }

    @Test
    public void trailingContent_2() throws JsonParseException, IOException {
        trailingContent("{}  \t  \r \n  \r\n   ");
    }

    @Test(expected = JsonParseException.class)
    public void trailingContent_3() throws JsonParseException, IOException {
        trailingContent("{}x");
    }

    @Test(expected = JsonParseException.class)
    public void trailingContent_4() throws JsonParseException, IOException {
        trailingContent("{}   x");
    }

    @Test(expected = JsonParseException.class)
    public void trailingContent_5() throws JsonParseException, IOException {
        trailingContent("{} \"x\"");
    }

    @Test(expected = JsonParseException.class)
    public void trailingContent_6() throws JsonParseException, IOException {
        trailingContent("{} {}");
    }

    @Test(expected = JsonParseException.class)
    public void trailingContent_7() throws JsonParseException, IOException {
        trailingContent("{},{}");
    }

    @Test(expected = JsonParseException.class)
    public void trailingContent_8() throws JsonParseException, IOException {
        trailingContent("{},[]");
    }

    private void trailingContent(String string) throws JsonParseException, IOException {
        JsonUtils.fromString(string);
    }
}

@@ -728,24 +728,90 @@
 ToResolve);%0A
+            assertEquals(baseUri + %22/%22 + pathToResolve, resolve);%0A
         %7D ca
@@ -881,70 +881,8 @@
   %7D%0A
-        assertEquals(baseUri + %22/%22 + pathToResolve, resolve);%0A
     
@@ -1272,84 +1272,8 @@
     
-    %7D catch (final Exception e) %7B%0A            assertTrue(false);%0A        %7D%0A%0A
     
@@ -1336,16 +1336,20 @@
 seq%22));%0A
+    
         
@@ -1417,16 +1417,95 @@
 Number);
+%0A        %7D catch (final Exception e) %7B%0A            assertTrue(false);%0A        %7D
 %0A%0A      

Put the assertEquals inside of the try-catch block