I have a question, I'm making a test class for a batch. This batch deletes custom objects depending on the date (for example, the constructor receives an amount of days, and the batch deletes all those objects older than those days). Here is the class:
global with sharing class BatchApexDeleteQuestions implements Database.Batchable<sObject>, Database.Stateful{
private Integer cantidadDias;
private Integer cantidadMeses;
private Map<String,Integer> mapMeses;
global BatchApexDeleteQuestions(Integer cantidadDias){
this.cantidadDias = cantidadDias;
this.cantidadMeses = null;
}
global BatchApexDeleteQuestions(Map<String,Integer> mapMeses){
if(mapMeses != null && mapMeses.containsKey('QUESTIONS')){
this.cantidadMeses = mapMeses.get('QUESTIONS');
}else{
this.cantidadMeses = 0;
}
this.mapMeses = mapMeses;
this.cantidadDias = null;
}
global Database.QueryLocator start(Database.BatchableContext BC){
ERPvs.ApexLogger.Debug('>>> BATCH START');
Datetime dateLimit;
if(cantidadDias != null){
dateLimit = Datetime.now();
dateLimit = dateLimit.addDays((cantidadDias * -1));
}else if(cantidadMeses != null){
Date dateAux = Date.today();
dateAux = dateAux.addMonths(cantidadMeses * -1).toStartOfMonth();
dateLimit = Datetime.newInstance(dateAux.year(),dateAux.month(),dateAux.day());
}
return Database.getQueryLocator([SELECT Id FROM Question__c WHERE Question_Date__c <= :dateLimit]);
}
global void execute(Database.BatchableContext BC, List<Question__c> scope){
ERPvs.ApexLogger.Debug('>>> BATCH Execute');
delete scope;
DataBase.emptyRecycleBin(scope);
}
global void finish(Database.BatchableContext BC){
ERPvs.ApexLogger.Debug('>>> BATCH Finish');
if(mapMeses != null){
Database.executeBatch(new BatchApexDeleteItems(mapMeses), 200);
}
}
}
here is my simple test class:
@isTest
public class Test_BatchApexDeleteQuestions {
@TestSetup
static void setup(){
TestFactory instance = TestFactory.instance;
Question__c question1 = instance.create(new Question__c(
Question_Date__c = DateTime.now().addDays(-40)
));
Question__c question2 = instance.create(new Question__c(
Question_Date__c = DateTime.now().addDays(-50)
));
Question__c question3 = instance.create(new Question__c(
Question_Date__c = DateTime.now().addDays(-60)
));
instance.insertAllByDependencies();
}
static testmethod void main(){
BatchApexDeleteQuestions batch = new BatchApexDeleteQuestions(39);
Test.startTest();
Id batchId = Database.executeBatch(batch);
Test.stopTest();
}
}
My question is, if I run my test, will it delete only the questions I'm defining in my setup, or will it affect all the other questions that match the criteria?