Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
565 changes: 285 additions & 280 deletions pom.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
* <li>{@link java.util.Calendar}</li>
* <li>{@link java.awt.Color}</li>
* <li>{@link java.net.InetAddress}</li>
* <li>{@code javax.mail.internet.InternetAddress} (requires Javamail in the classpath)</li>
* <li>{@code jakarta.mail.internet.InternetAddress} (requires Javamail in the classpath)</li>
* <li>{@code jakarta.mail.internet.InternetAddress} (requires Javamail 2.+ in the classpath)</li>
* <li>{@link Enum}</li>
* </ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ public final class PropertyConverter {
/** Constant for the argument classes of the Number constructor that takes a String. */
private static final Class<?>[] CONSTR_ARGS = {String.class};

/** The fully qualified name of {@code javax.mail.internet.InternetAddress}, as used in the javamail-1.* API. */
private static final String INTERNET_ADDRESS_CLASSNAME_JAVAX = "javax.mail.internet.InternetAddress";
/** The fully qualified name of {@code jakarta.mail.internet.InternetAddress}, as used in the javamail-1.* API. */
private static final String INTERNET_ADDRESS_CLASSNAME_JAVAX = "jakarta.mail.internet.InternetAddress";

/** The fully qualified name of {@code jakarta.mail.internet.InternetAddress}, as used in the javamail-2.0+ API. */
private static final String INTERNET_ADDRESS_CLASSNAME_JAKARTA = "jakarta.mail.internet.InternetAddress";
Expand Down Expand Up @@ -152,7 +152,7 @@ public static Object to(final Class<?> cls, final Object value, final DefaultCon
} else if (Color.class.equals(cls)) {
return toColor(value);
} else if (cls.getName().equals(INTERNET_ADDRESS_CLASSNAME_JAVAX)) {
// javamail-1.* With javax.mail.* namespace.
// javamail-1.* With jakarta.mail.* namespace.
return toInternetAddress(value, INTERNET_ADDRESS_CLASSNAME_JAVAX);
} else if (cls.getName().equals(INTERNET_ADDRESS_CLASSNAME_JAKARTA)) {
// javamail-2.0+, with jakarta.mail.* namespace.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import java.util.Enumeration;
import java.util.Iterator;

import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import jakarta.servlet.Servlet;
import jakarta.servlet.ServletConfig;

/**
* A configuration wrapper around a {@link ServletConfig}. This configuration is read only, adding or removing a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import java.util.Enumeration;
import java.util.Iterator;

import javax.servlet.Servlet;
import javax.servlet.ServletContext;
import jakarta.servlet.Servlet;
import jakarta.servlet.ServletContext;

/**
* A configuration wrapper to read the initialization parameters of a servlet context. This configuration is read only,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import java.util.Enumeration;
import java.util.Iterator;

import javax.servlet.FilterConfig;
import jakarta.servlet.FilterConfig;

/**
* A configuration wrapper around a {@link FilterConfig}. This configuration is read only, adding or removing a property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import java.util.List;
import java.util.Map;

import javax.servlet.ServletRequest;
import jakarta.servlet.ServletRequest;

/**
* A configuration wrapper to read the parameters of a servlet request. This configuration is read only, adding or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,15 @@
*/
package org.apache.commons.configuration2;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import javax.naming.*;
import javax.naming.spi.InitialContextFactory;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;

import javax.naming.Context;
import javax.naming.NameClassPair;
import javax.naming.NameNotFoundException;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.spi.InitialContextFactory;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

/**
* A mock implementation of the {@code InitialContextFactory} interface. This implementation will return a mock context
Expand Down Expand Up @@ -79,26 +74,36 @@ public void close() throws NamingException {
*/
public static final String PROP_CYCLES = "useCycles";

/** Constant for the name of the missing property. */
/**
* Constant for the name of the missing property.
*/
private static final String MISSING_PROP = "/missing";

/** Constant for the name of the prefix. */
/**
* Constant for the name of the prefix.
*/
private static final String PREFIX = "test/";

/** An array with the names of the supported properties. */
/**
* An array with the names of the supported properties.
*/
private static final String[] PROP_NAMES = {"key", "key2", "short", "boolean", "byte", "double", "float", "integer", "long", "onlyinjndi"};

/** An array with the values of the supported properties. */
/**
* An array with the values of the supported properties.
*/
private static final String[] PROP_VALUES = {"jndivalue", "jndivalue2", "1", "true", "10", "10.25", "20.25", "10", "1000000", "true"};

/** An array with properties that are requested, but are not in the context. */
/**
* An array with properties that are requested, but are not in the context.
*/
private static final String[] MISSING_NAMES = {"missing/list", "test/imaginarykey", "foo/bar"};

/**
* Adds a new name-and-value pair to list of {@link NameClassPair}s.
*
* @param pairs the list to add to
* @param name the name
* @param name the name
* @param value the value
*/
private void addEnumPair(final List<NameClassPair> pairs, final String name, final Object value) {
Expand All @@ -110,8 +115,8 @@ private void addEnumPair(final List<NameClassPair> pairs, final String name, fin
* Binds a property value to the mock context.
*
* @param mockCtx the context
* @param name the name of the property
* @param value the value of the property
* @param name the name of the property
* @param value the value of the property
*/
private void bind(final Context mockCtx, final String name, final String value) throws NamingException {
when(mockCtx.lookup(name)).thenReturn(value);
Expand All @@ -122,7 +127,7 @@ private void bind(final Context mockCtx, final String name, final String value)
* Configures the mock to expect a call for a non existing property.
*
* @param mockCtx the mock
* @param name the name of the property
* @param name the name of the property
*/
private void bindError(final Context mockCtx, final String name) throws NamingException {
when(mockCtx.lookup(name)).thenThrow(new NameNotFoundException("unknown property"));
Expand Down Expand Up @@ -152,7 +157,7 @@ private Context createCtxMock(final String prefix) throws NamingException {
* Creates and initializes a naming enumeration. This is a shortcut of wrapping the result of
* {@link #createNameClassPairs(String[], Object[])} in an instance of {@link ListBasedNamingEnumeration}.
*
* @param names the names contained in the iteration
* @param names the names contained in the iteration
* @param values the corresponding values
* @return the mock for the enumeration
*/
Expand All @@ -163,7 +168,7 @@ private NamingEnumeration<NameClassPair> createNamingEnumeration(final String[]
/**
* Creates and initializes a list of {@link NameClassPair}s that can be used to create a naming enumeration.
*
* @param names the names contained in the iteration
* @param names the names contained in the iteration
* @param values the corresponding values
* @return the mock for the enumeration
*/
Expand Down Expand Up @@ -199,15 +204,15 @@ public Context getInitialContext(@SuppressWarnings("rawtypes") final Hashtable e
if (useCycles) {
when(mockTopCtx.lookup("cycle")).thenReturn(mockCycleCtx);
when(mockTopCtx.list("")).thenAnswer(invocation ->
createNamingEnumeration(new String[] {"test", "cycle"}, new Object[] {mockPrfxCtx, mockCycleCtx}));
createNamingEnumeration(new String[]{"test", "cycle"}, new Object[]{mockPrfxCtx, mockCycleCtx}));
when(mockCycleCtx.list("")).thenAnswer(invocation -> {
final List<NameClassPair> pairs = createNameClassPairs(PROP_NAMES, PROP_VALUES);
addEnumPair(pairs, "cycleCtx", mockCycleCtx);
return new ListBasedNamingEnumeration(pairs);
});
when(mockCycleCtx.lookup("cycleCtx")).thenReturn(mockCycleCtx);
} else {
when(mockTopCtx.list("")).thenAnswer(invocation -> createNamingEnumeration(new String[] {"test"}, new Object[] {mockPrfxCtx}));
when(mockTopCtx.list("")).thenAnswer(invocation -> createNamingEnumeration(new String[]{"test"}, new Object[]{mockPrfxCtx}));
}
return mockBaseCtx;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@

import java.util.Properties;

import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.http.HttpServlet;
import jakarta.servlet.Servlet;
import jakarta.servlet.ServletConfig;
import jakarta.servlet.http.HttpServlet;

import org.apache.commons.configuration2.AbstractConfiguration;
import org.apache.commons.configuration2.TestAbstractConfiguration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@

import java.util.Properties;

import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServlet;
import jakarta.servlet.Servlet;
import jakarta.servlet.ServletConfig;
import jakarta.servlet.ServletContext;
import jakarta.servlet.http.HttpServlet;

import org.apache.commons.configuration2.AbstractConfiguration;
import org.apache.commons.configuration2.TestAbstractConfiguration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@

import static org.junit.jupiter.api.Assertions.assertThrows;

import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
import java.util.Properties;
import java.util.stream.Collectors;

import javax.servlet.FilterConfig;
import javax.servlet.ServletContext;
import jakarta.servlet.FilterConfig;
import jakarta.servlet.ServletContext;

import org.apache.commons.collections.iterators.IteratorEnumeration;
import org.apache.commons.configuration2.AbstractConfiguration;
import org.apache.commons.configuration2.TestAbstractConfiguration;
import org.apache.commons.configuration2.convert.DefaultListDelimiterHandler;
Expand All @@ -47,9 +51,12 @@ public String getInitParameter(final String key) {
return parameters.getProperty(key);
}



@Override
public Enumeration<?> getInitParameterNames() {
return parameters.keys();
public Enumeration<String> getInitParameterNames() {
final List<String> keys = parameters.keySet().stream().filter(o -> o instanceof String).map(o -> (String) o).collect(Collectors.toList());
return Collections.enumeration(keys);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletRequest;

import org.apache.commons.configuration2.AbstractConfiguration;
import org.apache.commons.configuration2.BaseConfiguration;
Expand Down