diff --git a/build.gradle b/build.gradle index 6364caf..96388f6 100644 --- a/build.gradle +++ b/build.gradle @@ -17,6 +17,7 @@ repositories { } dependencies { + testImplementation 'com.fasterxml.jackson.core:jackson-databind:2.16.0' testImplementation platform('org.junit:junit-bom:5.9.1') testImplementation 'org.junit.jupiter:junit-jupiter' } diff --git a/src/test/java/com/labelzoom/api/DeepCopyTests.java b/src/test/java/com/labelzoom/api/DeepCopyTests.java new file mode 100644 index 0000000..0717e0f --- /dev/null +++ b/src/test/java/com/labelzoom/api/DeepCopyTests.java @@ -0,0 +1,30 @@ +package com.labelzoom.api; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.labelzoom.api.model.components.CLabel; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +/** + * TODO: This test was succeeding when I ran it, but since I don't think the ordering of fields can be guaranteed, I + * disabled the test so that it won't interrupt CI/CD. But this is something we should expand on in the future. The + * goal is to ensure that if a developer adds a new field to a component, that they also update the cloning / deep copy + * logic. May look to use reflection to randomize the data in each field of the component. + */ +public class DeepCopyTests +{ + final ObjectMapper objectMapper = new ObjectMapper(); + + @Test + @Disabled + void testSimpleClone() + { + final CLabel label = new CLabel(); + final CLabel clone = label.clone(); + final String labelSerialized = assertDoesNotThrow(() -> objectMapper.writeValueAsString(label)); + final String cloneSerialized = assertDoesNotThrow(() -> objectMapper.writeValueAsString(clone)); + assertEquals(labelSerialized, cloneSerialized); + } +}