ST defect fixes and review comments fixes

Change-Id: Ib8c56a88c19cd9aa23918d0f9e37c89e74cb0d13
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGeneratorTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGeneratorTest.java
index 6d0056e..d2cb823 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGeneratorTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGeneratorTest.java
@@ -16,17 +16,16 @@
 
 package org.onosproject.yangutils.translator.tojava.utils;
 
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-
 import org.junit.Test;
 import org.onosproject.yangutils.translator.GeneratedFileType;
 import org.onosproject.yangutils.translator.tojava.GeneratedMethodTypes;
 import org.onosproject.yangutils.translator.tojava.TraversalType;
 import org.onosproject.yangutils.utils.UtilConstants;
 
-import static org.hamcrest.core.Is.is;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
 import static org.junit.Assert.assertNotNull;
+import static org.hamcrest.core.Is.is;
 import static org.junit.Assert.assertThat;
 
 /**
@@ -40,18 +39,14 @@
      * @throws SecurityException if any security violation is observed
      * @throws NoSuchMethodException if when the method is not found
      * @throws IllegalArgumentException if there is illegal argument found
-     * @throws InstantiationException if instantiation is provoked for the
-     *             private constructor
-     * @throws IllegalAccessException if instance is provoked or a method is
-     *             provoked
-     * @throws InvocationTargetException when an exception occurs by the method
-     *             or constructor
+     * @throws InstantiationException if instantiation is provoked for the private constructor
+     * @throws IllegalAccessException if instance is provoked or a method is provoked
+     * @throws InvocationTargetException when an exception occurs by the method or constructor
      */
     @Test
-    public void callPrivateConstructors() throws SecurityException, NoSuchMethodException,
-            IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException {
-        Class<?>[] classesToConstruct = {
-                ClassDefinitionGenerator.class };
+    public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException,
+    InstantiationException, IllegalAccessException, InvocationTargetException {
+        Class<?>[] classesToConstruct = {ClassDefinitionGenerator.class };
         for (Class<?> clazz : classesToConstruct) {
             Constructor<?> constructor = clazz.getDeclaredConstructor();
             constructor.setAccessible(true);
@@ -105,14 +100,14 @@
     }
 
     /**
-     * Unit test for invalid generated type.
+     * Unit test for typedef generated type.
      */
     @Test
-    public void generateInvalidDefinitionTest() {
+    public void generateTypeDefTest() {
 
-        //        String invalidDefinition = ClassDefinitionGenerator
-        //                .generateClassDefinition(GeneratedFileType.GENERATE_INTERFACE_WITH_BUILDER, "invalid");
-        //        assertThat(true, is(invalidDefinition == null));
+        String typeDef = ClassDefinitionGenerator.generateClassDefinition(GeneratedFileType.GENERATE_TYPEDEF_CLASS,
+                "invalid");
+        assertThat(true, is(typeDef.contains(UtilConstants.CLASS)));
     }
 
     /**
@@ -123,5 +118,6 @@
 
         TraversalType.valueOf(TraversalType.CHILD.toString());
         GeneratedMethodTypes.valueOf(GeneratedMethodTypes.CONSTRUCTOR.toString());
+        TempDataStoreTypes.valueOf(TempDataStoreTypes.CONSTRUCTOR.toString());
     }
 }
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGenTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGenTest.java
index fbd4183..f810ec9 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGenTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGenTest.java
@@ -25,8 +25,12 @@
 import org.onosproject.yangutils.utils.UtilConstants;
 
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertNotNull;
 import static org.hamcrest.core.Is.is;
 
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+
 /**
  * Unit test cases for java code snippet generator.
  */
@@ -40,6 +44,27 @@
     private static final String STRING = "String";
 
     /**
+     * Unit test for private constructor.
+     *
+     * @throws SecurityException if any security violation is observed
+     * @throws NoSuchMethodException if when the method is not found
+     * @throws IllegalArgumentException if there is illegal argument found
+     * @throws InstantiationException if instantiation is provoked for the private constructor
+     * @throws IllegalAccessException if instance is provoked or a method is provoked
+     * @throws InvocationTargetException when an exception occurs by the method or constructor
+     */
+    @Test
+    public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException,
+            InstantiationException, IllegalAccessException, InvocationTargetException {
+        Class<?>[] classesToConstruct = {JavaCodeSnippetGen.class };
+        for (Class<?> clazz : classesToConstruct) {
+            Constructor<?> constructor = clazz.getDeclaredConstructor();
+            constructor.setAccessible(true);
+            assertNotNull(constructor.newInstance());
+        }
+    }
+
+    /**
      * Unit test case for import text.
      */
     @Test
@@ -64,27 +89,6 @@
                 is(classDef.equals(UtilConstants.PUBLIC + UtilConstants.SPACE + UtilConstants.INTERFACE
                         + UtilConstants.SPACE + YANG_NAME + UtilConstants.SPACE + UtilConstants.OPEN_CURLY_BRACKET
                         + UtilConstants.NEW_LINE)));
-    }
-
-    /**
-     * Unit test case for java attribute info.
-     */
-    @SuppressWarnings("rawtypes")
-    @Test
-    public void testForJavaAttributeInfo() {
-        // TODO: need to update for new framework
-        //        String attributeWithType
-        //        = JavaCodeSnippetGen.getJavaAttributeDefination(FILE_GEN_TYPE, YANG_NAME, getType());
-        //        assertThat(true, is(attributeWithType.equals(UtilConstants.PRIVATE + UtilConstants.SPACE
-        //                + getType().getDataTypeName() + UtilConstants.SPACE + YANG_NAME + UtilConstants.SEMI_COLAN)));
-        //
-        //        String attributeWithoutType
-        //        = JavaCodeSnippetGen.getJavaAttributeDefination(FILE_GEN_TYPE, YANG_NAME, null);
-        //        assertThat(true,
-        //                is(attributeWithoutType.equals(
-        //                        UtilConstants.PRIVATE
-        //        + UtilConstants.SPACE + JavaIdentifierSyntax.getCaptialCase(YANG_NAME)
-        //                                + UtilConstants.SPACE + YANG_NAME + UtilConstants.SEMI_COLAN)));
 
     }
 
@@ -99,29 +103,62 @@
     }
 
     /**
-     * Unit test case for java method info.
+     * Unit test case for java class interface definition close.
      */
     @Test
