WorldpayMerchantConfigurationAppender implements WorldpaySupportEmailAppender { @Override public String appendContent() { final StringBuilder merchantConfiguration = new StringBuilder(); merchantConfiguration.append(System.lineSeparator()).append("Merchant Configuration:").append(System.lineSeparator()); final Map<String, WorldpayMerchantConfigData> merchantConfigurations = getConfiguredMerchants(); for (Map.Entry<String, WorldpayMerchantConfigData> configuredMerchant : merchantConfigurations.entrySet()) { merchantConfiguration.append(ONE_TAB).append("Configured Merchant Bean Name: ").append(configuredMerchant.getKey()).append(System.lineSeparator()); merchantConfiguration.append(TWO_TABS).append("Merchant Code: ").append(configuredMerchant.getValue().getCode()).append(System.lineSeparator()); merchantConfiguration.append(TWO_TABS).append("Merchant InstallationId: ").append(configuredMerchant.getValue().getInstallationId()).append(System.lineSeparator()); merchantConfiguration.append(TWO_TABS).append("Mac Validation: ").append(configuredMerchant.getValue().getMacValidation()).append(System.lineSeparator()); merchantConfiguration.append(TWO_TABS).append("Included payment methods: "); final List<String> includedPaymentTypes = configuredMerchant.getValue().getIncludedPaymentTypes(); if (includedPaymentTypes != null) { merchantConfiguration.append(join(includedPaymentTypes, ",")); } else { merchantConfiguration.append("None"); } merchantConfiguration.append(System.lineSeparator()).append(TWO_TABS).append("Excluded payment methods: "); final List<String> excludedPaymentTypes = configuredMerchant.getValue().getExcludedPaymentTypes(); if (excludedPaymentTypes != null) { merchantConfiguration.append(join(excludedPaymentTypes, ",")).append(System.lineSeparator()); } else { merchantConfiguration.append("None").append(System.lineSeparator()); } } return merchantConfiguration.toString(); }  @Override String appendContent();  }
@Test public void testAppendContent() throws Exception { final ImmutableMap<String, WorldpayMerchantConfigData> configuredMerchants = ImmutableMap.of(WEB_BEAN_ID, webWorldpayMerchantConfigDataMock, MOBILE_BEAN_ID, mobileWorldpayMerchantConfigDataMock); doReturn(configuredMerchants).when(testObj).getConfiguredMerchants(); final List<String> includedPaymentMethods = asList(PAYMENT_METHOD_1, PAYMENT_METHOD_2); final List<String> excludedPaymentMethods = asList(PAYMENT_METHOD_3, PAYMENT_METHOD_4); when(webWorldpayMerchantConfigDataMock.getIncludedPaymentTypes()).thenReturn(includedPaymentMethods); when(webWorldpayMerchantConfigDataMock.getExcludedPaymentTypes()).thenReturn(excludedPaymentMethods); when(webWorldpayMerchantConfigDataMock.getMacValidation()).thenReturn(MAC_VALIDATION); when(webWorldpayMerchantConfigDataMock.getCode()).thenReturn(MERCHANT_CODE); when(webWorldpayMerchantConfigDataMock.getInstallationId()).thenReturn(INSTALLATION_ID); when(mobileWorldpayMerchantConfigDataMock.getIncludedPaymentTypes()).thenReturn(includedPaymentMethods); when(mobileWorldpayMerchantConfigDataMock.getExcludedPaymentTypes()).thenReturn(excludedPaymentMethods); when(mobileWorldpayMerchantConfigDataMock.getMacValidation()).thenReturn(MAC_VALIDATION); when(mobileWorldpayMerchantConfigDataMock.getCode()).thenReturn(MERCHANT_CODE); when(mobileWorldpayMerchantConfigDataMock.getInstallationId()).thenReturn(INSTALLATION_ID); final String result = testObj.appendContent(); assertTrue(result.contains("Merchant Configuration")); assertTrue(result.contains(WEB_BEAN_ID)); assertTrue(result.contains(MOBILE_BEAN_ID)); assertEquals(2, StringUtils.countMatches(result, MERCHANT_CODE)); assertEquals(2, StringUtils.countMatches(result, INSTALLATION_ID)); assertEquals(2, StringUtils.countMatches(result, String.valueOf(MAC_VALIDATION))); assertTrue(result.contains("Included payment methods")); assertEquals(2, StringUtils.countMatches(result, String.valueOf(PAYMENT_METHOD_1))); assertEquals(2, StringUtils.countMatches(result, String.valueOf(PAYMENT_METHOD_2))); assertTrue(result.contains("Excluded payment methods")); assertEquals(2, StringUtils.countMatches(result, String.valueOf(PAYMENT_METHOD_3))); assertEquals(2, StringUtils.countMatches(result, String.valueOf(PAYMENT_METHOD_4))); }