Skip to content

Commit

Permalink
MAT-6058: Adding better test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
gregory-akins committed Sep 28, 2023
1 parent 4cc0917 commit baf76c2
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,45 +19,40 @@
@Slf4j
public class UpdateStratificationAssociation {

@Setter private List<Measure> tempMeasures;
@Setter
private List<Measure> tempMeasures;

@Execution
public void removeAssociationFromStratification(MeasureRepository measureRepository) {
List<Measure> measures = measureRepository.findAllByModel(ModelType.QDM_5_6.getValue());
if (CollectionUtils.isNotEmpty(measures)) {
setTempMeasures(measures);
measures.forEach(
measure -> {
if ("QDM v5.6".equals(measure.getModel())) {
List<Group> groups = measure.getGroups();
if (CollectionUtils.isNotEmpty(groups)) {
groups.forEach(
group -> {
List<Stratification> strats = group.getStratifications();
if (CollectionUtils.isNotEmpty((strats))) {
strats.forEach(
strat -> {
log.info("Stratification...", strat);
strat.setAssociation(null);
});
}
group.setStratifications(strats);
});
measure.setGroups(groups);
measureRepository.save(measure);
}
}
});
}
}
@Execution
public void removeAssociationFromStratification(MeasureRepository measureRepository) {
List<Measure> measures = measureRepository.findAllByModel(ModelType.QDM_5_6.getValue());
if (CollectionUtils.isNotEmpty(measures)) {
setTempMeasures(measures);
measures.forEach(measure -> {
List<Group> groups = measure.getGroups();
if (CollectionUtils.isNotEmpty(groups)) {
groups.forEach(group -> {
List<Stratification> strats = group.getStratifications();
if (CollectionUtils.isNotEmpty((strats))) {
strats.forEach(strat -> {
log.info("Stratification...", strat);
strat.setAssociation(null);
});
}
group.setStratifications(strats);
});
measure.setGroups(groups);
measureRepository.save(measure);
}
});
}
}

@RollbackExecution
public void rollbackExecution(MeasureRepository measureRepository) {
if (CollectionUtils.isNotEmpty(tempMeasures)) {
tempMeasures.forEach(
measure -> {
measureRepository.save(measure);
});
}
}
@RollbackExecution
public void rollbackExecution(MeasureRepository measureRepository) {
if (CollectionUtils.isNotEmpty(tempMeasures)) {
tempMeasures.forEach(measure -> {
measureRepository.save(measure);
});
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
package cms.gov.madie.measure.config;

import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.lessThan;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.doReturn;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.collections4.CollectionUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand Down Expand Up @@ -42,7 +50,7 @@ public void setUp() {
}

@Test
public void addPatientIdChangeUnitSuccess() {
public void updateStratificationAssociation() {
doReturn(List.of(testMeasure)).when(measureRepository).findAllByModel(ModelType.QDM_5_6.getValue());
updateStratificationAssociation.removeAssociationFromStratification(measureRepository);

Expand All @@ -52,6 +60,41 @@ public void addPatientIdChangeUnitSuccess() {
assertNull(strat.getAssociation());

}

@Test
public void updateStratificationAssociationWithoutGroups() {
testMeasure.setGroups(new ArrayList<Group>());
doReturn(List.of(testMeasure)).when(measureRepository).findAllByModel(ModelType.QDM_5_6.getValue());
updateStratificationAssociation.removeAssociationFromStratification(measureRepository);

List<Group> groups= testMeasure.getGroups();
assertTrue(CollectionUtils.isEmpty(groups));

}

@Test
public void updateStratificationAssociationWithoutStratifications() {
testMeasure.getGroups().get(0).setStratifications(new ArrayList<Stratification>());
doReturn(List.of(testMeasure)).when(measureRepository).findAllByModel(ModelType.QDM_5_6.getValue());
updateStratificationAssociation.removeAssociationFromStratification(measureRepository);

List<Stratification> strats= testMeasure.getGroups().get(0).getStratifications();
assertTrue(CollectionUtils.isEmpty(strats));

}

@Test
public void updateStratificationAssociation_ModelMismatch() {

doReturn(new ArrayList<Measure>()).when(measureRepository).findAllByModel(ModelType.QDM_5_6.getValue());
updateStratificationAssociation.removeAssociationFromStratification(measureRepository);

Stratification strat = testMeasure.getGroups().get(0).getStratifications().get(0);
assertNotNull(strat);

assertEquals(PopulationType.INITIAL_POPULATION, strat.getAssociation());

}



Expand All @@ -66,5 +109,17 @@ public void testRollbackExecutionHasMeasures() {

assertEquals(PopulationType.INITIAL_POPULATION, strat.getAssociation());
}

@Test
public void testRollbackExecutionNoMeasures() {
ReflectionTestUtils.setField(updateStratificationAssociation, "tempMeasures", new ArrayList());

updateStratificationAssociation.rollbackExecution(measureRepository);

Stratification strat = testMeasure.getGroups().get(0).getStratifications().get(0);
assertNotNull(strat);

assertEquals(PopulationType.INITIAL_POPULATION, strat.getAssociation());
}

}

0 comments on commit baf76c2

Please sign in to comment.