I am trying to finish up this test class, with the issue listed above. The Class I am testing is as follows:
public with sharing class CircularProgressController {
/**
* This class is used to return as JSON Object
**/
class WrapperJSON{
public Integer total {get;set;}
public Integer actual {get;set;}
public Integer val {get;set;}
}
@AuraEnabled
public static String computePercentage(String sObjectName, String recordId, String totalValueFieldName, String actualValueFieldName){
Integer retVal = 0 ;
String query = null;
WrapperJSON retObj = new WrapperJSON();
if(totalValueFieldName != null && totalValueFieldName.trim() != '' && actualValueFieldName != null && actualValueFieldName.trim() != '' ){
query = 'SELECT '+totalValueFieldName+', '+actualValueFieldName+' FROM '+sObjectName+' WHERE Id =: recordId';
}
else if (actualValueFieldName != null && actualValueFieldName.trim() != '' ) {
query = 'SELECT '+actualValueFieldName+' FROM '+sObjectName+' WHERE Id =: recordId';
}
if(query != null){
try{
List<SOBject> lstObj = Database.query(query);
if(lstObj.size() > 0){
Decimal totalVal = 0;
Decimal actualVal = 0;
if(totalValueFieldName != null && totalValueFieldName.trim() != ''){
totalVal = Decimal.valueOf(String.valueOf(lstObj[0].get(totalValueFieldName)));
retObj.total = Integer.valueOf(totalVal) ;
}
actualVal = Decimal.valueOf(String.valueOf(lstObj[0].get(actualValueFieldName)));
//Means only 1 API Name was supplied and field type is percentage
if(totalVal == 0){
retObj.val = Integer.valueOf(actualVal) ;
retObj.actual = Integer.valueOf(actualVal) ;
}else if (actualVal > 0){
retObj.val = Integer.valueOf( ( actualVal / totalVal ) * 100 );
retObj.actual = Integer.valueOf(actualVal) ;
}
}
}catch(Exception e){}
}
return JSON.serialize(retObj) ;
}
}
The test class I have is
@IsTest
public class circularProgressControllerTest {
private static testMethod void runTest()
{
Account acc = new Account(Name = 'Account Test', Type = 'Customer');
insert acc;
Case a = new Case(Subject = 'Account Tester', Status='New', Origin='Email', AccountId = acc.Id);
insert a;
a = [select id, Status from Case where id =:a.Id];
a.Status = 'Open';
update a;
a = [select id, First_Response_Time_Minutes_hidden__c, SLA_HI__c from Case where id =:a.Id];
CircularProgressController JsonString = new CircularProgressController(a, a.Id, a.SLA_HI__c, a.First_Response_Time_Minutes_hidden__c);
//String JsonString = CircularProgressController.computePercentage();
Map<String, Object> meta = (Map<String, Object>) JSON.deserializeUntyped(JsonString);
List<Map<String, String>> myMaps = (List<Map<String, String>>) meta.get('results');
Test.startTest();
System.assertNotEquals(null, myMaps.Val);
Test.stopTest();
}
}
And again, the error I am receiving is Result: [OPERATION FAILED]: classes/CircularProgressControllerTest.cls: Constructor not defined: [CircularProgressController].<Constructor>(Case, Id, Decimal, Decimal) (Line: 15, Column: 45)