-
Notifications
You must be signed in to change notification settings - Fork 810
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #931 from apache/fix/WW-5422-trimable
WW-5422 Fixes support for trimable locale string in request
- Loading branch information
Showing
8 changed files
with
329 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
174 changes: 174 additions & 0 deletions
174
core/src/test/java/com/opensymphony/xwork2/DefaultLocaleProviderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
/* | ||
* 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 com.opensymphony.xwork2; | ||
|
||
import org.junit.AfterClass; | ||
import org.junit.Before; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
import java.util.Locale; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class DefaultLocaleProviderTest { | ||
|
||
private DefaultLocaleProvider provider; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
provider = new DefaultLocaleProvider(); | ||
} | ||
|
||
@BeforeClass | ||
public static void beforeClass() throws Exception { | ||
ActionContext.of().bind(); | ||
} | ||
|
||
@AfterClass | ||
public static void afterClass() throws Exception { | ||
ActionContext.clear(); | ||
} | ||
|
||
@Test | ||
public void getLocale() { | ||
// given | ||
ActionContext.getContext().withLocale(Locale.ITALY); | ||
|
||
// when | ||
Locale actual = provider.getLocale(); | ||
|
||
// then | ||
assertEquals(Locale.ITALY, actual); | ||
} | ||
|
||
@Test | ||
public void getLocaleNull() { | ||
// given | ||
ActionContext backup = ActionContext.getContext(); | ||
ActionContext.clear(); | ||
|
||
// when | ||
Locale actual = provider.getLocale(); | ||
|
||
// then | ||
assertNull(actual); | ||
ActionContext.bind(backup); | ||
} | ||
|
||
@Test | ||
public void toLocale() { | ||
// given | ||
ActionContext.getContext().withLocale(Locale.GERMAN); | ||
|
||
// when | ||
Locale actual = provider.toLocale("it"); | ||
|
||
// then | ||
assertEquals(Locale.ITALIAN, actual); | ||
} | ||
|
||
@Test | ||
public void toLocaleFull() { | ||
// given | ||
ActionContext.getContext().withLocale(Locale.GERMAN); | ||
|
||
// when | ||
Locale actual = provider.toLocale("it_IT"); | ||
|
||
// then | ||
assertEquals(Locale.ITALY, actual); | ||
} | ||
|
||
@Test | ||
public void toLocaleTrimEndOfLine() { | ||
// given | ||
ActionContext.getContext().withLocale(Locale.GERMAN); | ||
|
||
// when | ||
Locale actual = provider.toLocale("it_IT\n"); | ||
|
||
// then | ||
assertEquals(Locale.ITALY, actual); | ||
} | ||
|
||
@Test | ||
public void toLocaleTrimEmptySpace() { | ||
// given | ||
ActionContext.getContext().withLocale(Locale.GERMAN); | ||
|
||
// when | ||
Locale actual = provider.toLocale(" it_IT "); | ||
|
||
// then | ||
assertEquals(Locale.ITALY, actual); | ||
} | ||
|
||
@Test | ||
public void isValidLocaleNull() { | ||
// given | ||
ActionContext.getContext().withLocale(Locale.GERMAN); | ||
|
||
// when | ||
boolean actual = provider.isValidLocale(null); | ||
|
||
// then | ||
assertFalse(actual); | ||
} | ||
|
||
@Test | ||
public void isValidLocale() { | ||
// given | ||
ActionContext.getContext().withLocale(Locale.GERMAN); | ||
|
||
// when | ||
boolean actual = provider.isValidLocale(Locale.ITALIAN); | ||
|
||
// then | ||
assertTrue(actual); | ||
} | ||
|
||
@Test | ||
public void isValidLocaleString() { | ||
// given | ||
ActionContext.getContext().withLocale(Locale.GERMAN); | ||
|
||
// when | ||
boolean actual = provider.isValidLocaleString("it"); | ||
|
||
// then | ||
assertTrue(actual); | ||
} | ||
|
||
@Test | ||
public void isValidLocaleStringNot() { | ||
// given | ||
ActionContext.getContext().withLocale(Locale.GERMAN); | ||
|
||
// when | ||
boolean actual = provider.isValidLocaleString("italy"); | ||
|
||
// then | ||
assertFalse(actual); | ||
} | ||
|
||
} |
Oops, something went wrong.