ReservationsPreferences 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 ReservationsPreferences(); p.accept(t); verify(z, never()).getPendingReservations(); }
@Test void disabled() { final Zonky z = harmlessZonky(); final Tenant t = mockTenant(z); when(t.getReservationStrategy()).thenReturn(Optional.of(WRONG_STRATEGY)); final TenantPayload p = new ReservationsPreferences(); p.accept(t); verify(z, never()).getReservationPreferences(); }
@Test void enable() { final Zonky z = harmlessZonky(); when(z.getReservationPreferences()).thenReturn(new ReservationPreferencesImpl()); final Tenant t = mockTenant(z); when(t.getReservationStrategy()).thenReturn(Optional.of(CORRECT_STRATEGY)); final TenantPayload p = new ReservationsPreferences(); p.accept(t); verify(z).getReservationPreferences(); verify(z).setReservationPreferences(any()); }
@Test void enabledAndDoesNotNeedChanging() { final Zonky z = harmlessZonky(); when(z.getReservationPreferences()).thenReturn(ReservationPreferencesImpl.TOTAL.get()); final Tenant t = mockTenant(z); when(t.getReservationStrategy()).thenReturn(Optional.of(CORRECT_STRATEGY)); final TenantPayload p = new ReservationsPreferences(); p.accept(t); verify(z).getReservationPreferences(); verify(z, never()).setReservationPreferences(any()); }
@Test void enabledAndNeedsChanging() { final ReservationPreferenceImpl rp = new ReservationPreferenceImpl(LoanTermInterval.FROM_0_TO_12, Rating.AAAAA, false); final Zonky z = harmlessZonky(); when(z.getReservationPreferences()).thenReturn(new ReservationPreferencesImpl(rp)); final Tenant t = mockTenant(z); when(t.getReservationStrategy()).thenReturn(Optional.of(CORRECT_STRATEGY)); final TenantPayload p = new ReservationsPreferences(); p.accept(t); verify(z).getReservationPreferences(); verify(z).setReservationPreferences(any()); }