Fix plugin wizard for foreign languages (#2086)

This fixes the plugin wizard, that throws a NullPointerException for other languages then Englisch or German.
This commit is contained in:
René Pfeuffer
2022-07-13 09:28:56 +02:00
committed by GitHub
parent fc2a40cab5
commit d7943a0551
3 changed files with 38 additions and 13 deletions

View File

@@ -0,0 +1,2 @@
- type: fixed
description: Plugin wizard for foreign languages ([#2086](https://github.com/scm-manager/scm-manager/pull/2086))

View File

@@ -59,6 +59,9 @@ public class PluginSetDtoMapper {
.collect(Collectors.toList());
PluginSet.Description description = pluginSet.getDescriptions().get(locale.getLanguage());
if (description == null) {
description = pluginSet.getDescriptions().get(Locale.ENGLISH.getLanguage());
}
return new PluginSetDto(pluginSet.getId(), pluginSet.getSequence(), pluginDtos, description.getName(), description.getFeatures(), pluginSet.getImages());
}

View File

@@ -52,6 +52,35 @@ class PluginSetDtoMapperTest {
@Test
void shouldMap() {
List<AvailablePlugin> availablePlugins = createAvailablePlugins();
ImmutableSet<PluginSet> pluginSets = createPluginSets();
List<PluginSetDto> dtos = mapper.map(pluginSets, availablePlugins, Locale.ENGLISH);
assertThat(dtos).hasSize(2);
PluginSetDto first = dtos.get(0);
assertThat(first.getSequence()).isZero();
assertThat(first.getName()).isEqualTo("My Plugin Set 2");
assertThat(first.getFeatures()).contains("this is also awesome!");
assertThat(first.getImages()).isNotEmpty();
assertThat(first.getPlugins()).hasSize(2);
assertThat(dtos.get(1).getSequence()).isEqualTo(1);
}
@Test
void shouldMapWithOtherLanguage() {
List<AvailablePlugin> availablePlugins = createAvailablePlugins();
ImmutableSet<PluginSet> pluginSets = createPluginSets();
List<PluginSetDto> dtos = mapper.map(pluginSets, availablePlugins, Locale.FRENCH);
assertThat(dtos).hasSize(2);
PluginSetDto first = dtos.get(0);
assertThat(first.getName()).isEqualTo("My Plugin Set 2");
}
private List<AvailablePlugin> createAvailablePlugins() {
AvailablePlugin git = createAvailable("scm-git-plugin");
AvailablePlugin svn = createAvailable("scm-svn-plugin");
AvailablePlugin hg = createAvailable("scm-hg-plugin");
@@ -66,8 +95,10 @@ class PluginSetDtoMapperTest {
when(pluginDtoMapper.mapAvailable(svn)).thenReturn(svnDto);
when(pluginDtoMapper.mapAvailable(hg)).thenReturn(hgDto);
List<AvailablePlugin> availablePlugins = List.of(git, svn, hg);
return List.of(git, svn, hg);
}
private ImmutableSet<PluginSet> createPluginSets() {
PluginSet pluginSet = new PluginSet(
"my-plugin-set",
1,
@@ -83,17 +114,6 @@ class PluginSetDtoMapperTest {
ImmutableMap.of("en", new PluginSet.Description("My Plugin Set 2", List.of("this is also awesome!"))),
ImmutableMap.of("standard", "base64image")
);
ImmutableSet<PluginSet> pluginSets = ImmutableSet.of(pluginSet, pluginSet2);
List<PluginSetDto> dtos = mapper.map(pluginSets, availablePlugins, Locale.ENGLISH);
assertThat(dtos).hasSize(2);
PluginSetDto first = dtos.get(0);
assertThat(first.getSequence()).isZero();
assertThat(first.getName()).isEqualTo("My Plugin Set 2");
assertThat(first.getFeatures()).contains("this is also awesome!");
assertThat(first.getImages()).isNotEmpty();
assertThat(first.getPlugins()).hasSize(2);
assertThat(dtos.get(1).getSequence()).isEqualTo(1);
return ImmutableSet.of(pluginSet, pluginSet2);
}
}