Skip to content

Commit

Permalink
✅ Add a Regression Test
Browse files Browse the repository at this point in the history
Added a test to help us identify strange behavior in our Jackson
configuration. Checking the test in to serve as a regression test.
  • Loading branch information
gilday committed Dec 3, 2024
1 parent eb4c689 commit 50041fd
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/test/java/io/codemodder/codetf/CodeTFChangeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import static org.junit.jupiter.api.Assertions.*;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.List;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -49,4 +51,45 @@ void equals_and_hash_code() {
assertEquals(change1, change2);
assertEquals(change1.hashCode(), change2.hashCode());
}

/**
* Presently, there is a known issue where our Jackson databind annotations on {@link
* CodeTFChange} allow for this type to be deserialized with either property name {@code findings}
* or {@code fixedFindings}. The spec calls for {@code findings}. While we have not yet fixed this
* issue, this test demonstrates that the deserialization works as expected and serves as a
* regression test when we do fix the issue.
*/
@Test
void parse_json() throws JsonProcessingException {
final CodeTFChange expected =
new CodeTFChange(
1,
null,
null,
CodeTFDiffSide.LEFT,
null,
null,
List.of(new FixedFinding("finding-id", new DetectorRule("java/xss", "XSS", null))));
String json =
"""
{
"lineNumber": 1,
"properties": null,
"description": null,
"diffSide": "left",
"packageActions": null,
"parameters": null,
"findings": [{
"id": "finding-id",
"rule": {
"id": "java/xss",
"name": "XSS"
}
}]
}
""";
final var mapper = new ObjectMapper();
final var actual = mapper.readValue(json, CodeTFChange.class);
assertEquals(expected, actual);
}
}

0 comments on commit 50041fd

Please sign in to comment.