diff --git a/core-java-modules/core-java-char/README.md b/core-java-modules/core-java-char/README.md new file mode 100644 index 0000000000..71f8e943aa --- /dev/null +++ b/core-java-modules/core-java-char/README.md @@ -0,0 +1,6 @@ +## Core Java Character + +This module contains articles about Java Character Class + +### Relevant Articles: +- Character#isAlphabetic vs Character#isLetter diff --git a/core-java-modules/core-java-char/pom.xml b/core-java-modules/core-java-char/pom.xml new file mode 100644 index 0000000000..3691079482 --- /dev/null +++ b/core-java-modules/core-java-char/pom.xml @@ -0,0 +1,42 @@ + + + 4.0.0 + core-java-char + 0.1.0-SNAPSHOT + core-java-char + jar + + com.baeldung.core-java-modules + core-java-modules + 0.0.1-SNAPSHOT + ../ + + + + + org.assertj + assertj-core + ${assertj.version} + test + + + org.openjdk.jmh + jmh-core + ${openjdk.jmh.version} + + + org.openjdk.jmh + jmh-generator-annprocess + ${openjdk.jmh.version} + + + + + 1.19 + 3.11.1 + + + diff --git a/core-java-modules/core-java-char/src/test/java/com/baeldung/character/CharacterGeneralCategoryTypeUnitTest.java b/core-java-modules/core-java-char/src/test/java/com/baeldung/character/CharacterGeneralCategoryTypeUnitTest.java new file mode 100644 index 0000000000..4bb41211a9 --- /dev/null +++ b/core-java-modules/core-java-char/src/test/java/com/baeldung/character/CharacterGeneralCategoryTypeUnitTest.java @@ -0,0 +1,37 @@ +package com.baeldung.character; + +import org.junit.Test; + +import static org.junit.Assert.assertTrue; + +public class CharacterGeneralCategoryTypeUnitTest { + @Test + public void givenACharacter_whenUpperCaseLetter_thenAssertTrue() { + assertTrue(Character.getType('U') == Character.UPPERCASE_LETTER); + } + + @Test + public void givenACharacter_whenLowerCaseLetter_thenAssertTrue() { + assertTrue(Character.getType('u') == Character.LOWERCASE_LETTER); + } + + @Test + public void givenACharacter_whenTitleCaseLetter_thenAssertTrue() { + assertTrue(Character.getType('\u01f2') == Character.TITLECASE_LETTER); + } + + @Test + public void givenACharacter_whenModifierLetter_thenAssertTrue() { + assertTrue(Character.getType('\u02b0') == Character.MODIFIER_LETTER); + } + + @Test + public void givenACharacter_whenOtherLetter_thenAssertTrue() { + assertTrue(Character.getType('\u05d0') == Character.OTHER_LETTER); + } + + @Test + public void givenACharacter_whenLetterNumber_thenAssertTrue() { + assertTrue(Character.getType('\u2164') == Character.LETTER_NUMBER); + } +} diff --git a/core-java-modules/core-java-char/src/test/java/com/baeldung/character/IsLetterOrAlphabetUnitTest.java b/core-java-modules/core-java-char/src/test/java/com/baeldung/character/IsLetterOrAlphabetUnitTest.java new file mode 100644 index 0000000000..734762ec7b --- /dev/null +++ b/core-java-modules/core-java-char/src/test/java/com/baeldung/character/IsLetterOrAlphabetUnitTest.java @@ -0,0 +1,28 @@ +package com.baeldung.character; + +import org.junit.Test; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertFalse; + +public class IsLetterOrAlphabetUnitTest { + @Test + public void givenACharacter_whenLetter_thenAssertIsLetterTrue() { + assertTrue(Character.isLetter('a')); + } + + @Test + public void givenACharacter_whenLetter_thenAssertIsAlphabeticTrue() { + assertTrue(Character.isAlphabetic('a')); + } + + @Test + public void givenACharacter_whenAlphabeticAndNotLetter_thenAssertIsLetterFalse() { + assertFalse(Character.isLetter('\u2164')); + } + + @Test + public void givenACharacter_whenAlphabeticAndNotLetter_thenAssertIsAlphabeticTrue() { + assertTrue(Character.isAlphabetic('\u2164')); + } +} diff --git a/core-java-modules/pom.xml b/core-java-modules/pom.xml index b995092782..2f3965b237 100644 --- a/core-java-modules/pom.xml +++ b/core-java-modules/pom.xml @@ -29,7 +29,8 @@ core-java-arrays-convert core-java-arrays-operations-basic core-java-arrays-operations-advanced - + + core-java-char core-java-collections core-java-collections-2 core-java-collections-3