I want be at least 75 % of cover of the code of my class
My class to be tested :
public class InactiveGroups_Class{
Public static void blockChange(FeedItem item){
List<CollaborationGroup> MyGroup = [Select Name From CollaborationGroup where Id = :item.ParentId LIMIT 1];
if(MyGroup.size() >0){
if(MyGroup.get(0).Name.toUpperCase().contains('#.INACTIF')){
item.addError('this is inactive group');
}
}
}
Public static void blockChange(FeedItem item, FeedComment comment){
List<CollaborationGroup> MyGroup = [Select Name From CollaborationGroup where Id = :item.ParentId LIMIT 1];
if(MyGroup.size() >0){
if(MyGroup.get(0).Name.toUpperCase().contains('#.INACTIF')){
comment.addError('this is inactive group');
}
}
}
}
My Test Class:
@isTest(SeeAllData=true)
public class InactiveGroups_ClassTest{
static testMethod void myUnitTest() {
Group gp= new Group();
gp.Name ='#.inactif';
FeedItem item = new FeedItem();
item.ParentId = gp.Id;
FeedComment comment = new FeedComment();
Test.startTest();
InactiveGroups_Class.blockChange(item);
InactiveGroups_Class.blockChange(item, comment);
Test.stopTest();
}
}
thx.
11 respuestas
thx for all with mixing help of @Neha Lund and @Puneet Mehta
i have solution :
static testMethod void myUnitTest() {
CollaborationGroup gp= new CollaborationGroup(Name = 'MyGroup To test', CollaborationType = 'Private');
gp.Name ='#.inactif';
insert gp;
FeedItem item = new FeedItem();
item.ParentId = gp.Id;
FeedComment comment = new FeedComment();
Test.startTest();
Natixis_InactiveGroups_Class.blockChange(item);
Natixis_InactiveGroups_Class.blockChange(item, comment);
Test.stopTest();
}
:)