Skip to content

Instantly share code, notes, and snippets.

@dcarroll
Created March 17, 2014 22:47
Show Gist options
  • Save dcarroll/9609978 to your computer and use it in GitHub Desktop.
Save dcarroll/9609978 to your computer and use it in GitHub Desktop.
@isTest
private class TestCleanUpBatchClass {
static testmethod void test() {
// The query used by the batch job.
String query = 'SELECT Id,CreatedDate FROM Merchandise__c ' +
'WHERE Id NOT IN (SELECT Merchandise__c FROM Line_Item__c)';
// Create some test merchandise items to be deleted by the batch job.
Warehouse__c w = new Warehouse__c(
Name='Warehouse 1',
City__c='San Francisco',
Location__Latitude__s=37.7833,
Location__Longitude__s=122.4167);
insert w;
Merchandise__c[] ml = new List<Merchandise__c>();
for (Integer i=0;i<10;i++) {
Merchandise__c m = new Merchandise__c(
Name='Merchandise ' + i,
Price__c=2,
Quantity__c=100,
Warehouse__c = w.Id);
ml.add(m);
}
insert ml;
Test.startTest();
CleanUpRecords c = new CleanUpRecords(query);
Database.executeBatch(c);
Test.stopTest();
// Verify merchandise items got deleted
Integer i = [SELECT COUNT() FROM Merchandise__c];
System.assertEquals(i, 0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment