Skip to content

Commit

Permalink
Create a deep copy of the first found fragment before merging other f…
Browse files Browse the repository at this point in the history
…ragments into it (openhab#2412)

Signed-off-by: Christoph Weitkamp <[email protected]>
  • Loading branch information
cweitkamp authored and ghys committed Sep 9, 2021
1 parent 3e7f8ed commit d0d4a31
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ public void removeStateDescriptionFragmentProvider(StateDescriptionFragmentProvi

// we pick up the first valid StateDescriptionFragment here:
if (result == null) {
result = (StateDescriptionFragmentImpl) fragment;
// create a deep copy of the first found fragment before merging other fragments into it
result = new StateDescriptionFragmentImpl((StateDescriptionFragmentImpl) fragment);
} else {
result.merge(fragment);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void testIsReadOnlyWhenTwoDescriptionProvidersHigherRankingIsNotReadOnly(

StateDescription stateDescription = item.getStateDescription();

assertThat(stateDescription.isReadOnly(), is(stateDescriptionFragment1.isReadOnly()));
assertThat(stateDescription.isReadOnly(), is(stateDescriptionFragment2.isReadOnly()));
}

@Test
Expand Down Expand Up @@ -167,8 +167,7 @@ public void testFragmentsAreMergedInProviderOrder() {
.withMinimum(BigDecimal.ZERO) //
.withMaximum(BigDecimal.TEN) //
.withPattern("pattern") //
.withReadOnly(Boolean.TRUE) //
.withOptions(options).build();
.withReadOnly(Boolean.TRUE).build();
registerStateDescriptionFragmentProvider(stateDescriptionFragment1, -1);

StateDescriptionFragment stateDescriptionFragment2 = StateDescriptionFragmentBuilder.create()
Expand All @@ -187,6 +186,8 @@ public void testFragmentsAreMergedInProviderOrder() {
assertThat(stateDescription.getPattern(), is("pattern"));
assertThat(stateDescription.isReadOnly(), is(true));
assertThat(stateDescription.getOptions(), is(options));
// check that fragement2 is not merged into fragement1
assertThat(stateDescriptionFragment1.getOptions().size(), is(0));
}

private void registerStateDescriptionFragmentProvider(StateDescriptionFragment stateDescriptionFragment,
Expand Down

0 comments on commit d0d4a31

Please sign in to comment.