File tree Expand file tree Collapse file tree 2 files changed +24
-6
lines changed
main/java/org/apache/ibatis/reflection/property
test/java/org/apache/ibatis/reflection/property Expand file tree Collapse file tree 2 files changed +24
-6
lines changed Original file line number Diff line number Diff line change 15
15
*/
16
16
package org .apache .ibatis .reflection .property ;
17
17
18
- import java .util . Locale ;
18
+ import java .beans . Introspector ;
19
19
20
20
import org .apache .ibatis .reflection .ReflectionException ;
21
21
@@ -37,11 +37,7 @@ public static String methodToProperty(String name) {
37
37
throw new ReflectionException ("Error parsing property name '" + name + "'. Didn't start with 'is', 'get' or 'set'." );
38
38
}
39
39
40
- if (name .length () == 1 || (name .length () > 1 && !Character .isUpperCase (name .charAt (1 )))) {
41
- name = name .substring (0 , 1 ).toLowerCase (Locale .ENGLISH ) + name .substring (1 );
42
- }
43
-
44
- return name ;
40
+ return Introspector .decapitalize (name );
45
41
}
46
42
47
43
public static boolean isProperty (String name ) {
Original file line number Diff line number Diff line change
1
+ package org .apache .ibatis .reflection .property ;
2
+
3
+ import org .junit .jupiter .api .Test ;
4
+
5
+ import static org .junit .jupiter .api .Assertions .*;
6
+
7
+ class PropertyNamerTest {
8
+
9
+ @ Test
10
+ void methodToProperty () {
11
+ assertEquals ("ok" , PropertyNamer .methodToProperty ("isOk" ));
12
+ assertEquals ("OK" , PropertyNamer .methodToProperty ("isOK" ));
13
+
14
+ assertEquals ("name" , PropertyNamer .methodToProperty ("getName" ));
15
+ assertEquals ("XName" , PropertyNamer .methodToProperty ("getXName" ));
16
+ assertEquals ("xName" , PropertyNamer .methodToProperty ("getxName" ));
17
+
18
+ assertEquals ("name" , PropertyNamer .methodToProperty ("setName" ));
19
+ assertEquals ("XName" , PropertyNamer .methodToProperty ("setXName" ));
20
+ assertEquals ("xName" , PropertyNamer .methodToProperty ("setxName" ));
21
+ }
22
+ }
You can’t perform that action at this time.
0 commit comments