I followed the following link to override the System.out.println
call in java.
this is the program
public class palstr
{
public String rev(String a)
{
String b=new StringBuffer(a).reverse().toString();
return b;
}
public int check(String a,String b)
{
if(a.equals(b))
{
return 1;
}
else
{
return 0;
}
}
public static void main(String a){
palstr obj = new palstr();
String b = obj.rev(a);
int check= obj.check(a, b);
if(check == 1){
System.out.println("palindrome");
} else {
System.out.println("not palindrome");
}
}
}
and this is the testcase
import java.io.*;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
public class palstrTest
{
@Test
public void mainTest(){
System.out.println("madam is a palindrome string");
ByteArrayOutputStream outContent = new ByteArrayOutputStream();
System.setOut(new PrintStream(outContent));
palstr.main("madam");
assertEquals("palindrome", outContent);
}
}
when i am running the test i am getting the following error
.madam is a palindrome string
E
Time: 0.026
There was 1 failure:
1) mainTest(palstrTest)
java.lang.AssertionError: expected:<palindrome> but was:<palindrome
>