APMAvailabilityBankStrategy implements APMAvailabilityStrategy { @Override public boolean isAvailable(final WorldpayAPMConfigurationModel apmConfiguration, final CartModel cartModel) { if (!apmConfiguration.getBank()) { return true; } else { return CollectionUtils.isNotEmpty(worldpayBankConfigurationLookupService.getActiveBankConfigurationsForCode(apmConfiguration.getCode())); } }  @Override boolean isAvailable(final WorldpayAPMConfigurationModel apmConfiguration, final CartModel cartModel); @Required void setWorldpayBankConfigurationLookupService(WorldpayBankConfigurationLookupService worldpayBankConfigurationLookupService);  }
@Test public void testIsAvailableWhenAPMIsBankAndThereAreBanksConfigured() { when(apmConfigurationMock.getBank()).thenReturn(Boolean.TRUE); when(apmConfigurationMock.getCode()).thenReturn(APM_CODE); when(worldpayBankConfigurationLookupServiceMock.getActiveBankConfigurationsForCode(APM_CODE)).thenReturn(Collections.singletonList(worldpayBankConfigurationModel)); final boolean result = testObj.isAvailable(apmConfigurationMock, cartModelMock); assertTrue(result); }
@Test public void testIsAvailableWhenAPMIsBankAndThereAreNoBanksConfigured() { when(apmConfigurationMock.getBank()).thenReturn(Boolean.TRUE); when(apmConfigurationMock.getCode()).thenReturn(APM_CODE); when(worldpayBankConfigurationLookupServiceMock.getActiveBankConfigurationsForCode(APM_CODE)).thenReturn(Collections.emptyList()); final boolean result = testObj.isAvailable(apmConfigurationMock, cartModelMock); assertFalse(result); }
@Test public void testIsAvailableWhenAPMIsNotBank() { when(apmConfigurationMock.getBank()).thenReturn(Boolean.FALSE); final boolean result = testObj.isAvailable(apmConfigurationMock, cartModelMock); assertTrue(result); }