11package com .baeldung .string ;
22
3- import java .util .Arrays ;
4-
5- import org .junit .Assert ;
3+ import static org .junit .Assert .*;
64import org .junit .Test ;
75
8- public class WhenCheckingPalindrome {
6+ public class PalindromeTest {
97
108 private String [] words = {
119 "Anna" ,
@@ -28,50 +26,50 @@ public class WhenCheckingPalindrome {
2826 @ Test
2927 public void whenWord_shouldBePalindrome () {
3028 for (String word :words )
31- Assert . assertTrue (palindrome .isPalindrome (word ));
29+ assertTrue (palindrome .isPalindrome (word ));
3230 }
3331
3432 @ Test
3533 public void whenSentence_shouldBePalindrome () {
3634 for (String sentence :sentences )
37- Assert . assertTrue (palindrome .isPalindrome (sentence ));
35+ assertTrue (palindrome .isPalindrome (sentence ));
3836 }
3937
4038 @ Test
4139 public void whenReverseWord_shouldBePalindrome () {
4240 for (String word :words )
43- Assert . assertTrue (palindrome .isPalindromeReverseTheString (word ));
41+ assertTrue (palindrome .isPalindromeReverseTheString (word ));
4442 }
4543
4644 @ Test
4745 public void whenReverseSentence_shouldBePalindrome () {
4846 for (String sentence :sentences )
49- Assert . assertTrue (palindrome .isPalindromeReverseTheString (sentence ));
47+ assertTrue (palindrome .isPalindromeReverseTheString (sentence ));
5048 }
5149
5250 @ Test
5351 public void whenStringBuilderWord_shouldBePalindrome () {
5452 for (String word :words )
55- Assert . assertTrue (palindrome .isPalindromeUsingStringBuilder (word ));
53+ assertTrue (palindrome .isPalindromeUsingStringBuilder (word ));
5654 }
5755
5856 @ Test
5957 public void whenStringBuilderSentence_shouldBePalindrome () {
6058 for (String sentence :sentences )
61- Assert . assertTrue (palindrome .isPalindromeUsingStringBuilder (sentence ));
59+ assertTrue (palindrome .isPalindromeUsingStringBuilder (sentence ));
6260 }
6361
6462 @ Test
6563 public void whenStringBufferWord_shouldBePalindrome () {
6664 for (String word :words )
67- Assert . assertTrue (palindrome .isPalindromeUsingStringBuffer (word ));
65+ assertTrue (palindrome .isPalindromeUsingStringBuffer (word ));
6866 }
6967
7068 @ Test
7169 public void whenStringBufferSentence_shouldBePalindrome () {
7270 for (String sentence :sentences )
7371
74- Assert . assertTrue (palindrome .isPalindromeUsingStringBuffer (sentence ));
72+ assertTrue (palindrome .isPalindromeUsingStringBuffer (sentence ));
7573 }
7674
7775 @ Test
@@ -80,7 +78,7 @@ public void whenPalindromeRecursive_wordShouldBePalindrome() {
8078 word = word .replaceAll ("\\ s+" , "" ).toLowerCase ();
8179 int backward = word .length ()-1 ;
8280
83- Assert . assertTrue (palindrome .isPalindromeRecursive (word ,0 ,backward ));
81+ assertTrue (palindrome .isPalindromeRecursive (word ,0 ,backward ));
8482 }
8583 }
8684
@@ -90,25 +88,21 @@ public void whenPalindromeRecursive_sentenceShouldBePalindrome() {
9088 sentence = sentence .replaceAll ("\\ s+" , "" ).toLowerCase ();
9189 int backward = sentence .length ()-1 ;
9290
93- Assert . assertTrue (palindrome .isPalindromeRecursive (sentence ,0 ,backward ));
91+ assertTrue (palindrome .isPalindromeRecursive (sentence ,0 ,backward ));
9492 }
9593 }
9694
9795 @ Test
9896 public void whenPalindromeStreams_wordShouldBePalindrome () {
99- String [] expected = Arrays .stream (words )
100- .filter (palindrome ::isPalindrome )
101- .toArray (String []::new );
102-
103- Assert .assertArrayEquals (expected , words );
97+ for (String word :words ) {
98+ assertTrue (palindrome .isPalindromeUsingIntStream (word ));
99+ }
104100 }
105101
106102 @ Test
107103 public void whenPalindromeStreams_sentenceShouldBePalindrome () {
108- String [] expected = Arrays .stream (sentences )
109- .filter (palindrome ::isPalindrome )
110- .toArray (String []::new );
111-
112- Assert .assertArrayEquals (expected , sentences );
104+ for (String sentence :sentences ) {
105+ assertTrue (palindrome .isPalindromeUsingIntStream (sentence ));
106+ }
113107 }
114108}
0 commit comments