unit test for java

how i can testing this code

 Optional<typeBooking> booking = typeBookingRepository.findById(
   (UUID) execution.getVariable(userId)
 );
if(!booking.isEmpty()) {
     booking.get().setCompletedAt(Timestamp.valueOf((getNow.atStartOfDay())));
   typeRepository.save(booking.get());
 }

file testing

void execute(DelegateExecution context) throws Exception {
  TypeBookingRepository typeBookingRepository = mock(TypeBookingRepository.class);
  EventBus mockBus = mock(EventBus.class);
  String dob = LocalDate.now().plusYears(-17).format(DateTimeFormatter.ISO_DATE);
  TypeBooking booking = TypeBooking.builder().ktpDob(dob).dob(dob).build();
  YellowAIIntegrationActivity activity = new YellowAIIntegrationActivity(mockBus, typeBookingRepository);
  when(typeBookingRepository.findById(any(UUID.class))).thenReturn(Optional.ofNullable(booking));
  UUID user_id = UUID.fromString("123e4567-e89b-42d3-a456-556642440000") ;
 activity.execute(context);
}
avatar yusufrajatamba
@yusufrajatamba

1 Kontribusi 0 Poin

Dipost 2 tahun yang lalu

Belum ada Jawaban. Jadi yang pertama Jawaban

Login untuk ikut Jawaban