package com.robohorse.robopojogenerator.generator.utils;

import com.robohorse.robopojogenerator.errors.RoboPluginException;
import com.robohorse.robopojogenerator.generator.utils.ClassGenerateHelper;
import com.robohorse.robopojogenerator.models.InnerArrayModel;
import org.junit.Test;

import static org.junit.Assert.*;

/**
 * Created by vadim on 28.09.16.
 */
public class ClassGenerateHelperTest {
    private ClassGenerateHelper classGenerateHelper = new ClassGenerateHelper();

    @Test
    public void getClassNameModification_isCorrect() throws Exception {
        assertEquals("Item", classGenerateHelper.getClassName("item"));
    }

    @Test
    public void testModification_isCorrect() throws Exception {
        Exception exception = null;
        try {
            classGenerateHelper.validateJsonContent("{\"data\":1}");
        } catch (RoboPluginException e) {
            exception = e;
        }
        assertNull(exception);
    }

    @Test
    public void testModificationWithWrongStructure_isCorrect() throws Exception {
        Exception exception = null;
        try {
            classGenerateHelper.validateJsonContent("1123");
        } catch (RoboPluginException e) {
            exception = e;
        }
        assertNotNull(exception);
    }

    @Test
    public void testValidateClassName_isCorrect() throws Exception {
        Exception exception = null;
        try {
            classGenerateHelper.validateClassName("MySuperAwesomeClass");
        } catch (RoboPluginException e) {
            exception = e;
        }
        assertNull(exception);
    }

    @Test
    public void testValidateClassNameWithWrongName_isCorrect() throws Exception {
        Exception exception = null;
        try {
            classGenerateHelper.validateClassName(".MySuperAwesomeClass23");
        } catch (RoboPluginException e) {
            exception = e;
        }
        assertNotNull(exception);
    }

    @Test
    public void testResolveMajorTypeWithSingleCount_isCorrect() throws Exception {
        final String type = "Double";
        InnerArrayModel innerArrayModel = new InnerArrayModel();
        innerArrayModel.increaseCount();

        innerArrayModel.setMajorType(type);
        assertEquals("List<" + type + ">", classGenerateHelper.resolveMajorType(innerArrayModel));
    }

    @Test
    public void testResolveMajorTypeWithDoubleCount_isCorrect() throws Exception {
        final String type = "Double";
        InnerArrayModel innerArrayModel = new InnerArrayModel();
        innerArrayModel.increaseCount();
        innerArrayModel.increaseCount();

        innerArrayModel.setMajorType(type);
        assertEquals("List<List<" + type + ">>", classGenerateHelper.resolveMajorType(innerArrayModel));
    }

    @Test
    public void testResolveMajorTypeWithZeroCount_isCorrect() throws Exception {
        final String type = "Double";
        InnerArrayModel innerArrayModel = new InnerArrayModel();

        innerArrayModel.setMajorType(type);
        assertEquals(type, classGenerateHelper.resolveMajorType(innerArrayModel));
    }
}

@@ -161,106 +161,100 @@
 tor.
-generator.utils.ClassGenerateHelper;%0Aimport com.robohorse.robopojogenerator.models.InnerArrayModel
+models.InnerArrayModel;%0A%0Aimport org.junit.Test;%0A%0Aimport static org.junit.Assert.assertEquals
 ;%0Aim
@@ -250,32 +250,39 @@
 tEquals;%0Aimport 
+static 
 org.junit.Test;%0A
@@ -267,38 +267,53 @@
 tatic org.junit.
-Test;%0A
+Assert.assertNotNull;
 %0Aimport static o
@@ -328,17 +328,26 @@
 .Assert.
-*
+assertNull
 ;%0A%0A/**%0A 
@@ -3106,11 +3106,913 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void testUpdateKotlinType() throws Exception %7B%0A        final String nestedListType = %22List%3CList%3CList%3CInteger%3E%3E%3E%22;%0A        final String nestedListTarget = %22List%3CList%3CList%3CInt?%3E?%3E?%3E%22;%0A%0A        final String nestedListObjectType = %22List%3CList%3CObject%3E%3E%22;%0A        final String nestedListObjectTarget = %22List%3CList%3CAny?%3E?%3E%22;%0A%0A        final String primitiveType = %22int%22;%0A        final String primitiveTarget = %22Int%22;%0A%0A        final String objectType = %22Object%22;%0A        final String objectTarget = %22Any%22;%0A%0A        assertEquals(nestedListTarget, classGenerateHelper.updateKotlinType(nestedListType));%0A        assertEquals(nestedListObjectTarget, classGenerateHelper.updateKotlinType(nestedListObjectType));%0A        assertEquals(primitiveTarget, classGenerateHelper.updateKotlinType(primitiveType));%0A        assertEquals(objectTarget, classGenerateHelper.updateKotlinType(objectType));%0A    %7D
 %0A%7D%0A

Add test for updateKotlinType