Repository: wicket Updated Branches: refs/heads/wicket-7.x 8e678fd26 -> d7a00f557
WICKET-6623 correctly remove consecutive temporary behaviors Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/d7a00f55 Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/d7a00f55 Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/d7a00f55 Branch: refs/heads/wicket-7.x Commit: d7a00f557cd576ba3cf0f1e9e2c26911bc9bb5b9 Parents: 8e678fd Author: Igor Vaynberg <[email protected]> Authored: Tue Dec 11 15:36:54 2018 -0800 Committer: Igor Vaynberg <[email protected]> Committed: Tue Dec 11 15:50:40 2018 -0800 ---------------------------------------------------------------------- .../main/java/org/apache/wicket/Behaviors.java | 4 +- .../apache/wicket/behavior/BehaviorTest.java | 66 ++++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/d7a00f55/wicket-core/src/main/java/org/apache/wicket/Behaviors.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/Behaviors.java b/wicket-core/src/main/java/org/apache/wicket/Behaviors.java index 3d406f2..672cc57 100644 --- a/wicket-core/src/main/java/org/apache/wicket/Behaviors.java +++ b/wicket-core/src/main/java/org/apache/wicket/Behaviors.java @@ -126,7 +126,7 @@ final class Behaviors implements IDetachable @Override public final void detach() { - final int len = component.data_length(); + int len = component.data_length(); for (int i = component.data_start(); i < len; i++) { Object obj = component.data_get(i); @@ -139,6 +139,8 @@ final class Behaviors implements IDetachable if (behavior.isTemporary(component)) { internalRemove(behavior); + i--; + len--; } } } http://git-wip-us.apache.org/repos/asf/wicket/blob/d7a00f55/wicket-core/src/test/java/org/apache/wicket/behavior/BehaviorTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/behavior/BehaviorTest.java b/wicket-core/src/test/java/org/apache/wicket/behavior/BehaviorTest.java new file mode 100644 index 0000000..37862f7 --- /dev/null +++ b/wicket-core/src/test/java/org/apache/wicket/behavior/BehaviorTest.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.wicket.behavior; + +import static org.hamcrest.Matchers.*; + +import org.apache.wicket.Component; +import org.apache.wicket.MockPageWithOneComponent; +import org.apache.wicket.markup.html.WebMarkupContainer; +import org.apache.wicket.util.tester.TagTester; +import org.apache.wicket.util.tester.WicketTestCase; +import org.junit.Test; + +/** + * Tests for {@link Behavior} + */ +public class BehaviorTest extends WicketTestCase +{ + + @Test + public void temporaryBehaviorsAreRemoved() { + WebMarkupContainer container = new WebMarkupContainer("test"); + TestTemporaryBehavior temp = new TestTemporaryBehavior(); + container.add(temp); + assertTrue(container.getBehaviors().contains(temp)); + container.detach(); + assertFalse(container.getBehaviors().contains(temp)); + } + + @Test + public void consecutiveTemporaryBehaviorsAreRemoved() { + WebMarkupContainer container = new WebMarkupContainer("test"); + TestTemporaryBehavior temp1 = new TestTemporaryBehavior(); + TestTemporaryBehavior temp2 = new TestTemporaryBehavior(); + container.add(temp1, temp2); + assertTrue(container.getBehaviors().contains(temp1)); + assertTrue(container.getBehaviors().contains(temp2)); + container.detach(); + assertFalse(container.getBehaviors().contains(temp1)); + assertFalse(container.getBehaviors().contains(temp2)); + } + + private static class TestTemporaryBehavior extends Behavior { + private static final long serialVersionUID = 1L; + + @Override + public boolean isTemporary(Component c) { + return true; + } + } + +}
