Skip to main content
deleted 115 characters in body
Source Link
public class documentctr {
    
    public String docName{get;set;}
    public String url{get;set;}
    
    public documentctr(){
        
        if(SystemApexPages.currentPageReferenceCurrentPage().getParameters().get('doc') != null){
        
            docName = System ApexPages.currentPageReferenceCurrentPage().getParameters().get('doc');
            List<Document> lstDocument = [select id from Document where DeveloperName =: docName];    
            if(lstDocument.size() > 0){
                url = '/servlet/servlet.FileDownload?file='+lstDocument[0].id;
            }
        }
    }
    
    public pagereference returnUrl(){
        
        if(url != null){
            pagereference page = new pagereference(url);
            page.setRedirect(true);
            return page;
        }
        return null;
    }
}

}

public class documentctr {
    
    public String docName{get;set;}
    public String url{get;set;}
    
    public documentctr(){
        
        if(System.currentPageReference().getParameters().get('doc') != null){
        
            docName = System.currentPageReference().getParameters().get('doc');
            List<Document> lstDocument = [select id from Document where DeveloperName =: docName];    
            if(lstDocument.size() > 0){
                url = '/servlet/servlet.FileDownload?file='+lstDocument[0].id;
            }
        }
    }
    
    public pagereference returnUrl(){
        
        if(url != null){
            pagereference page = new pagereference(url);
            page.setRedirect(true);
            return page;
        }
        return null;
    }
}
public class documentctr {

public String docName{get;set;}
public String url{get;set;}

public documentctr(){
    
    if(ApexPages.CurrentPage().getParameters().get('doc') != null){
    
        docName =  ApexPages.CurrentPage().getParameters().get('doc');
        List<Document> lstDocument = [select id from Document where DeveloperName =: docName];    
        if(lstDocument.size() > 0){
            url = '/servlet/servlet.FileDownload?file='+lstDocument[0].id;
        }
    }
}

public pagereference returnUrl(){
    
    if(url != null){
        pagereference page = new pagereference(url);
        page.setRedirect(true);
        return page;
    }
    return null;
}

}

added 205 characters in body
Source Link
@isTest 

public class documentctrTracker{
    
    static Folder objFolder;
    public String url;
    
    static testMethod void firstMethod() {
        
        loadData();
        
              
        documentctr ob1 = new documentctr();
        PageReference pageRef = ob1 .returnUrl();
        //ob1.returnUrl();
      
   
  PageReference newPage = Page.pvdocload;
    Test.setCurrentPage(newPage);
    newPage.getParameters().put('doc','newFile');
    //ApexPages.currentPage().getParameters().put('doc','newFile');
        documentctr ob = new documentctr();
        ob.returnUrl();
    }
    
    static void loadData(){
    
        insertFolder();
        insertDocument();
    }
    
    static void insertFolder(){
        
        objFolder = [select id from Folder where Type = 'Document' limit 1];        
    }
    
    static void insertDocument(){  
        
        Document obj = new Document();
        obj.Name = 'newFile';
        obj.FolderId = objFolder.Id;
    insert obj;
    insert obj;
     
   // ApexPages.currentPage().getParameters().put('doc','newFile');
        ApexPages.Standardcontroller sc = new ApexPages.Standardcontroller(obj);
    documentctr ob1 = new documentctr();
 ob1   
    try{
    PageReference newPage = newPage.pvdocload;
 documentctr   Test.setCurrentPage(newPage);
    newPage.getParameters().put('doc','newFile');
    ob1.returnUrl();
    }
    catch(DmlException e){
    }
}
@isTest
public class documentctrTracker{
    
    static Folder objFolder;
    public String url;
    
    static testMethod void firstMethod() {
        
        loadData();
        
              
        documentctr ob1 = new documentctr();
        PageReference pageRef = ob1 .returnUrl();
        //ob1.returnUrl();
        
         
        ApexPages.currentPage().getParameters().put('doc','newFile');
        documentctr ob = new documentctr();
        ob.returnUrl();
    }
    
