[ONOS-4350] Inter Jar dependency implementation and code restructuring.

Change-Id: Iacac75e4187aed93ce1754c170a9c19707e5b8c3
diff --git a/plugin/src/test/java/org/onosproject/yangutils/parser/impl/parseutils/AugmentListnerUtilTest.java b/plugin/src/test/java/org/onosproject/yangutils/parser/impl/parseutils/AugmentListnerUtilTest.java
new file mode 100644
index 0000000..3cf6eaa
--- /dev/null
+++ b/plugin/src/test/java/org/onosproject/yangutils/parser/impl/parseutils/AugmentListnerUtilTest.java
@@ -0,0 +1,320 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.parser.impl.parseutils;
+
+import org.junit.Test;
+import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+import static org.onosproject.yangutils.parser.impl.parserutils.AugmentListenerUtil.clearOccurrenceCount;
+import static org.onosproject.yangutils.parser.impl.parserutils.AugmentListenerUtil.createValidNameForAugment;
+import static org.onosproject.yangutils.parser.impl.parserutils.AugmentListenerUtil.getAugmentJavaFileNameList;
+import static org.onosproject.yangutils.parser.impl.parserutils.AugmentListenerUtil.updateNameWhenHasMultipleOuccrrence;
+
+/**
+ * Unit test case for augment listener utility.
+ */
+public class AugmentListnerUtilTest {
+
+    private static final String TEST1 = "test1Node";
+    private static final String PARENT_PREFIX = "if";
+    private static final String NODE_PREFIX = "rf";
+
+    private static final String TEST1_AUGMENTED_NAME_WITHOUT_PREFIX = "AugmentedTest1Node";
+    private static final String TEST1_AUGMENTED_NAME_WITHOUT_PREFIX_MULTI1 = "AugmentedTest1Node1";
+    private static final String TEST1_AUGMENTED_NAME_WITHOUT_PREFIX_MULTI2 = "AugmentedTest1Node2";
+    private static final String TEST1_AUGMENTED_NAME_WITHOUT_PREFIX_MULTI3 = "AugmentedTest1Node3";
+
+    private static final String TEST1_AUGMENTED_NAME_WITH_PREFIX = "AugmentedRfTest1Node";
+    private static final String TEST1_AUGMENTED_NAME_WITH_PREFIX_MULTI1 = "AugmentedRfTest1Node1";
+    private static final String TEST1_AUGMENTED_NAME_WITH_PREFIX_MULTI2 = "AugmentedRfTest1Node2";
+    private static final String TEST1_AUGMENTED_NAME_WITH_PREFIX_MULTI3 = "AugmentedRfTest1Node3";
+
+    private static String testString = "";
+
+    /**
+     * Unit test case when parent's prefix is present and one occurrence of augment node to update same target node.
+     */
+    @Test
+    public void testForAugmentNameWhenOneOuccrrenceWithParentPrefix() {
+        clearData();
+        testString = createValidNameForAugment(getStubNodeIdetifierWithParentPrefix(),
+                isPrefixPresent(getStubNodeIdetifierWithParentPrefix()));
+        assertThat(true, is(testString.equals(TEST1_AUGMENTED_NAME_WITHOUT_PREFIX)));
+    }
+
+    /**
+     * Unit test case when no prefix and one occurrence of augment node to update same target node.
+     */
+    @Test
+    public void testForAugmentNameWhenOneOuccrrenceWithNoPrefix() {
+        clearData();
+        testString = createValidNameForAugment(getStubNodeIdetifierWithNoPrefix(),
+                isPrefixPresent(getStubNodeIdetifierWithNoPrefix()));
+        assertThat(true, is(testString.equals(TEST1_AUGMENTED_NAME_WITHOUT_PREFIX)));
+    }
+
+    /**
+     * Unit test case when different prefix then parent is present and
+     * one occurrence of augment node to update same target node.
+     */
+    @Test
+    public void testForAugmentNameWhenOneOuccrrenceWithDiffPrefix() {
+        clearData();
+        testString = createValidNameForAugment(getStubNodeIdetifierWithDiffPrefix(),
+                isPrefixPresent(getStubNodeIdetifierWithDiffPrefix()));
+        assertThat(true, is(testString.equals(TEST1_AUGMENTED_NAME_WITH_PREFIX)));
+    }
+
+    /**
+     * Unit test case when parent's prefix is present and two occurrence of augment node to update
+     * same target node is present.
+     */
+    @Test
+    public void testForAugmentNameWhenTwoOuccrrenceWithParentPrefix() {
+        clearData();
+
+        createValidNameForAugment(getStubNodeIdetifierWithParentPrefix(),
+                isPrefixPresent(getStubNodeIdetifierWithParentPrefix()));
+        testString = updateNameWhenHasMultipleOuccrrence(getStubNodeIdetifierWithParentPrefix(),
+                isPrefixPresent(getStubNodeIdetifierWithParentPrefix()));
+
+        assertThat(true, is(testString.equals(TEST1_AUGMENTED_NAME_WITHOUT_PREFIX_MULTI2)));
+    }
+
+    /**
+     * Unit test case when no prefix and two occurrence of augment node to update
+     * same target node is present.
+     */
+    @Test
+    public void testForAugmentNameWhenTwoOuccrrenceWithNoPrefix() {
+        clearData();
+
+        createValidNameForAugment(getStubNodeIdetifierWithNoPrefix(),
+                isPrefixPresent(getStubNodeIdetifierWithNoPrefix()));
+        testString = updateNameWhenHasMultipleOuccrrence(getStubNodeIdetifierWithNoPrefix(),
+                isPrefixPresent(getStubNodeIdetifierWithNoPrefix()));
+        assertThat(true, is(testString.equals(TEST1_AUGMENTED_NAME_WITHOUT_PREFIX_MULTI2)));
+    }
+
+    /**
+     * Unit test case when different prefix then parent is present and
+     * two occurrence of augment node to update same target node is present.
+     */
+    @Test
+    public void testForAugmentNameWhenTwoOuccrrenceWithDiffPrefix() {
+        clearData();
+
+        createValidNameForAugment(getStubNodeIdetifierWithDiffPrefix(),
+                isPrefixPresent(getStubNodeIdetifierWithDiffPrefix()));
+        testString = updateNameWhenHasMultipleOuccrrence(getStubNodeIdetifierWithDiffPrefix(),
+                isPrefixPresent(getStubNodeIdetifierWithDiffPrefix()));
+        assertThat(true, is(testString.equals(TEST1_AUGMENTED_NAME_WITH_PREFIX_MULTI2)));
+    }
+
+    /**
+     * Unit test case when parent prefix and three occurrence of augment node to update
+     * same target node is present.
+     */
+    @Test
+    public void testForAugmentNameWhenThreeOuccrrenceWithParentPrefix() {
+        clearData();
+
+        createValidNameForAugment(getStubNodeIdetifierWithParentPrefix(),
+                isPrefixPresent(getStubNodeIdetifierWithParentPrefix()));
+        updateNameWhenHasMultipleOuccrrence(getStubNodeIdetifierWithParentPrefix(),
+                isPrefixPresent(getStubNodeIdetifierWithParentPrefix()));
+
+        testString = updateNameWhenHasMultipleOuccrrence(getStubNodeIdetifierWithParentPrefix(),
+                isPrefixPresent(getStubNodeIdetifierWithParentPrefix()));
+        assertThat(true, is(testString.equals(TEST1_AUGMENTED_NAME_WITHOUT_PREFIX_MULTI3)));
+    }
+
+    /**
+     * Unit test case when no prefix and three occurrence of augment node to update
+     * same target node is present.
+     */
+    @Test
+    public void testForAugmentNameWhenThreeOuccrrenceNoPrefix() {
+        clearData();
+
+        createValidNameForAugment(getStubNodeIdetifierWithNoPrefix(),
+                isPrefixPresent(getStubNodeIdetifierWithNoPrefix()));
+        updateNameWhenHasMultipleOuccrrence(getStubNodeIdetifierWithNoPrefix(),
+                isPrefixPresent(getStubNodeIdetifierWithNoPrefix()));
+
+        testString = updateNameWhenHasMultipleOuccrrence(getStubNodeIdetifierWithNoPrefix(),
+                isPrefixPresent(getStubNodeIdetifierWithNoPrefix()));
+        assertThat(true, is(testString.equals(TEST1_AUGMENTED_NAME_WITHOUT_PREFIX_MULTI3)));
+    }
+
+    /**
+     * Unit test case when different prefix and three occurrence of augment node to update
+     * same target node is present.
+     */
+    @Test
+    public void testForAugmentNameWhenThreeOuccrrenceWithDiffPrefix() {
+        clearData();
+
+        createValidNameForAugment(getStubNodeIdetifierWithDiffPrefix(),
+                isPrefixPresent(getStubNodeIdetifierWithDiffPrefix()));
+        updateNameWhenHasMultipleOuccrrence(getStubNodeIdetifierWithDiffPrefix(),
+                isPrefixPresent(getStubNodeIdetifierWithDiffPrefix()));
+
+        testString = updateNameWhenHasMultipleOuccrrence(getStubNodeIdetifierWithDiffPrefix(),
+                isPrefixPresent(getStubNodeIdetifierWithDiffPrefix()));
+        assertThat(true, is(testString.equals(TEST1_AUGMENTED_NAME_WITH_PREFIX_MULTI3)));
+    }
+
+    /**
+     * Unit test case for when three occurrence is there and parent prefix is present,
+     * all the names need to be updated in list.
+     */
+    @Test
+    public void testForPreviousNamesGotUpdatedWhenParentPrefix() {
+        clearData();
+
+        createValidNameForAugment(getStubNodeIdetifierWithParentPrefix(),
+                isPrefixPresent(getStubNodeIdetifierWithParentPrefix()));
+        updateNameWhenHasMultipleOuccrrence(getStubNodeIdetifierWithParentPrefix(),
+                isPrefixPresent(getStubNodeIdetifierWithParentPrefix()));
+        updateNameWhenHasMultipleOuccrrence(getStubNodeIdetifierWithParentPrefix(),
+                isPrefixPresent(getStubNodeIdetifierWithParentPrefix()));
+
+        testString = getAugmentJavaFileNameList().get(0);
+        assertThat(true, is(testString.equals(TEST1_AUGMENTED_NAME_WITHOUT_PREFIX_MULTI1)));
+
+        testString = getAugmentJavaFileNameList().get(1);
+        assertThat(true, is(testString.equals(TEST1_AUGMENTED_NAME_WITHOUT_PREFIX_MULTI2)));
+
+        testString = getAugmentJavaFileNameList().get(2);
+        assertThat(true, is(testString.equals(TEST1_AUGMENTED_NAME_WITHOUT_PREFIX_MULTI3)));
+    }
+
+    /**
+     * Unit test case for when three occurrence is there and no prefix is present,
+     * all the names need to be updated in list.
+     */
+    @Test
+    public void testForPreviousNamesGotUpdatedWhenNoPrefix() {
+        clearData();
+
+        createValidNameForAugment(getStubNodeIdetifierWithNoPrefix(),
+                isPrefixPresent(getStubNodeIdetifierWithNoPrefix()));
+        updateNameWhenHasMultipleOuccrrence(getStubNodeIdetifierWithNoPrefix(),
+                isPrefixPresent(getStubNodeIdetifierWithNoPrefix()));
+        updateNameWhenHasMultipleOuccrrence(getStubNodeIdetifierWithNoPrefix(),
+                isPrefixPresent(getStubNodeIdetifierWithNoPrefix()));
+
+        testString = getAugmentJavaFileNameList().get(0);
+        assertThat(true, is(testString.equals(TEST1_AUGMENTED_NAME_WITHOUT_PREFIX_MULTI1)));
+
+        testString = getAugmentJavaFileNameList().get(1);
+        assertThat(true, is(testString.equals(TEST1_AUGMENTED_NAME_WITHOUT_PREFIX_MULTI2)));
+
+        testString = getAugmentJavaFileNameList().get(2);
+        assertThat(true, is(testString.equals(TEST1_AUGMENTED_NAME_WITHOUT_PREFIX_MULTI3)));
+    }
+
+    /**
+     * Unit test case for when three occurrence is there and different prefix is present,
+     * all the names need to be updated in list.
+     */
+    @Test
+    public void testForPreviousNamesGotUpdatedWhenDifferentPrefix() {
+        clearData();
+
+        createValidNameForAugment(getStubNodeIdetifierWithDiffPrefix(),
+                isPrefixPresent(getStubNodeIdetifierWithDiffPrefix()));
+        updateNameWhenHasMultipleOuccrrence(getStubNodeIdetifierWithDiffPrefix(),
+                isPrefixPresent(getStubNodeIdetifierWithDiffPrefix()));
+        updateNameWhenHasMultipleOuccrrence(getStubNodeIdetifierWithDiffPrefix(),
+                isPrefixPresent(getStubNodeIdetifierWithDiffPrefix()));
+
+        testString = getAugmentJavaFileNameList().get(0);
+        assertThat(true, is(testString.equals(TEST1_AUGMENTED_NAME_WITH_PREFIX_MULTI1)));
+
+        testString = getAugmentJavaFileNameList().get(1);
+        assertThat(true, is(testString.equals(TEST1_AUGMENTED_NAME_WITH_PREFIX_MULTI2)));
+
+        testString = getAugmentJavaFileNameList().get(2);
+        assertThat(true, is(testString.equals(TEST1_AUGMENTED_NAME_WITH_PREFIX_MULTI3)));
+    }
+
+    /**
+     * Returns stub node identifier when parent prefix is used.
+     *
+     * @param name name of node
+     * @param prefix prefix of node
+     * @return node identifier for node
+     */
+    private YangNodeIdentifier getStubNodeIdetifierWithParentPrefix() {
+        YangNodeIdentifier nodeId = new YangNodeIdentifier();
+        nodeId.setName(TEST1);
+        nodeId.setPrefix(PARENT_PREFIX);
+        return nodeId;
+    }
+
+    /**
+     * Returns stub node identifier when no prefix is used.
+     *
+     * @param name name of node
+     * @param prefix prefix of node
+     * @return node identifier for node
+     */
+    private YangNodeIdentifier getStubNodeIdetifierWithNoPrefix() {
+        YangNodeIdentifier nodeId = new YangNodeIdentifier();
+        nodeId.setName(TEST1);
+        nodeId.setPrefix(null);
+        return nodeId;
+    }
+
+    /**
+     * Returns stub node identifier when different prefix is used.
+     *
+     * @param name name of node
+     * @param prefix prefix of node
+     * @return node identifier for node
+     */
+    private YangNodeIdentifier getStubNodeIdetifierWithDiffPrefix() {
+        YangNodeIdentifier nodeId = new YangNodeIdentifier();
+        nodeId.setName(TEST1);
+        nodeId.setPrefix(NODE_PREFIX);
+        return nodeId;
+    }
+
+    /**
+     * Returns true if a prefix is present and it is not equals to parents prefix.
+     *
+     * @param nodeId YANG node identifier
+     * @param parentsPrefix parent's prefix
+     * @return true if a prefix is present and it is not equals to parents prefix
+     */
+    private static boolean isPrefixPresent(YangNodeIdentifier nodeId) {
+        return nodeId.getPrefix() != null && nodeId.getPrefix() != PARENT_PREFIX;
+    }
+
+    /**
+     * Clears list of names and occurrence count after each test case.
+     */
+    private void clearData() {
+        getAugmentJavaFileNameList().clear();
+        clearOccurrenceCount();
+    }
+
+}
diff --git a/plugin/src/test/java/org/onosproject/yangutils/parser/impl/parseutils/ListenerErrorMessageConstructionTest.java b/plugin/src/test/java/org/onosproject/yangutils/parser/impl/parseutils/ListenerErrorMessageConstructionTest.java
new file mode 100644
index 0000000..bcfaf20
--- /dev/null
+++ b/plugin/src/test/java/org/onosproject/yangutils/parser/impl/parseutils/ListenerErrorMessageConstructionTest.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.parser.impl.parseutils;
+
+import org.junit.Test;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+import static org.onosproject.yangutils.datamodel.utils.YangConstructType.CONTACT_DATA;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
+
+/**
+ * Test case for testing listener error message construction util.
+ */
+public class ListenerErrorMessageConstructionTest {
+
+    /**
+     * Checks for error message construction with parsable data type name.
+     */
+    @Test
+    public void checkErrorMsgConstructionWithName() {
+
+        // Create an test error message
+        String testErrorMessage = constructListenerErrorMessage(INVALID_HOLDER, CONTACT_DATA, "Test Instance", ENTRY);
+
+        // Check message.
+        assertThat(testErrorMessage, is("Internal parser error detected: Invalid holder for contact "
+                + "\"Test Instance\" before processing."));
+    }
+
+    /**
+     * Checks for error message construction without parsable data type name.
+     */
+    @Test
+    public void checkErrorMsgConstructionWithoutName() {
+
+        // Create an test error message
+        String testErrorMessage = constructListenerErrorMessage(INVALID_HOLDER, CONTACT_DATA, "Test Instance", ENTRY);
+
+        // Check message.
+        assertThat(testErrorMessage,
+                   is("Internal parser error detected: Invalid holder for contact \"Test Instance\""
+                           + " before processing."));
+    }
+
+    /**
+     * Checks for extended error message construction with parsable data type
+     * name.
+     */
+    @Test
+    public void checkExtendedErrorMsgConstructionWithName() {
+
+        // Create an test error message
+        String testErrorMessage = constructExtendedListenerErrorMessage(INVALID_HOLDER, CONTACT_DATA,
+                                                                        "Test Instance", ENTRY,
+                                                                        "Extended Information");
+
+        // Check message.
+        assertThat(testErrorMessage,
+                   is("Internal parser error detected: Invalid holder for contact \"Test Instance\""
+                           + " before processing.\n" + "Error Information: Extended Information"));
+    }
+
+    /**
+     * Checks for extended error message construction without parsable data type
+     * name.
+     */
+    @Test
+    public void checkExtendedErrorMsgConstructionWithoutName() {
+
+        // Create an test error message
+        String testErrorMessage = constructExtendedListenerErrorMessage(INVALID_HOLDER, CONTACT_DATA, "", ENTRY,
+                                                                        "Extended Information");
+
+        // Check message.
+        assertThat(testErrorMessage, is("Internal parser error detected: Invalid holder for contact"
+                + " before processing.\n" + "Error Information: Extended Information"));
+    }
+}
diff --git a/plugin/src/test/java/org/onosproject/yangutils/parser/impl/parseutils/ListenerUtilTest.java b/plugin/src/test/java/org/onosproject/yangutils/parser/impl/parseutils/ListenerUtilTest.java
new file mode 100644
index 0000000..c29b126
--- /dev/null
+++ b/plugin/src/test/java/org/onosproject/yangutils/parser/impl/parseutils/ListenerUtilTest.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.parser.impl.parseutils;
+
+import java.io.IOException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
+
+/**
+ * Test case for testing listener util.
+ */
+public class ListenerUtilTest {
+
+    @Rule
+    public ExpectedException thrown = ExpectedException.none();
+
+    private final YangUtilsParserManager manager = new YangUtilsParserManager();
+
+    /**
+     * Checks whether exception is thrown when identifier starts with xml.
+     */
+    @Test
+    public void validateIdentifierStartsWithXml() throws IOException {
+        thrown.expect(ParserException.class);
+        thrown.expectMessage("YANG file error : module identifier xMlTest must not start" +
+                " with (('X'|'x') ('M'|'m') ('L'|'l'))");
+        manager.getDataModel("src/test/resources/InValidIdentifierXML.yang");
+    }
+}
diff --git a/plugin/src/test/java/org/onosproject/yangutils/parser/impl/parseutils/ListenerValidationTest.java b/plugin/src/test/java/org/onosproject/yangutils/parser/impl/parseutils/ListenerValidationTest.java
new file mode 100644
index 0000000..ce347d6
--- /dev/null
+++ b/plugin/src/test/java/org/onosproject/yangutils/parser/impl/parseutils/ListenerValidationTest.java
@@ -0,0 +1,112 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.parser.impl.parseutils;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.onosproject.yangutils.datamodel.YangRevision;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.TreeWalkListener;
+
+import static org.onosproject.yangutils.datamodel.utils.YangConstructType.YANGBASE_DATA;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsEmpty;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
+
+/**
+ * Test case for testing listener validation util.
+ */
+public class ListenerValidationTest {
+
+    @Rule
+    public ExpectedException thrown = ExpectedException.none();
+
+    /**
+     * Checks for exception in case parsable stack is empty while validating for
+     * not empty scenario.
+     */
+    @Test
+    public void validateStackIsNotEmptyForEmptyStack() {
+
+        String expectedError = constructListenerErrorMessage(MISSING_HOLDER, YANGBASE_DATA, "", EXIT);
+
+        // Get the exception occurred during parsing.
+        thrown.expect(ParserException.class);
+        thrown.expectMessage(expectedError);
+
+        // Create test walker and assign test error to it.
+        TreeWalkListener testWalker = new TreeWalkListener();
+
+        checkStackIsNotEmpty(testWalker, MISSING_HOLDER, YANGBASE_DATA, "", EXIT);
+    }
+
+    /**
+     * Checks if there is no exception in case parsable stack is not empty while
+     * validating for not empty scenario.
+     */
+    @Test
+    public void validateStackIsNotEmptyForNonEmptyStack() {
+
+        // Create test walker and assign test error to it.
+        TreeWalkListener testWalker = new TreeWalkListener();
+
+        // Create a temporary node of parsable.
+        YangRevision tmpNode = new YangRevision();
+        testWalker.getParsedDataStack().push(tmpNode);
+
+        checkStackIsNotEmpty(testWalker, MISSING_HOLDER, YANGBASE_DATA, "", EXIT);
+    }
+
+    /**
+     * Checks for exception in case parsable stack is not empty while validating
+     * for empty scenario.
+     */
+    @Test
+    public void validateStackIsEmptyForNonEmptyStack() {
+
+        String expectedError = constructListenerErrorMessage(MISSING_HOLDER, YANGBASE_DATA, "", EXIT);
+
+        // Get the exception occurred during parsing.
+        thrown.expect(ParserException.class);
+        thrown.expectMessage(expectedError);
+
+        // Create test walker and assign test error to it.
+        TreeWalkListener testWalker = new TreeWalkListener();
+
+        // Create a temporary node of parsable.
+        YangRevision tmpNode = new YangRevision();
+        testWalker.getParsedDataStack().push(tmpNode);
+
+        checkStackIsEmpty(testWalker, MISSING_HOLDER, YANGBASE_DATA, "", EXIT);
+    }
+
+    /**
+     * Checks if there is no exception in case parsable stack is empty while
+     * validating for empty scenario.
+     */
+    @Test
+    public void validateStackIsEmptyForEmptyStack() {
+
+        // Create test walker and assign test error to it.
+        TreeWalkListener testWalker = new TreeWalkListener();
+
+        checkStackIsEmpty(testWalker, MISSING_HOLDER, YANGBASE_DATA, "", EXIT);
+    }
+}
diff --git a/plugin/src/test/java/org/onosproject/yangutils/parser/impl/parseutils/ParseTreeErrorListenerTest.java b/plugin/src/test/java/org/onosproject/yangutils/parser/impl/parseutils/ParseTreeErrorListenerTest.java
new file mode 100644
index 0000000..4489e77
--- /dev/null
+++ b/plugin/src/test/java/org/onosproject/yangutils/parser/impl/parseutils/ParseTreeErrorListenerTest.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.parser.impl.parseutils;
+
+import org.antlr.v4.runtime.ANTLRFileStream;
+import org.antlr.v4.runtime.ANTLRInputStream;
+import org.antlr.v4.runtime.CommonTokenStream;
+import org.antlr.v4.runtime.tree.ParseTree;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangLexer;
+import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.CustomExceptionMatcher;
+import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
+import org.onosproject.yangutils.parser.impl.parserutils.ParseTreeErrorListener;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * Test case for testing parse tree error listener.
+ */
+public class ParseTreeErrorListenerTest {
+
+    YangUtilsParserManager manager = new YangUtilsParserManager();
+    File file;
+    BufferedWriter out;
+
+    @Rule
+    public ExpectedException thrown = ExpectedException.none();
+
+    /**
+     * Checks that no exception is generated for YANG file with valid syntax.
+     */
+    @Test
+    public void checkValidYangFileForNoSyntaxError() throws IOException {
+
+        ANTLRInputStream input = new ANTLRFileStream("src/test/resources/YangFileWithoutSyntaxError.yang");
+
+        // Create a lexer that feeds off of input char stream.
+        GeneratedYangLexer lexer = new GeneratedYangLexer(input);
+        // Create a buffer of tokens pulled from the lexer.
+        CommonTokenStream tokens = new CommonTokenStream(lexer);
+        // Create a parser that feeds off the tokens buffer.
+        GeneratedYangParser parser = new GeneratedYangParser(tokens);
+        // Remove console error listener.
+        parser.removeErrorListeners();
+        // Create instance of customized error listener.
+        ParseTreeErrorListener parseTreeErrorListener = new ParseTreeErrorListener();
+        // Add customized error listener to catch errors during parsing.
+        parser.addErrorListener(parseTreeErrorListener);
+        // Begin parsing YANG file and generate parse tree.
+        ParseTree tree = parser.yangfile();
+    }
+
+    /**
+     * Checks that exception is generated for YANG file with invalid syntax.
+     */
+    @Test
+    public void checkInvalidYangFileForSyntaxError() throws IOException {
+
+        // Get the exception occurred during parsing.
+        thrown.expect(ParserException.class);
+        thrown.expect(CustomExceptionMatcher.errorLocation(3, 0));
+        thrown.expectMessage("no viable alternative at input 'yang-version 1\\nnamespace'");
+
+        ANTLRInputStream input = new ANTLRFileStream("src/test/resources/YangFileWithSyntaxError.yang");
+
+        // Create a lexer that feeds off of input char stream.
+        GeneratedYangLexer lexer = new GeneratedYangLexer(input);
+        // Create a buffer of tokens pulled from the lexer.
+        CommonTokenStream tokens = new CommonTokenStream(lexer);
+        // Create a parser that feeds off the tokens buffer.
+        GeneratedYangParser parser = new GeneratedYangParser(tokens);
+        // Remove console error listener.
+        parser.removeErrorListeners();
+        // Create instance of customized error listener.
+        ParseTreeErrorListener parseTreeErrorListener = new ParseTreeErrorListener();
+        // Add customized error listener to catch errors during parsing.
+        parser.addErrorListener(parseTreeErrorListener);
+        // Begin parsing YANG file and generate parse tree.
+        ParseTree tree = parser.yangfile();
+    }
+}
\ No newline at end of file