Repository: wicket Updated Branches: refs/heads/master f734ad676 -> da937bb0f
WICKET-6322 remove lambda factories removed Lambdas; removed factory method with more than one lambda Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/da937bb0 Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/da937bb0 Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/da937bb0 Branch: refs/heads/master Commit: da937bb0fe990a02a96c389e8904d62cf172a89c Parents: f734ad6 Author: Sven Meier <[email protected]> Authored: Mon Apr 3 14:45:16 2017 +0200 Committer: Sven Meier <[email protected]> Committed: Mon Apr 3 14:48:34 2017 +0200 ---------------------------------------------------------------------- ...AjaxFormChoiceComponentUpdatingBehavior.java | 35 -- .../form/AjaxFormComponentUpdatingBehavior.java | 38 --- .../ajax/form/AjaxFormSubmitBehavior.java | 36 --- .../wicket/ajax/form/OnChangeAjaxBehavior.java | 36 --- .../java/org/apache/wicket/lambda/Lambdas.java | 316 ------------------- .../apache/wicket/behavior/BehaviorTest.java | 66 ++++ .../org/apache/wicket/lambda/LambdasTest.java | 68 ---- .../wicket/examples/compref/LinkPage.java | 4 +- 8 files changed, 68 insertions(+), 531 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/da937bb0/wicket-core/src/main/java/org/apache/wicket/ajax/form/AjaxFormChoiceComponentUpdatingBehavior.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/ajax/form/AjaxFormChoiceComponentUpdatingBehavior.java b/wicket-core/src/main/java/org/apache/wicket/ajax/form/AjaxFormChoiceComponentUpdatingBehavior.java index 7fe6c7c..e4e8b79 100644 --- a/wicket-core/src/main/java/org/apache/wicket/ajax/form/AjaxFormChoiceComponentUpdatingBehavior.java +++ b/wicket-core/src/main/java/org/apache/wicket/ajax/form/AjaxFormChoiceComponentUpdatingBehavior.java @@ -27,7 +27,6 @@ import org.apache.wicket.markup.html.form.FormComponent; import org.apache.wicket.markup.html.form.RadioChoice; import org.apache.wicket.markup.html.form.RadioGroup; import org.apache.wicket.util.lang.Args; -import org.danekja.java.util.function.serializable.SerializableBiConsumer; import org.danekja.java.util.function.serializable.SerializableConsumer; /** @@ -136,38 +135,4 @@ public abstract class AjaxFormChoiceComponentUpdatingBehavior extends } }; } - - /** - * Creates an {@link AjaxFormChoiceComponentUpdatingBehavior} based on lambda expressions - * - * @param onUpdateChoice - * the {@code SerializableConsumer} which accepts the {@link AjaxRequestTarget} - * @param onError - * the {@code SerializableBiConsumer} which accepts the {@link AjaxRequestTarget} and the - * {@link RuntimeException} - * @return the {@link AjaxFormChoiceComponentUpdatingBehavior} - */ - public static AjaxFormChoiceComponentUpdatingBehavior onUpdateChoice( - SerializableConsumer<AjaxRequestTarget> onUpdateChoice, - SerializableBiConsumer<AjaxRequestTarget, RuntimeException> onError) - { - Args.notNull(onUpdateChoice, "onUpdateChoice"); - Args.notNull(onError, "onError"); - return new AjaxFormChoiceComponentUpdatingBehavior() - { - private static final long serialVersionUID = 1L; - - @Override - protected void onUpdate(AjaxRequestTarget target) - { - onUpdateChoice.accept(target); - } - - @Override - protected void onError(AjaxRequestTarget target, RuntimeException e) - { - onError.accept(target, e); - } - }; - } } http://git-wip-us.apache.org/repos/asf/wicket/blob/da937bb0/wicket-core/src/main/java/org/apache/wicket/ajax/form/AjaxFormComponentUpdatingBehavior.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/ajax/form/AjaxFormComponentUpdatingBehavior.java b/wicket-core/src/main/java/org/apache/wicket/ajax/form/AjaxFormComponentUpdatingBehavior.java index 4236692..09474d5 100644 --- a/wicket-core/src/main/java/org/apache/wicket/ajax/form/AjaxFormComponentUpdatingBehavior.java +++ b/wicket-core/src/main/java/org/apache/wicket/ajax/form/AjaxFormComponentUpdatingBehavior.java @@ -26,7 +26,6 @@ import org.apache.wicket.ajax.attributes.AjaxRequestAttributes.Method; import org.apache.wicket.markup.html.form.FormComponent; import org.apache.wicket.markup.html.form.validation.IFormValidator; import org.apache.wicket.util.lang.Args; -import org.danekja.java.util.function.serializable.SerializableBiConsumer; import org.danekja.java.util.function.serializable.SerializableConsumer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -247,41 +246,4 @@ public abstract class AjaxFormComponentUpdatingBehavior extends AjaxEventBehavio } }; } - - /** - * Creates an {@link AjaxFormComponentUpdatingBehavior} based on lambda expressions - * - * @param eventName - * the event name - * @param onUpdate - * the {@code SerializableConsumer} which accepts the {@link AjaxRequestTarget} - * @param onError - * the {@code SerializableBiConsumer} which accepts the {@link AjaxRequestTarget} and - * the {@link RuntimeException} - * @return the {@link AjaxFormComponentUpdatingBehavior} - */ - public static AjaxFormComponentUpdatingBehavior onUpdate(String eventName, - SerializableConsumer<AjaxRequestTarget> onUpdate, - SerializableBiConsumer<AjaxRequestTarget, RuntimeException> onError) - { - Args.notNull(onUpdate, "onUpdate"); - Args.notNull(onError, "onError"); - - return new AjaxFormComponentUpdatingBehavior(eventName) - { - private static final long serialVersionUID = 1L; - - @Override - protected void onUpdate(AjaxRequestTarget target) - { - onUpdate.accept(target); - } - - @Override - protected void onError(AjaxRequestTarget target, RuntimeException e) - { - onError.accept(target, e); - } - }; - } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/wicket/blob/da937bb0/wicket-core/src/main/java/org/apache/wicket/ajax/form/AjaxFormSubmitBehavior.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/ajax/form/AjaxFormSubmitBehavior.java b/wicket-core/src/main/java/org/apache/wicket/ajax/form/AjaxFormSubmitBehavior.java index 8542379..0700d09 100644 --- a/wicket-core/src/main/java/org/apache/wicket/ajax/form/AjaxFormSubmitBehavior.java +++ b/wicket-core/src/main/java/org/apache/wicket/ajax/form/AjaxFormSubmitBehavior.java @@ -299,40 +299,4 @@ public abstract class AjaxFormSubmitBehavior extends AjaxEventBehavior } }; } - - /** - * Creates an {@link AjaxFormSubmitBehavior} based on lambda expressions - * - * @param eventName - * the event name - * @param onSubmit - * the {@code SerializableConsumer} which accepts the {@link AjaxRequestTarget} - * @param onError - * the {@code SerializableConsumer} which accepts the {@link AjaxRequestTarget} - * @return the {@link AjaxFormSubmitBehavior} - */ - public static AjaxFormSubmitBehavior onSubmit(String eventName, - SerializableConsumer<AjaxRequestTarget> onSubmit, - SerializableConsumer<AjaxRequestTarget> onError) - { - Args.notNull(onSubmit, "onSubmit"); - Args.notNull(onError, "onError"); - - return new AjaxFormSubmitBehavior(eventName) - { - private static final long serialVersionUID = 1L; - - @Override - protected void onSubmit(AjaxRequestTarget target) - { - onSubmit.accept(target); - } - - @Override - protected void onError(AjaxRequestTarget target) - { - onError.accept(target); - } - }; - } } http://git-wip-us.apache.org/repos/asf/wicket/blob/da937bb0/wicket-core/src/main/java/org/apache/wicket/ajax/form/OnChangeAjaxBehavior.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/ajax/form/OnChangeAjaxBehavior.java b/wicket-core/src/main/java/org/apache/wicket/ajax/form/OnChangeAjaxBehavior.java index 796dd33..f960d29 100644 --- a/wicket-core/src/main/java/org/apache/wicket/ajax/form/OnChangeAjaxBehavior.java +++ b/wicket-core/src/main/java/org/apache/wicket/ajax/form/OnChangeAjaxBehavior.java @@ -23,7 +23,6 @@ import org.apache.wicket.markup.html.form.FormComponent; import org.apache.wicket.markup.html.form.TextArea; import org.apache.wicket.markup.html.form.TextField; import org.apache.wicket.util.lang.Args; -import org.danekja.java.util.function.serializable.SerializableBiConsumer; import org.danekja.java.util.function.serializable.SerializableConsumer; /** @@ -103,39 +102,4 @@ public abstract class OnChangeAjaxBehavior extends AjaxFormComponentUpdatingBeha } }; } - - /** - * Creates an {@link OnChangeAjaxBehavior} based on lambda expressions - * - * @param onChange - * the {@code SerializableConsumer} which accepts the {@link AjaxRequestTarget} - * @param onError - * the {@code SerializableBiConsumer} which accepts the {@link AjaxRequestTarget} and - * the {@link RuntimeException} - * @return the {@link OnChangeAjaxBehavior} - */ - public static OnChangeAjaxBehavior onChange(SerializableConsumer<AjaxRequestTarget> onChange, - SerializableBiConsumer<AjaxRequestTarget, RuntimeException> onError) - { - Args.notNull(onChange, "onChange"); - Args.notNull(onError, "onError"); - - return new OnChangeAjaxBehavior() - { - private static final long serialVersionUID = 1L; - - @Override - protected void onUpdate(AjaxRequestTarget target) - { - onChange.accept(target); - } - - @Override - protected void onError(AjaxRequestTarget target, RuntimeException e) - { - onError.accept(target, e); - } - }; - } - } http://git-wip-us.apache.org/repos/asf/wicket/blob/da937bb0/wicket-core/src/main/java/org/apache/wicket/lambda/Lambdas.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/lambda/Lambdas.java b/wicket-core/src/main/java/org/apache/wicket/lambda/Lambdas.java deleted file mode 100644 index 185597c..0000000 --- a/wicket-core/src/main/java/org/apache/wicket/lambda/Lambdas.java +++ /dev/null @@ -1,316 +0,0 @@ -/* - * 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.lambda; - -import org.apache.wicket.Component; -import org.apache.wicket.ajax.AbstractAjaxTimerBehavior; -import org.apache.wicket.ajax.AjaxClientInfoBehavior; -import org.apache.wicket.ajax.AjaxEventBehavior; -import org.apache.wicket.ajax.AjaxNewWindowNotifyingBehavior; -import org.apache.wicket.ajax.AjaxRequestTarget; -import org.apache.wicket.ajax.AjaxSelfUpdatingTimerBehavior; -import org.apache.wicket.ajax.form.AjaxFormChoiceComponentUpdatingBehavior; -import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior; -import org.apache.wicket.ajax.form.AjaxFormSubmitBehavior; -import org.apache.wicket.ajax.form.OnChangeAjaxBehavior; -import org.apache.wicket.behavior.Behavior; -import org.apache.wicket.markup.ComponentTag; -import org.apache.wicket.protocol.http.request.WebClientInfo; -import org.apache.wicket.util.time.Duration; -import org.danekja.java.util.function.serializable.SerializableBiConsumer; -import org.danekja.java.util.function.serializable.SerializableConsumer; -import org.danekja.java.util.function.serializable.SerializableFunction; - -/** - * Convenience class for easy static importing of lambda factory methods in several components and - * behaviors. - */ -public final class Lambdas -{ - /** - * Creates an {@link AbstractAjaxTimerBehavior} based on lambda expressions - * - * @param interval - * the interval of the timer - * @param onTimer - * the {@code SerializableConsumer} which accepts the {@link AjaxRequestTarget} - * @return the {@link AbstractAjaxTimerBehavior} - * - * @see AbstractAjaxTimerBehavior#onTimer(Duration, SerializableConsumer) - */ - public static AbstractAjaxTimerBehavior onTimer(Duration interval, - SerializableConsumer<AjaxRequestTarget> onTimer) - { - return AbstractAjaxTimerBehavior.onTimer(interval, onTimer); - } - - /** - * Creates an {@link AjaxClientInfoBehavior} based on lambda expressions - * - * @param onClientInfo - * the {@code SerializableBiConsumer} which accepts the {@link AjaxRequestTarget} and - * the {@link WebClientInfo} - * @return the {@link AjaxClientInfoBehavior} - * - * @see AjaxClientInfoBehavior#onClientInfo(SerializableBiConsumer) - */ - public static AjaxClientInfoBehavior onClientInfo( - SerializableBiConsumer<AjaxRequestTarget, WebClientInfo> onClientInfo) - { - return AjaxClientInfoBehavior.onClientInfo(onClientInfo); - } - - /** - * Creates an {@link AjaxEventBehavior} based on lambda expressions - * - * @param eventName - * the event name - * @param onEvent - * the {@code SerializableConsumer} which accepts the {@link AjaxRequestTarget} - * @return the {@link AjaxEventBehavior} - * - * @see AjaxEventBehavior#onEvent(org.apache.wicket.Component, org.apache.wicket.event.IEvent) - */ - public static AjaxEventBehavior onEvent(String eventName, - SerializableConsumer<AjaxRequestTarget> onEvent) - { - return AjaxEventBehavior.onEvent(eventName, onEvent); - } - - /** - * Creates an {@link AjaxNewWindowNotifyingBehavior} based on lambda expressions - * - * @param windowName - * the window name - * @param onNewWindow - * the {@code SerializableConsumer} which accepts the {@link AjaxRequestTarget} - * @return the {@link AjaxNewWindowNotifyingBehavior} - * - * @see AjaxNewWindowNotifyingBehavior#onNewWindow(String, SerializableConsumer) - */ - public static AjaxNewWindowNotifyingBehavior onNewWindow(String windowName, - SerializableConsumer<AjaxRequestTarget> onNewWindow) - { - return AjaxNewWindowNotifyingBehavior.onNewWindow(windowName, onNewWindow); - } - - /** - * Creates an {@link AbstractAjaxTimerBehavior} based on lambda expressions - * - * @param interval - * the interval for the self update - * @param onTimer - * the {@code SerializableConsumer} which accepts the {@link AjaxRequestTarget} - * @return the {@link AjaxSelfUpdatingTimerBehavior} - * - * @see AjaxSelfUpdatingTimerBehavior#onSelfUpdate(Duration, SerializableConsumer) - */ - public static AjaxSelfUpdatingTimerBehavior onSelfUpdate(Duration interval, - SerializableConsumer<AjaxRequestTarget> onTimer) - { - return AjaxSelfUpdatingTimerBehavior.onSelfUpdate(interval, onTimer); - } - - /** - * Creates an {@link AjaxFormChoiceComponentUpdatingBehavior} based on lambda expressions - * - * @param onUpdateChoice - * the {@code SerializableConsumer} which accepts the {@link AjaxRequestTarget} - * @return the {@link AjaxFormChoiceComponentUpdatingBehavior} - * - * @see AjaxFormChoiceComponentUpdatingBehavior#onUpdateChoice(SerializableConsumer) - */ - public static AjaxFormChoiceComponentUpdatingBehavior onUpdateChoice( - SerializableConsumer<AjaxRequestTarget> onUpdateChoice) - { - return AjaxFormChoiceComponentUpdatingBehavior.onUpdateChoice(onUpdateChoice); - } - - /** - * Creates an {@link AjaxFormChoiceComponentUpdatingBehavior} based on lambda expressions - * - * @param onUpdateChoice - * the {@code SerializableConsumer} which accepts the {@link AjaxRequestTarget} - * @param onError - * the {@code SerializableBiConsumer} which accepts the {@link AjaxRequestTarget} and - * the {@link RuntimeException} - * @return the {@link AjaxFormChoiceComponentUpdatingBehavior} - * - * @see AjaxFormChoiceComponentUpdatingBehavior#onUpdateChoice(SerializableConsumer, - * SerializableBiConsumer) - */ - public static AjaxFormChoiceComponentUpdatingBehavior onUpdateChoice( - SerializableConsumer<AjaxRequestTarget> onUpdateChoice, - SerializableBiConsumer<AjaxRequestTarget, RuntimeException> onError) - { - return AjaxFormChoiceComponentUpdatingBehavior.onUpdateChoice(onUpdateChoice, onError); - } - - /** - * Creates an {@link AjaxFormComponentUpdatingBehavior} based on lambda expressions - * - * @param eventName - * the event name - * @param onUpdate - * the {@code SerializableConsumer} which accepts the {@link AjaxRequestTarget} - * @return the {@link AjaxFormComponentUpdatingBehavior} - * - * @see AjaxFormComponentUpdatingBehavior#onUpdate(String, SerializableConsumer) - */ - public static AjaxFormComponentUpdatingBehavior onUpdate(String eventName, - SerializableConsumer<AjaxRequestTarget> onUpdate) - { - return AjaxFormComponentUpdatingBehavior.onUpdate(eventName, onUpdate); - } - - /** - * Creates an {@link AjaxFormComponentUpdatingBehavior} based on lambda expressions - * - * @param eventName - * the event name - * @param onUpdate - * the {@code SerializableConsumer} which accepts the {@link AjaxRequestTarget} - * @param onError - * the {@code SerializableBiConsumer} which accepts the {@link AjaxRequestTarget} and - * the {@link RuntimeException} - * @return the {@link AjaxFormComponentUpdatingBehavior} - * - * @see AjaxFormComponentUpdatingBehavior#onUpdate(String, SerializableConsumer, - * SerializableBiConsumer) - */ - public static AjaxFormComponentUpdatingBehavior onUpdate(String eventName, - SerializableConsumer<AjaxRequestTarget> onUpdate, - SerializableBiConsumer<AjaxRequestTarget, RuntimeException> onError) - { - return AjaxFormComponentUpdatingBehavior.onUpdate(eventName, onUpdate, onError); - } - - /** - * Creates an {@link AjaxFormSubmitBehavior} based on lambda expressions - * - * @param eventName - * the event name - * @param onSubmit - * the {@code SerializableConsumer} which accepts the {@link AjaxRequestTarget} - * @return the {@link AjaxFormSubmitBehavior} - * - * @see AjaxFormSubmitBehavior#onSubmit(String, SerializableConsumer) - */ - public static AjaxFormSubmitBehavior onSubmit(String eventName, - SerializableConsumer<AjaxRequestTarget> onSubmit) - { - return AjaxFormSubmitBehavior.onSubmit(eventName, onSubmit); - } - - /** - * Creates an {@link AjaxFormSubmitBehavior} based on lambda expressions - * - * @param eventName - * the event name - * @param onSubmit - * the {@code SerializableConsumer} which accepts the {@link AjaxRequestTarget} - * @param onError - * the {@code SerializableConsumer} which accepts the {@link AjaxRequestTarget} - * @return the {@link AjaxFormSubmitBehavior} - * - * @see AjaxFormSubmitBehavior#onSubmit(String, SerializableConsumer, SerializableConsumer) - */ - public static AjaxFormSubmitBehavior onSubmit(String eventName, - SerializableConsumer<AjaxRequestTarget> onSubmit, - SerializableConsumer<AjaxRequestTarget> onError) - { - return AjaxFormSubmitBehavior.onSubmit(eventName, onSubmit, onError); - } - - /** - * Creates an {@link OnChangeAjaxBehavior} based on lambda expressions - * - * @param onChange - * the {@code SerializableConsumer} which accepts the {@link AjaxRequestTarget} - * @return the {@link OnChangeAjaxBehavior} - * - * @see OnChangeAjaxBehavior#onChange(SerializableConsumer) - */ - public static OnChangeAjaxBehavior onChange(SerializableConsumer<AjaxRequestTarget> onChange) - { - return OnChangeAjaxBehavior.onChange(onChange); - } - - /** - * Creates an {@link OnChangeAjaxBehavior} based on lambda expressions - * - * @param onChange - * the {@code SerializableConsumer} which accepts the {@link AjaxRequestTarget} - * @param onError - * the {@code SerializableBiConsumer} which accepts the {@link AjaxRequestTarget} and - * the {@link RuntimeException} - * @return the {@link OnChangeAjaxBehavior} - * - * @see OnChangeAjaxBehavior#onChange(SerializableConsumer, SerializableBiConsumer) - */ - public static OnChangeAjaxBehavior onChange(SerializableConsumer<AjaxRequestTarget> onChange, - SerializableBiConsumer<AjaxRequestTarget, RuntimeException> onError) - { - return OnChangeAjaxBehavior.onChange(onChange, onError); - } - - /** - * Creates a {@link Behavior} that uses the given {@code SerializableConsumer consumer} to do - * something with the component's tag. - * - * <p> - * Usage:<br/> - * <code>component.add(onTag(tag -> tag.put(key, value)));</code> - * </p> - * - * @param onTagConsumer - * the {@code SerializableConsumer} that accepts the {@link ComponentTag} - * @return The created behavior - * - * @see Behavior#onTag(SerializableBiConsumer) - */ - public static Behavior onTag(SerializableBiConsumer<Component, ComponentTag> onTagConsumer) - { - return Behavior.onTag(onTagConsumer); - } - - /** - * Creates a {@link Behavior} that uses the given {@code SerializableFunction function} to do - * something with a component's attribute. - * - * <p> - * Usage:<br/> - * <code>component.add(onAttribute("class", value -> condition ? "positive" : "negative"));</code> - * </p> - * - * @param attributeName - * the name of the attribute to manipulate - * @param onAttribute - * the function that is applied to the attribute value - * @return The created behavior - * - * @see Behavior#onAttribute(String, SerializableFunction) - */ - public static Behavior onAttribute(String attributeName, - SerializableFunction<String, CharSequence> onAttribute) - { - return Behavior.onAttribute(attributeName, onAttribute); - } - - private Lambdas() - {} -} http://git-wip-us.apache.org/repos/asf/wicket/blob/da937bb0/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..ed4f473 --- /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.equalTo; +import static org.hamcrest.Matchers.is; + +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 onTagTest() + { + WebMarkupContainer component = new WebMarkupContainer(MockPageWithOneComponent.COMPONENT_ID); + MockPageWithOneComponent page = new MockPageWithOneComponent(); + page.add(component); + String value = "value"; + String key = "key"; + component.add(Behavior.onTag((c, tag) -> tag.put(key, value))); + component.add(Behavior.onAttribute("class", oldValue -> "zzz")); + + tester.startPage(page); + + TagTester tagTester = tester.getTagByWicketId(MockPageWithOneComponent.COMPONENT_ID); + assertThat(tagTester.getAttribute(key), is(equalTo(value))); + assertThat(tagTester.getAttribute("class"), is(equalTo("zzz"))); + } + + @Test + public void onAttributeTest() + { + WebMarkupContainer component = new WebMarkupContainer(MockPageWithOneComponent.COMPONENT_ID); + MockPageWithOneComponent page = new MockPageWithOneComponent(); + page.add(component); + String value = "value"; + String key = "key"; + component.add(Behavior.onAttribute(key, oldValue -> value)); + + tester.startPage(page); + + TagTester tagTester = tester.getTagByWicketId(MockPageWithOneComponent.COMPONENT_ID); + assertThat(tagTester.getAttribute(key), is(equalTo(value))); + } +} http://git-wip-us.apache.org/repos/asf/wicket/blob/da937bb0/wicket-core/src/test/java/org/apache/wicket/lambda/LambdasTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/lambda/LambdasTest.java b/wicket-core/src/test/java/org/apache/wicket/lambda/LambdasTest.java deleted file mode 100644 index 594ced2..0000000 --- a/wicket-core/src/test/java/org/apache/wicket/lambda/LambdasTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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.lambda; - -import static org.apache.wicket.lambda.Lambdas.onTag; -import static org.apache.wicket.lambda.Lambdas.onAttribute; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.is; - -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 Lambdas} - */ -public class LambdasTest extends WicketTestCase -{ - @Test - public void onTagTest() - { - WebMarkupContainer component = new WebMarkupContainer(MockPageWithOneComponent.COMPONENT_ID); - MockPageWithOneComponent page = new MockPageWithOneComponent(); - page.add(component); - String value = "value"; - String key = "key"; - component.add(onTag((c, tag) -> tag.put(key, value))); - component.add(onAttribute("class", oldValue -> "zzz")); - - tester.startPage(page); - - TagTester tagTester = tester.getTagByWicketId(MockPageWithOneComponent.COMPONENT_ID); - assertThat(tagTester.getAttribute(key), is(equalTo(value))); - assertThat(tagTester.getAttribute("class"), is(equalTo("zzz"))); - } - - @Test - public void onAttributeTest() - { - WebMarkupContainer component = new WebMarkupContainer(MockPageWithOneComponent.COMPONENT_ID); - MockPageWithOneComponent page = new MockPageWithOneComponent(); - page.add(component); - String value = "value"; - String key = "key"; - component.add(onAttribute(key, oldValue -> value)); - - tester.startPage(page); - - TagTester tagTester = tester.getTagByWicketId(MockPageWithOneComponent.COMPONENT_ID); - assertThat(tagTester.getAttribute(key), is(equalTo(value))); - } -} http://git-wip-us.apache.org/repos/asf/wicket/blob/da937bb0/wicket-examples/src/main/java/org/apache/wicket/examples/compref/LinkPage.java ---------------------------------------------------------------------- diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/compref/LinkPage.java b/wicket-examples/src/main/java/org/apache/wicket/examples/compref/LinkPage.java index 58e5f55..096bfea 100644 --- a/wicket-examples/src/main/java/org/apache/wicket/examples/compref/LinkPage.java +++ b/wicket-examples/src/main/java/org/apache/wicket/examples/compref/LinkPage.java @@ -16,8 +16,8 @@ */ package org.apache.wicket.examples.compref; +import org.apache.wicket.behavior.Behavior; import org.apache.wicket.examples.WicketExamplePage; -import org.apache.wicket.lambda.Lambdas; import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.markup.html.link.Link; import org.apache.wicket.model.PropertyModel; @@ -112,7 +112,7 @@ public class LinkPage extends WicketExamplePage { super(id); count3 = new Count(); - add(Lambdas.onAttribute("value", oldValue -> "this button is clicked " + count3.getCount() + " times")); + add(Behavior.onAttribute("value", oldValue -> "this button is clicked " + count3.getCount() + " times")); } @Override