-    public void testForJavaMethodInfo() {
-        //TODO: update to new framework.
-        //        String method
-        //        = JavaCodeSnippetGen.getJavaMethodInfo(FILE_GEN_TYPE, YANG_NAME, METHOD_GEN_TYPE, getType());
-        //        assertThat(true,
-        //                is(method.equals(UtilConstants.FOUR_SPACE_INDENTATION
-        //                        + JavaIdentifierSyntax.getCaptialCase(getType().getDataTypeName())
-        //        + UtilConstants.SPACE
-        //                        + UtilConstants.GET_METHOD_PREFIX + JavaIdentifierSyntax.getCaptialCase(YANG_NAME)
-        //                        + UtilConstants.OPEN_PARENTHESIS + UtilConstants.CLOSE_PARENTHESIS
-        //                        + UtilConstants.SEMI_COLAN)));
+    public void testForJavaClassDefInterfaceClose() {
+        String interfaceDef = JavaCodeSnippetGen.getJavaClassDefClose(FILE_GEN_TYPE, YANG_NAME);
+        assertThat(true, is(interfaceDef.equals(UtilConstants.CLOSE_CURLY_BRACKET)));
     }
 
     /**
-     * Unit test case for java class definition close.
+     * Unit test case for java class builder class definition close.
      */
     @Test
-    public void testForJavaClassDefClose() {
-        String classDef = JavaCodeSnippetGen.getJavaClassDefClose(FILE_GEN_TYPE, YANG_NAME);
-        assertThat(true, is(classDef.equals(UtilConstants.CLOSE_CURLY_BRACKET)));
+    public void testForJavaClassDefBuilderClassClose() {
+        String builderClassDef = JavaCodeSnippetGen.getJavaClassDefClose(GeneratedFileType.BUILDER_CLASS_MASK,
+                YANG_NAME);
+        assertThat(true, is(builderClassDef.equals(UtilConstants.CLOSE_CURLY_BRACKET)));
+    }
+
+    /**
+     * Unit test case for java class typedef definition close.
+     */
+    @Test
+    public void testForJavaClassDefTypeDefClose() {
+        String typeDef = JavaCodeSnippetGen.getJavaClassDefClose(GeneratedFileType.GENERATE_TYPEDEF_CLASS, YANG_NAME);
+        assertThat(true, is(typeDef.equals(UtilConstants.CLOSE_CURLY_BRACKET)));
+    }
+
+    /**
+     * Unit test case for java attribute info.
+     */
+    @SuppressWarnings("rawtypes")
+    @Test
+    public void testForJavaAttributeInfo() {
+
+        String attributeWithoutTypePkg = JavaCodeSnippetGen.getJavaAttributeDefination(null, "String", YANG_NAME,
+                false);
+        assertThat(true, is(attributeWithoutTypePkg.equals(UtilConstants.PRIVATE + UtilConstants.SPACE + "String"
+                + UtilConstants.SPACE + YANG_NAME + UtilConstants.SEMI_COLAN)));
+        String attributeWithTypePkg = JavaCodeSnippetGen.getJavaAttributeDefination("java.lang", "String", YANG_NAME,
+                false);
+        assertThat(true, is(attributeWithTypePkg.equals(UtilConstants.PRIVATE + UtilConstants.SPACE + "java.lang."
+                + "String" + UtilConstants.SPACE + YANG_NAME + UtilConstants.SEMI_COLAN)));
+        String attributeWithListPkg = JavaCodeSnippetGen.getJavaAttributeDefination("java.lang", "String", YANG_NAME,
+                true);
+        assertThat(true,
+                is(attributeWithListPkg.equals(UtilConstants.PRIVATE + UtilConstants.SPACE + UtilConstants.LIST
+                        + UtilConstants.DIAMOND_OPEN_BRACKET + "java.lang."
+                        + "String" + UtilConstants.DIAMOND_CLOSE_BRACKET + UtilConstants.SPACE + YANG_NAME
+                        + UtilConstants.SEMI_COLAN)));
+        String attributeWithListWithoutPkg = JavaCodeSnippetGen.getJavaAttributeDefination(null, "String", YANG_NAME,
+                true);
+        assertThat(true,
+                is(attributeWithListWithoutPkg.equals(UtilConstants.PRIVATE + UtilConstants.SPACE + UtilConstants.LIST
+                        + UtilConstants.DIAMOND_OPEN_BRACKET + "String"
+                        + UtilConstants.DIAMOND_CLOSE_BRACKET + UtilConstants.SPACE + YANG_NAME
+                        + UtilConstants.SEMI_COLAN)));
     }
 
     /**
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntaxTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntaxTest.java
index 6e89d936..b7bbbec 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntaxTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntaxTest.java
@@ -36,8 +36,8 @@
     public static final String DATE2 = "1992-01-25";
     public static final String PARENT_WITH_PERIOD = "test5.test6.test7";
     public static final String CHILD_WITH_PERIOD = "test1.test2.test3";
-    public static final String DATE_WITH_REV1 = "rev000105";
-    public static final String DATE_WITH_REV2 = "rev920125";
+    public static final String DATE_WITH_REV1 = "rev20000105";
+    public static final String DATE_WITH_REV2 = "rev19920125";
     public static final String VERSION_NUMBER = "v1";
     public static final String INVALID_NAME_SPACE1 = "byte:#test2:9test3";
     public static final String INVALID_NAME_SPACE2 = "const:#test2://9test3";
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGeneratorTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGeneratorTest.java
index 5ee059c..91a723f 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGeneratorTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGeneratorTest.java
@@ -16,18 +16,18 @@
 
 package org.onosproject.yangutils.translator.tojava.utils;
 
+import org.junit.Test;
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertNotNull;
+import org.onosproject.yangutils.datamodel.YangDataTypes;
+import org.onosproject.yangutils.datamodel.YangType;
+import org.onosproject.yangutils.translator.tojava.AttributeInfo;
+import org.onosproject.yangutils.translator.tojava.ImportInfo;
+import org.onosproject.yangutils.utils.UtilConstants;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
 
-import org.junit.Test;
-import org.onosproject.yangutils.datamodel.YangType;
-import org.onosproject.yangutils.translator.GeneratedFileType;
-import org.onosproject.yangutils.translator.tojava.AttributeInfo;
-
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThat;
-
 /**
  * Unit tests for generated methods from the file type.
  */
@@ -42,19 +42,15 @@
      * @throws SecurityException if any security violation is observed
      * @throws NoSuchMethodException if when the method is not found
      * @throws IllegalArgumentException if there is illegal argument found
-     * @throws InstantiationException if instantiation is provoked for the
-     *             private constructor
-     * @throws IllegalAccessException if instance is provoked or a method is
-     *             provoked
-     * @throws InvocationTargetException when an exception occurs by the method
-     *             or constructor
+     * @throws InstantiationException if instantiation is provoked for the private constructor
+     * @throws IllegalAccessException if instance is provoked or a method is provoked
+     * @throws InvocationTargetException when an exception occurs by the method or constructor
      */
     @Test
     public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException,
-            InstantiationException, IllegalAccessException, InvocationTargetException {
+    InstantiationException, IllegalAccessException, InvocationTargetException {
 
-        Class<?>[] classesToConstruct = {
-                MethodsGenerator.class };
+        Class<?>[] classesToConstruct = {MethodsGenerator.class };
         for (Class<?> clazz : classesToConstruct) {
             Constructor<?> constructor = clazz.getDeclaredConstructor();
             constructor.setAccessible(true);
@@ -63,27 +59,100 @@
     }
 
     /**
-     * Unit test for checking the values received from constructor, default
-     * constructor and build string formation.
+     * Unit test case for checking the parse builder and typedef constructor.
+     */
+    @Test
+    public void getParseBuilderInterfaceMethodConstructorTest() {
+        ImportInfo forSetter = new ImportInfo();
+        attrType.setDataTypeName("binary");
+        attrType.getDataTypeName();
+        attrType.setDataType(YangDataTypes.BINARY);
+        attrType.getDataType();
+        testAttr.setAttributeName("attributeTest");
+        testAttr.setAttributeType(attrType);
+        forSetter.setPkgInfo("test1/test3");
+        forSetter.setClassInfo("This class contains");
+        testAttr.setImportInfo(forSetter);
+        String parseBuilderInterface = MethodsGenerator.parseBuilderInterfaceMethodString(testAttr, "newTestName");
+        assertThat(parseBuilderInterface.contains("attributeTest") && parseBuilderInterface.contains("newTestName"),
+                is(true));
+        String parseBuilderInterfaceBuild = MethodsGenerator.parseBuilderInterfaceBuildMethodString("testname7");
+        assertThat(parseBuilderInterfaceBuild.contains("Builds object of")
+                && parseBuilderInterfaceBuild.contains("testname7"), is(true));
+        String stringTypeDef = MethodsGenerator.getTypeDefConstructor(testAttr, "Testname");
+    }
+
+    /**
+     * Unit test case for checking the values received from constructor, default constructor and build string formation.
      */
     @Test
     public void getValuesTest() {
         String stringConstructor = MethodsGenerator.getConstructorString("testname");
-        assertThat(
-                stringConstructor.contains("Construct the object of testnameImpl.")
-                        && stringConstructor.contains("@param testnameObject builder object of  testname")
-                        && stringConstructor.contains("public testnameImpl(testnameBuilder testnameObject) {"),
-                is(true));
-        String stringDefaultConstructor = MethodsGenerator.getDefaultConstructorString(
-                GeneratedFileType.BUILDER_CLASS_MASK,
-                "testname");
-        assertThat(stringDefaultConstructor.contains("Default Constructor.")
-                && stringDefaultConstructor.contains("public testnameBuilder() {")
-                && stringDefaultConstructor.contains("}"), is(true));
+        assertThat(stringConstructor.contains(UtilConstants.JAVA_DOC_CONSTRUCTOR)
+                && stringConstructor.contains(UtilConstants.JAVA_DOC_PARAM)
+                && stringConstructor.contains(UtilConstants.BUILDER_OBJECT), is(true));
+        String stringDefaultConstructor = MethodsGenerator.getDefaultConstructorString("testnameBuilder", "public");
+        assertThat(stringDefaultConstructor.contains(UtilConstants.JAVA_DOC_DEFAULT_CONSTRUCTOR)
+                && stringDefaultConstructor.contains(UtilConstants.BUILDER)
+                && stringDefaultConstructor.contains("testname"), is(true));
         String stringBuild = MethodsGenerator.getBuildString("testname");
-        assertThat(
-                stringBuild.contains("public testname build() {")
-                        && stringBuild.contains("return new testnameImpl(this);") && stringBuild.contains("}"),
-                is(true));
+        assertThat(stringBuild.contains(UtilConstants.OVERRIDE) && stringBuild.contains(UtilConstants.BUILD)
+                && stringBuild.contains(UtilConstants.RETURN), is(true));
+
     }
-}
\ No newline at end of file
+
+    /**
+     * Unit test for checking the values received for class getter, class and typedef setters with list data type.
+     */
+    @Test
+    public void getGetterSetterTest() {
+
+        ImportInfo forGetterSetter = new ImportInfo();
+        attrType.setDataTypeName("int");
+        attrType.getDataTypeName();
+        attrType.setDataType(YangDataTypes.UINT8);
+        attrType.getDataType();
+        testAttr.setAttributeName("AttributeTest1");
+        testAttr.setAttributeType(attrType);
+        forGetterSetter.setPkgInfo(null);
+        forGetterSetter.setClassInfo("This class contains");
+        testAttr.setImportInfo(forGetterSetter);
+        testAttr.setListAttr(true);
+        String getterForClass = MethodsGenerator.getGetterForClass(testAttr);
+        assertThat(getterForClass.contains(UtilConstants.GET_METHOD_PREFIX) && getterForClass.contains("List<")
+                && getterForClass.contains("attributeTest1"), is(true));
+        String setterForClass = MethodsGenerator.getSetterForClass(testAttr, "TestThis");
+        assertThat(setterForClass.contains(UtilConstants.SET_METHOD_PREFIX) && setterForClass.contains("List<")
+                && setterForClass.contains("attributeTest1"), is(true));
+        String typeDefSetter = MethodsGenerator.getSetterForTypeDefClass(testAttr);
+        assertThat(typeDefSetter.contains(UtilConstants.SET_METHOD_PREFIX) && typeDefSetter.contains("List<")
+                && typeDefSetter.contains("attributeTest1") && typeDefSetter.contains("this."), is(true));
+    }
+
+    /**
+     * Unit test case for checking the parse builder and typedef constructor with list data type.
+     */
+    @Test
+    public void getConstructorWithListTypeTest() {
+        ImportInfo forSetter = new ImportInfo();
+        attrType.setDataTypeName("binary");
+        attrType.getDataTypeName();
+        attrType.setDataType(YangDataTypes.BINARY);
+        attrType.getDataType();
+        testAttr.setAttributeName("attributeTest");
+        testAttr.setAttributeType(attrType);
+        forSetter.setPkgInfo(null);
+        forSetter.setClassInfo("This class contains");
+        testAttr.setImportInfo(forSetter);
+        testAttr.setListAttr(true);
+        String parseBuilderInterface = MethodsGenerator.parseBuilderInterfaceMethodString(testAttr, "newTestName");
+        assertThat(parseBuilderInterface.contains("attributeTest") && parseBuilderInterface.contains("List<"),
+                is(true));
+        String parseBuilderInterfaceBuild = MethodsGenerator.parseBuilderInterfaceBuildMethodString("testname7");
+        assertThat(parseBuilderInterfaceBuild.contains("Builds object of")
+                && parseBuilderInterfaceBuild.contains("testname7"), is(true));
+        String stringTypeDef = MethodsGenerator.getTypeDefConstructor(testAttr, "Testname");
+        assertThat(stringTypeDef.contains("(List<") && stringTypeDef.contains("Testname")
+                && stringTypeDef.contains(UtilConstants.THIS), is(true));
+    }
+}