Skip to content

Commit 982e897

Browse files
committed
Additional test case, clear several Sonar warnings
Signed-off-by: Michael Edgar <[email protected]>
1 parent f181678 commit 982e897

File tree

2 files changed

+58
-8
lines changed

2 files changed

+58
-8
lines changed

core/src/test/java/io/smallrye/openapi/runtime/scanner/PropertyNamingStrategyTest.java

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,21 @@ void testJacksonNamingOverridesConfig() throws Exception {
5050
}
5151

5252
@Test
53-
void testInvalidNamingStrategyClass() throws Exception {
53+
void testInvalidNamingStrategyClass() {
5454
Config config = config(SmallRyeOASConfig.SMALLRYE_PROPERTY_NAMING_STRATEGY,
5555
"com.fasterxml.jackson.databind.PropertyNamingStrategies$InvalidStrategy");
5656
assertThrows(OpenApiRuntimeException.class, () -> scan(config, NameStrategyKebab.class));
5757
}
5858

5959
@Test
60-
void testNoValidTranslationMethods() throws Exception {
60+
void testNoValidTranslationMethods() {
6161
Config config = config(SmallRyeOASConfig.SMALLRYE_PROPERTY_NAMING_STRATEGY,
6262
NoValidTranslationMethods.class.getName());
6363
assertThrows(OpenApiRuntimeException.class, () -> scan(config, NameStrategyKebab.class));
6464
}
6565

6666
@Test
67-
void testInvalidPropertyNameTranslationAttempt() throws Exception {
67+
void testInvalidPropertyNameTranslationAttempt() {
6868
Config config = config(SmallRyeOASConfig.SMALLRYE_PROPERTY_NAMING_STRATEGY,
6969
TranslationThrowsException.class.getName());
7070
assertThrows(OpenApiRuntimeException.class, () -> scan(config, NameStrategyBean3.class));
@@ -79,7 +79,7 @@ void testInvalidPropertyNameTranslationAttempt() throws Exception {
7979
JsonbConstants.UPPER_CAMEL_CASE_WITH_SPACES + ", Simple String One|Another Field|Y|Z|SOME Value",
8080
JsonbConstants.CASE_INSENSITIVE + ", simpleStringOne|anotherField|Y|z|SOMEValue"
8181
})
82-
void testJsonbConstantStrategy(String strategy, String expectedNames) throws Exception {
82+
void testJsonbConstantStrategy(String strategy, String expectedNames) {
8383
OpenAPI result = scan(config(SmallRyeOASConfig.SMALLRYE_PROPERTY_NAMING_STRATEGY, strategy), NameStrategyBean3.class);
8484
List<String> expectedNameList = Arrays.asList(expectedNames.split("\\|"));
8585
Collections.sort(expectedNameList, String::compareToIgnoreCase);
@@ -92,6 +92,12 @@ void testJsonbConstantStrategy(String strategy, String expectedNames) throws Exc
9292
assertEquals(expectedNameList, actualNameList);
9393
}
9494

95+
@Test
96+
void testMethodNamePreserved() throws Exception {
97+
OpenAPI result = scan(NameStrategyBean4.class);
98+
assertJsonEquals("components.schemas.method-name-preserved.json", result);
99+
}
100+
95101
@Schema
96102
static class NameStrategyBean1 {
97103
String simpleStringValue;
@@ -119,9 +125,9 @@ static class NameStrategyKebab {
119125
static class NameStrategyBean3 {
120126
String simpleStringOne;
121127
Integer anotherField;
122-
BigDecimal Y;
128+
BigDecimal Y; // NOSONAR - naming intentional
123129
double z;
124-
String SOMEValue;
130+
String SOMEValue; // NOSONAR - naming intentional
125131

126132
public String getSimpleStringOne() {
127133
return simpleStringOne;
@@ -144,14 +150,35 @@ public String getSOMEValue() {
144150
}
145151
}
146152

147-
public static class NoValidTranslationMethods {
148-
public NoValidTranslationMethods() {
153+
@Schema
154+
static class NameStrategyBean4 {
155+
@Schema(name = "TESTValue", title = "Test Value")
156+
Integer TestValue; // NOSONAR - naming intentional
157+
158+
@Schema(name = "eValue", title = "e-Value")
159+
String EValue; // NOSONAR - naming intentional
160+
161+
@Schema(description = "Property for TestValue")
162+
public Integer getTESTValue() {
163+
return TestValue;
164+
}
165+
166+
@Schema(description = "Property for e-Value")
167+
public String geteValue() {
168+
return EValue;
149169
}
150170

171+
}
172+
173+
public static class NoValidTranslationMethods {
151174
public String translate() {
152175
return null;
153176
}
154177

178+
/**
179+
* @param v1 unused, demonstrated unsuitable translate method signature
180+
* @param v2 unused, demonstrated unsuitable translate method signature
181+
*/
155182
public String translate(String v1, String v2) {
156183
return null;
157184
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"openapi" : "3.1.0",
3+
"components" : {
4+
"schemas" : {
5+
"NameStrategyBean4" : {
6+
"type" : "object",
7+
"properties" : {
8+
"TESTValue" : {
9+
"type" : "integer",
10+
"format" : "int32",
11+
"description" : "Property for TestValue",
12+
"title" : "Test Value"
13+
},
14+
"eValue" : {
15+
"type" : "string",
16+
"description" : "Property for e-Value",
17+
"title" : "e-Value"
18+
}
19+
}
20+
}
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)