diff --git a/force-app/main/default/classes/AsyncTest.cls b/force-app/main/default/classes/AsyncTest.cls index 555fcf1..b284028 100644 --- a/force-app/main/default/classes/AsyncTest.cls +++ b/force-app/main/default/classes/AsyncTest.cls @@ -2,8 +2,12 @@ * PMD False Positives: * - ApexAssertionsShouldIncludeMessage: IMO not all assertions need a message * - EmptyStatementBlock: It is test class, some methods are just to create jobs placeholders + * - NcssTypeCount: It is a library and all of its tests live in ONE test class + * - NcssCount: It is a library and all of its tests live in ONE test class **/ -@SuppressWarnings('PMD.ApexAssertionsShouldIncludeMessage,PMD.EmptyStatementBlock') +@SuppressWarnings( + 'PMD.ApexAssertionsShouldIncludeMessage,PMD.EmptyStatementBlock,PMD.NcssTypeCount,PMD.NcssCount' +) @IsTest @TestVisible private class AsyncTest implements Database.Batchable { @@ -3178,14 +3182,8 @@ private class AsyncTest implements Database.Batchable { @IsTest private static void shouldDeleteOnlyOldNonFailedResultsWhenOnlyOthersRetentionIsSet() { - AsyncResult__c oldCompleted = insertAsyncResultWithAge( - QueueableManager.STATUS_COMPLETED, - 31 - ); - AsyncResult__c oldSkipped = insertAsyncResultWithAge( - QueueableManager.STATUS_SKIPPED_DEPENDENCY, - 31 - ); + insertAsyncResultWithAge(QueueableManager.STATUS_COMPLETED, 31); + insertAsyncResultWithAge(QueueableManager.STATUS_SKIPPED_DEPENDENCY, 31); AsyncResult__c veryOldFailed = insertAsyncResultWithAge( QueueableManager.STATUS_FAILED, 400 @@ -3214,18 +3212,12 @@ private class AsyncTest implements Database.Batchable { @IsTest private static void shouldApplySeparateRetentionCutoffsPerTrack() { - AsyncResult__c failedPastCutoff = insertAsyncResultWithAge( - QueueableManager.STATUS_FAILED, - 100 - ); + insertAsyncResultWithAge(QueueableManager.STATUS_FAILED, 100); AsyncResult__c failedWithinCutoff = insertAsyncResultWithAge( QueueableManager.STATUS_FAILED, 60 ); - AsyncResult__c completedPastCutoff = insertAsyncResultWithAge( - QueueableManager.STATUS_COMPLETED, - 60 - ); + insertAsyncResultWithAge(QueueableManager.STATUS_COMPLETED, 60); AsyncResult__c completedWithinCutoff = insertAsyncResultWithAge( QueueableManager.STATUS_COMPLETED, 10 @@ -4060,7 +4052,7 @@ private class AsyncTest implements Database.Batchable { @IsTest private static void shouldInjectQueueableMockIntoAChunkPage() { List accounts = createAccounts(2); - Id mockJobId = '707000000000001AAA'; + Id mockJobId = fakeId(AsyncApexJob.SObjectType, 1); AsyncMock.whenQueueable('chunk-page') .thenReturn(new AsyncMock.MockQueueableContext().setJobId(mockJobId)); @@ -4669,6 +4661,12 @@ private class AsyncTest implements Database.Batchable { return accounts; } + private static Id fakeId(Schema.SObjectType sObjectType, Integer index) { + String prefix = sObjectType.getDescribe(SObjectDescribeOptions.DEFERRED).getKeyPrefix(); + String suffix = String.valueOf(index); + return Id.valueOf(prefix + '0'.repeat(15 - prefix.length() - suffix.length()) + suffix); + } + private static List accountsWithOneFailingRecord() { List accounts = new List{ new Account(Name = 'ok first'), diff --git a/force-app/main/default/classes/queue/QueueableJob.cls b/force-app/main/default/classes/queue/QueueableJob.cls index aac91dd..6eafe08 100644 --- a/force-app/main/default/classes/queue/QueueableJob.cls +++ b/force-app/main/default/classes/queue/QueueableJob.cls @@ -226,7 +226,8 @@ public abstract class QueueableJob implements Queueable, Comparable { private String getFullClassName(Object job) { String result; try { - DateTime typeCheck = (DateTime) job; + // A failed cast is the only way to read the runtime type with its namespace + String.valueOf((DateTime) job); } catch (System.TypeException expectedTypeException) { String message = expectedTypeException.getMessage() .substringAfter('Invalid conversion from runtime type ');