Skip to content

Commit

Permalink
#120 - Added test case
Browse files Browse the repository at this point in the history
  • Loading branch information
starnowski committed Apr 10, 2024
1 parent f3f1a96 commit 5a66d36
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

public class JsonTextArray {
Expand All @@ -13,6 +14,19 @@ public JsonTextArray(List<Object> path) {
this.path = path == null ? new ArrayList<>() : Collections.unmodifiableList(path);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
JsonTextArray that = (JsonTextArray) o;
return Objects.equals(path, that.path);
}

@Override
public int hashCode() {
return Objects.hash(path);
}

public List<Object> getPath() {
return path;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ public JsonUpdateStatementConfigurationBuilder withPostSortFilter(JsonUpdateStat
}

public JsonUpdateStatementConfigurationBuilder append(JsonUpdateStatementOperationType operation, JsonTextArray jsonTextArray, String value) {
operations.add(new JsonUpdateStatementConfiguration.JsonUpdateStatementOperation(jsonTextArray, operation, value));
return this;
return append(new JsonUpdateStatementConfiguration.JsonUpdateStatementOperation(jsonTextArray, operation, value));
}

public JsonUpdateStatementConfigurationBuilder append(JsonUpdateStatementConfiguration.JsonUpdateStatementOperation operation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.github.starnowski.posjsonhelper.json.core.sql

import spock.lang.Specification

import static com.github.starnowski.posjsonhelper.json.core.sql.JsonUpdateStatementOperationType.JSONB_SET

class JsonUpdateStatementConfigurationBuilderTest extends Specification {

def "should build configuration based on components if component are defined"()
Expand Down Expand Up @@ -53,4 +55,20 @@ class JsonUpdateStatementConfigurationBuilderTest extends Specification {
result
result.getOperations() == [operation1, operation2, operation3, operation4]
}

def "should build correct configuration"()
{
given:
def tested = new JsonUpdateStatementConfigurationBuilder()
.append(JSONB_SET, (new JsonTextArrayBuilder()).append("parent").append("child1").build(), "some value1")
.withPostSortFilter(null)
.withSort(null)

when:
def result = tested.build()

then:
result
result.getOperations() == [new JsonUpdateStatementConfiguration.JsonUpdateStatementOperation((new JsonTextArrayBuilder()).append("parent").append("child1").build(), JSONB_SET, "some value1")]
}
}

0 comments on commit 5a66d36

Please sign in to comment.