This is an automated email from the ASF dual-hosted git repository.

adelbene pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/wicket.git


The following commit(s) were added to refs/heads/master by this push:
     new d718c419a9 WICKET-7148: Make deletion of Metadata in Application 
possible again (#1101)
d718c419a9 is described below

commit d718c419a99269196ad568b08861270ae7aa30f4
Author: hosea <[email protected]>
AuthorDate: Tue Feb 18 17:43:33 2025 +0100

    WICKET-7148: Make deletion of Metadata in Application possible again (#1101)
    
    Co-authored-by: Schäfer, H.H. (Hans Hosea) <[email protected]>
---
 .../main/java/org/apache/wicket/Application.java   |  7 ++-
 .../org/apache/wicket/ApplicationMetadataTest.java | 65 ++++++++++++++++++++++
 2 files changed, 71 insertions(+), 1 deletion(-)

diff --git a/wicket-core/src/main/java/org/apache/wicket/Application.java 
b/wicket-core/src/main/java/org/apache/wicket/Application.java
index 0c48666ee9..7fbd6a58ff 100644
--- a/wicket-core/src/main/java/org/apache/wicket/Application.java
+++ b/wicket-core/src/main/java/org/apache/wicket/Application.java
@@ -25,6 +25,7 @@ import java.util.ServiceLoader;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.function.Supplier;
+
 import org.apache.wicket.application.ComponentInitializationListenerCollection;
 import org.apache.wicket.application.ComponentInstantiationListenerCollection;
 import org.apache.wicket.application.ComponentOnAfterRenderListenerCollection;
@@ -512,7 +513,11 @@ public abstract class Application implements 
UnboundListener, IEventSink, IMetad
        @Override
        public final <T> Application setMetaData(final MetaDataKey<T> key, 
final T object)
        {
-               metaData.put(key, object);
+               if (object == null) {
+                       metaData.remove(key);
+               } else {
+                       metaData.put(key, object);
+               }
                return this;
        }
 
diff --git 
a/wicket-core/src/test/java/org/apache/wicket/ApplicationMetadataTest.java 
b/wicket-core/src/test/java/org/apache/wicket/ApplicationMetadataTest.java
new file mode 100644
index 0000000000..7117e74cb8
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/ApplicationMetadataTest.java
@@ -0,0 +1,65 @@
+/*
+ * 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;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+import java.io.Serializable;
+
+import org.apache.wicket.mock.MockApplication;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Test cases for the <code>Application-Metadata</code> class.
+ *
+ * @author Hans Hosea Schaefer
+ */
+public class ApplicationMetadataTest {
+
+       private static final MetaDataKey<Serializable> MY_METADATA_KEY = new 
MetaDataKey<>() {};
+
+       @AfterEach
+       void detachThreadContext() {
+               ThreadContext.detach();
+       }
+
+       @Test
+       void metadataAdded() {
+               final MockApplication application = new MockApplication();
+               assertNull(application.getMetaData(MY_METADATA_KEY));
+               application.setMetaData(MY_METADATA_KEY, "I love wicket");
+               assertEquals("I love wicket", 
application.getMetaData(MY_METADATA_KEY));
+       }
+
+       @Test
+       void metadataReplaced() {
+               final MockApplication application = new MockApplication();
+               application.setMetaData(MY_METADATA_KEY, "I love wicket");
+               application.setMetaData(MY_METADATA_KEY, "I love Idea");
+               assertEquals("I love Idea", 
application.getMetaData(MY_METADATA_KEY));
+       }
+
+       @Test
+       void metadataRemoved() {
+               final MockApplication application = new MockApplication();
+               application.setMetaData(MY_METADATA_KEY, "I love wicket");
+               application.setMetaData(MY_METADATA_KEY, null);
+               assertNull(application.getMetaData(MY_METADATA_KEY));
+       }
+}

Reply via email to