Skip to content

Commit

Permalink
Update tests, change trim checks and exception text
Browse files Browse the repository at this point in the history
  • Loading branch information
ksdev-pl committed Jan 15, 2018
1 parent 86f3d14 commit f47aaa0
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 16 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ Via Maven
<dependency>
<groupId>pl.ksdev</groupId>
<artifactId>slugify</artifactId>
<version>0.2</version>
<version>0.3</version>
</dependency>
```

Via Gradle

```groovy
compile 'pl.ksdev:slugify:0.2'
compile 'pl.ksdev:slugify:0.3'
```

## Usage
Expand All @@ -45,5 +45,5 @@ The MIT License (MIT). Please see [License File](LICENSE) for more information.
[ico-coveralls]: https://img.shields.io/coveralls/github/ksdev-pl/slugify.svg?style=flat-square

[link-travis]: https://travis-ci.org/ksdev-pl/slugify
[link-maven]: http://search.maven.org/#artifactdetails%7Cpl.ksdev%7Cslugify%7C0.2%7Cjar
[link-maven]: http://search.maven.org/#artifactdetails%7Cpl.ksdev%7Cslugify%7C0.3%7Cjar
[link-coveralls]: https://coveralls.io/github/ksdev-pl/slugify?branch=master
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>pl.ksdev</groupId>
<artifactId>slugify</artifactId>
<version>0.2</version>
<version>0.3</version>
<packaging>jar</packaging>

<name>Slugify</name>
Expand Down
16 changes: 6 additions & 10 deletions src/main/java/pl/ksdev/slugify/SimpleSlugService.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,7 @@ public SimpleSlugService() {
*/
public SimpleSlugService(int maxSlugLength) {
if (maxSlugLength <= 0) {
throw new IllegalArgumentException(
"maxSlugLength must be greater than zero"
);
throw new IllegalArgumentException("maxSlugLength must be > 0");
}

this.maxSlugLength = maxSlugLength;
Expand Down Expand Up @@ -253,13 +251,11 @@ public String slugify(String text) {
}

// Trim dashes
if (slug.length() > 0) {
if (slug.charAt(0) == '-') {
slug.deleteCharAt(0);
}
if (slug.charAt(slug.length() - 1) == '-') {
slug.deleteCharAt(slug.length() - 1);
}
if (slug.length() > 0 && slug.charAt(0) == '-') {
slug.deleteCharAt(0);
}
if (slug.length() > 0 && slug.charAt(slug.length() - 1) == '-') {
slug.deleteCharAt(slug.length() - 1);
}

return slug.toString();
Expand Down
34 changes: 32 additions & 2 deletions src/test/java/pl/ksdev/slugify/SimpleSlugServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,44 @@ public void shouldReturnEmptyString() {
// given
String text1 = "";
String text2 = " @ \n#* \\ $/&) !(&*\r# . ..";
String text3 = "*****************************************************" +
"****************************************************************" +
"****************************************************************" +
"****************************************************************" +
"****************************************************************" +
"****************************************************************" +
"****************************************************************" +
"****************************************************************" +
"****************************************************************" +
"****************************************************************" +
"****************************************************************" +
"****************************************************************" +
"****************************************************************" +
"****************************************************************" +
"****************************************************************" +
"****************************************************************" +
"****************************************************************" +
"****************************************************************" +
"****************************************************************" +
"****************************************************************" +
"****************************************************************" +
"****************************************************************" +
"****************************************************************" +
"****************************************************************" +
"****************************************************************" +
"****************************************************************" +
"****************************************************************" +
"****************************************************************";

// when
String result1 = new SimpleSlugService().slugify("");
String result2 = new SimpleSlugService().slugify("");
String result1 = new SimpleSlugService().slugify(text1);
String result2 = new SimpleSlugService().slugify(text2);
String result3 = new SimpleSlugService().slugify(text3);

// then
assertEquals("", result1);
assertEquals("", result2);
assertEquals("", result3);
}

@Test
Expand Down

0 comments on commit f47aaa0

Please sign in to comment.