Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions src/main/java/se/cygni/palmithor/tdd/StringUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,26 @@
public class StringUtils {


public boolean isPalindrome(final String str) {
throw new RuntimeException("Not yet implemented");
public boolean isPalindrome(final String str) {
if (str == null) {
return false;
}
StringBuilder string = new StringBuilder(str);
return string.reverse().toString().equals(str);
}


/**
* Checks if a String is empty (""), null or whitespace only.
* @param str the string to check
*
* @return true if str is null, empty or whitespace only, otherwise false
*/
public boolean isBlank(final String str) {
throw new RuntimeException("Not yet implemented");
/**
* Checks if a String is empty (""), null or whitespace only.
*
* @param str the string to check
* @return true if str is null, empty or whitespace only, otherwise false
*/
public boolean isBlank(final String str) {
if (str == null ) {
return true;
}
String trimmed = str.trim();
return trimmed.equals("");
}
}
12 changes: 8 additions & 4 deletions src/test/java/se/cygni/palmithor/tdd/CalculatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ public class CalculatorTest {
private Calculator calculator = new Calculator();

@Test
public void test() {
assertThat(calculator.sumAll().get()).isEqualTo(1); // TODO failing on purpose please fix
public void test()
{
assertThat(calculator.sumAll(1).get()).isEqualTo(1);
assertThat(calculator.sumAll(null)).isEqualTo(Optional.empty());
assertThat(calculator.sumAll().get()).isEqualTo(0);
assertThat(calculator.sumAll(1, 2, 3).get()).isEqualTo(6);
assertThat(calculator.sumAll(-1, -2, -3).get()).isEqualTo(-6);
assertThat(calculator.sumAll(-1, null, -3).get()).isEqualTo(-4);
}


}
9 changes: 8 additions & 1 deletion src/test/java/se/cygni/palmithor/tdd/StringUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ public void isPalindrome() {
*/
@Test
public void isBlank() {
// stringUtils.isBlank()
assertThat(stringUtils.isBlank(null)).isTrue();
assertThat(stringUtils.isBlank("hej")).isFalse();
assertThat(stringUtils.isBlank("hej jon")).isFalse();
assertThat(stringUtils.isBlank("")).isTrue();
assertThat(stringUtils.isBlank(" ")).isTrue();
assertThat(stringUtils.isBlank(" ")).isTrue();
assertThat(stringUtils.isBlank(" _")).isFalse();
assertThat(stringUtils.isBlank("\n\t\r")).isTrue();
}
}