b.janani | 0d4517a | 2016-02-25 12:25:55 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0f7908b | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
b.janani | 0d4517a | 2016-02-25 12:25:55 +0530 | [diff] [blame] | 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 | |
b.janani | 0d4517a | 2016-02-25 12:25:55 +0530 | [diff] [blame] | 19 | import java.lang.reflect.Constructor; |
| 20 | import java.lang.reflect.InvocationTargetException; |
| 21 | |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 22 | import org.junit.Rule; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 23 | import org.junit.Test; |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 24 | import org.junit.rules.ExpectedException; |
| 25 | import org.onosproject.yangutils.translator.exception.TranslatorException; |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 26 | import org.onosproject.yangutils.utils.io.impl.YangToJavaNamingConflictUtil; |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 27 | |
| 28 | import static org.hamcrest.core.Is.is; |
Bharat saraswal | 780eca3 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 29 | import static org.hamcrest.core.IsNot.not; |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 30 | import static org.junit.Assert.assertThat; |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 31 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase; |
| 32 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase; |
| 33 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getJavaPackageFromPackagePath; |
| 34 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getPackageDirPathFromJavaJPackage; |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 35 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage; |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 36 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getSmallCase; |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 37 | import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT_BASE_PKG; |
| 38 | import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 39 | |
b.janani | 0d4517a | 2016-02-25 12:25:55 +0530 | [diff] [blame] | 40 | /** |
| 41 | * Unit tests for java identifier syntax. |
| 42 | */ |
| 43 | public final class JavaIdentifierSyntaxTest { |
| 44 | |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 45 | @Rule |
| 46 | public ExpectedException thrown = ExpectedException.none(); |
| 47 | |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 48 | private static final String PARENT_PACKAGE = "test5/test6/test7"; |
| 49 | private static final String CHILD_PACKAGE = "test1:test2:test3"; |
| 50 | private static final String DATE1 = "2000-1-5"; |
| 51 | private static final String DATE2 = "1992-01-25"; |
| 52 | private static final String PARENT_WITH_PERIOD = "test5.test6.test7"; |
| 53 | private static final String CHILD_WITH_PERIOD = "test1.test2.test3"; |
| 54 | private static final String DATE_WITH_REV1 = "rev20000105"; |
| 55 | private static final String DATE_WITH_REV2 = "rev19920125"; |
| 56 | private static final String VERSION_NUMBER = "v1"; |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 57 | private static final String VALID_PREFIX = "123add-prefix"; |
| 58 | private static final String INVALID_PREFIX = "-*()&^&#$%"; |
| 59 | private static final String INVALID_PREFIX1 = "abc~!@#$%^&*()_+}{:<>?`1234567890-=[]''|,./SS"; |
| 60 | private static final String INVALID_NAME_SPACE_FOR_INVALID_PREFIX = "try:#test3:9case3"; |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 61 | private static final String INVALID_NAME_SPACE1 = "byte:#test2:9test3"; |
| 62 | private static final String INVALID_NAME_SPACE2 = "const:#test2://9test3"; |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 63 | private static final String INVALID_NAME_SPACE3 = "CONST:TRY://9test3"; |
| 64 | private static final String VALID_NAME_SPACE1 = "123addprefixbyte.test2.123addprefix9test3"; |
janani b | 1c6acc4 | 2016-04-15 16:18:30 +0530 | [diff] [blame] | 65 | private static final String VALID_NAME_SPACE2 = "yangautoprefixconst.test2.yangautoprefix9test3"; |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 66 | private static final String VALID_NAME_SPACE3 = "abc1234567890ssconst.test2.abc1234567890ss9test3"; |
| 67 | private static final String VALID_NAME_SPACE4 = "yangautoprefixconst.yangautoprefixtry.yangautoprefix9test3"; |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 68 | private static final String WITHOUT_CAMEL_CASE = "test-camel-case-identifier"; |
| 69 | private static final String WITH_CAMEL_CASE = "testCamelCaseIdentifier"; |
janani b | 1c6acc4 | 2016-04-15 16:18:30 +0530 | [diff] [blame] | 70 | private static final String WITHOUT_CAMEL_CASE1 = ".-_try-._-.123"; |
| 71 | private static final String WITH_CAMEL_CASE1 = "try123"; |
| 72 | private static final String WITHOUT_CAMEL_CASE2 = "_try"; |
| 73 | private static final String WITH_CAMEL_CASE2 = "yangAutoPrefixTry"; |
| 74 | private static final String WITHOUT_CAMEL_CASE3 = "-1-123g-123ga-a"; |
| 75 | private static final String WITH_CAMEL_CASE3 = "yangAutoPrefix1123G123Gaa"; |
| 76 | private static final String WITHOUT_CAMEL_CASE4 = "a-b-c-d-e-f-g-h"; |
| 77 | private static final String WITH_CAMEL_CASE4 = "aBcDeFgh"; |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 78 | private static final String WITHOUT_CAMEL_CASE5 = "TestName"; |
| 79 | private static final String WITH_CAMEL_CASE5 = "testName"; |
| 80 | private static final String WITHOUT_CAMEL_CASE6 = "TEST-NAME"; |
| 81 | private static final String WITH_CAMEL_CASE6 = "testName"; |
| 82 | private static final String WITHOUT_CAMEL_CASE7 = "TESTNAME"; |
| 83 | private static final String WITH_CAMEL_CASE7 = "testname"; |
| 84 | private static final String WITHOUT_CAMEL_CASE8 = "TE-ST-NA-ME"; |
| 85 | private static final String WITH_CAMEL_CASE8 = "teStNaMe"; |
| 86 | private static final String WITHOUT_CAMEL_CASE9 = "TEST3NAME"; |
| 87 | private static final String WITH_CAMEL_CASE9 = "test3Name"; |
| 88 | private static final String WITHOUT_CAMEL_CASE10 = "TEST3"; |
| 89 | private static final String WITH_CAMEL_CASE10 = "test3"; |
| 90 | private static final String WITHOUT_CAMEL_CASE11 = "TEST3nAMe"; |
| 91 | private static final String WITH_CAMEL_CASE11 = "test3Name"; |
| 92 | private static final String WITHOUT_CAMEL_CASE12 = "TEST3name"; |
| 93 | private static final String WITH_CAMEL_CASE12 = "test3Name"; |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 94 | private static final String WITHOUT_CAMEL_CASE13 = "t-RY"; |
| 95 | private static final String WITH_CAMEL_CASE13 = "tRy"; |
| 96 | private static final String WITHOUT_CAMEL_CASE14 = "TRY"; |
| 97 | private static final String WITH_CAMEL_CASE14 = "yangAutoPrefixTry"; |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 98 | private static final String WITHOUT_CAPITAL = "test_this"; |
| 99 | private static final String WITH_CAPITAL = "Test_this"; |
| 100 | private static final String WITH_SMALL = "test_this"; |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 101 | private static final String WITH_CAMEL_CASE_WITH_PREFIX = "123addPrefixTry"; |
| 102 | private static final String WITH_CAMEL_CASE_WITH_PREFIX1 = "abc1234567890Ss1123G123Gaa"; |
| 103 | private static YangToJavaNamingConflictUtil conflictResolver = new YangToJavaNamingConflictUtil(); |
b.janani | e6d43af | 2016-03-04 12:29:05 +0530 | [diff] [blame] | 104 | |
b.janani | 0d4517a | 2016-02-25 12:25:55 +0530 | [diff] [blame] | 105 | /** |
| 106 | * Unit test for private constructor. |
| 107 | * |
| 108 | * @throws SecurityException if any security violation is observed. |
| 109 | * @throws NoSuchMethodException if when the method is not found. |
| 110 | * @throws IllegalArgumentException if there is illegal argument found. |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 111 | * @throws InstantiationException if instantiation is provoked for the |
| 112 | * private constructor. |
| 113 | * @throws IllegalAccessException if instance is provoked or a method is |
| 114 | * provoked. |
| 115 | * @throws InvocationTargetException when an exception occurs by the method |
| 116 | * or constructor. |
b.janani | 0d4517a | 2016-02-25 12:25:55 +0530 | [diff] [blame] | 117 | */ |
b.janani | e6d43af | 2016-03-04 12:29:05 +0530 | [diff] [blame] | 118 | @Test |
b.janani | 0d4517a | 2016-02-25 12:25:55 +0530 | [diff] [blame] | 119 | public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException, |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 120 | InstantiationException, IllegalAccessException, InvocationTargetException { |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 121 | |
b.janani | 0d4517a | 2016-02-25 12:25:55 +0530 | [diff] [blame] | 122 | Class<?>[] classesToConstruct = {JavaIdentifierSyntax.class }; |
| 123 | for (Class<?> clazz : classesToConstruct) { |
| 124 | Constructor<?> constructor = clazz.getDeclaredConstructor(); |
| 125 | constructor.setAccessible(true); |
Bharat saraswal | 780eca3 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 126 | assertThat(null, not(constructor.newInstance())); |
b.janani | 0d4517a | 2016-02-25 12:25:55 +0530 | [diff] [blame] | 127 | } |
| 128 | } |
| 129 | |
| 130 | /** |
b.janani | 0d4517a | 2016-02-25 12:25:55 +0530 | [diff] [blame] | 131 | * Unit test for root package generation with revision complexity. |
| 132 | */ |
| 133 | @Test |
| 134 | public void getRootPackageTest() { |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 135 | conflictResolver.setPrefixForIdentifier(null); |
| 136 | String rootPackage = getRootPackage((byte) 1, CHILD_PACKAGE, DATE1, conflictResolver); |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 137 | assertThat(rootPackage.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER |
| 138 | + PERIOD + CHILD_WITH_PERIOD + PERIOD + DATE_WITH_REV1), is(true)); |
b.janani | 0d4517a | 2016-02-25 12:25:55 +0530 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | /** |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 142 | * Unit test for root package generation with invalid prefix. |
| 143 | */ |
| 144 | @Test |
| 145 | public void getRootPackageWithInvalidPrefix() throws TranslatorException { |
| 146 | thrown.expect(TranslatorException.class); |
| 147 | thrown.expectMessage("The given prefix in pom.xml is invalid."); |
| 148 | conflictResolver.setPrefixForIdentifier(INVALID_PREFIX); |
| 149 | String rootPackage1 = getRootPackage((byte) 1, INVALID_NAME_SPACE_FOR_INVALID_PREFIX, DATE1, conflictResolver); |
| 150 | } |
| 151 | |
| 152 | /** |
b.janani | e6d43af | 2016-03-04 12:29:05 +0530 | [diff] [blame] | 153 | * Unit test for root package generation with special characters presence. |
| 154 | */ |
| 155 | @Test |
| 156 | public void getRootPackageWithSpecialCharactersTest() { |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 157 | conflictResolver.setPrefixForIdentifier(VALID_PREFIX); |
| 158 | String rootPackage = getRootPackage((byte) 1, INVALID_NAME_SPACE1, DATE1, conflictResolver); |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 159 | assertThat(rootPackage.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER |
| 160 | + PERIOD + VALID_NAME_SPACE1 + PERIOD + DATE_WITH_REV1), is(true)); |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 161 | conflictResolver.setPrefixForIdentifier(null); |
| 162 | String rootPackage1 = getRootPackage((byte) 1, INVALID_NAME_SPACE2, DATE1, conflictResolver); |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 163 | assertThat(rootPackage1.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER |
| 164 | + PERIOD + VALID_NAME_SPACE2 + PERIOD + DATE_WITH_REV1), is(true)); |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 165 | String rootPackage2 = getRootPackage((byte) 1, INVALID_NAME_SPACE3, DATE1, conflictResolver); |
| 166 | assertThat(rootPackage2.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER |
| 167 | + PERIOD + VALID_NAME_SPACE4 + PERIOD + DATE_WITH_REV1), is(true)); |
| 168 | conflictResolver.setPrefixForIdentifier(INVALID_PREFIX1); |
| 169 | String rootPackage3 = getRootPackage((byte) 1, INVALID_NAME_SPACE2, DATE1, conflictResolver); |
| 170 | assertThat(rootPackage3.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER |
| 171 | + PERIOD + VALID_NAME_SPACE3 + PERIOD + DATE_WITH_REV1), is(true)); |
| 172 | |
b.janani | e6d43af | 2016-03-04 12:29:05 +0530 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | /** |
| 176 | * Unit test for root package generation without complexity in revision. |
b.janani | 0d4517a | 2016-02-25 12:25:55 +0530 | [diff] [blame] | 177 | */ |
| 178 | @Test |
| 179 | public void getRootPackageWithRevTest() { |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 180 | String rootPkgWithRev = getRootPackage((byte) 1, CHILD_PACKAGE, DATE2, null); |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 181 | assertThat(rootPkgWithRev.equals( |
| 182 | DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER + PERIOD + CHILD_WITH_PERIOD + PERIOD + DATE_WITH_REV2), |
b.janani | e6d43af | 2016-03-04 12:29:05 +0530 | [diff] [blame] | 183 | is(true)); |
b.janani | 0d4517a | 2016-02-25 12:25:55 +0530 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | /** |
| 187 | * Unit test for capitalizing the incoming string. |
| 188 | */ |
| 189 | @Test |
| 190 | public void getCapitalCaseTest() { |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 191 | String capitalCase = getCapitalCase(WITHOUT_CAPITAL); |
b.janani | e6d43af | 2016-03-04 12:29:05 +0530 | [diff] [blame] | 192 | assertThat(capitalCase.equals(WITH_CAPITAL), is(true)); |
b.janani | 0d4517a | 2016-02-25 12:25:55 +0530 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | /** |
| 196 | * Unit test for getting the camel case for the received string. |
| 197 | */ |
| 198 | @Test |
| 199 | public void getCamelCaseTest() { |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 200 | conflictResolver.setPrefixForIdentifier(null); |
| 201 | String camelCase = getCamelCase(WITHOUT_CAMEL_CASE, conflictResolver); |
b.janani | e6d43af | 2016-03-04 12:29:05 +0530 | [diff] [blame] | 202 | assertThat(camelCase.equals(WITH_CAMEL_CASE), is(true)); |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 203 | String camelCase1 = getCamelCase(WITHOUT_CAMEL_CASE1, conflictResolver); |
janani b | 1c6acc4 | 2016-04-15 16:18:30 +0530 | [diff] [blame] | 204 | assertThat(camelCase1.equals(WITH_CAMEL_CASE1), is(true)); |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 205 | String camelCase2 = getCamelCase(WITHOUT_CAMEL_CASE2, conflictResolver); |
janani b | 1c6acc4 | 2016-04-15 16:18:30 +0530 | [diff] [blame] | 206 | assertThat(camelCase2.equals(WITH_CAMEL_CASE2), is(true)); |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 207 | String camelCase3 = getCamelCase(WITHOUT_CAMEL_CASE3, conflictResolver); |
janani b | 1c6acc4 | 2016-04-15 16:18:30 +0530 | [diff] [blame] | 208 | assertThat(camelCase3.equals(WITH_CAMEL_CASE3), is(true)); |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 209 | String camelCase4 = getCamelCase(WITHOUT_CAMEL_CASE4, conflictResolver); |
janani b | 1c6acc4 | 2016-04-15 16:18:30 +0530 | [diff] [blame] | 210 | assertThat(camelCase4.equals(WITH_CAMEL_CASE4), is(true)); |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 211 | String camelCase5 = getCamelCase(WITHOUT_CAMEL_CASE5, conflictResolver); |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 212 | assertThat(camelCase5.equals(WITH_CAMEL_CASE5), is(true)); |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 213 | String camelCase6 = getCamelCase(WITHOUT_CAMEL_CASE6, conflictResolver); |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 214 | assertThat(camelCase6.equals(WITH_CAMEL_CASE6), is(true)); |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 215 | String camelCase7 = getCamelCase(WITHOUT_CAMEL_CASE7, conflictResolver); |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 216 | assertThat(camelCase7.equals(WITH_CAMEL_CASE7), is(true)); |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 217 | String camelCase8 = getCamelCase(WITHOUT_CAMEL_CASE8, conflictResolver); |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 218 | assertThat(camelCase8.equals(WITH_CAMEL_CASE8), is(true)); |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 219 | String camelCase9 = getCamelCase(WITHOUT_CAMEL_CASE9, conflictResolver); |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 220 | assertThat(camelCase9.equals(WITH_CAMEL_CASE9), is(true)); |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 221 | String camelCase10 = getCamelCase(WITHOUT_CAMEL_CASE10, conflictResolver); |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 222 | assertThat(camelCase10.equals(WITH_CAMEL_CASE10), is(true)); |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 223 | String camelCase11 = getCamelCase(WITHOUT_CAMEL_CASE11, conflictResolver); |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 224 | assertThat(camelCase11.equals(WITH_CAMEL_CASE11), is(true)); |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 225 | String camelCase12 = getCamelCase(WITHOUT_CAMEL_CASE12, conflictResolver); |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 226 | assertThat(camelCase12.equals(WITH_CAMEL_CASE12), is(true)); |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 227 | String camelCase13 = getCamelCase(WITHOUT_CAMEL_CASE13, conflictResolver); |
| 228 | assertThat(camelCase13.equals(WITH_CAMEL_CASE13), is(true)); |
| 229 | String camelCase14 = getCamelCase(WITHOUT_CAMEL_CASE14, conflictResolver); |
| 230 | assertThat(camelCase14.equals(WITH_CAMEL_CASE14), is(true)); |
| 231 | } |
| 232 | |
| 233 | /** |
| 234 | * Unit test for getting the camel case along with the prefix provided. |
| 235 | */ |
| 236 | @Test |
| 237 | public void getCamelCaseWithPrefixTest() { |
| 238 | |
| 239 | conflictResolver.setPrefixForIdentifier(VALID_PREFIX); |
| 240 | String camelCase = getCamelCase(WITHOUT_CAMEL_CASE2, conflictResolver); |
| 241 | assertThat(camelCase.equals(WITH_CAMEL_CASE_WITH_PREFIX), is(true)); |
| 242 | conflictResolver.setPrefixForIdentifier(INVALID_PREFIX1); |
| 243 | String camelCase2 = getCamelCase(WITHOUT_CAMEL_CASE3, conflictResolver); |
| 244 | assertThat(camelCase2.equals(WITH_CAMEL_CASE_WITH_PREFIX1), is(true)); |
| 245 | } |
| 246 | |
| 247 | /** |
| 248 | * Unit test for getting the camel case along with the invalid prefix provided. |
| 249 | */ |
| 250 | @Test |
| 251 | public void getCamelCaseWithInvalidPrefixTest() throws TranslatorException { |
| 252 | |
| 253 | thrown.expect(TranslatorException.class); |
| 254 | thrown.expectMessage("The given prefix in pom.xml is invalid."); |
| 255 | conflictResolver.setPrefixForIdentifier(INVALID_PREFIX); |
| 256 | String camelCase = getCamelCase(WITHOUT_CAMEL_CASE3, conflictResolver); |
b.janani | 0d4517a | 2016-02-25 12:25:55 +0530 | [diff] [blame] | 257 | } |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 258 | |
| 259 | /** |
| 260 | * Unit test for getting the camel case for the received string. |
| 261 | */ |
| 262 | @Test |
| 263 | public void getSmallCaseTest() { |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 264 | String smallCase = getSmallCase(WITHOUT_CAPITAL); |
| 265 | assertThat(smallCase.equals(WITH_SMALL), is(true)); |
| 266 | } |
| 267 | |
| 268 | /** |
| 269 | * Unit test for getting the camel case for the received string. |
| 270 | */ |
| 271 | @Test |
| 272 | public void getPackageFromPathTest() { |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 273 | String pkg = getJavaPackageFromPackagePath(PARENT_PACKAGE); |
| 274 | assertThat(pkg.equals(PARENT_WITH_PERIOD), is(true)); |
| 275 | } |
| 276 | |
| 277 | /** |
| 278 | * Unit test for getting the camel case for the received string. |
| 279 | */ |
| 280 | @Test |
| 281 | public void getPathFromPackageTest() { |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 282 | String path = getPackageDirPathFromJavaJPackage(PARENT_WITH_PERIOD); |
| 283 | assertThat(path.equals(PARENT_PACKAGE), is(true)); |
| 284 | } |
b.janani | 0d4517a | 2016-02-25 12:25:55 +0530 | [diff] [blame] | 285 | } |