Skip to content

Commit f47aaa0

Browse files
committed
Update tests, change trim checks and exception text
1 parent 86f3d14 commit f47aaa0

File tree

4 files changed

+42
-16
lines changed

4 files changed

+42
-16
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ Via Maven
1515
<dependency>
1616
<groupId>pl.ksdev</groupId>
1717
<artifactId>slugify</artifactId>
18-
<version>0.2</version>
18+
<version>0.3</version>
1919
</dependency>
2020
```
2121

2222
Via Gradle
2323

2424
```groovy
25-
compile 'pl.ksdev:slugify:0.2'
25+
compile 'pl.ksdev:slugify:0.3'
2626
```
2727

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

4747
[link-travis]: https://travis-ci.org/ksdev-pl/slugify
48-
[link-maven]: http://search.maven.org/#artifactdetails%7Cpl.ksdev%7Cslugify%7C0.2%7Cjar
48+
[link-maven]: http://search.maven.org/#artifactdetails%7Cpl.ksdev%7Cslugify%7C0.3%7Cjar
4949
[link-coveralls]: https://coveralls.io/github/ksdev-pl/slugify?branch=master

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<modelVersion>4.0.0</modelVersion>
66
<groupId>pl.ksdev</groupId>
77
<artifactId>slugify</artifactId>
8-
<version>0.2</version>
8+
<version>0.3</version>
99
<packaging>jar</packaging>
1010

1111
<name>Slugify</name>

src/main/java/pl/ksdev/slugify/SimpleSlugService.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,7 @@ public SimpleSlugService() {
217217
*/
218218
public SimpleSlugService(int maxSlugLength) {
219219
if (maxSlugLength <= 0) {
220-
throw new IllegalArgumentException(
221-
"maxSlugLength must be greater than zero"
222-
);
220+
throw new IllegalArgumentException("maxSlugLength must be > 0");
223221
}
224222

225223
this.maxSlugLength = maxSlugLength;
@@ -253,13 +251,11 @@ public String slugify(String text) {
253251
}
254252

255253
// Trim dashes
256-
if (slug.length() > 0) {
257-
if (slug.charAt(0) == '-') {
258-
slug.deleteCharAt(0);
259-
}
260-
if (slug.charAt(slug.length() - 1) == '-') {
261-
slug.deleteCharAt(slug.length() - 1);
262-
}
254+
if (slug.length() > 0 && slug.charAt(0) == '-') {
255+
slug.deleteCharAt(0);
256+
}
257+
if (slug.length() > 0 && slug.charAt(slug.length() - 1) == '-') {
258+
slug.deleteCharAt(slug.length() - 1);
263259
}
264260

265261
return slug.toString();

src/test/java/pl/ksdev/slugify/SimpleSlugServiceTest.java

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,44 @@ public void shouldReturnEmptyString() {
3636
// given
3737
String text1 = "";
3838
String text2 = " @ \n#* \\ $/&) !(&*\r# . ..";
39+
String text3 = "*****************************************************" +
40+
"****************************************************************" +
41+
"****************************************************************" +
42+
"****************************************************************" +
43+
"****************************************************************" +
44+
"****************************************************************" +
45+
"****************************************************************" +
46+
"****************************************************************" +
47+
"****************************************************************" +
48+
"****************************************************************" +
49+
"****************************************************************" +
50+
"****************************************************************" +
51+
"****************************************************************" +
52+
"****************************************************************" +
53+
"****************************************************************" +
54+
"****************************************************************" +
55+
"****************************************************************" +
56+
"****************************************************************" +
57+
"****************************************************************" +
58+
"****************************************************************" +
59+
"****************************************************************" +
60+
"****************************************************************" +
61+
"****************************************************************" +
62+
"****************************************************************" +
63+
"****************************************************************" +
64+
"****************************************************************" +
65+
"****************************************************************" +
66+
"****************************************************************";
3967

4068
// when
41-
String result1 = new SimpleSlugService().slugify("");
42-
String result2 = new SimpleSlugService().slugify("");
69+
String result1 = new SimpleSlugService().slugify(text1);
70+
String result2 = new SimpleSlugService().slugify(text2);
71+
String result3 = new SimpleSlugService().slugify(text3);
4372

4473
// then
4574
assertEquals("", result1);
4675
assertEquals("", result2);
76+
assertEquals("", result3);
4777
}
4878

4979
@Test

0 commit comments

Comments
 (0)