Skip to content

Commit

Permalink
WICKET-7135 Work on deprecation warnings (#1049)
Browse files Browse the repository at this point in the history
* Migrate new Locale constructor invocations to Locale.of calls

* Migrate new URL constructor invocations to URI#toURL

* Migrate deprecated API calls to their replacements
  • Loading branch information
aldaris authored Dec 2, 2024
1 parent e04d58b commit da01909
Show file tree
Hide file tree
Showing 37 changed files with 118 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,9 @@ public LocaleDropDownChoice(String id)
}

/** Relevant locales wrapped in a list. */
private static final List<Locale> LOCALES = Arrays.asList(Locale.ENGLISH, new Locale("nl"),
Locale.GERMAN, Locale.SIMPLIFIED_CHINESE, Locale.JAPANESE, new Locale("pt", "BR"),
new Locale("fa", "IR"), new Locale("da", "DK"));
private static final List<Locale> LOCALES = Arrays.asList(Locale.ENGLISH, Locale.of("nl"),
Locale.GERMAN, Locale.SIMPLIFIED_CHINESE, Locale.JAPANESE, Locale.of("pt", "BR"),
Locale.of("fa", "IR"), Locale.of("da", "DK"));

/** available sites for the multiple select. */
private static final List<String> SITES = Arrays.asList("The Server Side", "Java Lobby",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ void testTwoComponents()
assertEquals("value 1", localizer.getString("null", page.drop1));
assertEquals("value 2", localizer.getString("null", page.drop2));

Session.get().setLocale(new Locale("nl"));
Session.get().setLocale(Locale.of("nl"));
assertEquals("waarde 1", localizer.getString("null", page.drop1));
assertEquals("waarde 2", localizer.getString("null", page.drop2));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void english() throws Exception
@Test
void dutch() throws Exception
{
tester.getSession().setLocale(new Locale("nl"));
tester.getSession().setLocale(Locale.of("nl"));
tester.startPage(Page1.class);
tester.assertRenderedPage(Page1.class);
tester.assertResultPage(getClass(), "PageMarkupLoadingTest$Page1_nl_expected.html");
Expand All @@ -63,7 +63,7 @@ void dutch() throws Exception
@Test
void testDutchMyStyle() throws Exception
{
tester.getSession().setLocale(new Locale("nl"));
tester.getSession().setLocale(Locale.of("nl"));
tester.getSession().setStyle("mystyle");
tester.startPage(Page1.class);
tester.assertRenderedPage(Page1.class);
Expand All @@ -78,7 +78,7 @@ void testDutchMyStyle() throws Exception
@Test
void dutchMyStyleMyVar() throws Exception
{
tester.getSession().setLocale(new Locale("nl"));
tester.getSession().setLocale(Locale.of("nl"));
tester.getSession().setStyle("mystyle");
tester.startPage(Page2.class);
tester.assertRenderedPage(Page2.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public IResource getResource()
};

ResourceReference reference2 = new ResourceReference(
AbstractResourceReferenceMapperTest.class, "reference2/name2", new Locale("en", "en"),
AbstractResourceReferenceMapperTest.class, "reference2/name2", Locale.of("en", "en"),
null, null)
{
private static final long serialVersionUID = 1L;
Expand All @@ -146,7 +146,7 @@ public IResource getResource()
};

private ResourceReference reference2_a = new ResourceReference(
AbstractResourceReferenceMapperTest.class, "reference2/name2", new Locale("en", "en"),
AbstractResourceReferenceMapperTest.class, "reference2/name2", Locale.of("en", "en"),
"style", null)
{
private static final long serialVersionUID = 1L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ void decode3()
assertThat(handler).isInstanceOf(ResourceReferenceRequestHandler.class);
ResourceReferenceRequestHandler h = (ResourceReferenceRequestHandler)handler;
assertEquals(resource2, h.getResource());
assertEquals(new Locale("en", "en"), h.getLocale());
assertEquals(Locale.of("en", "en"), h.getLocale());
assertNull(h.getStyle());
assertNull(h.getVariation());
assertEquals(0, h.getPageParameters().getIndexedCount());
Expand All @@ -180,7 +180,7 @@ void decode3A()
assertThat(handler).isInstanceOf(ResourceReferenceRequestHandler.class);
ResourceReferenceRequestHandler h = (ResourceReferenceRequestHandler)handler;
assertEquals(resource2, h.getResource());
assertEquals(new Locale("en", "en"), h.getLocale());
assertEquals(Locale.of("en", "en"), h.getLocale());
assertEquals("style", h.getStyle());
assertNull(h.getVariation());
assertEquals(0, h.getPageParameters().getIndexedCount());
Expand Down Expand Up @@ -210,7 +210,7 @@ void decode4()
assertThat(handler).isInstanceOf(ResourceReferenceRequestHandler.class);
ResourceReferenceRequestHandler h = (ResourceReferenceRequestHandler)handler;
assertEquals(resource2, h.getResource());
assertEquals(new Locale("en", "en"), h.getLocale());
assertEquals(Locale.of("en", "en"), h.getLocale());
assertNull(h.getStyle());
assertNull(h.getVariation());
assertEquals("v1", h.getPageParameters().get("p1").toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class PackageResourceReferenceTest extends WicketTestCase
{
private static Class<PackageResourceReferenceTest> scope = PackageResourceReferenceTest.class;
private static final Locale defaultLocale = Locale.CHINA;
private static final Locale[] locales = { null, new Locale("en"), new Locale("en", "US") };
private static final Locale[] locales = { null, Locale.of("en"), Locale.of("en", "US") };
private static final String[] styles = { null, "style" };
private static final String[] variations = { null, "var" };

Expand Down Expand Up @@ -173,7 +173,7 @@ void resourceResponse()
@Test
void sessionAttributesRelevance()
{
for (Locale locale : new Locale[] { new Locale("en"), new Locale("en", "US") })
for (Locale locale : new Locale[] { Locale.of("en"), Locale.of("en", "US") })
{
tester.getSession().setLocale(locale);
for (String style : styles)
Expand All @@ -198,10 +198,10 @@ void sessionAttributesRelevance()
@Test
void userAttributesPreference()
{
tester.getSession().setLocale(new Locale("en"));
tester.getSession().setLocale(Locale.of("en"));
tester.getSession().setStyle("style");

Locale[] userLocales = { null, new Locale("pt"), new Locale("pt", "BR") };
Locale[] userLocales = { null, Locale.of("pt"), Locale.of("pt", "BR") };
String userStyle = "style2";

for (Locale userLocale : userLocales)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;

import java.net.URI;
import java.net.URL;
import jakarta.servlet.ServletContext;

Expand All @@ -35,7 +36,7 @@ class WebApplicationPathTest
@Test
void doNotServeResourcesFromWebInf() throws Exception
{
URL webUrl = new URL("file://dummyFile");
URL webUrl = URI.create("file://dummyFile").toURL();

ServletContext context = Mockito.mock(ServletContext.class);
Mockito.when(context.getResource(ArgumentMatchers.any(String.class))).thenReturn(webUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,21 @@
*/
public class ResourceStreamLocatorTest extends WicketTestCase
{
private final Locale locale_de = new Locale("de");
private final Locale locale_de_DE = new Locale("de", "DE");
private final Locale locale_de_DE_POSIX = new Locale("de", "DE", "POSIX");
private final Locale locale_de_POSIX = new Locale("de", "", "POSIX");
private final Locale locale_de_CH = new Locale("de", "CH");

private final Locale locale_en = new Locale("en");
private final Locale locale_en_US = new Locale("en", "US");
private final Locale locale_en_US_WIN = new Locale("en", "US", "WIN");
private final Locale locale_en_WIN = new Locale("en", "", "WIN");

private final Locale locale_fr = new Locale("fr");
private final Locale locale_fr_FR = new Locale("fr", "FR");
private final Locale locale_fr_FR_WIN = new Locale("fr", "FR", "WIN");
private final Locale locale_fr_WIN = new Locale("fr", "", "WIN");
private final Locale locale_de = Locale.of("de");
private final Locale locale_de_DE = Locale.of("de", "DE");
private final Locale locale_de_DE_POSIX = Locale.of("de", "DE", "POSIX");
private final Locale locale_de_POSIX = Locale.of("de", "", "POSIX");
private final Locale locale_de_CH = Locale.of("de", "CH");

private final Locale locale_en = Locale.of("en");
private final Locale locale_en_US = Locale.of("en", "US");
private final Locale locale_en_US_WIN = Locale.of("en", "US", "WIN");
private final Locale locale_en_WIN = Locale.of("en", "", "WIN");

private final Locale locale_fr = Locale.of("fr");
private final Locale locale_fr_FR = Locale.of("fr", "FR");
private final Locale locale_fr_FR_WIN = Locale.of("fr", "FR", "WIN");
private final Locale locale_fr_WIN = Locale.of("fr", "", "WIN");

/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;
Expand Down Expand Up @@ -66,7 +67,7 @@ void loadJustOnce() throws IOException, ResourceStreamNotFoundException {

final AtomicInteger connectCounter = new AtomicInteger(0);
final AtomicInteger streamCounter = new AtomicInteger(0);
URL url = new URL(null, "test://anything", new CountingURLStreamHandler(realURL,
URL url = URL.of(URI.create("test://anything"), new CountingURLStreamHandler(realURL,
connectCounter, streamCounter));

UrlResourceStream countingStream = new UrlResourceStream(url);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import static org.mockito.Mockito.when;

import java.io.File;
import java.net.URI;
import java.net.URL;
import java.util.Locale;

Expand Down Expand Up @@ -108,7 +109,7 @@ void strictMatchingDoesntInvalidateNonStrictMatching()

String style = null;
String variation = null;
Locale locale = new Locale("nl", "NL");
Locale locale = Locale.of("nl", "NL");
String extension = null;

String filename = "org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js";
Expand Down Expand Up @@ -138,7 +139,7 @@ void nonStrictMatchingDoesntResultInInvalidStrictMatch()

String style = null;
String variation = null;
Locale locale = new Locale("nl", "NL");
Locale locale = Locale.of("nl", "NL");
String extension = null;

String filename = "org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js";
Expand Down Expand Up @@ -218,7 +219,7 @@ void urlResource() throws Exception
{
IResourceStreamLocator resourceStreamLocator = mock(IResourceStreamLocator.class);

UrlResourceStream urs = new UrlResourceStream(new URL("file:///"));
UrlResourceStream urs = new UrlResourceStream(URI.create("file:///").toURL());

when(resourceStreamLocator.locate(String.class, "path")).thenReturn(urs);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ResourceNameIteratorTest extends WicketTestCase
@Test
void localeResourceNameIterator()
{
Locale locale = new Locale("a", "b", "c");
Locale locale = Locale.of("a", "b", "c");
LocaleResourceNameIterator iterator = new LocaleResourceNameIterator(locale, false);
HashSet<String> variations = new HashSet<String>();
while (iterator.hasNext())
Expand All @@ -52,7 +52,7 @@ void localeResourceNameIterator()
assertTrue(variations.contains("_a"));
assertTrue(variations.contains(""));

locale = new Locale("a", "b");
locale = Locale.of("a", "b");
iterator = new LocaleResourceNameIterator(locale, false);
variations = new HashSet<String>();
while (iterator.hasNext())
Expand All @@ -64,7 +64,7 @@ void localeResourceNameIterator()
assertTrue(variations.contains("_a"));
assertTrue(variations.contains(""));

locale = new Locale("a");
locale = Locale.of("a");
iterator = new LocaleResourceNameIterator(locale, false);
variations = new HashSet<String>();
while (iterator.hasNext())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,36 +40,36 @@ void localeLanguageCountryVariant()
Foo foo = new Foo("foo");
assertEquals("org.apache.wicket.markup.Foo.html", provider.getCacheKey(foo, foo.getClass()));

foo.locale = new Locale("");
foo.locale = Locale.of("");
assertEquals("org.apache.wicket.markup.Foo_.html",
provider.getCacheKey(foo, foo.getClass()));

foo.locale = new Locale("language");
foo.locale = Locale.of("language");
assertEquals("org.apache.wicket.markup.Foo_language.html", provider.getCacheKey(foo,
foo.getClass()));

foo.locale = new Locale("", "COUNTRY");
foo.locale = Locale.of("", "COUNTRY");
assertEquals("org.apache.wicket.markup.Foo__COUNTRY.html", provider.getCacheKey(foo,
foo.getClass()));

// variant only is ignored
foo.locale = new Locale("", "", "variant");
foo.locale = Locale.of("", "", "variant");
assertEquals("org.apache.wicket.markup.Foo_.html",
provider.getCacheKey(foo, foo.getClass()));

foo.locale = new Locale("language", "COUNTRY");
foo.locale = Locale.of("language", "COUNTRY");
assertEquals("org.apache.wicket.markup.Foo_language_COUNTRY.html", provider.getCacheKey(
foo, foo.getClass()));

foo.locale = new Locale("language", "", "variant");
foo.locale = Locale.of("language", "", "variant");
assertEquals("org.apache.wicket.markup.Foo_language__variant.html", provider.getCacheKey(
foo, foo.getClass()));

foo.locale = new Locale("", "COUNTRY", "variant");
foo.locale = Locale.of("", "COUNTRY", "variant");
assertEquals("org.apache.wicket.markup.Foo__COUNTRY_variant.html", provider.getCacheKey(
foo, foo.getClass()));

foo.locale = new Locale("language", "COUNTRY", "variant");
foo.locale = Locale.of("language", "COUNTRY", "variant");
assertEquals("org.apache.wicket.markup.Foo_language_COUNTRY_variant.html",
provider.getCacheKey(foo, foo.getClass()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class LocalizedErrorMessageTest extends WicketTestCase
@Test
void wicket891()
{
tester.getSession().setLocale(new Locale("nl"));
tester.getSession().setLocale(Locale.of("nl"));

LocalizedMessagePage page = new LocalizedMessagePage();
tester.startPage(page);
Expand All @@ -42,7 +42,7 @@ void wicket891()
tester.submitForm(page.form);

tester.assertErrorMessages("'Number' moet een getal zijn. ");
tester.getSession().setLocale(new Locale("us"));
tester.getSession().setLocale(Locale.of("us"));

tester.clearFeedbackMessages();

Expand All @@ -62,7 +62,7 @@ void wicket891()
@Test
void testConvertedVars()
{
tester.getSession().setLocale(new Locale("de"));
tester.getSession().setLocale(Locale.of("de"));

LocalizedMessagePage page = new LocalizedMessagePage();
tester.startPage(page);
Expand All @@ -84,7 +84,7 @@ void testConvertedVars()
void wicket_1927()
{
tester.getApplication().getMarkupSettings().setDefaultMarkupEncoding("UTF-8");
tester.getSession().setLocale(new Locale("de"));
tester.getSession().setLocale(Locale.of("de"));

LocalizedMessagePage page = new LocalizedMessagePage();
tester.startPage(page);
Expand All @@ -94,7 +94,7 @@ void wicket_1927()
tester.submitForm(page.form);

tester.assertErrorMessages("Der Wert von 'Number' ist kein g\u00FCltiger Wert f\u00FCr 'Double'.");
tester.getSession().setLocale(new Locale("pl"));
tester.getSession().setLocale(Locale.of("pl"));

tester.clearFeedbackMessages();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ void test1()

// now test Dutch

tester.getSession().setLocale(new Locale("nl"));
tester.getSession().setLocale(Locale.of("nl"));
page = new TestPage();
form = (Form<?>)page.get("form1");
assertNotNull(form);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void onClick()
@Override
public void onClick()
{
getSession().setLocale(new Locale("nl", "NL"));
getSession().setLocale(Locale.of("nl", "NL"));
}
});
add(new Link<Void>("goGerman")
Expand All @@ -84,7 +84,7 @@ public void onClick()
@Override
public void onClick()
{
getSession().setLocale(new Locale("de", "DE"));
getSession().setLocale(Locale.of("de", "DE"));
}
});
add(new Link<Void>("goChinese")
Expand All @@ -94,7 +94,7 @@ public void onClick()
@Override
public void onClick()
{
getSession().setLocale(new Locale("zh", "CN"));
getSession().setLocale(Locale.of("zh", "CN"));
}
});
add(new Link<Void>("goDanish")
Expand All @@ -104,7 +104,7 @@ public void onClick()
@Override
public void onClick()
{
getSession().setLocale(new Locale("da", "DK"));
getSession().setLocale(Locale.of("da", "DK"));
}
});
}
Expand Down
Loading

0 comments on commit da01909

Please sign in to comment.