Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix JavaBeans naming convention #1023 #1030

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/core/lombok/core/handlers/HandlerUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -420,11 +420,11 @@ public static String buildAccessorName(String prefix, String suffix) {

char first = suffix.charAt(0);
if (Character.isLowerCase(first)) {
boolean useUpperCase = suffix.length() > 2 &&
boolean useLowerCase = suffix.length() >= 2 &&
(Character.isTitleCase(suffix.charAt(1)) || Character.isUpperCase(suffix.charAt(1)));
suffix = String.format("%s%s",
useUpperCase ? Character.toUpperCase(first) : Character.toTitleCase(first),
suffix.subSequence(1, suffix.length()));
useLowerCase ? Character.toLowerCase(first) : Character.toUpperCase(first),
suffix.subSequence(1, suffix.length()));
}
return String.format("%s%s", prefix, suffix);
}
Expand Down
2 changes: 1 addition & 1 deletion test/core/src/lombok/core/RunCoreTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
import org.junit.runners.Suite.SuiteClasses;

@RunWith(Suite.class)
@SuiteClasses({TestSingulars.class})
@SuiteClasses({TestSingulars.class, TestHandlerUtil.class})
public class RunCoreTests {
}
54 changes: 54 additions & 0 deletions test/core/src/lombok/core/TestHandlerUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (C) 2015 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package lombok.core;

import static lombok.core.handlers.HandlerUtil.buildAccessorName;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import org.junit.Test;

public class TestHandlerUtil {

@Test
public void testBuildAccessorName() {

/* normal cases */
assertEquals("setFieldName", buildAccessorName("set", "fieldName"));
assertEquals("setI", buildAccessorName("set", "i"));
assertEquals("setI", buildAccessorName("set", "I"));
assertEquals("setUrl", buildAccessorName("set", "Url"));

/* when the second character is uppercase, leave the first character unchanged */

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can also be shifted to a new method
testBuildAccessorNameWithUpperCaseSecondCharacterInSuffix()

assertEquals("setURL", buildAccessorName("set", "URL"));
assertEquals("setaI", buildAccessorName("set", "aI"));
assertEquals("setaIr", buildAccessorName("set", "aIr"));

/* handle empty string cases */

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a good practice to have a separate test for exceptions. Can you please take this try-catch section, and put it in a new test?

To verify if the correct exception was thrown or not, we state the expected Exception class in the @test annotation e.g
If we expect and ABCException to be thrown, we can specify it as

@test(expected = ABCException.class)

Further Reading: Test Annotation

assertEquals("URL", buildAccessorName("", "URL"));
assertEquals("set", buildAccessorName("set", ""));
try{
buildAccessorName("set", null);
buildAccessorName(null, "something");
fail("it's not supposed to be null");
}catch(NullPointerException e){}
}
}