update the PR with removal of README file and update pom.xml files according to comments

This commit is contained in:
Usman Mohyuddin 2020-09-10 22:39:44 +05:00
parent 8415ee8096
commit 43fb479c81
4 changed files with 108 additions and 53 deletions

View File

@ -1,8 +0,0 @@
# Core Groovy Strings
This module contains articles about core Groovy strings concepts
## Relevant articles:
- [Remove prefix in Groovy]()
- [[<-- Prev]](/core-groovy-strings)

View File

@ -3,70 +3,120 @@
xmlns="http://maven.apache.org/POM/4.0.0" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<groupId>com.baeldung</groupId>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>core-groovy-strings</artifactId> <artifactId>core-groovy-strings</artifactId>
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
<name>core-groovy-strings</name> <name>core-groovy-strings</name>
<packaging>jar</packaging> <packaging>jar</packaging>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.codehaus.groovy</groupId> <groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId> <artifactId>groovy</artifactId>
<version>${groovy.version}</version> <version>${groovy.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>${groovy-all.version}</version>
<type>pom</type> <type>pom</type>
</dependency> </dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-dateutil</artifactId>
<version>${groovy.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-sql</artifactId>
<version>${groovy-sql.version}</version>
</dependency>
<dependency> <dependency>
<groupId>org.junit.platform</groupId> <groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId> <artifactId>junit-platform-runner</artifactId>
<version>${junit.platform.version}</version> <version>${junit.platform.version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>${hsqldb.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
<version>${spock-core.version}</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>
<scriptSourceDirectory>src/main/groovy</scriptSourceDirectory>
<sourceDirectory>src/main/java</sourceDirectory>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.codehaus.groovy</groupId> <groupId>org.codehaus.gmavenplus</groupId>
<artifactId>groovy-eclipse-compiler</artifactId> <artifactId>gmavenplus-plugin</artifactId>
<version>${groovy.compiler.version}</version> <version>${gmavenplus-plugin.version}</version>
<extensions>true</extensions> <executions>
<execution>
<goals>
<goal>addSources</goal>
<goal>addTestSources</goal>
<goal>compile</goal>
<goal>compileTests</goal>
</goals>
</execution>
</executions>
</plugin> </plugin>
<plugin> <plugin>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-failsafe-plugin</artifactId>
<version>${compiler.plugin.version}</version> <version>${maven-failsafe-plugin.version}</version>
<configuration>
<compilerId>groovy-eclipse-compiler</compilerId>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.codehaus.groovy</groupId> <groupId>org.junit.platform</groupId>
<artifactId>groovy-eclipse-compiler</artifactId> <artifactId>junit-platform-surefire-provider</artifactId>
<version>${groovy.compiler.version}</version> <version>${junit.platform.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
<version>${groovy.version}-01</version>
</dependency> </dependency>
</dependencies> </dependencies>
<executions>
<execution>
<id>junit5</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<includes>
<include>**/*Test5.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin> </plugin>
</plugins> </plugins>
</build> </build>
<repositories>
<repository>
<id>central</id>
<url>https://jcenter.bintray.com</url>
</repository>
</repositories>
<properties> <properties>
<junit.platform.version>1.0.0</junit.platform.version> <junit.platform.version>1.0.0</junit.platform.version>
<groovy-wslite.version>1.1.3</groovy-wslite.version> <groovy.version>2.5.6</groovy.version>
<groovy.version>2.5.7</groovy.version> <groovy-all.version>2.5.6</groovy-all.version>
<surefire.plugin.version>2.20.1</surefire.plugin.version> <groovy-sql.version>2.5.6</groovy-sql.version>
<compiler.plugin.version>3.8.0</compiler.plugin.version> <hsqldb.version>2.4.0</hsqldb.version>
<groovy.compiler.version>3.3.0-01</groovy.compiler.version> <spock-core.version>1.1-groovy-2.4</spock-core.version>
<java.version>1.8</java.version> <gmavenplus-plugin.version>1.6</gmavenplus-plugin.version>
</properties> </properties>
</project> </project>

View File

@ -9,23 +9,28 @@ class RemovePrefixTest {
@Test @Test
public void whenCasePrefixIsRemoved_thenReturnTrue() { public void whenCasePrefixIsRemoved_thenReturnTrue() {
def trimPrefix = { def trimPrefix = {
it.startsWith('Groovy') ? it.minus('Groovy') : it it.startsWith('Groovy-') ? it.minus('Groovy-') : it
} }
def actual = trimPrefix("Groovy-Tutorials at Baeldung")
def expected = "Tutorials at Baeldung"
Assert.assertEquals(trimPrefix("GroovyTutorials at Baeldung"), "Tutorials at Baeldung") Assert.assertEquals(expected, actual)
} }
@Test @Test
public void whenPrefixIsRemovedWithIgnoreCase_thenReturnTrue() { public void whenPrefixIsRemoved_thenReturnTrue() {
String prefix = "groovy-" String prefix = "groovy-"
String trimPrefix = "Groovy-Tutorials at Baeldung" String trimPrefix = "Groovy-Tutorials at Baeldung"
def result; def actual;
if(trimPrefix.startsWithIgnoreCase(prefix)) { if(trimPrefix.startsWithIgnoreCase(prefix)) {
result = trimPrefix.substring(prefix.length()) actual = trimPrefix.substring(prefix.length())
} }
def expected = "Tutorials at Baeldung"
Assert.assertEquals("Tutorials at Baeldung", result) Assert.assertEquals(expected, actual)
} }
@Test @Test
@ -33,26 +38,32 @@ class RemovePrefixTest {
def regex = ~"^([Gg])roovy-" def regex = ~"^([Gg])roovy-"
String trimPrefix = "Groovy-Tutorials at Baeldung" String trimPrefix = "Groovy-Tutorials at Baeldung"
String result = trimPrefix - regex String actual = trimPrefix - regex
def expected = "Tutorials at Baeldung"
Assert.assertEquals("Tutorials at Baeldung", result) Assert.assertEquals(expected, actual)
} }
@Test public void whenPrefixIsRemovedUsingReplaceFirst_thenReturnTrue() { @Test public void whenPrefixIsRemovedUsingReplaceFirst_thenReturnTrue() {
def regex = ~"^groovy" def regex = ~"^groovy"
String trimPrefix = "groovyTutorials at Baeldung's groovy page" String trimPrefix = "groovyTutorials at Baeldung's groovy page"
String result = trimPrefix.replaceFirst(regex, "") String actual = trimPrefix.replaceFirst(regex, "")
Assert.assertEquals("Tutorials at Baeldung's groovy page", result) def expected = "Tutorials at Baeldung's groovy page"
Assert.assertEquals(expected, actual)
} }
@Test @Test
public void whenPrefixIsRemovedUsingReplaceAll_thenReturnTrue() { public void whenPrefixIsRemovedUsingReplaceAll_thenReturnTrue() {
String trimPrefix = "groovyTutorials at Baeldung groovy" String trimPrefix = "groovyTutorials at Baeldung groovy"
String result = trimPrefix.replaceAll(/^groovy/, "") String actual = trimPrefix.replaceAll(/^groovy/, "")
def expected = "Tutorials at Baeldung groovy"
Assert.assertEquals("Tutorials at Baeldung groovy", result) Assert.assertEquals(expected, actual)
} }
} }

View File

@ -383,6 +383,7 @@
<module>core-groovy</module> <module>core-groovy</module>
<module>core-groovy-2</module> <module>core-groovy-2</module>
<module>core-groovy-collections</module> <module>core-groovy-collections</module>
<module>core-groovy-strings</module>
<module>core-java-modules</module> <module>core-java-modules</module>
<module>core-kotlin-modules</module> <module>core-kotlin-modules</module>
@ -898,6 +899,7 @@
<module>core-groovy</module> <module>core-groovy</module>
<module>core-groovy-2</module> <module>core-groovy-2</module>
<module>core-groovy-collections</module> <module>core-groovy-collections</module>
<module>core-groovy-strings</module>
<module>core-java-modules</module> <module>core-java-modules</module>
<module>core-kotlin-modules</module> <module>core-kotlin-modules</module>