b.janani | 0d4517a | 2016-02-25 12:25:55 +0530 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2016 Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package org.onosproject.yangutils.translator.tojava.utils; |
| 18 | |
| 19 | import org.junit.Test; |
| 20 | import static org.junit.Assert.assertNotNull; |
| 21 | import static org.hamcrest.core.Is.is; |
| 22 | import static org.junit.Assert.assertThat; |
| 23 | import java.lang.reflect.Constructor; |
| 24 | import java.lang.reflect.InvocationTargetException; |
| 25 | |
| 26 | /** |
| 27 | * Unit tests for java identifier syntax. |
| 28 | */ |
| 29 | public final class JavaIdentifierSyntaxTest { |
| 30 | |
| 31 | /** |
| 32 | * Unit test for private constructor. |
| 33 | * |
| 34 | * @throws SecurityException if any security violation is observed. |
| 35 | * @throws NoSuchMethodException if when the method is not found. |
| 36 | * @throws IllegalArgumentException if there is illegal argument found. |
| 37 | * @throws InstantiationException if instantiation is provoked for the private constructor. |
| 38 | * @throws IllegalAccessException if instance is provoked or a method is provoked. |
| 39 | * @throws InvocationTargetException when an exception occurs by the method or constructor. |
| 40 | */ |
| 41 | public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException, |
| 42 | InstantiationException, IllegalAccessException, InvocationTargetException { |
| 43 | Class<?>[] classesToConstruct = {JavaIdentifierSyntax.class }; |
| 44 | for (Class<?> clazz : classesToConstruct) { |
| 45 | Constructor<?> constructor = clazz.getDeclaredConstructor(); |
| 46 | constructor.setAccessible(true); |
| 47 | assertNotNull(constructor.newInstance()); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Unit test for testing the package path generation from a parent package. |
| 53 | */ |
| 54 | @Test |
| 55 | public void getPackageFromParentTest() { |
| 56 | String pkgFromParent = JavaIdentifierSyntax.getPackageFromParent("test5.test6.test7", "test1:test2:test3"); |
| 57 | assertThat(pkgFromParent.equals("test5.test6.test7.test1.test2.test3"), is(true)); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Unit test for root package generation with revision complexity. |
| 62 | */ |
| 63 | @Test |
| 64 | public void getRootPackageTest() { |
| 65 | |
| 66 | String rootPackage = JavaIdentifierSyntax.getRootPackage((byte) 0, "test1:test2:test3", "5-1-2000"); |
| 67 | assertThat(rootPackage.equals("org.onosproject.yang.gen.v0.test1.test2.test3.rev05012000"), is(true)); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Unit test for root package generation without revision complexity. |
| 72 | */ |
| 73 | @Test |
| 74 | public void getRootPackageWithRevTest() { |
| 75 | |
| 76 | String rootPkgWithRev = JavaIdentifierSyntax.getRootPackage((byte) 0, "test1:test2:test3", "25-01-1992"); |
| 77 | assertThat(rootPkgWithRev.equals("org.onosproject.yang.gen.v0.test1.test2.test3.rev25011992"), is(true)); |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Unit test for capitalizing the incoming string. |
| 82 | */ |
| 83 | @Test |
| 84 | public void getCapitalCaseTest() { |
| 85 | |
| 86 | String capitalCase = JavaIdentifierSyntax.getCaptialCase("test_this"); |
| 87 | assertThat(capitalCase.equals("Test_this"), is(true)); |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Unit test for getting the camel case for the received string. |
| 92 | */ |
| 93 | @Test |
| 94 | public void getCamelCaseTest() { |
| 95 | String camelCase = JavaIdentifierSyntax.getCamelCase("test-camel-case-identifier"); |
| 96 | assertThat(camelCase.equals("testCamelCaseIdentifier"), is(true)); |
| 97 | } |
| 98 | } |