@Test public void testTranslateLocaleNoMapping() throws Exception { final PaymentGateway pg = context.mock(PaymentGateway.class); context.checking(new Expectations() {{ allowing(pg).getParameterValue("LANGUAGE_MAP"); will(returnValue("")); }}); final PaymentLocaleTranslator translator = new PaymentLocaleTranslatorImpl(); assertEquals("de", translator.translateLocale(pg, "de")); context.assertIsSatisfied(); }
@Override public String translateLocale(final PaymentGateway paymentGateway, final String locale) { final String mapping = paymentGateway.getParameterValue("LANGUAGE_MAP"); if (StringUtils.isNotBlank(mapping)) { final Map<String, String> all = new HashMap<>(); final String[] map = StringUtils.split(mapping, ','); for (final String mapItem : map) { final String[] item = StringUtils.split(mapItem.trim(), '='); all.put(item[0].trim(), item[1].trim()); } if (all.containsKey(locale)) { return all.get(locale); } if (all.containsKey(I18NModel.DEFAULT)) { return all.get(I18NModel.DEFAULT); } } return locale; }
PaymentLocaleTranslatorImpl implements PaymentLocaleTranslator { @Override public String translateLocale(final PaymentGateway paymentGateway, final String locale) { final String mapping = paymentGateway.getParameterValue("LANGUAGE_MAP"); if (StringUtils.isNotBlank(mapping)) { final Map<String, String> all = new HashMap<>(); final String[] map = StringUtils.split(mapping, ','); for (final String mapItem : map) { final String[] item = StringUtils.split(mapItem.trim(), '='); all.put(item[0].trim(), item[1].trim()); } if (all.containsKey(locale)) { return all.get(locale); } if (all.containsKey(I18NModel.DEFAULT)) { return all.get(I18NModel.DEFAULT); } } return locale; } }
PaymentLocaleTranslatorImpl implements PaymentLocaleTranslator { @Override public String translateLocale(final PaymentGateway paymentGateway, final String locale) { final String mapping = paymentGateway.getParameterValue("LANGUAGE_MAP"); if (StringUtils.isNotBlank(mapping)) { final Map<String, String> all = new HashMap<>(); final String[] map = StringUtils.split(mapping, ','); for (final String mapItem : map) { final String[] item = StringUtils.split(mapItem.trim(), '='); all.put(item[0].trim(), item[1].trim()); } if (all.containsKey(locale)) { return all.get(locale); } if (all.containsKey(I18NModel.DEFAULT)) { return all.get(I18NModel.DEFAULT); } } return locale; }  }
PaymentLocaleTranslatorImpl implements PaymentLocaleTranslator { @Override public String translateLocale(final PaymentGateway paymentGateway, final String locale) { final String mapping = paymentGateway.getParameterValue("LANGUAGE_MAP"); if (StringUtils.isNotBlank(mapping)) { final Map<String, String> all = new HashMap<>(); final String[] map = StringUtils.split(mapping, ','); for (final String mapItem : map) { final String[] item = StringUtils.split(mapItem.trim(), '='); all.put(item[0].trim(), item[1].trim()); } if (all.containsKey(locale)) { return all.get(locale); } if (all.containsKey(I18NModel.DEFAULT)) { return all.get(I18NModel.DEFAULT); } } return locale; }  @Override String translateLocale(final PaymentGateway paymentGateway, final String locale); }
PaymentLocaleTranslatorImpl implements PaymentLocaleTranslator { @Override public String translateLocale(final PaymentGateway paymentGateway, final String locale) { final String mapping = paymentGateway.getParameterValue("LANGUAGE_MAP"); if (StringUtils.isNotBlank(mapping)) { final Map<String, String> all = new HashMap<>(); final String[] map = StringUtils.split(mapping, ','); for (final String mapItem : map) { final String[] item = StringUtils.split(mapItem.trim(), '='); all.put(item[0].trim(), item[1].trim()); } if (all.containsKey(locale)) { return all.get(locale); } if (all.containsKey(I18NModel.DEFAULT)) { return all.get(I18NModel.DEFAULT); } } return locale; }  @Override String translateLocale(final PaymentGateway paymentGateway, final String locale);  }