Skip to content

Commit

Permalink
MAT-7208: change equals and hashcode for ElementLookup to exclude ID,…
Browse files Browse the repository at this point in the history
… so uniqueness is more accurate
  • Loading branch information
nmorasb committed May 15, 2024
1 parent 8530eb6 commit 8f6337a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ElementLookup> set = new HashSet<>();
set.add(elementLookup1);
set.add(elementLookup2);
assertThat(set.size(), is(equalTo(1)));
}
}

0 comments on commit 8f6337a

Please sign in to comment.