Browse Source

refactor: Design Smells

pull/1008/head
Vaibhav Ramchandani 11 months ago
parent
commit
5b33010609
  1. 13
      json-path/src/main/java/com/jayway/jsonpath/internal/CharacterIndex.java
  2. 10
      json-path/src/main/java/com/jayway/jsonpath/internal/path/PathCompiler.java
  3. 57
      json-path/src/test/java/com/jayway/jsonpath/Configurations.java
  4. 3
      json-path/src/test/java/com/jayway/jsonpath/internal/function/Issue191.java
  5. 3
      json-path/src/test/java/com/jayway/jsonpath/internal/function/JSONEntityPathFunctionTest.java
  6. 2
      json-path/src/test/java/com/jayway/jsonpath/internal/function/KeySetFunctionTest.java
  7. 2
      json-path/src/test/java/com/jayway/jsonpath/internal/function/SequentialPathFunctionTest.java

13
json-path/src/main/java/com/jayway/jsonpath/internal/CharacterIndex.java

@ -3,7 +3,6 @@ package com.jayway.jsonpath.internal;
import com.jayway.jsonpath.InvalidPathException;
public class CharacterIndex {
private static final char OPEN_PARENTHESIS = '(';
private static final char CLOSE_PARENTHESIS = ')';
private static final char CLOSE_SQUARE_BRACKET = ']';
@ -29,6 +28,7 @@ public class CharacterIndex {
this.endPosition = charSequence.length() - 1;
}
public int length() {
return endPosition + 1;
}
@ -320,4 +320,15 @@ public class CharacterIndex {
skipBlanksAtEnd();
return this;
}
public void readWhitespace() {
while (inBounds()) {
char c = currentChar();
if (!Character.isWhitespace(c)) {
break;
}
incrementPosition(1);
}
}
}

10
json-path/src/main/java/com/jayway/jsonpath/internal/path/PathCompiler.java

