@Override
  public List<Badge> convert(
      final List<Locale> acceptableLanguages,
      final List<AccountBadge> accountBadges,
      final boolean isSelf) {
    if (accountBadges.isEmpty() && badgeIdsEnabledForAll.isEmpty()) {
      return List.of();
    }

    final Instant now = clock.instant();
    final ResourceBundle resourceBundle = headerControlledResourceBundleLookup.getResourceBundle(BASE_NAME,
        acceptableLanguages);
    List<Badge> badges = accountBadges.stream()
        .filter(accountBadge -> (isSelf || accountBadge.isVisible())
            && now.isBefore(accountBadge.getExpiration())
            && knownBadges.containsKey(accountBadge.getId()))
        .map(accountBadge -> {
          BadgeConfiguration configuration = knownBadges.get(accountBadge.getId());
          return newBadge(
              isSelf,
              accountBadge.getId(),
              configuration.getCategory(),
              resourceBundle.getString(accountBadge.getId() + "_name"),
              resourceBundle.getString(accountBadge.getId() + "_description"),
              configuration.getSprites(),
              configuration.getSvg(),
              configuration.getSvgs(),
              accountBadge.getExpiration(),
              accountBadge.isVisible());
        })
        .collect(Collectors.toCollection(ArrayList::new));
    badges.addAll(badgeIdsEnabledForAll.stream().filter(knownBadges::containsKey).map(id -> {
      BadgeConfiguration configuration = knownBadges.get(id);
      return newBadge(
          isSelf,
          id,
          configuration.getCategory(),
          resourceBundle.getString(id + "_name"),
          resourceBundle.getString(id + "_description"),
          configuration.getSprites(),
          configuration.getSvg(),
          configuration.getSvgs(),
          now.plus(Duration.ofDays(1)),
          true);
    }).collect(Collectors.toList()));
    return badges;
  }
@Test
  void testCustomControl() {
    BadgesConfiguration badgesConfiguration = createBadges(1);
    ConfiguredProfileBadgeConverter badgeConverter =
        new ConfiguredProfileBadgeConverter(clock, badgesConfiguration,
            new HeaderControlledResourceBundleLookup(resourceBundleFactory));

    Locale defaultLocale = Locale.getDefault();
    Locale enGb = new Locale("en", "GB");
    Locale en = new Locale("en");
    Locale esUs = new Locale("es", "US");

    ArgumentCaptor<Control> controlArgumentCaptor = setupResourceBundle(enGb);
    badgeConverter.convert(List.of(enGb, en, esUs),
        List.of(new AccountBadge(idFor(0), Instant.ofEpochSecond(43), true)), false);
    Control control = controlArgumentCaptor.getValue();

    assertThatNullPointerException().isThrownBy(() -> control.getFormats(null));
    assertThatNullPointerException().isThrownBy(() -> control.getFallbackLocale(null, enGb));
    assertThatNullPointerException().isThrownBy(
        () -> control.getFallbackLocale(ConfiguredProfileBadgeConverter.BASE_NAME, null));

    assertThat(control.getFormats(ConfiguredProfileBadgeConverter.BASE_NAME)).isNotNull().hasSize(1).containsOnly(
        Control.FORMAT_PROPERTIES.toArray(new String[0]));

    try {
      // temporarily override for purpose of ensuring this test doesn't change based on system default locale
      Locale.setDefault(new Locale("xx", "XX"));

      assertThat(control.getFallbackLocale(ConfiguredProfileBadgeConverter.BASE_NAME, enGb)).isEqualTo(en);
      assertThat(control.getFallbackLocale(ConfiguredProfileBadgeConverter.BASE_NAME, en)).isEqualTo(esUs);
      assertThat(control.getFallbackLocale(ConfiguredProfileBadgeConverter.BASE_NAME, esUs)).isEqualTo(
          Locale.getDefault());
      assertThat(control.getFallbackLocale(ConfiguredProfileBadgeConverter.BASE_NAME, Locale.getDefault())).isNull();

      // now test what happens if the system default locale is in the list
      // this should always terminate at the system default locale since the development defined bundle should get
      // returned at that point anyhow
      badgeConverter.convert(List.of(enGb, Locale.getDefault(), en, esUs),
          List.of(new AccountBadge(idFor(0), Instant.ofEpochSecond(43), true)), false);
      Control control2 = controlArgumentCaptor.getValue();

      assertThat(control2.getFallbackLocale(ConfiguredProfileBadgeConverter.BASE_NAME, enGb)).isEqualTo(
          Locale.getDefault());
      assertThat(control2.getFallbackLocale(ConfiguredProfileBadgeConverter.BASE_NAME, Locale.getDefault())).isNull();
    } finally {
      Locale.setDefault(defaultLocale);
    }
  }