diff --git a/src/main/java/org/hisp/dhis/api/ApiFields.java b/src/main/java/org/hisp/dhis/api/ApiFields.java index 7c2c9b60..d5d97b5f 100644 --- a/src/main/java/org/hisp/dhis/api/ApiFields.java +++ b/src/main/java/org/hisp/dhis/api/ApiFields.java @@ -292,12 +292,15 @@ public class ApiFields { /** Tracked entity attribute fields. */ public static final String TRACKED_ENTITY_ATTRIBUTE_FIELDS = - String.format("%s,valueType,aggregationType,confidential,unique,orgunitScope", NAME_FIELDS); + String.format( + "%s,valueType,aggregationType,confidential,unique,orgunitScope,skipSynchronization", + NAME_FIELDS); /** Tracked entity attribute extended fields. */ public static final String TRACKED_ENTITY_ATTRIBUTE_EXT_FIELDS = String.format( - "%s,valueType,aggregationType,confidential,unique,orgunitScope", NAME_EXT_FIELDS); + "%s,valueType,aggregationType,confidential,unique,orgunitScope,skipSynchronization", + NAME_EXT_FIELDS); /** Tracked entity type fields. */ public static final String TRACKED_ENTITY_TYPE_FIELDS = diff --git a/src/main/java/org/hisp/dhis/model/Program.java b/src/main/java/org/hisp/dhis/model/Program.java index 004ac612..dcc415a0 100644 --- a/src/main/java/org/hisp/dhis/model/Program.java +++ b/src/main/java/org/hisp/dhis/model/Program.java @@ -154,7 +154,7 @@ public List getNonConfidentialTrackedEntityTypeAttribute return trackedEntityType.getTrackedEntityTypeAttributes().stream() .map(TrackedEntityTypeAttribute::getTrackedEntityAttribute) - .filter(tea -> !tea.isConfidentialNullSafe()) + .filter(tea -> !tea.isConfidential()) .collect(Collectors.toUnmodifiableList()); } @@ -179,7 +179,22 @@ public List getTrackedEntityAttributes() { public List getNonConfidentialTrackedEntityAttributes() { return programTrackedEntityAttributes.stream() .map(ProgramTrackedEntityAttribute::getTrackedEntityAttribute) - .filter(tea -> !tea.isConfidentialNullSafe()) + .filter(tea -> !tea.isConfidential()) + .toList(); + } + + /** + * Returns tracked entity attributes which are not confidential and synchronizable and part of the + * program. + * + * @return an immutable list of {@link TrackedEntityAttribute}. + */ + @JsonIgnore + public List getSynchronizableTrackedEntityAttributes() { + return programTrackedEntityAttributes.stream() + .map(ProgramTrackedEntityAttribute::getTrackedEntityAttribute) + .filter(tea -> !tea.isConfidential()) + .filter(tea -> !tea.isSkipSynchronization()) .toList(); } diff --git a/src/main/java/org/hisp/dhis/model/trackedentity/TrackedEntityAttribute.java b/src/main/java/org/hisp/dhis/model/trackedentity/TrackedEntityAttribute.java index 5a445c72..55259fcd 100644 --- a/src/main/java/org/hisp/dhis/model/trackedentity/TrackedEntityAttribute.java +++ b/src/main/java/org/hisp/dhis/model/trackedentity/TrackedEntityAttribute.java @@ -27,6 +27,8 @@ */ package org.hisp.dhis.model.trackedentity; +import static org.apache.commons.lang3.BooleanUtils.isTrue; + import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Getter; @@ -53,13 +55,25 @@ public class TrackedEntityAttribute extends NameableObject { @JsonProperty private Boolean orgunitScope = false; + @JsonProperty private Boolean skipSynchronization = false; + + @JsonIgnore + public boolean isConfidential() { + return isTrue(confidential); + } + + @JsonIgnore + public boolean isUnique() { + return isTrue(unique); + } + @JsonIgnore - public boolean isConfidentialNullSafe() { - return confidential != null && confidential; + public boolean isOrgUnitScope() { + return isTrue(orgunitScope); } @JsonIgnore - public boolean isUniqueNullSafe() { - return unique != null && unique; + public boolean isSkipSynchronization() { + return isTrue(skipSynchronization); } } diff --git a/src/main/java/org/hisp/dhis/response/data/ImportCount.java b/src/main/java/org/hisp/dhis/response/data/ImportCount.java index 09103e4f..952b495e 100644 --- a/src/main/java/org/hisp/dhis/response/data/ImportCount.java +++ b/src/main/java/org/hisp/dhis/response/data/ImportCount.java @@ -27,6 +27,7 @@ */ package org.hisp.dhis.response.data; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Getter; import lombok.NoArgsConstructor; @@ -45,4 +46,9 @@ public class ImportCount { @JsonProperty private int ignored; @JsonProperty private int deleted; + + @JsonIgnore + public long getTotal() { + return (long) imported + updated + ignored + deleted; + } } diff --git a/src/test/java/org/hisp/dhis/ApiFieldsTest.java b/src/test/java/org/hisp/dhis/ApiFieldsTest.java index ccd8ab1a..d040238b 100644 --- a/src/test/java/org/hisp/dhis/ApiFieldsTest.java +++ b/src/test/java/org/hisp/dhis/ApiFieldsTest.java @@ -79,7 +79,7 @@ void testProgramExtFields() { createdBy,lastUpdatedBy,translations,sharing,access,shortName,description,formName,\ trackedEntityTypeAttributes[id,\ trackedEntityAttribute[id,code,name,created,lastUpdated,attributeValues,shortName,description,valueType,\ - aggregationType,confidential,unique,orgunitScope],displayInList,mandatory,searchable]],\ + aggregationType,confidential,unique,orgunitScope,skipSynchronization],displayInList,mandatory,searchable]],\ categoryCombo[id,code,name,created,lastUpdated,attributeValues,shortName,description,\ categories[id,code,name,created,lastUpdated,attributeValues,createdBy,lastUpdatedBy,translations,\ sharing,access,shortName,description,formName,dataDimensionType,dataDimension,\ @@ -115,7 +115,7 @@ void testProgramExtFields() { programTrackedEntityAttributes[id,code,name,program[id,code,name,created,lastUpdated,\ attributeValues,shortName,description],\ trackedEntityAttribute[id,code,name,created,lastUpdated,attributeValues,\ - shortName,description,valueType,aggregationType,confidential,unique,orgunitScope],\ + shortName,description,valueType,aggregationType,confidential,unique,orgunitScope,skipSynchronization],\ sortOrder,displayInList,mandatory,allowFutureDate,searchable],\ programRuleVariables[id,code,name,created,lastUpdated,attributeValues,createdBy,\ lastUpdatedBy,translations,sharing,access,program[id,code,name,created,lastUpdated,attributeValues],\ @@ -147,7 +147,7 @@ void testProgramMinFields() { programTrackedEntityAttributes[id,code,name,\ program[id,code,name,created,lastUpdated,attributeValues,shortName,description],\ trackedEntityAttribute[id,code,name,created,lastUpdated,attributeValues,shortName,\ - description,valueType,aggregationType,confidential,unique,orgunitScope],\ + description,valueType,aggregationType,confidential,unique,orgunitScope,skipSynchronization],\ sortOrder,displayInList,mandatory,allowFutureDate,searchable],\ programType,\ enrollmentDateLabel,incidentDateLabel,enrollmentLabel,followUpLabel,\ diff --git a/src/test/java/org/hisp/dhis/CategoryOptionApiTest.java b/src/test/java/org/hisp/dhis/CategoryOptionApiTest.java index 7b7f6763..99179f5f 100644 --- a/src/test/java/org/hisp/dhis/CategoryOptionApiTest.java +++ b/src/test/java/org/hisp/dhis/CategoryOptionApiTest.java @@ -86,7 +86,7 @@ void testGetCategoryOptionsWithPaging() { assertFalse(categoryOptions.isEmpty()); assertNotNull(categoryOptions.get(0).getId()); assertNotNull(categoryOptions.get(0).getName()); - assertFalse(categoryOptions.get(0).getCategories().isEmpty()); + assertNotEmpty(categoryOptions.get(0).getCategories()); } @Test @@ -104,7 +104,7 @@ void testGetCategoryOption() { CategoryOption categoryOption = dhis2.getCategoryOption("jRbMi0aBjYn"); - assertEquals("Male", categoryOption.getName()); + assertNotBlank(categoryOption.getName()); } @Test @@ -119,7 +119,7 @@ void testUpdateCategoryOption() { assertEquals(Status.OK, response.getStatus()); categoryOption = dhis2.getCategoryOption("jRbMi0aBjYn"); - assertEquals("Male gender", categoryOption.getDescription()); + assertNotBlank(categoryOption.getDescription()); assertNotNull(categoryOption.getLastUpdatedBy()); } } diff --git a/src/test/java/org/hisp/dhis/CategoryOptionComboApiTest.java b/src/test/java/org/hisp/dhis/CategoryOptionComboApiTest.java index 79c3f49a..3686c49f 100644 --- a/src/test/java/org/hisp/dhis/CategoryOptionComboApiTest.java +++ b/src/test/java/org/hisp/dhis/CategoryOptionComboApiTest.java @@ -27,6 +27,7 @@ */ package org.hisp.dhis; +import static org.hisp.dhis.support.Assertions.assertNotBlank; import static org.hisp.dhis.support.Assertions.assertNotEmpty; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -45,7 +46,7 @@ void testGetCategoryOptionCombo() { CategoryOptionCombo coc = dhis2.getCategoryOptionCombo("KQ50BVoUrd6"); assertEquals("KQ50BVoUrd6", coc.getId()); - assertEquals("Male", coc.getName()); + assertNotBlank(coc.getName()); assertFalse(coc.getIgnoreApproval()); assertNotEmpty(coc.getCategoryOptions()); } diff --git a/src/test/java/org/hisp/dhis/DataElementApiTest.java b/src/test/java/org/hisp/dhis/DataElementApiTest.java index e6f182ca..49f15038 100644 --- a/src/test/java/org/hisp/dhis/DataElementApiTest.java +++ b/src/test/java/org/hisp/dhis/DataElementApiTest.java @@ -29,6 +29,7 @@ import static org.hisp.dhis.support.Assertions.assertNotBlank; import static org.hisp.dhis.support.Assertions.assertNotEmpty; +import static org.hisp.dhis.support.Assertions.assertSize; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -185,8 +186,8 @@ void testSaveGetDataElementWithSharing() { assertNotNull(sharing); assertNotBlank(sharing.getOwner()); assertNotBlank(sharing.getPublicAccess()); - assertEquals(2, sharing.getUsers().size()); - assertEquals(2, sharing.getUserGroups().size()); + assertSize(2, sharing.getUsers().values()); + assertSize(2, sharing.getUserGroups().values()); UserAccess userAccess = sharing.getUsers().get("awtnYWiVEd5"); diff --git a/src/test/java/org/hisp/dhis/DataElementGroupApiTest.java b/src/test/java/org/hisp/dhis/DataElementGroupApiTest.java index 4f554899..f35c6c31 100644 --- a/src/test/java/org/hisp/dhis/DataElementGroupApiTest.java +++ b/src/test/java/org/hisp/dhis/DataElementGroupApiTest.java @@ -27,6 +27,7 @@ */ package org.hisp.dhis; +import static org.hisp.dhis.support.Assertions.assertSize; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; @@ -67,7 +68,7 @@ void testGetDataElementGroup() { List dataElements = deg.getDataElements(); assertNotNull(dataElements); - assertEquals(3, dataElements.size()); + assertSize(3, dataElements); List deIds = dataElements.stream().map(IdentifiableObject::getId).collect(Collectors.toList()); diff --git a/src/test/java/org/hisp/dhis/DataSetApiTest.java b/src/test/java/org/hisp/dhis/DataSetApiTest.java index c47b004c..6ab3528b 100644 --- a/src/test/java/org/hisp/dhis/DataSetApiTest.java +++ b/src/test/java/org/hisp/dhis/DataSetApiTest.java @@ -105,7 +105,7 @@ void testGetDataSetsWithExpandAssociations() { .withExpandAssociations() .addFilter(Filter.in("id", list("BfMAe6Itzgt")))); - assertEquals(1, dataSets.size()); + assertSize(1, dataSets); DataSet dataSet = dataSets.get(0); diff --git a/src/test/java/org/hisp/dhis/DataStoreApiTest.java b/src/test/java/org/hisp/dhis/DataStoreApiTest.java index c8787817..8a2c7b5a 100644 --- a/src/test/java/org/hisp/dhis/DataStoreApiTest.java +++ b/src/test/java/org/hisp/dhis/DataStoreApiTest.java @@ -27,6 +27,7 @@ */ package org.hisp.dhis; +import static org.hisp.dhis.support.Assertions.assertSize; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -86,7 +87,7 @@ void testCrud() { dhis2.getDatastoreEntries("fruits", List.of("name", "color")); assertNotNull(fruits); - assertEquals(2, fruits.size()); + assertSize(2, fruits); assertNotNull(fruits.get(0)); assertNotNull(fruits.get(0).get("name")); assertNotNull(fruits.get(0).get("color")); diff --git a/src/test/java/org/hisp/dhis/Dhis2CrudApiTest.java b/src/test/java/org/hisp/dhis/Dhis2CrudApiTest.java index e60b25e4..86819ca4 100644 --- a/src/test/java/org/hisp/dhis/Dhis2CrudApiTest.java +++ b/src/test/java/org/hisp/dhis/Dhis2CrudApiTest.java @@ -27,6 +27,7 @@ */ package org.hisp.dhis; +import static org.hisp.dhis.support.Assertions.assertSize; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -87,7 +88,7 @@ void testCrudCategoryOption() { assertEquals(codeA, coA.getCode()); assertEquals(nameA, coA.getName()); assertEquals(shortNameA, coA.getShortName()); - assertEquals(2, coA.getOrganisationUnits().size()); + assertSize(2, coA.getOrganisationUnits()); assertTrue(coA.getOrganisationUnits().contains(ouA)); assertTrue(coA.getOrganisationUnits().contains(ouB)); @@ -112,7 +113,7 @@ void testCrudCategoryOption() { assertNotNull(coA.getAttributeValues()); assertEquals(uidA, coA.getId()); assertEquals(codeA, coA.getCode()); - assertEquals(2, coA.getOrganisationUnits().size()); + assertSize(2, coA.getOrganisationUnits()); assertTrue(coA.getOrganisationUnits().contains(ouA)); assertTrue(coA.getOrganisationUnits().contains(ouB)); diff --git a/src/test/java/org/hisp/dhis/EnrollmentsApiTest.java b/src/test/java/org/hisp/dhis/EnrollmentsApiTest.java index 618232ec..cede9ecb 100644 --- a/src/test/java/org/hisp/dhis/EnrollmentsApiTest.java +++ b/src/test/java/org/hisp/dhis/EnrollmentsApiTest.java @@ -27,6 +27,7 @@ */ package org.hisp.dhis; +import static org.hisp.dhis.support.Assertions.assertSize; import static org.hisp.dhis.util.DateTimeUtils.toDate; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -126,7 +127,7 @@ void testSaveGetRemoveEnrollments() { assertEquals(trackedEntity, enrollment.getTrackedEntity()); assertNotNull(enrollment.getNotes()); - assertEquals(1, enrollment.getNotes().size()); + assertSize(1, enrollment.getNotes()); note = enrollment.getNotes().get(0); assertEquals(noteId, note.getNote()); assertEquals(5000, note.getValue().length()); diff --git a/src/test/java/org/hisp/dhis/EventsApiTest.java b/src/test/java/org/hisp/dhis/EventsApiTest.java index f0f67719..980219d8 100644 --- a/src/test/java/org/hisp/dhis/EventsApiTest.java +++ b/src/test/java/org/hisp/dhis/EventsApiTest.java @@ -27,6 +27,7 @@ */ package org.hisp.dhis; +import static org.hisp.dhis.support.Assertions.assertSize; import static org.hisp.dhis.util.CollectionUtils.list; import static org.hisp.dhis.util.DateTimeUtils.toDate; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -252,7 +253,7 @@ void testSaveEventsMissingOccurredAt() { assertTrue(response.hasErrorReports()); assertEquals(Status.ERROR, response.getStatus(), response.toString()); assertEquals(1, response.getStats().getIgnored()); - assertEquals(1, response.getValidationReport().getErrorReports().size()); + assertSize(1, response.getValidationReport().getErrorReports()); ErrorReport errorReport = response.getValidationReport().getErrorReports().get(0); assertEquals("E1031", errorReport.getErrorCode()); @@ -269,7 +270,7 @@ void testGetEvents() { assertNotNull(events); assertNotNull(events.getEvents()); - assertEquals(50, events.getEvents().size()); + assertSize(50, events.getEvents()); Event event = events.getEvents().get(0); @@ -294,7 +295,7 @@ void testGetEventsWithFilter() { assertNotNull(events); assertNotNull(events.getEvents()); - assertEquals(50, events.getEvents().size()); + assertSize(50, events.getEvents()); Event event = events.getEvents().get(0); @@ -323,7 +324,7 @@ void testGetEventsWithOrder() { assertNotNull(events); assertNotNull(events.getEvents()); - assertEquals(10, events.getEvents().size()); + assertSize(10, events.getEvents()); Event firstEvent = events.getEvents().get(0); int firstValue = Integer.parseInt(firstEvent.getDataValue("qrur9Dvnyt5")); diff --git a/src/test/java/org/hisp/dhis/IndicatorApiTest.java b/src/test/java/org/hisp/dhis/IndicatorApiTest.java index 26d61ef5..668c383f 100644 --- a/src/test/java/org/hisp/dhis/IndicatorApiTest.java +++ b/src/test/java/org/hisp/dhis/IndicatorApiTest.java @@ -28,6 +28,7 @@ package org.hisp.dhis; import static org.hisp.dhis.support.Assertions.assertNotEmpty; +import static org.hisp.dhis.support.Assertions.assertSize; import static org.hisp.dhis.support.Assertions.assertSuccessResponse; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -107,7 +108,7 @@ void testGetIndicatorsWithInFilter() { List indicators = dhis2.getIndicators(query); assertNotEmpty(indicators); - assertEquals(3, indicators.size()); + assertSize(3, indicators); } @Test diff --git a/src/test/java/org/hisp/dhis/IndicatorTypeApiTest.java b/src/test/java/org/hisp/dhis/IndicatorTypeApiTest.java index 7f6ff8c2..0b03de51 100644 --- a/src/test/java/org/hisp/dhis/IndicatorTypeApiTest.java +++ b/src/test/java/org/hisp/dhis/IndicatorTypeApiTest.java @@ -28,6 +28,7 @@ package org.hisp.dhis; import static org.hisp.dhis.support.Assertions.assertNotEmpty; +import static org.hisp.dhis.support.Assertions.assertSize; import static org.hisp.dhis.support.Assertions.assertSuccessResponse; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -70,7 +71,7 @@ void testGetIndicatorTypesWithInFilter() { List indicatorTypes = dhis2.getIndicatorTypes(query); assertNotEmpty(indicatorTypes); - assertEquals(2, indicatorTypes.size()); + assertSize(2, indicatorTypes); } @Test diff --git a/src/test/java/org/hisp/dhis/MetadataApiTest.java b/src/test/java/org/hisp/dhis/MetadataApiTest.java index 56d8648f..f2b26230 100644 --- a/src/test/java/org/hisp/dhis/MetadataApiTest.java +++ b/src/test/java/org/hisp/dhis/MetadataApiTest.java @@ -28,6 +28,7 @@ package org.hisp.dhis; import static org.hisp.dhis.support.Assertions.assertNotEmpty; +import static org.hisp.dhis.support.Assertions.assertSize; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -78,7 +79,7 @@ void testImportMetadata() { assertEquals(4, stats.getTotal()); assertNotEmpty(response.getTypeReports()); - assertEquals(2, response.getTypeReports().size()); + assertSize(2, response.getTypeReports()); ObjectResponse removeResponse = dhis2.removeMetadataObject(MetadataEntity.OPTION_SET, "gKdxTM8BcI7"); diff --git a/src/test/java/org/hisp/dhis/OrgUnitApiTest.java b/src/test/java/org/hisp/dhis/OrgUnitApiTest.java index aded8b1b..a15deed9 100644 --- a/src/test/java/org/hisp/dhis/OrgUnitApiTest.java +++ b/src/test/java/org/hisp/dhis/OrgUnitApiTest.java @@ -28,6 +28,7 @@ package org.hisp.dhis; import static org.hisp.dhis.support.Assertions.assertNotEmpty; +import static org.hisp.dhis.support.Assertions.assertSize; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -111,7 +112,7 @@ void testSaveOrgUnitWithAttributes() { assertNotNull(orgUnit); assertEquals(uidA, orgUnit.getId()); - assertEquals(2, orgUnit.getAttributeValues().size()); + assertSize(2, orgUnit.getAttributeValues()); response = dhis2.removeOrgUnit(uidA); @@ -154,7 +155,7 @@ void testGetOrgUnitWithRootJunctionAnd() { .addFilter(Filter.like("name", "Sierra Leone")) .addFilter(Filter.like("name", "Agape CHP"))); - assertEquals(0, orgUnits.size()); + assertSize(0, orgUnits); } @Test @@ -165,10 +166,10 @@ void testGetOrgUnitWithRootJunctionOr() { dhis2.getOrgUnits( Query.instance() .withRootJunction(RootJunction.OR) - .addFilter(Filter.like("name", "Sierra Leone")) - .addFilter(Filter.like("name", "Agape CHP"))); + .addFilter(Filter.eq("id", "eIQbndfxQMb")) + .addFilter(Filter.eq("id", "at6UHUQatSo"))); - assertEquals(2, orgUnits.size()); + assertSize(2, orgUnits); } @Test diff --git a/src/test/java/org/hisp/dhis/OrgUnitGroupApiTest.java b/src/test/java/org/hisp/dhis/OrgUnitGroupApiTest.java index efcafb63..f91a807f 100644 --- a/src/test/java/org/hisp/dhis/OrgUnitGroupApiTest.java +++ b/src/test/java/org/hisp/dhis/OrgUnitGroupApiTest.java @@ -29,6 +29,7 @@ import static org.hisp.dhis.support.Assertions.assertNotBlank; import static org.hisp.dhis.support.Assertions.assertNotEmpty; +import static org.hisp.dhis.support.Assertions.assertSize; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; @@ -68,7 +69,7 @@ void testGetOrgUnitGroup() { List orgUnits = oug.getOrgUnits(); assertNotNull(orgUnits); - assertEquals(1, orgUnits.size()); + assertSize(1, orgUnits); assertEquals("ImspTQPwCqd", orgUnits.get(0).getId()); assertNotBlank(orgUnits.get(0).getName()); diff --git a/src/test/java/org/hisp/dhis/OrgUnitsApiTest.java b/src/test/java/org/hisp/dhis/OrgUnitsApiTest.java index a7ba6500..d78e1bb0 100644 --- a/src/test/java/org/hisp/dhis/OrgUnitsApiTest.java +++ b/src/test/java/org/hisp/dhis/OrgUnitsApiTest.java @@ -27,6 +27,7 @@ */ package org.hisp.dhis; +import static org.hisp.dhis.support.Assertions.assertSize; import static org.hisp.dhis.util.CollectionUtils.list; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -197,19 +198,19 @@ void testSaveOrgUnitsMissingRequiredProperty() { assertEquals( "org.hisp.dhis.organisationunit.OrganisationUnit", response.getTypeReport().getKlass()); assertEquals(2, response.getTypeReport().getStats().getIgnored()); - assertEquals(1, response.getTypeReports().size()); - assertEquals(2, response.getTypeReport().getObjectReports().size()); + assertSize(1, response.getTypeReports()); + assertSize(2, response.getTypeReport().getObjectReports()); ObjectReport objectReport1 = response.getTypeReport().getObjectReports().get(0); ObjectReport objectReport2 = response.getTypeReport().getObjectReports().get(1); assertNotNull(objectReport1); assertEquals("org.hisp.dhis.organisationunit.OrganisationUnit", objectReport1.getKlass()); - assertEquals(2, objectReport1.getErrorReports().size()); + assertSize(2, objectReport1.getErrorReports()); assertNotNull(objectReport2); assertEquals("org.hisp.dhis.organisationunit.OrganisationUnit", objectReport2.getKlass()); - assertEquals(2, objectReport2.getErrorReports().size()); + assertSize(2, objectReport2.getErrorReports()); ErrorReport errorReport1 = objectReport1.getErrorReports().get(0); ErrorReport errorReport2 = objectReport1.getErrorReports().get(1); @@ -233,7 +234,7 @@ void testGetOrgUnits() { .addFilter(Filter.in("id", list("YuQRtpLP10I", "jPidqyo7cpF", "vWbkYPRmKyS")))); assertNotNull(orgUnits); - assertEquals(3, orgUnits.size()); + assertSize(3, orgUnits); OrgUnit ou = orgUnits.get(0); @@ -273,7 +274,7 @@ void testGetOrgUnitsByAttributeValue() { .addFilter(Filter.eq("attributeValues.attribute.id", "l1VmqIHKk6t")) .addFilter(Filter.eq("attributeValues.value", "KE02"))); - assertEquals(1, orgUnits.size()); + assertSize(1, orgUnits); assertTrue(orgUnits.contains(new OrgUnit("g8upMTyEZGZ", "Njandama MCHP"))); } @@ -283,7 +284,7 @@ void testGetOrgUnitSubHierarchy() { List orgUnits = dhis2.getOrgUnitSubHierarchy("O6uvpzGd5pu", 1, Query.instance()); - assertEquals(15, orgUnits.size()); + assertSize(15, orgUnits); assertTrue(orgUnits.contains(new OrgUnit("YuQRtpLP10I", "Badjia"))); assertTrue(orgUnits.contains(new OrgUnit("dGheVylzol6", "Bargbe"))); assertTrue(orgUnits.contains(new OrgUnit("kU8vhUkAGaT", "Lugbu"))); @@ -297,6 +298,6 @@ void testInFilter() { List orgUnits = dhis2.getOrgUnits(Query.instance().addFilter(Filter.in("id", values))); - assertEquals(3, orgUnits.size()); + assertSize(3, orgUnits); } } diff --git a/src/test/java/org/hisp/dhis/ProgramApiTest.java b/src/test/java/org/hisp/dhis/ProgramApiTest.java index 7242e1ef..eea7b5ea 100644 --- a/src/test/java/org/hisp/dhis/ProgramApiTest.java +++ b/src/test/java/org/hisp/dhis/ProgramApiTest.java @@ -188,13 +188,21 @@ void testSaveGetRemoveProgramObjects() { assertEquals("NkvU4urhVNv", ptea.getId()); assertNotNull(ptea.getProgram()); assertEquals(PR_ID, ptea.getProgram().getId()); - assertNotNull(ptea.getTrackedEntityAttribute()); - assertEquals("lZGmxYbs97q", ptea.getTrackedEntityAttribute().getId()); assertTrue(ptea.getDisplayInList()); assertTrue(ptea.getMandatory()); assertFalse(ptea.getAllowFutureDate()); assertTrue(ptea.getSearchable()); + TrackedEntityAttribute tea = ptea.getTrackedEntityAttribute(); + + assertNotNull(tea); + assertNotNull(tea.getId()); + assertNotBlank(tea.getName()); + assertNotNull(tea.getConfidential()); + assertNotNull(tea.getUnique()); + assertNotNull(tea.getOrgunitScope()); + assertNotNull(tea.getSkipSynchronization()); + ProgramStage ps = retrieved.getProgramStages().get(0); assertNotNull(ps); @@ -233,7 +241,7 @@ void testSaveGetRemoveProgramObjects() { assertEquals("Information", sc.getDescription()); assertNotNull(sc.getProgram()); assertNotBlank(sc.getProgram().getId()); - assertEquals(5, sc.getTrackedEntityAttributes().size()); + assertSize(5, sc.getTrackedEntityAttributes()); ProgramStageSection pss = retrieved.getProgramStageSections().get(0); @@ -358,7 +366,12 @@ void testGetProgramExtChildProgramme() { TrackedEntityAttribute tea = ptea.getTrackedEntityAttribute(); assertNotNull(tea); - assertNotBlank(tea.getId()); + assertNotNull(tea.getId()); + assertNotBlank(tea.getName()); + assertNotNull(tea.getConfidential()); + assertNotNull(tea.getUnique()); + assertNotNull(tea.getOrgunitScope()); + assertNotNull(tea.getSkipSynchronization()); ProgramStage ps = pr.getProgramStages().get(0); @@ -464,7 +477,12 @@ void testGetProgramStdChildProgramme() { TrackedEntityAttribute tea = ptea.getTrackedEntityAttribute(); assertNotNull(tea); - assertNotBlank(tea.getId()); + assertNotNull(tea.getId()); + assertNotBlank(tea.getName()); + assertNotNull(tea.getConfidential()); + assertNotNull(tea.getUnique()); + assertNotNull(tea.getOrgunitScope()); + assertNotNull(tea.getSkipSynchronization()); ProgramStage ps = pr.getProgramStages().get(0); diff --git a/src/test/java/org/hisp/dhis/TrackedEntitiesApiTest.java b/src/test/java/org/hisp/dhis/TrackedEntitiesApiTest.java index 71869a61..dcf8ae8e 100644 --- a/src/test/java/org/hisp/dhis/TrackedEntitiesApiTest.java +++ b/src/test/java/org/hisp/dhis/TrackedEntitiesApiTest.java @@ -27,6 +27,7 @@ */ package org.hisp.dhis; +import static org.hisp.dhis.support.Assertions.assertSize; import static org.hisp.dhis.util.DateTimeUtils.toDate; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -131,7 +132,7 @@ void testGetTrackedEntitiesWithId() { List trackedEntities = result.getTrackedEntities(); assertNotNull(trackedEntities); - assertEquals(1, trackedEntities.size()); + assertSize(1, trackedEntities); TrackedEntity trackedEntity = trackedEntities.get(0); assertNotNull(trackedEntity); diff --git a/src/test/java/org/hisp/dhis/TrackedEntityApiTest.java b/src/test/java/org/hisp/dhis/TrackedEntityApiTest.java index c6c0a774..9c3db4be 100644 --- a/src/test/java/org/hisp/dhis/TrackedEntityApiTest.java +++ b/src/test/java/org/hisp/dhis/TrackedEntityApiTest.java @@ -28,6 +28,7 @@ package org.hisp.dhis; import static org.hisp.dhis.support.Assertions.assertNotEmpty; +import static org.hisp.dhis.support.Assertions.assertSize; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -116,6 +117,6 @@ void testGetTrackedEntitiesWithPaging() { assertNotNull(trackedEntities); assertNotEmpty(trackedEntities.getTrackedEntities()); - assertEquals(2, trackedEntities.getTrackedEntities().size()); + assertSize(2, trackedEntities.getTrackedEntities()); } } diff --git a/src/test/java/org/hisp/dhis/TrackedEntityAttributeApiTest.java b/src/test/java/org/hisp/dhis/TrackedEntityAttributeApiTest.java index a72aa846..1df64bfb 100644 --- a/src/test/java/org/hisp/dhis/TrackedEntityAttributeApiTest.java +++ b/src/test/java/org/hisp/dhis/TrackedEntityAttributeApiTest.java @@ -29,7 +29,6 @@ import static org.hisp.dhis.support.Assertions.assertNotEmpty; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import java.util.List; @@ -60,6 +59,10 @@ void testGetTrackedEntityAttribute() { assertEquals("VqEFza8wbwA", trackedEntityAttribute.getId()); assertEquals("Address", trackedEntityAttribute.getName()); assertNotNull(trackedEntityAttribute.getCreatedBy()); + assertNotNull(trackedEntityAttribute.getConfidential()); + assertNotNull(trackedEntityAttribute.getUnique()); + assertNotNull(trackedEntityAttribute.getOrgunitScope()); + assertNotNull(trackedEntityAttribute.getSkipSynchronization()); } @Test @@ -70,11 +73,10 @@ void testGetTrackedEntityAttributes() { dhis2.getTrackedEntityAttributes(Query.instance()); assertNotNull(trackedEntityAttributes); - assertFalse(trackedEntityAttributes.isEmpty()); + assertNotEmpty(trackedEntityAttributes); TrackedEntityAttribute trackedEntityAttribute = trackedEntityAttributes.get(0); - assertEquals("VqEFza8wbwA", trackedEntityAttribute.getId()); - assertEquals("Address", trackedEntityAttribute.getName()); + assertNotNull(trackedEntityAttribute); } @Test diff --git a/src/test/java/org/hisp/dhis/TrackedEntityTypeApiTest.java b/src/test/java/org/hisp/dhis/TrackedEntityTypeApiTest.java index 9921e071..37cfb6f5 100644 --- a/src/test/java/org/hisp/dhis/TrackedEntityTypeApiTest.java +++ b/src/test/java/org/hisp/dhis/TrackedEntityTypeApiTest.java @@ -29,6 +29,7 @@ import static org.hisp.dhis.support.Assertions.assertNotBlank; import static org.hisp.dhis.support.Assertions.assertNotEmpty; +import static org.hisp.dhis.support.Assertions.assertSize; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -97,7 +98,7 @@ void testGetTrackedEntityTypes() { .addFilter(Filter.in("id", List.of("hyKZglfYp0C", "nEenWmSyUEp", "kIeke8tAQnd"))) .setOrder(Order.asc("id"))); - assertEquals(3, types.size()); + assertSize(3, types); assertEquals("hyKZglfYp0C", types.get(0).getId()); assertEquals("kIeke8tAQnd", types.get(1).getId()); assertEquals("nEenWmSyUEp", types.get(2).getId()); diff --git a/src/test/java/org/hisp/dhis/TrackedObjectsImportApiTest.java b/src/test/java/org/hisp/dhis/TrackedObjectsImportApiTest.java index da99753f..7cbf182b 100644 --- a/src/test/java/org/hisp/dhis/TrackedObjectsImportApiTest.java +++ b/src/test/java/org/hisp/dhis/TrackedObjectsImportApiTest.java @@ -27,6 +27,7 @@ */ package org.hisp.dhis; +import static org.hisp.dhis.support.Assertions.assertSize; import static org.hisp.dhis.util.CollectionUtils.list; import static org.hisp.dhis.util.DateTimeUtils.toDate; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -247,7 +248,7 @@ void testSaveAndRemoveRelationship() { RelationshipsResult relationshipResult = dhis2.getRelationships(relationshipQuery); assertNotNull(relationshipResult); assertNotNull(relationshipResult.getRelationships()); - assertEquals(1, relationshipResult.getRelationships().size()); + assertSize(1, relationshipResult.getRelationships()); assertEquals(relationshipUidA, relationshipResult.getRelationships().get(0).getRelationship()); TrackedEntityObjects trackedEntityRelationship = new TrackedEntityObjects(); @@ -294,7 +295,7 @@ void testSaveEnrollmentWithError() { assertEquals(0, response.getStats().getDeleted()); assertNotNull(response.getValidationReport()); - assertEquals(1, response.getValidationReport().getErrorReports().size()); + assertSize(1, response.getValidationReport().getErrorReports()); ErrorReport errorReport = response.getValidationReport().getErrorReports().get(0); assertNotNull(errorReport); diff --git a/src/test/java/org/hisp/dhis/UserApiTest.java b/src/test/java/org/hisp/dhis/UserApiTest.java index 41537687..43337eb2 100644 --- a/src/test/java/org/hisp/dhis/UserApiTest.java +++ b/src/test/java/org/hisp/dhis/UserApiTest.java @@ -27,6 +27,8 @@ */ package org.hisp.dhis; +import static org.hisp.dhis.support.Assertions.assertNotBlank; +import static org.hisp.dhis.support.Assertions.assertSize; import static org.hisp.dhis.support.Assertions.assertSuccessResponse; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -58,11 +60,11 @@ void testGetUser() { assertNotNull(user); assertEquals("xE7jOejl9FI", user.getId()); - assertEquals("John Traore", user.getName()); - assertEquals("admin", user.getUsername()); - assertEquals("John", user.getFirstName()); - assertEquals("Traore", user.getSurname()); - assertEquals("dummy@dhis2.org", user.getEmail()); + assertNotBlank(user.getName()); + assertNotBlank(user.getUsername()); + assertNotBlank(user.getFirstName()); + assertNotBlank(user.getSurname()); + assertNotBlank(user.getEmail()); assertNotNull(user.getCreatedBy()); assertFalse(user.getOrganisationUnits().isEmpty()); @@ -80,7 +82,7 @@ void testGetUserByUsername() { List users = dhis2.getUsers(Query.instance().addFilter(Filter.eq("username", "admin"))); assertNotNull(users); - assertEquals(1, users.size()); + assertSize(1, users); User user = users.get(0); diff --git a/src/test/java/org/hisp/dhis/analytics/AnalyticsDataApiTest.java b/src/test/java/org/hisp/dhis/analytics/AnalyticsDataApiTest.java index bb41de76..ee6b4f56 100644 --- a/src/test/java/org/hisp/dhis/analytics/AnalyticsDataApiTest.java +++ b/src/test/java/org/hisp/dhis/analytics/AnalyticsDataApiTest.java @@ -84,7 +84,7 @@ void testGetAnalyticsDataWithDataElements() { List headers = data.getHeaders(); assertNotNull(headers); - assertEquals(3, headers.size()); + assertSize(3, headers); AnalyticsHeader firstHeader = headers.get(0); diff --git a/src/test/java/org/hisp/dhis/model/AttributeValueTest.java b/src/test/java/org/hisp/dhis/model/AttributeValueTest.java index 55782298..b38f675b 100644 --- a/src/test/java/org/hisp/dhis/model/AttributeValueTest.java +++ b/src/test/java/org/hisp/dhis/model/AttributeValueTest.java @@ -27,6 +27,7 @@ */ package org.hisp.dhis.model; +import static org.hisp.dhis.support.Assertions.assertSize; import static org.hisp.dhis.support.TestObjects.set; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -54,7 +55,7 @@ void testAddGetAttributeValues() { orgUnit.addAttributeValue(avB); orgUnit.addAttributeValue(avC); - assertEquals(3, orgUnit.getAttributeValues().size()); + assertSize(3, orgUnit.getAttributeValues()); assertTrue(orgUnit.getAttributeValues().contains(avA)); assertTrue(orgUnit.getAttributeValues().contains(avB)); assertTrue(orgUnit.getAttributeValues().contains(avC)); @@ -139,21 +140,21 @@ void testRemoveAttributeValue() { orgUnit.addAttributeValue(avB); orgUnit.addAttributeValue(avC); - assertEquals(3, orgUnit.getAttributeValues().size()); + assertSize(3, orgUnit.getAttributeValues()); assertTrue(orgUnit.getAttributeValues().contains(avA)); assertTrue(orgUnit.getAttributeValues().contains(avB)); assertTrue(orgUnit.getAttributeValues().contains(avC)); orgUnit.removeAttributeValue(atA.getId()); - assertEquals(2, orgUnit.getAttributeValues().size()); + assertSize(2, orgUnit.getAttributeValues()); assertFalse(orgUnit.getAttributeValues().contains(avA)); assertTrue(orgUnit.getAttributeValues().contains(avB)); assertTrue(orgUnit.getAttributeValues().contains(avC)); orgUnit.removeAttributeValue(atB.getId()); - assertEquals(1, orgUnit.getAttributeValues().size()); + assertSize(1, orgUnit.getAttributeValues()); assertFalse(orgUnit.getAttributeValues().contains(avA)); assertFalse(orgUnit.getAttributeValues().contains(avB)); assertTrue(orgUnit.getAttributeValues().contains(avC)); diff --git a/src/test/java/org/hisp/dhis/model/DataElementTest.java b/src/test/java/org/hisp/dhis/model/DataElementTest.java index 32ffbc03..cd262db1 100644 --- a/src/test/java/org/hisp/dhis/model/DataElementTest.java +++ b/src/test/java/org/hisp/dhis/model/DataElementTest.java @@ -27,6 +27,7 @@ */ package org.hisp.dhis.model; +import static org.hisp.dhis.support.Assertions.assertSize; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -44,7 +45,7 @@ void testDeserializeDataElement() { assertNotNull(dataElement); assertEquals("cZtM3Zhg3FQ", dataElement.getId()); - assertEquals(6, dataElement.getTranslations().size()); + assertSize(6, dataElement.getTranslations()); assertNotNull(dataElement.getSharing()); } } diff --git a/src/test/java/org/hisp/dhis/model/EventTest.java b/src/test/java/org/hisp/dhis/model/EventTest.java index 750b1f8a..a65584b8 100644 --- a/src/test/java/org/hisp/dhis/model/EventTest.java +++ b/src/test/java/org/hisp/dhis/model/EventTest.java @@ -27,6 +27,7 @@ */ package org.hisp.dhis.model; +import static org.hisp.dhis.support.Assertions.assertSize; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNull; @@ -49,7 +50,7 @@ void testAddEventDataValue() { event.addDataValue(new EventDataValue("b5VnIJbjioI", "4")); event.addDataValue(new EventDataValue("hK06Hg9jDSB", "5")); // Exists - assertEquals(3, event.getDataValues().size()); + assertSize(3, event.getDataValues()); assertEquals("3", event.getEventDataValue("i7LbGuGEana").getValue()); assertEquals("5", event.getEventDataValue("hK06Hg9jDSB").getValue()); assertEquals("4", event.getEventDataValue("b5VnIJbjioI").getValue()); diff --git a/src/test/java/org/hisp/dhis/model/analytics/AnalyticsDataIndexTest.java b/src/test/java/org/hisp/dhis/model/analytics/AnalyticsDataIndexTest.java index f2f8b448..d30b17cb 100644 --- a/src/test/java/org/hisp/dhis/model/analytics/AnalyticsDataIndexTest.java +++ b/src/test/java/org/hisp/dhis/model/analytics/AnalyticsDataIndexTest.java @@ -30,6 +30,7 @@ import static org.hisp.dhis.model.analytics.AnalyticsDimension.DATA_X; import static org.hisp.dhis.model.analytics.AnalyticsDimension.ORG_UNIT; import static org.hisp.dhis.model.analytics.AnalyticsDimension.PERIOD; +import static org.hisp.dhis.support.Assertions.assertSize; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -108,7 +109,7 @@ void testGetValue() { AnalyticsDataIndex index = data.getIndex(3); - assertEquals(8, index.keySet().size()); + assertSize(8, index.keySet()); assertEquals("2", index.getValue("A1", "B1", "C1")); assertEquals("4", index.getValue("A2", "B2", "C2")); @@ -128,7 +129,7 @@ void testGetDoubleValue() { AnalyticsDataIndex index = data.getIndex(3); - assertEquals(8, index.keySet().size()); + assertSize(8, index.keySet()); assertEquals(2d, index.getDoubleValue("A1", "B1", "C1")); assertEquals(4d, index.getDoubleValue("A2", "B2", "C2")); diff --git a/src/test/java/org/hisp/dhis/model/analytics/AnalyticsDataTest.java b/src/test/java/org/hisp/dhis/model/analytics/AnalyticsDataTest.java index 08e87e70..979d9a5e 100644 --- a/src/test/java/org/hisp/dhis/model/analytics/AnalyticsDataTest.java +++ b/src/test/java/org/hisp/dhis/model/analytics/AnalyticsDataTest.java @@ -31,6 +31,7 @@ import static org.hisp.dhis.model.analytics.AnalyticsDimension.ORG_UNIT; import static org.hisp.dhis.model.analytics.AnalyticsDimension.PERIOD; import static org.hisp.dhis.support.Assertions.assertContainsExactly; +import static org.hisp.dhis.support.Assertions.assertSize; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -135,7 +136,7 @@ void testGetCopyOfHeaders() { List copy = data.getCopyOfHeaders(); - assertEquals(4, copy.size()); + assertSize(4, copy); assertEquals("dx", copy.get(0).getName()); assertEquals("ou", copy.get(2).getName()); } diff --git a/src/test/java/org/hisp/dhis/model/analytics/AnalyticsMetadataTest.java b/src/test/java/org/hisp/dhis/model/analytics/AnalyticsMetadataTest.java index 8e930c67..f3f55a47 100644 --- a/src/test/java/org/hisp/dhis/model/analytics/AnalyticsMetadataTest.java +++ b/src/test/java/org/hisp/dhis/model/analytics/AnalyticsMetadataTest.java @@ -98,9 +98,9 @@ void testGetMetadataItemName() { @Test void testGetDimensionItems() { - assertEquals(8, metadata.getDimensionItems(DATA_X).size()); - assertEquals(4, metadata.getDimensionItems(PERIOD).size()); - assertEquals(0, metadata.getDimensionItems("foo").size()); + assertSize(8, metadata.getDimensionItems(DATA_X)); + assertSize(4, metadata.getDimensionItems(PERIOD)); + assertSize(0, metadata.getDimensionItems("foo")); } @Test @@ -134,19 +134,19 @@ void testGetOrgUnitItemCount() { void testGetMetadataItems() { List dataItems = metadata.getMetadataItems(DATA_X); - assertEquals(8, dataItems.size()); + assertSize(8, dataItems); assertEquals("A1", dataItems.get(0).getUid()); assertEquals("Indicator 1", dataItems.get(0).getName()); List periodItems = metadata.getMetadataItems(PERIOD); - assertEquals(4, periodItems.size()); + assertSize(4, periodItems); assertEquals("B1", periodItems.get(0).getUid()); assertEquals("Month 1", periodItems.get(0).getName()); List orgUnitItems = metadata.getMetadataItems(ORG_UNIT); - assertEquals(2, orgUnitItems.size()); + assertSize(2, orgUnitItems); assertEquals("C1", orgUnitItems.get(0).getUid()); assertEquals("Facility 1", orgUnitItems.get(0).getName()); } @@ -160,7 +160,7 @@ void testGetMetadataItemsEmpty() { void testGetDimensionItemNameIdMap() { Map map = metadata.getDimensionItemNameIdMap(AnalyticsDimension.PERIOD); - assertEquals(4, map.keySet().size()); + assertSize(4, map.keySet()); assertEquals("B1", map.get("Month 1")); assertEquals("B2", map.get("Month 2")); assertEquals("B4", map.get("Month 4")); diff --git a/src/test/java/org/hisp/dhis/model/trackedentity/TrackedEntityTest.java b/src/test/java/org/hisp/dhis/model/trackedentity/TrackedEntityTest.java index 25c943dd..ee17c3b6 100644 --- a/src/test/java/org/hisp/dhis/model/trackedentity/TrackedEntityTest.java +++ b/src/test/java/org/hisp/dhis/model/trackedentity/TrackedEntityTest.java @@ -27,6 +27,7 @@ */ package org.hisp.dhis.model.trackedentity; +import static org.hisp.dhis.support.Assertions.assertSize; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; @@ -97,26 +98,26 @@ void testAddTrackedEntityAttributeValue() { TrackedEntity te = new TrackedEntity(); te.addAttributeValue("jTyx81h4qnD", "blue"); assertEquals("blue", te.getAttributeValue("jTyx81h4qnD")); - assertEquals(1, te.getAttributes().size()); + assertSize(1, te.getAttributes()); te.addAttributeValue("nfWLML6SZ4G", "heavy"); assertEquals("heavy", te.getAttributeValue("nfWLML6SZ4G")); - assertEquals(2, te.getAttributes().size()); + assertSize(2, te.getAttributes()); te.addAttributeValue("nfWLML6SZ4G", "light"); assertEquals("light", te.getAttributeValue("nfWLML6SZ4G")); - assertEquals(2, te.getAttributes().size()); + assertSize(2, te.getAttributes()); te.addAttributeValue("nfWLML6SZ4G", "super_light"); assertEquals("super_light", te.getAttributeValue("nfWLML6SZ4G")); - assertEquals(2, te.getAttributes().size()); + assertSize(2, te.getAttributes()); te.addAttributeValue("aug8T4IreCz", "large"); assertEquals("large", te.getAttributeValue("aug8T4IreCz")); - assertEquals(3, te.getAttributes().size()); + assertSize(3, te.getAttributes()); te.addAttributeValue("aug8T4IreCz", "small"); assertEquals("small", te.getAttributeValue("aug8T4IreCz")); - assertEquals(3, te.getAttributes().size()); + assertSize(3, te.getAttributes()); } } diff --git a/src/test/java/org/hisp/dhis/query/datavalue/DataValueSetQueryTest.java b/src/test/java/org/hisp/dhis/query/datavalue/DataValueSetQueryTest.java index 14204d7d..e35e9959 100644 --- a/src/test/java/org/hisp/dhis/query/datavalue/DataValueSetQueryTest.java +++ b/src/test/java/org/hisp/dhis/query/datavalue/DataValueSetQueryTest.java @@ -27,8 +27,8 @@ */ package org.hisp.dhis.query.datavalue; +import static org.hisp.dhis.support.Assertions.assertSize; import static org.hisp.dhis.util.CollectionUtils.list; -import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import org.hisp.dhis.support.TestTags; @@ -41,7 +41,7 @@ class DataValueSetQueryTest { void testAddSingleDataElement() { DataValueSetQuery query = DataValueSetQuery.instance().addDataElements(list("xEW3d2waDed")); - assertEquals(1, query.getDataElements().size()); + assertSize(1, query.getDataElements()); assertTrue(query.getDataElements().contains("xEW3d2waDed")); } @@ -52,7 +52,7 @@ void testAddMultipleDataElements() { .addDataElements(list("xEW3d2waDed", "rFew4sdfare")) .addDataElements(list("merSed1wrwL")); - assertEquals(3, query.getDataElements().size()); + assertSize(3, query.getDataElements()); assertTrue(query.getDataElements().contains("merSed1wrwL")); assertTrue(query.getDataElements().contains("rFew4sdfare")); } diff --git a/src/test/java/org/hisp/dhis/util/CollectionUtilsTest.java b/src/test/java/org/hisp/dhis/util/CollectionUtilsTest.java index 1807aeb4..058830b7 100644 --- a/src/test/java/org/hisp/dhis/util/CollectionUtilsTest.java +++ b/src/test/java/org/hisp/dhis/util/CollectionUtilsTest.java @@ -29,6 +29,7 @@ import static org.hisp.dhis.support.Assertions.assertContainsExactly; import static org.hisp.dhis.support.Assertions.assertEmpty; +import static org.hisp.dhis.support.Assertions.assertSize; import static org.hisp.dhis.util.CollectionUtils.anyStartsWith; import static org.hisp.dhis.util.CollectionUtils.empty; import static org.hisp.dhis.util.CollectionUtils.excludeIndexes; @@ -80,7 +81,7 @@ void testIndex() { Map map = index(list, value -> value.getId()); - assertEquals(3, map.keySet().size()); + assertSize(3, map.keySet()); assertEquals(pA, map.get("P01")); assertEquals(pB, map.get("P02")); assertEquals(pC, map.get("P03")); @@ -172,28 +173,28 @@ void testAnyStartsWith() { void testSetAcceptsNull() { Set set = set("a", null, "b"); - assertEquals(3, set.size()); + assertSize(3, set); } @Test void testMutableSetAcceptsNull() { Set set = mutableSet("a", null, "b"); - assertEquals(3, set.size()); + assertSize(3, set); } @Test void testListAcceptsNull() { List list = list("a", null, "b"); - assertEquals(3, list.size()); + assertSize(3, list); } @Test void testMutableListAcceptsNull() { List list = mutableList("a", null, "b"); - assertEquals(3, list.size()); + assertSize(3, list); } @Test @@ -362,7 +363,7 @@ void testMapToMapKeyMapper() { Map map = mapToMap(list, DataElement::getId); - assertEquals(3, map.keySet().size()); + assertSize(3, map.keySet()); assertEquals(deA.getId(), map.get(deA.getId()).getId()); assertEquals(deB.getId(), map.get(deB.getId()).getId()); assertEquals(deC.getId(), map.get(deC.getId()).getId()); @@ -384,7 +385,7 @@ void testMapToMapKeyAndValueMapper() { Map map = mapToMap(list, DataElement::getId, DataElement::getName); - assertEquals(3, map.keySet().size()); + assertSize(3, map.keySet()); assertEquals("Red", map.get(deA.getId())); assertEquals("Green", map.get(deB.getId())); assertEquals("Blue", map.get(deC.getId())); diff --git a/src/test/java/org/hisp/dhis/util/DuplicateFinderTest.java b/src/test/java/org/hisp/dhis/util/DuplicateFinderTest.java index 408c1bee..6fc02996 100644 --- a/src/test/java/org/hisp/dhis/util/DuplicateFinderTest.java +++ b/src/test/java/org/hisp/dhis/util/DuplicateFinderTest.java @@ -27,6 +27,7 @@ */ package org.hisp.dhis.util; +import static org.hisp.dhis.support.Assertions.assertSize; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -59,7 +60,7 @@ void testAddSingleDuplicate() { Map duplicates = finder.getDuplicates(); - assertEquals(1, duplicates.size(), "Should be one duplicate"); + assertSize(1, duplicates.keySet()); assertTrue(duplicates.containsKey("apple"), "Duplicate should be 'apple'"); assertEquals(2, duplicates.get("apple"), "'apple' should have a count of 2"); } @@ -73,7 +74,7 @@ void testAddAllSingleDuplicate() { Map duplicates = finder.getDuplicates(); - assertEquals(1, duplicates.size(), "Should be one duplicate"); + assertSize(1, duplicates.keySet()); assertTrue(duplicates.containsKey("apple"), "Duplicate should be 'apple'"); assertEquals(2, duplicates.get("apple"), "'apple' should have a count of 2"); } @@ -90,7 +91,7 @@ void testAddMultipleDuplicates() { Map duplicates = finder.getDuplicates(); - assertEquals(2, duplicates.size(), "Should be two duplicates"); + assertSize(2, duplicates.keySet()); assertTrue(duplicates.containsKey("apple"), "Duplicate should contain 'apple'"); assertEquals(2, duplicates.get("apple"), "'apple' should have a count of 2"); assertTrue(duplicates.containsKey("banana"), "Duplicate should contain 'banana'"); @@ -106,7 +107,7 @@ void testAddCaseSensitivityDuplicates() { finder.add("apple"); Map duplicates = finder.getDuplicates(); - assertEquals(2, duplicates.size(), "Should be two duplicates (case-sensitive)"); + assertSize(2, duplicates.keySet()); assertTrue(duplicates.containsKey("Apple"), "'Apple' should be a duplicate"); assertEquals(2, duplicates.get("Apple"), "'Apple' should have a count of 2"); assertTrue(duplicates.containsKey("apple"), "'apple' should be a duplicate"); @@ -133,7 +134,7 @@ void testAddOnlyDuplicates() { Map duplicates = finder.getDuplicates(); - assertEquals(2, duplicates.size(), "Should be two duplicates"); + assertSize(2, duplicates.keySet()); assertTrue(duplicates.containsKey("a"), "Duplicate should contain 'a'"); assertEquals(2, duplicates.get("a"), "'a' should have a count of 2"); assertTrue(duplicates.containsKey("b"), "Duplicate should contain 'b'"); diff --git a/src/test/java/org/hisp/dhis/util/UidUtilsTest.java b/src/test/java/org/hisp/dhis/util/UidUtilsTest.java index de9e81d9..3e5d7437 100644 --- a/src/test/java/org/hisp/dhis/util/UidUtilsTest.java +++ b/src/test/java/org/hisp/dhis/util/UidUtilsTest.java @@ -27,6 +27,7 @@ */ package org.hisp.dhis.util; +import static org.hisp.dhis.support.Assertions.assertSize; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -51,7 +52,7 @@ void testGenerateUid() { @Test void testGenerateUids() { - assertEquals(3, UidUtils.generateUids(3).size()); + assertSize(3, UidUtils.generateUids(3)); } @Test