Fix configuration replacement (#10081)

* Fix configuration replacement
This commit is contained in:
Jan Bartel 2023-07-08 09:36:56 +02:00 committed by GitHub
parent 0c5b07b0ae
commit e22fbbf175
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 1 deletions

View File

@ -231,7 +231,10 @@ public class Configurations extends AbstractList<Configuration> implements Dumpa
public Configurations(List<Configuration> configurations)
{
_configurations = new ArrayList<>(configurations == null ? Collections.emptyList() : configurations);
_configurations = new ArrayList<>();
//ensure replacements are processed
if (configurations != null)
configurations.forEach(this::add);
}
public Configurations(Configuration... configurations)

View File

@ -135,6 +135,44 @@ public class ConfigurationsTest
assertThat(configs.getConfigurations().size(), equalTo(2));
}
@Test
public void testReplacementWithInstances()
{
//ConfigDick should be replaced by ReplacementDick
Configurations configs = new Configurations(
new ConfigDick(),
new ConfigBar(),
new ConfigZ(),
new ConfigY(),
new ConfigX(),
new ConfigTom(),
new ReplacementDick(),
new ConfigHarry(),
new ConfigAdditionalHarry(),
new ConfigFoo()
);
configs.sort();
assertThat(configs.stream().map(c -> c.getClass().getName()).collect(toList()),
contains(
ConfigFoo.class.getName(),
ConfigBar.class.getName(),
ConfigX.class.getName(),
ConfigY.class.getName(),
ConfigZ.class.getName(),
ConfigTom.class.getName(),
ReplacementDick.class.getName(),
ConfigHarry.class.getName(),
ConfigAdditionalHarry.class.getName()
));
assertThat(configs.stream().map(c -> c.getClass().getName()).collect(toList()),
not(contains(
ConfigDick.class.getName()
)));
}
@Test
public void testReplacement()
{