Reputation: 1
In TimelineCase class, Here We are send the recordId and pageNo and pase size in processTimelineItem() Method, Expecting it will fetch the case record by using sql in this class. but here we able to cover the sql case record and unable to fetch the case record.
I wrote some test class by my knowledge, i able to achieve the 100% apex code coverage but still my test class is failed due to System.assertEquals(applicantId, testFilteredObjects[0].actor); this followed line, now try to understand my test class or using that please write new test class by understanding. Many thanks in advance !
I wrote some test class, i able to 100 % code coverage in class but still my test class is failed.
TimelineCase class
public class TimelineCase extends TimelineObject implements TimelineObject{
public List<TimelineObject> processTimelineItem(id recordId, Integer pageNo, Integer pageSize){
List<TimelineObject> wrappedCase = new List<TimelineObject>();
List<Case> t = [SELECT Id, Subject, AccountId, CreatedDate, CreatedBy.Name
FROM Case
WHERE Applicant__c = :recordId
LIMIT :pageSize
OFFSET :pageNo];
if(t != null){
for(Integer i = 0, CaseSize = t.size(); i < CaseSize; i++){
wrappedCase.add(new TimelineObject().setActor(t[i].CreatedBy.Name)
.setHeader(t[i].Subject)
.setDate(t[i].CreatedDate.format())
.setIconName('standard:case')
.setIconColour('put the colour in here'));
}
}
return wrappedCase;
}
}
I have tried some test class for your reference,
Test class for TimelineCase
@isTest
public class TimelineCaseTest {
@isTest
public static void itShouldBeAbleToGetApplicantCaseListTest1(){
String applicantId = new TimelineControllerBuilder().save();
Case caseApplicant = new CaseBuilder().withApplicant(applicantId)
.save();
TimelineCase TimelineCase = new TimelineCase();
Test.startTest();
List<TimelineObject> testFilteredObjects = TimelineCase.processTimelineItem(applicantId, 1, 10);
Test.stopTest();
System.debug('Case result' + caseApplicant.CreatedBy.Name + testFilteredObjects[0].actor);
System.assertEquals(1, testFilteredObjects.size());
// applicantId returns case record
System.assertEquals(applicantId, testFilteredObjects[0].actor);
// applicantId returns current created date and time of case record
System.assertEquals((applicantId, , testFilteredObjects[0].itemDate);
System.assertEquals('standard:case', testFilteredObjects[0].iconName);
System.assertEquals('put the colour in here', testFilteredObjects[0].iconColour);
}
}
Please let me know if you need further information
// returning the user name who is creating the case record
System.assertEquals(applicantId, testFilteredObjects[0].actor);
//// returning the created date and time who is creating the case record
System.assertEquals(applicantId, testFilteredObjects[0].itemDate);
}
Upvotes: 0
Views: 3204