<commit_before>package com.bluelinelabs.logansquare.processor;

import com.bluelinelabs.logansquare.LoganSquare;
import com.bluelinelabs.logansquare.processor.model.NestedCollectionModel;
import com.bluelinelabs.logansquare.processor.model.SimpleModel;
import com.bluelinelabs.logansquare.processor.model.SimpleModelWithoutNullObjects;
import org.junit.Test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.UUID;

import static com.google.common.truth.Truth.ASSERT;

public class RoundTripTests {

    @Test
    public void simpleObject() {
        String json = "{\"date\":\"2015-02-21T18:45:50.748+0000\",\"string\":\"testString\",\"test_double\":342.0,\"test_double_obj\":345.0,\"test_float\":898.0,\"test_float_obj\":382.0,\"test_int\":32,\"test_int_obj\":323,\"test_long\":932,\"test_long_obj\":3920,\"test_string\":\"anotherTestString\"}";

        String reserialized = null;
        try {
            SimpleModel simpleModel = LoganSquare.parse(json, SimpleModel.class);
            reserialized = LoganSquare.serialize(simpleModel);
        } catch (Exception ignored) { }

        ASSERT.that(json.equals(reserialized)).isTrue();
    }

    @Test
    public void simpleObjectList() {
        String json = "[{\"date\":\"2015-02-21T18:45:50.748+0000\",\"string\":\"testString\",\"test_double\":342.0,\"test_double_obj\":345.0,\"test_float\":898.0,\"test_float_obj\":382.0,\"test_int\":32,\"test_int_obj\":323,\"test_long\":932,\"test_long_obj\":3920,\"test_string\":\"anotherTestString\"}," +
                "{\"date\":\"2015-02-22T18:45:50.748+0000\",\"string\":\"testString2\",\"test_double\":342.0,\"test_double_obj\":345.0,\"test_float\":898.0,\"test_float_obj\":382.0,\"test_int\":32,\"test_int_obj\":323,\"test_long\":932,\"test_long_obj\":3920,\"test_string\":\"anotherTestString\"}]";

        String reserialized = null;
        try {
            List<SimpleModel> simpleModels = LoganSquare.parseList(json, SimpleModel.class);
            reserialized = LoganSquare.serialize(simpleModels, SimpleModel.class);
        } catch (Exception ignored) { }

        ASSERT.that(json.equals(reserialized)).isTrue();
    }

    @Test
    public void simpleObjectListWithNulls() {
        String json = "[{\"date\":\"2015-02-21T18:45:50.748+0000\",\"string\":\"testString\",\"test_double\":342.0,\"test_double_obj\":345.0,\"test_float\":898.0,\"test_float_obj\":382.0,\"test_int\":32,\"test_int_obj\":323,\"test_long\":932,\"test_long_obj\":3920,\"test_string\":\"anotherTestString\"}," +
                "{\"date\":\"2015-02-22T18:45:50.748+0000\",\"string\":\"testString2\",\"test_double\":342.0,\"test_double_obj\":345.0,\"test_float\":898.0,\"test_float_obj\":382.0,\"test_int\":32,\"test_int_obj\":323,\"test_long\":932,\"test_long_obj\":3920,\"test_string\":\"anotherTestString\"}," +
                "{\"date\":null,\"string\":\"testString2\",\"test_double\":342.0,\"test_double_obj\":null,\"test_float\":898.0,\"test_float_obj\":null,\"test_int\":32,\"test_int_obj\":null,\"test_long\":932,\"test_long_obj\":null,\"test_string\":null}," +
                "null," +
                "null]";

        String reserialized = null;
        try {
            List<SimpleModel> simpleModels = LoganSquare.parseList(json, SimpleModel.class);
            reserialized = LoganSquare.serialize(simpleModels, SimpleModel.class);
        } catch (Exception ignored) {
            ignored.printStackTrace();
        }

        ASSERT.that(json.equals(reserialized)).isTrue();
    }

