Skip to content

Commit

Permalink
Sonar fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gpspatacean committed Aug 25, 2024
1 parent d43ee4b commit 9ee509e
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import static org.junit.Assert.*;

Expand All @@ -35,7 +34,7 @@ public JsonSchemaParserTests() throws JsonProcessingException {
public void testBasicProperties() {
assertEquals("Name of the main Schema is \"Product\"", "Product", generatorData.getName());
assertEquals("Main Schema should have 4 models", 4, generatorData.getModels().size());
final List<String> models = generatorData.getModels().stream().map(ModelData::getModelName).collect(Collectors.toList());
final List<String> models = generatorData.getModels().stream().map(ModelData::getModelName).toList();
assertTrue("Main Schema should have \"Product\", \"dimensions\", \"review\" models", models.containsAll(Arrays.asList("Product", "dimensions", "review")));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
*/
@SuppressWarnings("OptionalGetWithoutIsPresent")
public class GeneratorsHandlerTests {
private final static String testGeneratorName = "test-generator";
private final static GeneratorsHandler generatorService = GeneratorsHandler.getInstance();
private static final String testGeneratorName = "test-generator";
private static final GeneratorsHandler generatorService = GeneratorsHandler.getInstance();

@Test
public void testBasicGeneratorData() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,25 @@
import static org.junit.Assert.assertTrue;

public class JsonSchemaTests {
private static final String jsonSchemaAsJson = "{\n" +
" \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n" +
" \"$id\": \"https://example.com/product.schema.json\",\n" +
" \"title\": \"Product\",\n" +
" \"description\": \"A product from Acme's catalog\",\n" +
" \"type\": \"object\",\n" +
" \"properties\": {\n" +
" \"productId\": {\n" +
" \"description\": \"The unique identifier for a product\",\n" +
" \"type\": \"integer\"\n" +
" },\n" +
" \"productName\": {\n" +
" \"description\": \"Name of the product\",\n" +
" \"type\": \"string\"\n" +
" }\n" +
" },\n" +
" \"required\": [ \"productId\", \"productName\" ]\n" +
"}";
private static final String JSON_SCHEMA_AS_JSON = """
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://example.com/product.schema.json",
"title": "Product",
"description": "A product from Acme's catalog",
"type": "object",
"properties": {
"productId": {
"description": "The unique identifier for a product",
"type": "integer"
},
"productName": {
"description": "Name of the product",
"type": "string"
}
},
"required": [ "productId", "productName" ]
}""";
private final ObjectMapper objectMapper = ObjectMapperFactory.createDefaultObjectMapper();
private JsonSchema jsonSchemaTest;

Expand Down Expand Up @@ -61,7 +62,7 @@ public void Setup() {

@Test
public void simpleDeserialization() throws JsonProcessingException {
final JsonSchema jsonSchema = objectMapper.readValue(jsonSchemaAsJson, JsonSchema.class);
final JsonSchema jsonSchema = objectMapper.readValue(JSON_SCHEMA_AS_JSON, JsonSchema.class);
assert jsonSchema != null;
assertEquals("Product", jsonSchema.getTitle());
assertEquals("A product from Acme's catalog", jsonSchema.getDescription());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import static org.junit.Assert.assertEquals;

public class PropertiesTests {
private static final String propertiesJson = "{\n" +
private static final String PROPERTIES_JSON = "{\n" +
"\t\t\"prop1\":{\n" +
"\t\t\t\"description\":\"Description of 1st property\",\n" +
"\t\t\t\"type\":\"object\"\n" +
Expand Down Expand Up @@ -44,7 +44,7 @@ public void Setup() {
@Test
public void testFullSerialization() throws JsonProcessingException {
final String actual = objectMapper.writeValueAsString(properties);
final String liniarExpected = propertiesJson.replaceAll("[\\r\\n\\t]", "");
final String liniarExpected = PROPERTIES_JSON.replaceAll("[\\r\\n\\t]", "");
assertEquals(liniarExpected, actual);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import static org.junit.Assert.*;

public class PropertyTests {
private static final String propertyJson = "{\n" +
private static final String PROPERTY_JSON = "{\n" +
"\t\"productId\":{\n" +
"\t\t\"description\":\"The unique identifier for a product\",\n" +
"\t\t\"type\":\"integer\"\n" +
Expand All @@ -20,7 +20,7 @@ public class PropertyTests {

@Test
public void nonNullObjectIsReturned() throws JsonProcessingException {
final Property property = objectMapper.readValue(propertyJson, Property.class);
final Property property = objectMapper.readValue(PROPERTY_JSON, Property.class);
assertNotNull(property);
}

Expand All @@ -32,7 +32,7 @@ public void objectToJsonString() throws JsonProcessingException {
.type(JsonDataTypes.INTEGER)
.build();
final String result = objectMapper.writeValueAsString(property);
final String linearizedExpectedJson = propertyJson.replaceAll("[\\n\\t]", "");
final String linearizedExpectedJson = PROPERTY_JSON.replaceAll("[\\n\\t]", "");
assertEquals(linearizedExpectedJson, result);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/
@SuppressWarnings("OptionalGetWithoutIsPresent")
public class SchemaArraysTests {
private final ObjectMapper objectMapper = ObjectMapperFactory.createDefaultObjectMapper();
private final ObjectMapper defaultObjectMapper = ObjectMapperFactory.createDefaultObjectMapper();

@Test
public void DeserializeArrayWithSimpleTypes() throws JsonProcessingException {
Expand All @@ -34,7 +34,7 @@ public void DeserializeArrayWithSimpleTypes() throws JsonProcessingException {
assertFalse("Test Failure: failed to read input file", false);
}
final String schema = jsonSchema.get();
final JsonSchema workingSchema = objectMapper.readValue(schema, JsonSchema.class);
final JsonSchema workingSchema = defaultObjectMapper.readValue(schema, JsonSchema.class);
final Properties properties = workingSchema.getProperties();
final Optional<Property> tagsProperty = properties.getPropertyByName("tags");
if (!tagsProperty.isPresent()) {
Expand All @@ -51,7 +51,7 @@ public void DeserializeArrayWithComplexTypes() throws JsonProcessingException {
assertFalse("Test Failure: failed to read input file", false);
}
final String schema = jsonSchema.get();
final JsonSchema workingSchema = objectMapper.readValue(schema, JsonSchema.class);
final JsonSchema workingSchema = defaultObjectMapper.readValue(schema, JsonSchema.class);
final Properties properties = workingSchema.getProperties();
final Optional<Property> reviews = properties.getPropertyByName("reviews");
if (!reviews.isPresent()) {
Expand Down

0 comments on commit 9ee509e

Please sign in to comment.