@ -85,13 +85,7 @@ public class PathCompiler {
}
private void readWhitespace() {
while (path.inBounds()) {
char c = path.currentChar();
if (!isWhitespace(c)) {
break;
}
path.incrementPosition(1);
}
path.readWhitespace();
}
private Boolean isPathContext(char c) {
@ -101,7 +95,7 @@ public class PathCompiler {
//[$ | @]
private RootPathToken readContextToken() {
readWhitespace();
path.readWhitespace();
if (!isPathContext(path.currentChar())) {
throw new InvalidPathException("Path must start with '$' or '@'");

57
json-path/src/test/java/com/jayway/jsonpath/Configurations.java

@ -16,37 +16,37 @@ import java.util.Arrays;
public class Configurations {
public static final Configuration JSON_ORG_CONFIGURATION = Configuration
private static final Configuration JSON_ORG_CONFIGURATION = Configuration
.builder()
.mappingProvider(new JsonOrgMappingProvider())
.jsonProvider(new JsonOrgJsonProvider())
.build();
public static final Configuration GSON_CONFIGURATION = Configuration
private static final Configuration GSON_CONFIGURATION = Configuration
.builder()
.mappingProvider(new GsonMappingProvider())
.jsonProvider(new GsonJsonProvider())
.build();
public static final Configuration JACKSON_CONFIGURATION = Configuration
private static final Configuration JACKSON_CONFIGURATION = Configuration
.builder()
.mappingProvider(new JacksonMappingProvider())
.jsonProvider(new JacksonJsonProvider())
.build();
public static final Configuration JACKSON_JSON_NODE_CONFIGURATION = Configuration
private static final Configuration JACKSON_JSON_NODE_CONFIGURATION = Configuration
.builder()
.mappingProvider(new JacksonMappingProvider())
.jsonProvider(new JacksonJsonNodeJsonProvider())
.build();
public static final Configuration JSON_SMART_CONFIGURATION = Configuration
private static final Configuration JSON_SMART_CONFIGURATION = Configuration
.builder()
.mappingProvider(new JsonSmartMappingProvider())
.jsonProvider(new JsonSmartJsonProvider())
.build();
public static final Configuration JAKARTA_CONFIGURATION = Configuration
private static final Configuration JAKARTA_CONFIGURATION = Configuration
.builder()
.mappingProvider(new JakartaMappingProvider())
.jsonProvider(new JakartaJsonProvider())
@ -54,21 +54,46 @@ public class Configurations {
public static Iterable<Configuration> configurations() {
return Arrays.asList(
JSON_SMART_CONFIGURATION
,GSON_CONFIGURATION
,JACKSON_CONFIGURATION
,JACKSON_JSON_NODE_CONFIGURATION
,JSON_ORG_CONFIGURATION
,JAKARTA_CONFIGURATION
JSON_SMART_CONFIGURATION,
GSON_CONFIGURATION,
JACKSON_CONFIGURATION,
JACKSON_JSON_NODE_CONFIGURATION,
JSON_ORG_CONFIGURATION,
JAKARTA_CONFIGURATION
);
}
public static Iterable<Configuration> objectMappingConfigurations() {
return Arrays.asList(
GSON_CONFIGURATION
,JACKSON_CONFIGURATION
,JACKSON_JSON_NODE_CONFIGURATION
,JAKARTA_CONFIGURATION
GSON_CONFIGURATION,
JACKSON_CONFIGURATION,
JACKSON_JSON_NODE_CONFIGURATION,
JAKARTA_CONFIGURATION
);
}
// Public getter methods for accessing configurations
public static Configuration getJsonOrgConfiguration() {
return JSON_ORG_CONFIGURATION;
}
public static Configuration getGsonConfiguration() {
return GSON_CONFIGURATION;
}
public static Configuration getJacksonConfiguration() {
return JACKSON_CONFIGURATION;
}
public static Configuration getJacksonJsonNodeConfiguration() {
return JACKSON_JSON_NODE_CONFIGURATION;
}
public static Configuration getJsonSmartConfiguration() {
return JSON_SMART_CONFIGURATION;
}
public static Configuration getJakartaConfiguration() {
return JAKARTA_CONFIGURATION;
}
}

3
json-path/src/test/java/com/jayway/jsonpath/internal/function/Issue191.java

@ -16,7 +16,8 @@ import java.io.InputStream;
*/
public class Issue191 {
private Configuration conf = Configurations.GSON_CONFIGURATION;
private Configuration conf = Configurations.getGsonConfiguration();
@Test
public void testResultSetNumericComputation() {

3
json-path/src/test/java/com/jayway/jsonpath/internal/function/JSONEntityPathFunctionTest.java

@ -52,7 +52,8 @@ public class JSONEntityPathFunctionTest extends BaseFunctionTest {
private Configuration conf = Configurations.JSON_SMART_CONFIGURATION;
private Configuration conf= Configurations.getJsonSmartConfiguration();
@Test
public void testLengthOfTextArray() {

2
json-path/src/test/java/com/jayway/jsonpath/internal/function/KeySetFunctionTest.java

@ -14,7 +14,7 @@ import java.util.HashSet;
*/
public class KeySetFunctionTest extends BaseFunctionTest {
private Configuration conf = Configurations.JACKSON_CONFIGURATION;
private Configuration conf = Configurations.getJsonSmartConfiguration();
@Test
public void testKeySet() throws Exception {

2
json-path/src/test/java/com/jayway/jsonpath/internal/function/SequentialPathFunctionTest.java

@ -15,7 +15,7 @@ import org.junit.jupiter.api.Test;
*/
public class SequentialPathFunctionTest extends BaseFunctionTest {
private Configuration conf = Configurations.JACKSON_CONFIGURATION;
private Configuration conf = Configurations.getJsonSmartConfiguration();
@Test
public void testFirstOfNumbers() throws Exception {

Loading…
Cancel
Save