-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix edge case of getter/setter naming when second char is uppercase
A little known part of the been spec, since a getter/setter with a capital letter in second position indicates that the first char is also a capital. If the first char is in fact not a capital, then it needs to be lowercase in the getter/setter also. See also: * https://stackoverflow.com/questions/8969112/confused-about-naming-of-javabean-properties-with-respect-to-getters-and-setter * FasterXML/jackson-databind#653 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=322223 Fixes #756
- Loading branch information
1 parent
da3e8e2
commit e86db10
Showing
2 changed files
with
76 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
jsonschema2pojo-core/src/test/java/org/jsonschema2pojo/util/NameHelperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* Copyright © 2010-2017 Nokia | ||
* | ||
* 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.jsonschema2pojo.util; | ||
|
||
import static org.hamcrest.Matchers.*; | ||
import static org.junit.Assert.*; | ||
|
||
import org.jsonschema2pojo.DefaultGenerationConfig; | ||
import org.junit.Test; | ||
|
||
import com.fasterxml.jackson.databind.node.JsonNodeFactory; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
import com.sun.codemodel.JCodeModel; | ||
|
||
public class NameHelperTest { | ||
|
||
private static final ObjectNode NODE = JsonNodeFactory.instance.objectNode(); | ||
|
||
private final NameHelper nameHelper = new NameHelper(new DefaultGenerationConfig()); | ||
|
||
@Test | ||
public void testGetterNamedCorrectly() { | ||
assertThat(nameHelper.getGetterName("foo", new JCodeModel().BOOLEAN, NODE), is("isFoo")); | ||
assertThat(nameHelper.getGetterName("foo", new JCodeModel().INT, NODE), is("getFoo")); | ||
assertThat(nameHelper.getGetterName("oAuth2State", new JCodeModel().INT, NODE), is("getoAuth2State")); | ||
assertThat(nameHelper.getGetterName("URL", new JCodeModel().INT, NODE), is("getURL")); | ||
} | ||
|
||
@Test | ||
public void testSetterNamedCorrectly() { | ||
assertThat(nameHelper.getSetterName("foo", NODE), is("setFoo")); | ||
assertThat(nameHelper.getSetterName("oAuth2State", NODE), is("setoAuth2State")); | ||
assertThat(nameHelper.getSetterName("URL", NODE), is("setURL")); | ||
} | ||
|
||
} |