package com.github.nsnjson;

import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.node.*;
import org.junit.Assert;

import java.util.*;

public abstract class AbstractTest {

    protected static NullNode getNull() {
        return NullNode.getInstance();
    }

    protected static NumericNode getNumberInt() {
        return new IntNode(new Random().nextInt());
    }

    protected static NumericNode getNumberLong() {
        return new LongNode(new Random().nextLong());
    }

    protected static NumericNode getNumberDouble() {
        return new DoubleNode(new Random().nextDouble());
    }

    protected static TextNode getEmptyString() {
        return new TextNode("");
    }

    protected static TextNode getString() {
        return new TextNode(UUID.randomUUID().toString().replaceAll("-", ""));
    }

    protected static BooleanNode getBooleanTrue() {
        return BooleanNode.getTrue();
    }

    protected static BooleanNode getBooleanFalse() {
        return BooleanNode.getFalse();
    }

    protected static ArrayNode getEmptyArray() {
        return new ObjectMapper().createArrayNode();
    }

    protected static ArrayNode getArray() {
        ArrayNode array = getEmptyArray();
        array.add(getNull());
        array.add(getBooleanTrue());
        array.add(getBooleanFalse());
        array.add(getNumberInt());
        array.add(getNumberLong());
        array.add(getNumberDouble());
        array.add(getString());

        return array;
    }

    protected static ObjectNode getEmptyObject() {
        return new ObjectMapper().createObjectNode();
    }

    protected static ObjectNode getObject() {
        ObjectNode object = new ObjectMapper().createObjectNode();
        object.set("null_field", getNull());
        object.set("int_field", getNumberInt());
        object.set("long_field", getNumberLong());
        object.set("double_field", getNumberDouble());
        object.set("true_field", getBooleanTrue());
        object.set("false_field", getBooleanFalse());
        object.set("string_field", getString());

        return object;
    }

    protected abstract JsonNode getNullPresentation();

    protected abstract JsonNode getNumberIntPresentation(NumericNode value);

    protected abstract JsonNode getNumberLongPresentation(NumericNode value);

    protected abstract JsonNode getNumberDoublePresentation(NumericNode value);

    protected abstract JsonNode getStringPresentation(TextNode value);

    protected abstract JsonNode getBooleanPresentation(BooleanNode value);

    protected abstract JsonNode getArrayPresentation(ArrayNode array);

    protected abstract JsonNode getObjectPresentation(ObjectNode object);

    protected abstract Optional<JsonNode> getPresentation(JsonNode json);

    protected static JsonNode assertAndGetValue(Optional<JsonNode> valueOption) {
        Assert.assertTrue(valueOption.isPresent());

        return valueOption.get();
    }

    protected static JsonNode assertAndGetPresentation(Optional<JsonNode> presentationOption) {
        Assert.assertTrue(presentationOption.isPresent());

        return presentationOption.get();
    }

}
@@ -194,16 +194,1942 @@
 Test %7B%0A%0A
+    protected Optional%3CJsonNode%3E getPresentation(JsonNode json) %7B%0A        if (json instanceof NullNode) %7B%0A            return Optional.of(getNullPresentation());%0A        %7D%0A%0A        if (json instanceof NumericNode) %7B%0A            NumericNode value = (NumericNode) json;%0A%0A            if (value.isInt()) %7B%0A                return Optional.of(getNumberIntPresentation(value));%0A            %7D%0A%0A            if (value.isLong()) %7B%0A                return Optional.of(getNumberLongPresentation(value));%0A            %7D%0A%0A            if (value.isDouble()) %7B%0A                return Optional.of(getNumberDoublePresentation(value));%0A            %7D%0A        %7D%0A%0A        if (json instanceof TextNode) %7B%0A            TextNode value = (TextNode) json;%0A%0A            return Optional.of(getStringPresentation(value));%0A        %7D%0A%0A        if (json instanceof BooleanNode) %7B%0A            BooleanNode value = (BooleanNode) json;%0A%0A            return Optional.of(getBooleanPresentation(value));%0A        %7D%0A%0A        if (json instanceof ArrayNode) %7B%0A            ArrayNode array = (ArrayNode) json;%0A%0A            return Optional.of(getArrayPresentation(array));%0A        %7D%0A%0A        if (json instanceof ObjectNode) %7B%0A            ObjectNode object = (ObjectNode) json;%0A%0A            return Optional.of(getObjectPresentation(object));%0A        %7D%0A%0A        return Optional.empty();%0A    %7D%0A%0A    protected abstract JsonNode getNullPresentation();%0A%0A    protected abstract JsonNode getNumberIntPresentation(NumericNode value);%0A%0A    protected abstract JsonNode getNumberLongPresentation(NumericNode value);%0A%0A    protected abstract JsonNode getNumberDoublePresentation(NumericNode value);%0A%0A    protected abstract JsonNode getStringPresentation(TextNode value);%0A%0A    protected abstract JsonNode getBooleanPresentation(BooleanNode value);%0A%0A    protected abstract JsonNode getArrayPresentation(ArrayNode array);%0A%0A    protected abstract JsonNode getObjectPresentation(ObjectNode object);%0A%0A
     prot
@@ -2158,24 +2158,24 @@
 getNull() %7B%0A
-
         retu
@@ -4042,679 +4042,15 @@
 ct;%0A
+
     %7D%0A%0A
-    protected abstract JsonNode getNullPresentation();%0A%0A    protected abstract JsonNode getNumberIntPresentation(NumericNode value);%0A%0A    protected abstract JsonNode getNumberLongPresentation(NumericNode value);%0A%0A    protected abstract JsonNode getNumberDoublePresentation(NumericNode value);%0A%0A    protected abstract JsonNode getStringPresentation(TextNode value);%0A%0A    protected abstract JsonNode getBooleanPresentation(BooleanNode value);%0A%0A    protected abstract JsonNode getArrayPresentation(ArrayNode array);%0A%0A    protected abstract JsonNode getObjectPresentation(ObjectNode object);%0A%0A    protected abstract Optional%3CJsonNode%3E getPresentation(JsonNode json);%0A%0A
     

Implement method { AbstractTest @ getPresentation }