    static void loadData(){
    
        insertFolder();
        insertDocument();
    }
    
    static void insertFolder(){
        
        objFolder = [select id from Folder where Type = 'Document' limit 1];        
    }
    
    static void insertDocument(){  
        
        Document obj = new Document();
        obj.Name = 'newFile';
        obj.FolderId = objFolder.Id;
        insert obj;
        ApexPages.currentPage().getParameters().put('doc','newFile');
        ApexPages.Standardcontroller sc = new ApexPages.Standardcontroller(obj);
        documentctr ob1 = new documentctr();
        ob1.returnUrl();
    }
}
@isTest 

public class documentctrTracker{

static Folder objFolder;
public String url;

static testMethod void firstMethod() {
    
    loadData();
    
          
    documentctr ob1 = new documentctr();
    PageReference pageRef = ob1 .returnUrl();
    //ob1.returnUrl();
     
    PageReference newPage = Page.pvdocload;
    Test.setCurrentPage(newPage);
    newPage.getParameters().put('doc','newFile');
    //ApexPages.currentPage().getParameters().put('doc','newFile');
    documentctr ob = new documentctr();
    ob.returnUrl();
}

static void loadData(){

    insertFolder();
    insertDocument();
}

static void insertFolder(){
    
    objFolder = [select id from Folder where Type = 'Document' limit 1];        
}

static void insertDocument(){  
    
    Document obj = new Document();
    obj.Name = 'newFile';
    obj.FolderId = objFolder.Id;
    insert obj;
     
    
   // ApexPages.currentPage().getParameters().put('doc','newFile');
    ApexPages.Standardcontroller sc = new ApexPages.Standardcontroller(obj);
    documentctr ob1 = new documentctr();
    
    try{
    PageReference newPage = Page.pvdocload;
    Test.setCurrentPage(newPage);
    newPage.getParameters().put('doc','newFile');
    ob1.returnUrl();
    }
    catch(DmlException e){
    }
}
Formatted code
Source Link
Sebastian Kessel
  • 13.2k
  • 12
  • 38
  • 61

I am trying to cover this class but unable to cover "url = '/servlet/servlet.FileDownload?file='+lstDocument[0].id;"url = '/servlet/servlet.FileDownload?file='+lstDocument[0].id; and pagereference method. Need help in increasing test coverage.

public class documentctr {

public class documentctr {
    
    public String docName{get;set;}
    public String url{get;set;}
    
    public documentctr(){
        
        if(System.currentPageReference().getParameters().get('doc') != null){
        
            docName = System.currentPageReference().getParameters().get('doc');
            List<Document> lstDocument = [select id from Document where DeveloperName =: docName];    
            if(lstDocument.size() > 0){
                url = '/servlet/servlet.FileDownload?file='+lstDocument[0].id;
            }
        }
    }
    
    public pagereference returnUrl(){
        
        if(url != null){
            pagereference page = new pagereference(url);
            page.setRedirect(true);
            return page;
        }
        return null;
    }
}

}

Test Class:

@isTest public class documentctrTracker{

@isTest
public class documentctrTracker{
    
    static Folder objFolder;
    public String url;
    
    static testMethod void firstMethod() {
        
        loadData();
        
              
        documentctr ob1 = new documentctr();
        PageReference pageRef = ob1 .returnUrl();
        //ob1.returnUrl();
        
        
        ApexPages.currentPage().getParameters().put('doc','newFile');
        documentctr ob = new documentctr();
        ob.returnUrl();
    }
    
    static void loadData(){
    
        insertFolder();
        insertDocument();
    }
    
    static void insertFolder(){
        
        objFolder = [select id from Folder where Type = 'Document' limit 1];        
    }
    
