function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
kirankumarreddy punurukirankumarreddy punuru 

can someone tell me why these 3 lines are not covering in test class

here is my test class:
@isTest(SeeAllData = true)
Public with sharing class ChatterPostTriggerTest{
    // Positive test class for ChatterPostTrigger.trigger
    public static testMethod void PosTestForSinglePost(){
     
       Profile p = [SELECT Id FROM Profile WHERE Name='Standard User']; 
       User u = new User(Alias = 'dardt', Email='normaluser@testorg.com', 
            EmailEncodingKey='UTF-8', LastName='Testuser', LanguageLocaleKey='en_US', 
            LocaleSidKey='en_US', ProfileId = p.Id, 
            TimeZoneSidKey='America/Los_Angeles', UserName='normaluser@testorg.com', DMS_FS_CTS__c = 'FS');
            insert u;

        
     
        FeedItem feed = new FeedItem();
        feed.Body = 'This is test class';
        feed.ParentId = Userinfo.getUserId(); 
        feed.ContentDescription = 'this is test class for feed item';
        feed.Type = 'QuestionPost'; // added this because of the above line
        feed.Title ='test class';
        feed.Revision =2;
        // this is required if revision > 1
        feed.LastEditById = Userinfo.getUserId();
        // this is reired if revision > 1  
        feed.LastEditDate = date.today();   
        insert feed; 
    }
}

In the below trigger BOLDED 3 lines are not covered can someone tell me

This is my trigger:
trigger ChatterPostTrigger on FeedItem (before insert, after update) {
  IF(trigger.isInsert){
    // create set off all the user who posted on chatter
    // Create a map of UserId against FeedItem/post
    Map<ID, FeedItem> userFeedMap = new Map<ID, FeedItem>();
    for(FeedItem feed : trigger.New){
      userFeedMap.put(feed.ParentId, feed);
    }
    
    //get Id of chatterGroup
    CollaborationGroup chatterGroup = [Select Id, Name from CollaborationGroup where Name =: 'FS Onsites_FS' LIMIT 1];
    
    // get the chatterGroup name
    if(chatterGroup.Id != null){
      //Map of FS Onsite_FS against userID
      Map<ID, Boolean> groupMemberMap = new Map<ID, Boolean>(); 
      for(CollaborationGroupMember groupMember : [Select Id, CollaborationGroupId, memberId from CollaborationGroupMember where CollaborationGroupId =: chatterGroup.Id]){
        groupMemberMap.put(groupMember.memberId, True);
      }
      
      // filter the FS users only and create a list of FeedItems or Posts of FS USERS
      Set<ID> fsUserIds = new Set<ID>(); 
      for(User user : [Select Id, DMS_FS_CTS__c from User where Id IN : userFeedMap.KeySet() and DMS_FS_CTS__c =: 'FS']){
        fsUserIds.add(user.Id);
      }
      
      for(FeedItem feed : Trigger.New){
        for(ID userId : fsUserIds){
            if(feed.parentId == userId && groupMemberMap.get(userId) == true)
              feed.parentId = chatterGroup.Id
;
        } 
      }
    }
    
    
    //get Id of chatterGroup 'DMS Onsites & Sr. Ops_DMS'
    CollaborationGroup chatterGroup2 = [Select Id, Name from CollaborationGroup where Name =: 'DMS Onsites & Sr. Ops_DMS' LIMIT 1];
    
    // get the chatterGroup name
    if(chatterGroup2.Id != null){
      //Map of FS Onsite_FS against userID
      Map<ID, Boolean> groupMemberMap = new Map<ID, Boolean>(); 
      for(CollaborationGroupMember groupMember : [Select Id, CollaborationGroupId, memberId from CollaborationGroupMember where CollaborationGroupId =: chatterGroup2.Id]){
        groupMemberMap.put(groupMember.memberId, True);
      }
      
      // filter the FS users only and create a list of FeedItems or Posts of FS USERS
      Set<ID> fsUserIds = new Set<ID>(); 
      for(User user : [Select Id, DMS_FS_CTS__c from User where Id IN : userFeedMap.KeySet() and DMS_FS_CTS__c =: 'DMS']){
        fsUserIds.add(user.Id);
      }
      
      for(FeedItem feed : Trigger.New){
        for(ID userId : fsUserIds){
            if(feed.parentId == userId && groupMemberMap.get(userId) == true)
              feed.parentId = chatterGroup2.Id;
        } 
      }
    } 
  }
}
sharathchandra thukkanisharathchandra thukkani
this [Select Id, DMS_FS_CTS__c from User where Id IN : userFeedMap.KeySet() and DMS_FS_CTS__c =: 'FS'] is returning zero result debug this.
kirankumarreddy punurukirankumarreddy punuru
What to write in test class to cover this 
userFeedMap.KeySet()
KaranrajKaranraj
Don't use seeAllData=true in your test. Create all test data in your test class to have proper code coverage.
In your test class change 
feed.ParentId = Userinfo.getUserId();
into
feed.ParentId = u.Id;

Below is the updated test class code, you may have to insert collabarationgroup and other required test data in your test class to have full code coverage.
@isTest(SeeAllData = false)
Public with sharing class ChatterPostTriggerTest{
    // Positive test class for ChatterPostTrigger.trigger
    public static testMethod void PosTestForSinglePost(){
     
       Profile p = [SELECT Id FROM Profile WHERE Name='Standard User']; 
       User u = new User(Alias = 'dardt', Email='normaluser@testorg.com', 
            EmailEncodingKey='UTF-8', LastName='Testuser', LanguageLocaleKey='en_US', 
            LocaleSidKey='en_US', ProfileId = p.Id, 
            TimeZoneSidKey='America/Los_Angeles', UserName='normaluser@testorg.com', DMS_FS_CTS__c = 'FS');
            insert u;
      
        //Create collabaration group and other test data here
        
     
        FeedItem feed = new FeedItem();
        feed.Body = 'This is test class';
        feed.ParentId = Userinfo.getUserId(); 
        feed.ContentDescription = 'this is test class for feed item';
        feed.Type = 'QuestionPost'; // added this because of the above line
        feed.Title ='test class';
        feed.Revision =2;
        // this is required if revision > 1
        feed.LastEditById = Userinfo.getUserId();
        // this is reired if revision > 1  
        feed.LastEditDate = date.today();   
        insert feed; 
    }
}