You need to sign in to do that
Don't have an account?
Linga_Ramin
Unable to cover below Try catch block in Test class.Below is my method
public string amtStrData(string rstr){
string strg = rstr;
if(rstr.contains(' " ')){
try{
integer index1= rstr.indexOf('"')+1;
string p1= rstr.substring(index1);
integer index2= p1.indexOf('"')+index1;
string amount = rowstr.substring(index1,index2);
amount = amount.replace(',','');
strg = rstr.substring(0,index1-1)+amount+rstr.substring(index2+1);
}catch(Exception e){}
}
string strg = rstr;
if(rstr.contains(' " ')){
try{
integer index1= rstr.indexOf('"')+1;
string p1= rstr.substring(index1);
integer index2= p1.indexOf('"')+index1;
string amount = rowstr.substring(index1,index2);
amount = amount.replace(',','');
strg = rstr.substring(0,index1-1)+amount+rstr.substring(index2+1);
}catch(Exception e){}
}
or if you dont wanna remove spaces
when you call this methond in your test class pass string which contains spaces like this amtStrData(' " teststring " ');
I hope you find the above solution helpful. If it does mark as Best Answer to help others too.
Thanks,
Ramesh D
try this
@isTest public class amtStrData{
@isTest public static void amtStrDataTest()
{
String strg = '';
Test.StartTest();
yourclassname.amtStrData(strg);
Test.StopTest();
}
}
and i don't understand "rstr.contains(' " ')" if you are checking null value of string please correct it.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha
I have gone through your code and everything seems to work fine except if(rstr.contains(' " ')) due to which control doesn't gets into try block (here I am believing you are passing the string having ". Coming to problem, I don't think its a proper way to check " try using if(rstr.contains(' \" ')) instead of if(rstr.contains(' " ')).
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi