-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
c77689a
commit 891eb37
Showing
6 changed files
with
90 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/java/com/github/blagerweij/sessionlock/util/StringUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.github.blagerweij.sessionlock.util; | ||
|
||
import java.util.Locale; | ||
|
||
public class StringUtils { | ||
|
||
StringUtils() { | ||
throw new IllegalArgumentException("Utility class"); | ||
} | ||
|
||
public static String truncate(final String str, final int maxlength) { | ||
if (str == null || str.length() <= maxlength) { | ||
return str; | ||
} else { | ||
return str.substring(0, maxlength); | ||
} | ||
} | ||
|
||
public static String toUpperCase(final String str) { | ||
if (str == null) { | ||
return null; | ||
} else { | ||
return str.toUpperCase(Locale.ROOT); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/test/java/com/github/blagerweij/sessionlock/util/StringUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.github.blagerweij.sessionlock.util; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
class StringUtilsTest { | ||
@Test | ||
void constructor() { | ||
assertThatThrownBy(() -> new StringUtils()).isInstanceOf(IllegalArgumentException.class); | ||
} | ||
|
||
@Test | ||
void truncate() { | ||
assertThat(StringUtils.truncate("testing", 4)).isEqualTo("test"); | ||
assertThat(StringUtils.truncate("test", 4)).isEqualTo("test"); | ||
assertThat(StringUtils.truncate("t", 4)).isEqualTo("t"); | ||
assertThat(StringUtils.truncate(null, 4)).isEqualTo(null); | ||
} | ||
|
||
@Test | ||
void toUpperCase() { | ||
assertThat(StringUtils.toUpperCase("testing")).isEqualTo("TESTING"); | ||
assertThat(StringUtils.toUpperCase(null)).isEqualTo(null); | ||
} | ||
} |