BAEL-3153: Added test cases for String toLowerCase and toUpperCase
The toLowerCase and toUpperCase methods are simple enough that no new classes are needed under the main/ directory. The included tests exercise the changing of case for an English string using the default locale, a foreign string using the default locale, and a foreign string using a provided locale.
This commit is contained in:
parent
79a50387d1
commit
4998ed9be4
@ -1,7 +1,7 @@
|
|||||||
## Relevant Articles
|
## Relevant Articles
|
||||||
|
|
||||||
- [Java Localization – Formatting Messages](https://www.baeldung.com/java-localization-messages-formatting)
|
- [Java Localization – Formatting Messages](https://www.baeldung.com/java-localization-messages-formatting)
|
||||||
- [Check If a String Contains a Substring](https://www.baeldung.com/java-string-contains-substring)
|
- [Check If a String Contains a Substring](https://www.baeldung.com/java-string-contains-substring)
|
||||||
- [Removing Stopwords from a String in Java](https://www.baeldung.com/java-string-remove-stopwords)
|
- [Removing Stopwords from a String in Java](https://www.baeldung.com/java-string-remove-stopwords)
|
||||||
- [Blank and Empty Strings in Java](https://www.baeldung.com/java-blank-empty-strings)
|
- [Blank and Empty Strings in Java](https://www.baeldung.com/java-blank-empty-strings)
|
||||||
- [String Initialization in Java](https://www.baeldung.com/java-string-initialization)
|
- [String Initialization in Java](https://www.baeldung.com/java-string-initialization)
|
||||||
|
@ -0,0 +1,29 @@
|
|||||||
|
package com.baeldung.string.changecase;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class ToLowerCaseUnitTest {
|
||||||
|
|
||||||
|
private static final Locale TURKISH = new Locale("tr");
|
||||||
|
private String name = "John Doe";
|
||||||
|
private String foreignUppercase = "\u0049";
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenMixedCaseString_WhenToLowerCase_ThenResultIsLowerCase() {
|
||||||
|
assertEquals("john doe", name.toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenForeignString_WhenToLowerCaseWithoutLocale_ThenResultIsLowerCase() {
|
||||||
|
assertEquals("\u0069", foreignUppercase.toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenForeignString_WhenToLowerCaseWithLocale_ThenResultIsLowerCase() {
|
||||||
|
assertEquals("\u0131", foreignUppercase.toLowerCase(TURKISH));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
package com.baeldung.string.changecase;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class ToUpperCaseUnitTest {
|
||||||
|
|
||||||
|
private static final Locale TURKISH = new Locale("tr");
|
||||||
|
private String name = "John Doe";
|
||||||
|
private String foreignUppercase = "\u0069";
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenMixedCaseString_WhenToUpperCase_ThenResultIsUpperCase() {
|
||||||
|
assertEquals("JOHN DOE", name.toUpperCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenForeignString_WhenToUpperCaseWithoutLocale_ThenResultIsUpperCase() {
|
||||||
|
assertEquals("\u0049", foreignUppercase.toUpperCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenForeignString_WhenToUpperCaseWithLocale_ThenResultIsUpperCase() {
|
||||||
|
assertEquals("\u0130", foreignUppercase.toUpperCase(TURKISH));
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user