DefaultAPMConfigurationLookupService implements APMConfigurationLookupService { @Override public WorldpayAPMConfigurationModel getAPMConfigurationForCode(final String paymentTypeCode) { final Map<String, String> queryParams = Collections.singletonMap(WorldpayAPMConfigurationModel.CODE, paymentTypeCode); final List<WorldpayAPMConfigurationModel> worldpayAPMConfigurationModels = worldpayAPMConfigurationDao.find(queryParams); if (worldpayAPMConfigurationModels.isEmpty()) { LOG.error(MessageFormat.format("Could not find unique WorldpayAlternativePaymentMethod with code [{0}]", paymentTypeCode)); return null; } else { final WorldpayAPMConfigurationModel worldpayAPMConfigurationModel = worldpayAPMConfigurationModels.get(0); if (worldpayAPMConfigurationModels.size() > 1) { LOG.error(MessageFormat.format("Multiple WorldpayAPMConfiguration with code [{0}], returning first [{1}]", paymentTypeCode, worldpayAPMConfigurationModel.getCode())); return worldpayAPMConfigurationModel; } else { return worldpayAPMConfigurationModel; } } }  @Override WorldpayAPMConfigurationModel getAPMConfigurationForCode(final String paymentTypeCode); @Override Set<String> getAllApmPaymentTypeCodes(); @Required void setWorldpayAPMConfigurationDao(final WorldpayAPMConfigurationDao worldpayAPMConfigurationDao);  }
@Test public void getAPMConfigReturnsAWorldpayAPMConfigModel() { when(worldpayAPMConfigurationDaoMock.find(Collections.singletonMap(WorldpayAPMConfigurationModel.CODE, PAYMENT_TYPE_CODE))).thenReturn(Collections.singletonList(worldpayAPMConfigurationModelMock)); when(worldpayAPMConfigurationModelMock.getName()).thenReturn(PAYMENT_APM_NAME); final WorldpayAPMConfigurationModel result = testObj.getAPMConfigurationForCode(PAYMENT_TYPE_CODE); assertEquals(worldpayAPMConfigurationModelMock, result); assertEquals(worldpayAPMConfigurationModelMock.getName(), PAYMENT_APM_NAME); }
@Test public void getAPMConfigDaoReturnsEmptyList() { when(worldpayAPMConfigurationDaoMock.find(Collections.singletonMap(WorldpayAPMConfigurationModel.CODE, PAYMENT_TYPE_CODE))).thenReturn(Collections.emptyList()); final WorldpayAPMConfigurationModel result = testObj.getAPMConfigurationForCode(PAYMENT_TYPE_CODE); assertEquals(null, result); }
@Test public void getAPMConfigDaoReturnsMoreThan1APM() { when(mockedList.size()).thenReturn(2); when(mockedList.get(0)).thenReturn(worldpayAPMConfigurationModelMock); when(worldpayAPMConfigurationDaoMock.find(Collections.singletonMap(WorldpayAPMConfigurationModel.CODE, PAYMENT_TYPE_CODE))).thenReturn(mockedList); final WorldpayAPMConfigurationModel result = testObj.getAPMConfigurationForCode(PAYMENT_TYPE_CODE); assertEquals(worldpayAPMConfigurationModelMock, result); }