diff --git a/.gitignore b/.gitignore index 0c084f8..a7dc592 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ *.iml .idea .DS_Store -target \ No newline at end of file +target +.classpath +.project +.settings/ \ No newline at end of file diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..76fbf04 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,6 @@ +coverage: + status: + project: + default: + # basic + target: 100% \ No newline at end of file diff --git a/pom.xml b/pom.xml index 759fad7..32ecf5d 100644 --- a/pom.xml +++ b/pom.xml @@ -1,100 +1,96 @@ - 4.0.0 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + 4.0.0 - se.cygni - ci-tdd-java-template - 1..00-SNAPSHOT + se.cygni + ci-tdd-java-template + 1..00-SNAPSHOT - ci-tdd-java-template + ci-tdd-java-template - - UTF-8 - UTF-8 - 1.8 - 5.1.0 - 1.1.0 - + + UTF-8 + UTF-8 + 1.8 + 5.1.0 + 1.1.0 + - - - junit - junit - 4.12 - test - - - org.assertj - assertj-core - 3.9.0 - test - + + + junit + junit + 4.12 + test + + + org.assertj + assertj-core + 3.9.0 + test + - + - - - - maven-compiler-plugin - 3.7.0 - - ${java.version} - ${java.version} - - - - maven-surefire-plugin - 2.19.1 - - - ${surefireArgLine} - - **/Test*.java - **/*Test.java - **/*Tests.java - **/*TestCase.java - - - - - - org.jacoco - jacoco-maven-plugin - 0.8.0 - - - - pre-unit-test - - prepare-agent - - - ${project.build.directory}/coverage-reports/jacoco-ut.exec - surefireArgLine - - - - - post-unit-test - package - - report - - - ${project.build.directory}/coverage-reports/jacoco-ut.exec - ${project.reporting.outputDirectory}/jacoco-ut - - - - - - + + + + maven-compiler-plugin + 3.7.0 + + ${java.version} + ${java.version} + + + + maven-surefire-plugin + 2.19.1 + + + ${surefireArgLine} + + **/Test*.java + **/*Test.java + **/*Tests.java + **/*TestCase.java + + + + + + org.jacoco + jacoco-maven-plugin + 0.8.0 + + + + pre-unit-test + + prepare-agent + + + ${project.build.directory}/coverage-reports/jacoco-ut.exec + surefireArgLine + + + + + post-unit-test + package + + report + + + ${project.build.directory}/coverage-reports/jacoco-ut.exec + ${project.reporting.outputDirectory}/jacoco-ut + + + + + + diff --git a/src/main/java/se/cygni/palmithor/tdd/StringUtils.java b/src/main/java/se/cygni/palmithor/tdd/StringUtils.java index 3b36d6b..9c612f8 100644 --- a/src/main/java/se/cygni/palmithor/tdd/StringUtils.java +++ b/src/main/java/se/cygni/palmithor/tdd/StringUtils.java @@ -1,20 +1,27 @@ package se.cygni.palmithor.tdd; -public class StringUtils { - +import java.util.stream.IntStream; - public boolean isPalindrome(final String str) { - throw new RuntimeException("Not yet implemented"); - } +public class StringUtils { + public boolean isPalindrome(final String str) { + if(str != null) { + String temp = str.replaceAll("\\s+", "").toLowerCase(); + return IntStream.range(0, temp.length() / 2) + .noneMatch(i -> temp.charAt(i) != temp.charAt(temp.length() - i - 1)); + } + return false; + } - /** - * 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) { + return str == null || str.trim().length() == 0; + } } diff --git a/src/test/java/se/cygni/palmithor/tdd/CalculatorTest.java b/src/test/java/se/cygni/palmithor/tdd/CalculatorTest.java index ed4264e..0302120 100644 --- a/src/test/java/se/cygni/palmithor/tdd/CalculatorTest.java +++ b/src/test/java/se/cygni/palmithor/tdd/CalculatorTest.java @@ -13,7 +13,12 @@ public class CalculatorTest { @Test public void test() { - //assertThat(calculator.sumAll().get()).isEqualTo(1); // fail un purpose + assertThat(calculator.sumAll(1).get()).isEqualTo(1); // TODO failing on purpose please fix + assertThat(calculator.sumAll(1,3).get()).isEqualTo(4); + assertThat(calculator.sumAll().get()).isEqualTo(0); + assertThat(calculator.sumAll(null).isPresent()).isFalse(); + + } diff --git a/src/test/java/se/cygni/palmithor/tdd/StringUtilsTest.java b/src/test/java/se/cygni/palmithor/tdd/StringUtilsTest.java index 09cabc4..595bc1f 100644 --- a/src/test/java/se/cygni/palmithor/tdd/StringUtilsTest.java +++ b/src/test/java/se/cygni/palmithor/tdd/StringUtilsTest.java @@ -11,14 +11,12 @@ public class StringUtilsTest { @Test public void isPalindrome() { - /* assertThat(stringUtils.isPalindrome("aabb")).isFalse(); assertThat(stringUtils.isPalindrome(null)).isFalse(); assertThat(stringUtils.isPalindrome("NotEvenClose")).isFalse(); assertThat(stringUtils.isPalindrome("")).isTrue(); assertThat(stringUtils.isPalindrome("abba")).isTrue(); assertThat(stringUtils.isPalindrome("tattarrattat")).isTrue(); - */ } /** @@ -26,6 +24,9 @@ public void isPalindrome() { */ @Test public void isBlank() { - // stringUtils.isBlank() + assertThat(stringUtils.isBlank("")).isTrue(); + assertThat(stringUtils.isBlank("NotEmpty")).isFalse(); + assertThat(stringUtils.isBlank(null)).isTrue(); + assertThat(stringUtils.isBlank(" ")).isTrue(); } } \ No newline at end of file