-
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.
WW-5422 Adds dedicate unit test to cover DefaultLocaleProvider
- Loading branch information
1 parent
649760d
commit adec73e
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 expected = provider.getLocale(); | ||
|
||
// then | ||
assertEquals(expected, Locale.ITALY); | ||
} | ||
|
||
@Test | ||
public void getLocaleNull() { | ||
// given | ||
ActionContext backup = ActionContext.getContext(); | ||
ActionContext.clear(); | ||
|
||
// when | ||
Locale expected = provider.getLocale(); | ||
|
||
// then | ||
assertNull(expected); | ||
ActionContext.bind(backup); | ||
} | ||
|
||
@Test | ||
public void toLocale() { | ||
// given | ||
ActionContext.getContext().withLocale(Locale.GERMAN); | ||
|
||
// when | ||
Locale expected = provider.toLocale("it"); | ||
|
||
// then | ||
assertEquals(expected, Locale.ITALIAN); | ||
} | ||
|
||
@Test | ||
public void toLocaleFull() { | ||
// given | ||
ActionContext.getContext().withLocale(Locale.GERMAN); | ||
|
||
// when | ||
Locale expected = provider.toLocale("it_IT"); | ||
|
||
// then | ||
assertEquals(expected, Locale.ITALY); | ||
} | ||
|
||
@Test | ||
public void toLocaleTrimEndOfLine() { | ||
// given | ||
ActionContext.getContext().withLocale(Locale.GERMAN); | ||
|
||
// when | ||
Locale expected = provider.toLocale("it_IT\n"); | ||
|
||
// then | ||
assertEquals(expected, Locale.ITALY); | ||
} | ||
|
||
@Test | ||
public void toLocaleTrimEmptySpace() { | ||
// given | ||
ActionContext.getContext().withLocale(Locale.GERMAN); | ||
|
||
// when | ||
Locale expected = provider.toLocale(" it_IT "); | ||
|
||
// then | ||
assertEquals(expected, Locale.ITALY); | ||
} | ||
|
||
@Test | ||
public void isValidLocaleNull() { | ||
// given | ||
ActionContext.getContext().withLocale(Locale.GERMAN); | ||
|
||
// when | ||
boolean expected = provider.isValidLocale(null); | ||
|
||
// then | ||
assertFalse(expected); | ||
} | ||
|
||
@Test | ||
public void isValidLocale() { | ||
// given | ||
ActionContext.getContext().withLocale(Locale.GERMAN); | ||
|
||
// when | ||
boolean expected = provider.isValidLocale(Locale.ITALIAN); | ||
|
||
// then | ||
assertTrue(expected); | ||
} | ||
|
||
@Test | ||
public void isValidLocaleString() { | ||
// given | ||
ActionContext.getContext().withLocale(Locale.GERMAN); | ||
|
||
// when | ||
boolean expected = provider.isValidLocaleString("it"); | ||
|
||
// then | ||
assertTrue(expected); | ||
} | ||
|
||
@Test | ||
public void isValidLocaleStringNot() { | ||
// given | ||
ActionContext.getContext().withLocale(Locale.GERMAN); | ||
|
||
// when | ||
boolean expected = provider.isValidLocaleString("italy"); | ||
|
||
// then | ||
assertFalse(expected); | ||
} | ||
|
||
} |
Oops, something went wrong.