Skip to content

Commit

Permalink
add test to check failure
Browse files Browse the repository at this point in the history
  • Loading branch information
zubaira committed Nov 25, 2024
1 parent 916f741 commit ff9444a
Showing 1 changed file with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@

import java.time.Duration;
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
import org.hisp.dhis.common.CodeGenerator;
import org.hisp.dhis.common.UID;
import org.hisp.dhis.program.EnrollmentStatus;
Expand Down Expand Up @@ -119,6 +121,38 @@ void testDatesMustNotBeInTheFuture() {
() -> assertHasError(reporter, enrollment, E1021));
}

@Test
void testDatesMustNotBeInTheFuture1() {
// Get "tomorrow" based on the system's default time zone
ZoneId systemZone = ZoneId.systemDefault();
LocalDate tomorrow = LocalDate.now(systemZone).plusDays(1);
Instant dateTomorrow = tomorrow.atStartOfDay(systemZone).toInstant();

// Create enrollment with dates set to tomorrow
Enrollment enrollment =
Enrollment.builder()
.enrollment(UID.generate())
.program(MetadataIdentifier.ofUid(CodeGenerator.generateUid()))
.occurredAt(dateTomorrow)
.enrolledAt(dateTomorrow)
.build();

// Mock a program that does not allow future enrollment/incident dates
Program program = new Program();
program.setSelectEnrollmentDatesInFuture(false);
program.setSelectIncidentDatesInFuture(false);
when(preheat.getProgram(enrollment.getProgram())).thenReturn(program);

// Run validation
validator.validate(reporter, bundle, enrollment);

// Assert that the future dates are detected as errors
assertAll(
() -> assertHasError(reporter, enrollment, E1020), // enrolledAt in the future
() -> assertHasError(reporter, enrollment, E1021) // occurredAt in the future
);
}

@Test
void testDatesShouldBeAllowedOnSameDayIfFutureDatesAreNotAllowed() {
final Instant today = now().plus(Duration.ofMinutes(1));
Expand Down

0 comments on commit ff9444a

Please sign in to comment.