ReservationsProcessing implements TenantPayload { @Override public void accept(final Tenant tenant) { tenant.getReservationStrategy() .ifPresent(s -> process((PowerTenant) tenant, s)); }  @Override void accept(final Tenant tenant);  }
@Test void noStrategy() { final Zonky z = harmlessZonky(); final Tenant t = mockTenant(z); final TenantPayload p = new ReservationsProcessing(); p.accept(t); verify(z, never()).getPendingReservations(); }
@Test void disabledOnline() { final Zonky z = harmlessZonky(); when(z.getReservationPreferences()).thenReturn(new ReservationPreferencesImpl()); final Tenant t = mockTenant(z); when(t.getReservationStrategy()).thenReturn(Optional.of(ALL_ACCEPTING_STRATEGY)); final TenantPayload p = new ReservationsProcessing(); p.accept(t); verify(z).getReservationPreferences(); verify(z, never()).getPendingReservations(); }
@Test void enabled() { final Zonky z = harmlessZonky(); final Reservation simple = new MockReservationBuilder() .set(ReservationImpl::setMyReservation, mockMyReservation()) .build(); final Loan fresh = MockLoanBuilder.fresh(); when(z.getLoan(eq(simple.getId()))).thenReturn(fresh); when(z.getReservationPreferences()).thenReturn(new ReservationPreferencesImpl(SOME_PREFERENCE)); when(z.getPendingReservations()).thenReturn(Stream.of(simple)); final Tenant t = mockTenant(z, false); when(t.getReservationStrategy()).thenReturn(Optional.of(ALL_ACCEPTING_STRATEGY)); final TenantPayload p = new ReservationsProcessing(); p.accept(t); verify(z).accept(eq(simple)); assertThat(getEventsRequested()).hasSize(4); }
@Test void skipsInvestmentsProperly() { final Zonky z = harmlessZonky(); final Reservation simple = new MockReservationBuilder() .set(ReservationImpl::setMyReservation, mockMyReservation()) .build(); final Reservation simple2 = new MockReservationBuilder() .set(ReservationImpl::setMyReservation, mockMyReservation()) .build(); final Loan fresh1 = MockLoanBuilder.fresh(); final Loan fresh2 = MockLoanBuilder.fresh(); when(z.getLoan(eq(simple.getId()))).thenReturn(fresh1); when(z.getLoan(eq(simple2.getId()))).thenReturn(fresh2); when(z.getReservationPreferences()).thenReturn(new ReservationPreferencesImpl(SOME_PREFERENCE)); when(z.getPendingReservations()).thenReturn(Stream.of(simple, simple, simple2)); final Tenant t = mockTenant(z, false); when(t.getReservationStrategy()).thenReturn(Optional.of(ALL_ACCEPTING_STRATEGY)); final TenantPayload p = new ReservationsProcessing(); p.accept(t); verify(z, times(1)).accept(eq(simple)); verify(z, times(1)).accept(eq(simple2)); assertThat(getEventsRequested()).hasSize(6); }