diff --git a/core-groovy-strings/pom.xml b/core-groovy-strings/pom.xml new file mode 100644 index 0000000000..1144d748ee --- /dev/null +++ b/core-groovy-strings/pom.xml @@ -0,0 +1,122 @@ + + + 4.0.0 + core-groovy-strings + 1.0-SNAPSHOT + core-groovy-strings + jar + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + + + + + org.codehaus.groovy + groovy + ${groovy.version} + + + org.codehaus.groovy + groovy-all + ${groovy-all.version} + pom + + + org.codehaus.groovy + groovy-dateutil + ${groovy.version} + + + org.codehaus.groovy + groovy-sql + ${groovy-sql.version} + + + org.junit.platform + junit-platform-runner + ${junit.platform.version} + test + + + org.hsqldb + hsqldb + ${hsqldb.version} + test + + + org.spockframework + spock-core + ${spock-core.version} + test + + + + + + + org.codehaus.gmavenplus + gmavenplus-plugin + ${gmavenplus-plugin.version} + + + + addSources + addTestSources + compile + compileTests + + + + + + maven-failsafe-plugin + ${maven-failsafe-plugin.version} + + + org.junit.platform + junit-platform-surefire-provider + ${junit.platform.version} + + + + + junit5 + + integration-test + verify + + + + **/*Test5.java + + + + + + + + + + + central + https://jcenter.bintray.com + + + + + 1.0.0 + 2.5.6 + 2.5.6 + 2.5.6 + 2.4.0 + 1.1-groovy-2.4 + 1.6 + + + \ No newline at end of file diff --git a/core-groovy-strings/src/test/groovy/com/baeldung/removeprefix/RemovePrefixTest.groovy b/core-groovy-strings/src/test/groovy/com/baeldung/removeprefix/RemovePrefixTest.groovy new file mode 100644 index 0000000000..61b81fe1b2 --- /dev/null +++ b/core-groovy-strings/src/test/groovy/com/baeldung/removeprefix/RemovePrefixTest.groovy @@ -0,0 +1,70 @@ +package com.baeldung.removeprefix + +import org.junit.Assert +import org.junit.Test + +class RemovePrefixTest { + + + @Test + public void whenCasePrefixIsRemoved_thenReturnTrue() { + def trimPrefix = { + it.startsWith('Groovy-') ? it.minus('Groovy-') : it + } + + def actual = trimPrefix("Groovy-Tutorials at Baeldung") + def expected = "Tutorials at Baeldung" + + Assert.assertEquals(expected, actual) + } + + @Test + public void whenPrefixIsRemoved_thenReturnTrue() { + + String prefix = "groovy-" + String trimPrefix = "Groovy-Tutorials at Baeldung" + def actual; + if(trimPrefix.startsWithIgnoreCase(prefix)) { + actual = trimPrefix.substring(prefix.length()) + } + + def expected = "Tutorials at Baeldung" + + Assert.assertEquals(expected, actual) + } + + @Test + public void whenPrefixIsRemovedUsingRegex_thenReturnTrue() { + + def regex = ~"^([Gg])roovy-" + String trimPrefix = "Groovy-Tutorials at Baeldung" + String actual = trimPrefix - regex + + def expected = "Tutorials at Baeldung" + + Assert.assertEquals(expected, actual) + } + + @Test + public void whenPrefixIsRemovedUsingReplaceFirst_thenReturnTrue() { + def regex = ~"^groovy" + String trimPrefix = "groovyTutorials at Baeldung's groovy page" + String actual = trimPrefix.replaceFirst(regex, "") + + def expected = "Tutorials at Baeldung's groovy page" + + Assert.assertEquals(expected, actual) + } + + @Test + public void whenPrefixIsRemovedUsingReplaceAll_thenReturnTrue() { + + String trimPrefix = "groovyTutorials at Baeldung groovy" + String actual = trimPrefix.replaceAll(/^groovy/, "") + + def expected = "Tutorials at Baeldung groovy" + + Assert.assertEquals(expected, actual) + } + +} \ No newline at end of file diff --git a/pom.xml b/pom.xml index 030e56107c..8e3fc2aaa4 100644 --- a/pom.xml +++ b/pom.xml @@ -383,6 +383,7 @@ core-groovy core-groovy-2 core-groovy-collections + core-groovy-strings core-java-modules core-kotlin-modules @@ -894,6 +895,7 @@ core-groovy core-groovy-2 core-groovy-collections + core-groovy-strings core-java-modules core-kotlin-modules