    @Test
    public void simpleObjectMap() {
        String json = "{\"obj1\":{\"date\":\"2015-02-21T18:45:50.748+0000\",\"string\":\"testString\",\"test_double\":342.0,\"test_double_obj\":345.0,\"test_float\":898.0,\"test_float_obj\":382.0,\"test_int\":32,\"test_int_obj\":323,\"test_long\":932,\"test_long_obj\":3920,\"test_string\":\"anotherTestString\"}," +
                "\"obj2\":{\"date\":\"2015-02-22T18:45:50.748+0000\",\"string\":\"testString2\",\"test_double\":342.0,\"test_double_obj\":345.0,\"test_float\":898.0,\"test_float_obj\":382.0,\"test_int\":32,\"test_int_obj\":323,\"test_long\":932,\"test_long_obj\":3920,\"test_string\":\"anotherTestString\"}}";

        String reserialized = null;
        try {
            Map<String, SimpleModel> simpleModelMap = LoganSquare.parseMap(json, SimpleModel.class);
            reserialized = LoganSquare.serialize(simpleModelMap, SimpleModel.class);
        } catch (Exception ignored) { }

        ASSERT.that(json.equals(reserialized)).isTrue();
    }

    @Test
    public void simpleObjectMapWithNulls() {
        String json = "{\"obj1\":{\"date\":\"2015-02-21T18:45:50.748+0000\",\"string\":\"testString\",\"test_double\":342.0,\"test_double_obj\":345.0,\"test_float\":898.0,\"test_float_obj\":382.0,\"test_int\":32,\"test_int_obj\":323,\"test_long\":932,\"test_long_obj\":3920,\"test_string\":\"anotherTestString\"}," +<commit_msg>Fixed failing test when run with JDK 8<commit_after>package com.bluelinelabs.logansquare.processor;

import com.bluelinelabs.logansquare.LoganSquare;
import com.bluelinelabs.logansquare.processor.model.NestedCollectionModel;
import com.bluelinelabs.logansquare.processor.model.SimpleModel;
import com.bluelinelabs.logansquare.processor.model.SimpleModelWithoutNullObjects;
import org.junit.Test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.UUID;

import static com.google.common.truth.Truth.ASSERT;

public class RoundTripTests {

    @Test
    public void simpleObject() {
        String json = "{\"date\":\"2015-02-21T18:45:50.748+0000\",\"string\":\"testString\",\"test_double\":342.0,\"test_double_obj\":345.0,\"test_float\":898.0,\"test_float_obj\":382.0,\"test_int\":32,\"test_int_obj\":323,\"test_long\":932,\"test_long_obj\":3920,\"test_string\":\"anotherTestString\"}";

        String reserialized = null;
        try {
            SimpleModel simpleModel = LoganSquare.parse(json, SimpleModel.class);
            reserialized = LoganSquare.serialize(simpleModel);
        } catch (Exception ignored) { }

        ASSERT.that(json.equals(reserialized)).isTrue();
    }

    @Test
    public void simpleObjectList() {
        String json = "[{\"date\":\"2015-02-21T18:45:50.748+0000\",\"string\":\"testString\",\"test_double\":342.0,\"test_double_obj\":345.0,\"test_float\":898.0,\"test_float_obj\":382.0,\"test_int\":32,\"test_int_obj\":323,\"test_long\":932,\"test_long_obj\":3920,\"test_string\":\"anotherTestString\"}," +
                "{\"date\":\"2015-02-22T18:45:50.748+0000\",\"string\":\"testString2\",\"test_double\":342.0,\"test_double_obj\":345.0,\"test_float\":898.0,\"test_float_obj\":382.0,\"test_int\":32,\"test_int_obj\":323,\"test_long\":932,\"test_long_obj\":3920,\"test_string\":\"anotherTestString\"}]";

        String reserialized = null;
        try {
            List<SimpleModel> simpleModels = LoganSquare.parseList(json, SimpleModel.class);
            reserialized = LoganSquare.serialize(simpleModels, SimpleModel.class);
        } catch (Exception ignored) { }

        ASSERT.that(json.equals(reserialized)).isTrue();
    }

    @Test
    public void simpleObjectListWithNulls() {
        String json = "[{\"date\":\"2015-02-21T18:45:50.748+0000\",\"string\":\"testString\",\"test_double\":342.0,\"test_double_obj\":345.0,\"test_float\":898.0,\"test_float_obj\":382.0,\"test_int\":32,\"test_int_obj\":323,\"test_long\":932,\"test_long_obj\":3920,\"test_string\":\"anotherTestString\"}," +
                "{\"date\":\"2015-02-22T18:45:50.748+0000\",\"string\":\"testString2\",\"test_double\":342.0,\"test_double_obj\":345.0,\"test_float\":898.0,\"test_float_obj\":382.0,\"test_int\":32,\"test_int_obj\":323,\"test_long\":932,\"test_long_obj\":3920,\"test_string\":\"anotherTestString\"}," +
                "{\"date\":null,\"string\":\"testString2\",\"test_double\":342.0,\"test_double_obj\":null,\"test_float\":898.0,\"test_float_obj\":null,\"test_int\":32,\"test_int_obj\":null,\"test_long\":932,\"test_long_obj\":null,\"test_string\":null}," +
                "null," +
                "null]";

        String reserialized = null;
        try {
            List<SimpleModel> simpleModels = LoganSquare.parseList(json, SimpleModel.class);
            reserialized = LoganSquare.serialize(simpleModels, SimpleModel.class);
        } catch (Exception ignored) {
            ignored.printStackTrace();
        }

        ASSERT.that(json.equals(reserialized)).isTrue();
    }

    @Test
    public void simpleObjectMap() {
        String json = "{\"obj1\":{\"date\":\"2015-02-21T18:45:50.748+0000\",\"string\":\"testString\",\"test_double\":342.0,\"test_double_obj\":345.0,\"test_float\":898.0,\"test_float_obj\":382.0,\"test_int\":32,\"test_int_obj\":323,\"test_long\":932,\"test_long_obj\":3920,\"test_string\":\"anotherTestString\"}," +
                "\"obj2\":{\"date\":\"2015-02-22T18:45:50.748+0000\",\"string\":\"testString2\",\"test_double\":342.0,\"test_double_obj\":345.0,\"test_float\":898.0,\"test_float_obj\":382.0,\"test_int\":32,\"test_int_obj\":323,\"test_long\":932,\"test_long_obj\":3920,\"test_string\":\"anotherTestString\"}}";

        String reserialized = null;
        try {
            Map<String, SimpleModel> simpleModelMap = new TreeMap<>(LoganSquare.parseMap(json, SimpleModel.class));
            reserialized = LoganSquare.serialize(simpleModelMap, SimpleModel.class);
        } catch (Exception ignored) { }

        ASSERT.that(json.equals(reserialized)).isTrue();
    }

    @Test
    public void simpleObjectMapWithNulls() {
        String json = "{\"obj1\":{\"date\":\"2015-02-21T18:45:50.748+0000\",\"string\":\"testString\",\"test_double\":342.0,\"test_double_obj\":345.0,\"test_float\":898.0,\"test_float_obj\":382.0,\"test_int\":32,\"test_int_obj\":323,\"test_long\":932,\"test_long_obj\":3920,\"test_string\":\"anotherTestString\"}," +
{'fraction_non_alphanumeric': 0.21354992076069731, 'fraction_numerical': 0.08171553090332805, 'mean_word_length': 3.918168533852898, 'pattern_counts': {'":': 204, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3440196', 'n_tokens_mistral': 3942, 'n_tokens_neox': 3454, 'n_words': 280}