    static void insertDocument(){  
        
        Document obj = new Document();
        obj.Name = 'newFile';
        obj.FolderId = objFolder.Id;
        insert obj;
        ApexPages.currentPage().getParameters().put('doc','newFile');
        ApexPages.Standardcontroller sc = new ApexPages.Standardcontroller(obj);
        documentctr ob1 = new documentctr();
        ob1.returnUrl();
    }
}

}

I am trying to cover this class but unable to cover "url = '/servlet/servlet.FileDownload?file='+lstDocument[0].id;" and pagereference method. Need help in increasing test coverage.

public class documentctr {

public String docName{get;set;}
public String url{get;set;}

public documentctr(){
    
    if(System.currentPageReference().getParameters().get('doc') != null){
    
        docName = System.currentPageReference().getParameters().get('doc');
        List<Document> lstDocument = [select id from Document where DeveloperName =: docName];    
        if(lstDocument.size() > 0){
            url = '/servlet/servlet.FileDownload?file='+lstDocument[0].id;
        }
    }
}

public pagereference returnUrl(){
    
    if(url != null){
        pagereference page = new pagereference(url);
        page.setRedirect(true);
        return page;
    }
    return null;
}

}

Test Class:

@isTest public class documentctrTracker{

static Folder objFolder;
public String url;

static testMethod void firstMethod() {
    
    loadData();
    
          
    documentctr ob1 = new documentctr();
    PageReference pageRef = ob1 .returnUrl();
    //ob1.returnUrl();
    
    
    ApexPages.currentPage().getParameters().put('doc','newFile');
    documentctr ob = new documentctr();
    ob.returnUrl();
}

static void loadData(){

    insertFolder();
    insertDocument();
}

static void insertFolder(){
    
    objFolder = [select id from Folder where Type = 'Document' limit 1];        
}

static void insertDocument(){  
    
    Document obj = new Document();
    obj.Name = 'newFile';
    obj.FolderId = objFolder.Id;
    insert obj;
    ApexPages.currentPage().getParameters().put('doc','newFile');
    ApexPages.Standardcontroller sc = new ApexPages.Standardcontroller(obj);
    documentctr ob1 = new documentctr();
    ob1.returnUrl();
}

}

I am trying to cover this class but unable to cover url = '/servlet/servlet.FileDownload?file='+lstDocument[0].id; and pagereference method. Need help in increasing test coverage.

public class documentctr {
    
    public String docName{get;set;}
    public String url{get;set;}
    
    public documentctr(){
        
        if(System.currentPageReference().getParameters().get('doc') != null){
        
            docName = System.currentPageReference().getParameters().get('doc');
            List<Document> lstDocument = [select id from Document where DeveloperName =: docName];    
            if(lstDocument.size() > 0){
                url = '/servlet/servlet.FileDownload?file='+lstDocument[0].id;
            }
        }
    }
    
    public pagereference returnUrl(){
        
        if(url != null){
            pagereference page = new pagereference(url);
            page.setRedirect(true);
            return page;
        }
        return null;
    }
}

Test Class:

@isTest
public class documentctrTracker{
    
    static Folder objFolder;
    public String url;
    
    static testMethod void firstMethod() {
        
        loadData();
        
              
        documentctr ob1 = new documentctr();
        PageReference pageRef = ob1 .returnUrl();
        //ob1.returnUrl();
        
        
        ApexPages.currentPage().getParameters().put('doc','newFile');
        documentctr ob = new documentctr();
        ob.returnUrl();
    }
    
    static void loadData(){
    
        insertFolder();
        insertDocument();
    }
    
    static void insertFolder(){
        
        objFolder = [select id from Folder where Type = 'Document' limit 1];        
    }
    
    static void insertDocument(){  
        
        Document obj = new Document();
        obj.Name = 'newFile';
        obj.FolderId = objFolder.Id;
        insert obj;
        ApexPages.currentPage().getParameters().put('doc','newFile');
        ApexPages.Standardcontroller sc = new ApexPages.Standardcontroller(obj);
        documentctr ob1 = new documentctr();
        ob1.returnUrl();
    }
}
Source Link
Loading