diff --git a/src/main/java/gov/cms/mat/cql_elm_translation/dto/ElementLookup.java b/src/main/java/gov/cms/mat/cql_elm_translation/dto/ElementLookup.java index 7903798a..394a27c3 100644 --- a/src/main/java/gov/cms/mat/cql_elm_translation/dto/ElementLookup.java +++ b/src/main/java/gov/cms/mat/cql_elm_translation/dto/ElementLookup.java @@ -1,14 +1,21 @@ package gov.cms.mat.cql_elm_translation.dto; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; @Data -@Builder +@NoArgsConstructor +@AllArgsConstructor +@Builder(toBuilder = true) +@EqualsAndHashCode public class ElementLookup { private String value; private boolean code; private String datatype; + @EqualsAndHashCode.Exclude // ID is a randomly generated UUID and will never be equal to another private String id; private String name; private String oid; diff --git a/src/test/java/gov/cms/mat/cql_elm_translation/dto/ElementLookupTest.java b/src/test/java/gov/cms/mat/cql_elm_translation/dto/ElementLookupTest.java new file mode 100644 index 00000000..f0c7f0fe --- /dev/null +++ b/src/test/java/gov/cms/mat/cql_elm_translation/dto/ElementLookupTest.java @@ -0,0 +1,35 @@ +package gov.cms.mat.cql_elm_translation.dto; + +import org.junit.jupiter.api.Test; + +import java.util.HashSet; +import java.util.Set; + + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.equalTo; + +class ElementLookupTest { + + @Test + void testHashSetUniqueness() { + ElementLookup elementLookup1 = ElementLookup.builder() + .id("ID1") + .oid("111.222.333") + .name("TestCode") + .codeName("TestCodeName") + .codeSystemName("Amazing Code System") + .release("Release1") + .displayName("Test Code") + .datatype("Code") + .build(); + + ElementLookup elementLookup2 = elementLookup1.toBuilder().id("ID2").build(); + + Set set = new HashSet<>(); + set.add(elementLookup1); + set.add(elementLookup2); + assertThat(set.size(), is(equalTo(1))); + } +} \ No newline at end of file