Skip to content

Commit

Permalink
WICKET-7148: Make deletion of Metadata in Application possible again (#…
Browse files Browse the repository at this point in the history
…1101)

Co-authored-by: Schäfer, H.H. (Hans Hosea) <HansHosea.Schaefer@ing.de>
  • Loading branch information
hosea and Schäfer, H.H. (Hans Hosea) authored Feb 18, 2025
1 parent 8945e69 commit e480c7f
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
7 changes: 6 additions & 1 deletion wicket-core/src/main/java/org/apache/wicket/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
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;
Expand Down Expand Up @@ -512,7 +513,11 @@ public void logResponseTarget(final IRequestHandler requestTarget)
@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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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));
}
}

0 comments on commit e480c7f

Please sign in to comment.