55
66import java .lang .reflect .Method ;
77import java .lang .reflect .Type ;
8+ import java .util .Locale ;
89import java .util .Map ;
910
1011import static org .hamcrest .CoreMatchers .startsWith ;
@@ -33,10 +34,36 @@ void can_transform_string_to_type() throws Throwable {
3334 assertThat (transformed , is ("transform_string_to_type" ));
3435 }
3536
37+ @ Test
38+ void can_transform_string_to_type_ignoring_locale () throws Throwable {
39+ Method method = JavaDefaultParameterTransformerDefinitionTest .class .getMethod ("transform_string_to_type" ,
40+ String .class , Type .class );
41+ JavaDefaultParameterTransformerDefinition definition = new JavaDefaultParameterTransformerDefinition (method ,
42+ lookup );
43+ Object transformed = definition .parameterByTypeTransformer ().transform ("something" , String .class ,
44+ Locale .ENGLISH );
45+ assertThat (transformed , is ("transform_string_to_type" ));
46+ }
47+
3648 public Object transform_string_to_type (String fromValue , Type toValueType ) {
3749 return "transform_string_to_type" ;
3850 }
3951
52+ @ Test
53+ void can_transform_string_to_type_using_locale () throws Throwable {
54+ Method method = JavaDefaultParameterTransformerDefinitionTest .class .getMethod (
55+ "transform_string_to_type_with_locale" , String .class , Type .class , Locale .class );
56+ JavaDefaultParameterTransformerDefinition definition = new JavaDefaultParameterTransformerDefinition (method ,
57+ lookup );
58+ Object transformed = definition .parameterByTypeTransformer ().transform ("something" , String .class ,
59+ Locale .ENGLISH );
60+ assertThat (transformed , is ("transform_string_to_type_with_locale_en" ));
61+ }
62+
63+ public Object transform_string_to_type_with_locale (String fromValue , Type toValueType , Locale locale ) {
64+ return "transform_string_to_type_with_locale_" + locale .getLanguage ();
65+ }
66+
4067 @ Test
4168 void can_transform_object_to_type () throws Throwable {
4269 Method method = JavaDefaultParameterTransformerDefinitionTest .class .getMethod ("transform_object_to_type" ,
@@ -47,10 +74,36 @@ void can_transform_object_to_type() throws Throwable {
4774 assertThat (transformed , is ("transform_object_to_type" ));
4875 }
4976
77+ @ Test
78+ void can_transform_object_to_type_ignoring_locale () throws Throwable {
79+ Method method = JavaDefaultParameterTransformerDefinitionTest .class .getMethod ("transform_object_to_type" ,
80+ Object .class , Type .class );
81+ JavaDefaultParameterTransformerDefinition definition = new JavaDefaultParameterTransformerDefinition (method ,
82+ lookup );
83+ String transformed = (String ) definition .parameterByTypeTransformer ().transform ("something" , String .class ,
84+ Locale .ENGLISH );
85+ assertThat (transformed , is ("transform_object_to_type" ));
86+ }
87+
5088 public Object transform_object_to_type (Object fromValue , Type toValueType ) {
5189 return "transform_object_to_type" ;
5290 }
5391
92+ @ Test
93+ void can_transform_object_to_type_using_locale () throws Throwable {
94+ Method method = JavaDefaultParameterTransformerDefinitionTest .class .getMethod (
95+ "transform_object_to_type_with_locale" , Object .class , Type .class , Locale .class );
96+ JavaDefaultParameterTransformerDefinition definition = new JavaDefaultParameterTransformerDefinition (method ,
97+ lookup );
98+ String transformed = (String ) definition .parameterByTypeTransformer ().transform ("something" , String .class ,
99+ Locale .ENGLISH );
100+ assertThat (transformed , is ("transform_object_to_type_with_locale_en" ));
101+ }
102+
103+ public Object transform_object_to_type_with_locale (Object fromValue , Type toValueType , Locale locale ) {
104+ return "transform_object_to_type_with_locale_" + locale .getLanguage ();
105+ }
106+
54107 @ Test
55108 void must_have_non_void_return () throws Throwable {
56109 Method method = JavaDefaultParameterTransformerDefinitionTest .class .getMethod ("transforms_string_to_void" ,
@@ -61,29 +114,31 @@ void must_have_non_void_return() throws Throwable {
61114 "A @DefaultParameterTransformer annotated method must have one of these signatures:\n " +
62115 " * public Object defaultDataTableEntry(String fromValue, Type toValueType)\n " +
63116 " * public Object defaultDataTableEntry(Object fromValue, Type toValueType)\n " +
117+ " * public Object defaultDataTableEntry(String fromValue, Type toValueType, Locale locale)\n " +
118+ " * public Object defaultDataTableEntry(Object fromValue, Type toValueType, Locale locale)\n " +
64119 "at io.cucumber.java.JavaDefaultParameterTransformerDefinitionTest.transforms_string_to_void(java.lang.String,java.lang.reflect.Type)" ));
65120 }
66121
67122 public void transforms_string_to_void (String fromValue , Type toValueType ) {
68123 }
69124
70125 @ Test
71- void must_have_two_arguments () throws Throwable {
126+ void must_have_two_or_three_arguments () throws Throwable {
72127 Method oneArg = JavaDefaultParameterTransformerDefinitionTest .class .getMethod ("one_argument" , String .class );
73128 assertThrows (InvalidMethodSignatureException .class ,
74129 () -> new JavaDefaultParameterTransformerDefinition (oneArg , lookup ));
75- Method threeArg = JavaDefaultParameterTransformerDefinitionTest .class .getMethod ("three_arguments " , String .class ,
76- Type .class , Object .class );
130+ Method fourArg = JavaDefaultParameterTransformerDefinitionTest .class .getMethod ("four_arguments " , String .class ,
131+ Type .class , Locale . class , Object .class );
77132 assertThrows (InvalidMethodSignatureException .class ,
78- () -> new JavaDefaultParameterTransformerDefinition (threeArg , lookup ));
133+ () -> new JavaDefaultParameterTransformerDefinition (fourArg , lookup ));
79134 }
80135
81136 public Object one_argument (String fromValue ) {
82137 return "one_argument" ;
83138 }
84139
85- public Object three_arguments (String fromValue , Type toValueType , Object extra ) {
86- return "three_arguments " ;
140+ public Object four_arguments (String fromValue , Type toValueType , Locale locale , Object extra ) {
141+ return "four_arguments " ;
87142 }
88143
89144 @ Test
@@ -92,22 +147,38 @@ void must_have_string_or_object_as_from_value() throws Throwable {
92147 Type .class );
93148 assertThrows (InvalidMethodSignatureException .class ,
94149 () -> new JavaDefaultParameterTransformerDefinition (twoArg , lookup ));
150+ Method threeArg = JavaDefaultParameterTransformerDefinitionTest .class .getMethod ("map_as_from_value_with_locale" ,
151+ Map .class , Type .class , Locale .class );
152+ assertThrows (InvalidMethodSignatureException .class ,
153+ () -> new JavaDefaultParameterTransformerDefinition (threeArg , lookup ));
95154 }
96155
97156 public Object map_as_from_value (Map <String , String > fromValue , Type toValueType ) {
98157 return "map_as_from_value" ;
99158 }
100159
160+ public Object map_as_from_value_with_locale (Map <String , String > fromValue , Type toValueType , Locale locale ) {
161+ return "map_as_from_value_with_locale" ;
162+ }
163+
101164 @ Test
102165 void must_have_type_as_to_value_type () throws Throwable {
103166 Method twoArg = JavaDefaultParameterTransformerDefinitionTest .class .getMethod ("object_as_to_value_type" ,
104167 String .class , Object .class );
105168 assertThrows (InvalidMethodSignatureException .class ,
106169 () -> new JavaDefaultParameterTransformerDefinition (twoArg , lookup ));
170+ Method threeArg = JavaDefaultParameterTransformerDefinitionTest .class .getMethod (
171+ "object_as_to_value_type_with_locale" , String .class , Object .class , Locale .class );
172+ assertThrows (InvalidMethodSignatureException .class ,
173+ () -> new JavaDefaultParameterTransformerDefinition (threeArg , lookup ));
107174 }
108175
109176 public Object object_as_to_value_type (String fromValue , Object toValueType ) {
110177 return "object_as_to_value_type" ;
111178 }
112179
180+ public Object object_as_to_value_type_with_locale (String fromValue , Object toValueType , Locale locale ) {
181+ return "object_as_to_value_type_with_locale" ;
182+ }
183+
113184}
0 commit comments