From fd320e5d9e7f72c1c36049682c7b2a8248546074 Mon Sep 17 00:00:00 2001 From: Leo Horwitz Date: Wed, 26 Jul 2023 10:35:42 -0700 Subject: [PATCH] @W-13569669@: update tests to use 2d arrays --- .../SharingPolicyComplexInheritanceTest.java | 148 +++++++++--------- .../SharingPolicyInheritanceParentTest.java | 49 +++--- 2 files changed, 95 insertions(+), 102 deletions(-) diff --git a/sfge/src/test/java/com/salesforce/rules/usewithsharingondatabaseoperation/SharingPolicyComplexInheritanceTest.java b/sfge/src/test/java/com/salesforce/rules/usewithsharingondatabaseoperation/SharingPolicyComplexInheritanceTest.java index 641cc4a3f..b5dd5de1a 100644 --- a/sfge/src/test/java/com/salesforce/rules/usewithsharingondatabaseoperation/SharingPolicyComplexInheritanceTest.java +++ b/sfge/src/test/java/com/salesforce/rules/usewithsharingondatabaseoperation/SharingPolicyComplexInheritanceTest.java @@ -55,40 +55,39 @@ private static Stream provideNoViolationTests() { Stream.Builder sb = Stream.builder(); Stream databaseOperations = provideSelectDatabaseOperations(); - String[] noViolationSharingPolicyCombos = { + String[][] noViolationSharingPolicyCombos = { // when Two (center column) has "inherited sharing", the calling class (rightmost // column) must be "with sharing" or "inherited sharing" (entrypoint OK) - "with sharing , inherited sharing , inherited sharing ", - "without sharing , inherited sharing , inherited sharing ", - "inherited sharing , inherited sharing , inherited sharing ", - " , inherited sharing , inherited sharing ", - "with sharing , inherited sharing , with sharing ", - "without sharing , inherited sharing , with sharing ", - "inherited sharing , inherited sharing , with sharing ", - " , inherited sharing , with sharing ", + {"with sharing "," inherited sharing "," inherited sharing ",}, + {"without sharing "," inherited sharing "," inherited sharing ",}, + {"inherited sharing "," inherited sharing "," inherited sharing ",}, + {" "," inherited sharing "," inherited sharing ",}, + {"with sharing "," inherited sharing "," with sharing ",}, + {"without sharing "," inherited sharing "," with sharing ",}, + {"inherited sharing "," inherited sharing "," with sharing ",}, + {" "," inherited sharing "," with sharing ",}, // when Two (center column) has "with sharing," anything goes - "with sharing , with sharing , inherited sharing ", - "without sharing , with sharing , inherited sharing ", - "inherited sharing , with sharing , inherited sharing ", - " , with sharing , inherited sharing ", - "with sharing , with sharing , without sharing ", - "without sharing , with sharing , without sharing ", - "inherited sharing , with sharing , without sharing ", - " , with sharing , without sharing ", - "with sharing , with sharing , with sharing ", - "without sharing , with sharing , with sharing ", - "inherited sharing , with sharing , with sharing ", - " , with sharing , with sharing ", - "with sharing , with sharing , ", - "without sharing , with sharing , ", - "inherited sharing , with sharing , ", - " , with sharing , ", + {"with sharing "," with sharing "," inherited sharing ",}, + {"without sharing "," with sharing "," inherited sharing ",}, + {"inherited sharing "," with sharing "," inherited sharing ",}, + {" "," with sharing "," inherited sharing ",}, + {"with sharing "," with sharing "," without sharing ",}, + {"without sharing "," with sharing "," without sharing ",}, + {"inherited sharing "," with sharing "," without sharing ",}, + {" "," with sharing "," without sharing ",}, + {"with sharing "," with sharing "," with sharing ",}, + {"without sharing "," with sharing "," with sharing ",}, + {"inherited sharing "," with sharing "," with sharing ",}, + {" "," with sharing "," with sharing ",}, + {"with sharing "," with sharing "," ",}, + {"without sharing "," with sharing "," ",}, + {"inherited sharing "," with sharing "," ",}, + {" "," with sharing "," ",}, }; databaseOperations.forEach( operationArg -> { - for (String sharingPolicyCombo : noViolationSharingPolicyCombos) { - String[] policies = sharingPolicyCombo.split(","); + for (String[] policies : noViolationSharingPolicyCombos) { sb.add( Arguments.of( operationArg.get()[0], @@ -117,54 +116,53 @@ private static Stream provideViolationTests() { Stream.Builder sb = Stream.builder(); Stream databaseOperations = provideSelectDatabaseOperations(); - String[] violationSharingPolicyCombos = { + String[][] violationSharingPolicyCombos = { // when Two (center column) has no declaration, look to its parent, One (left column) - "without sharing , , inherited sharing ", - "without sharing , , without sharing ", - "without sharing , , with sharing ", - "without sharing , , ", + {"without sharing "," "," inherited sharing ",}, + {"without sharing "," "," without sharing ",}, + {"without sharing "," "," with sharing ",}, + {"without sharing "," "," ",}, // when Two (center) has no declaration and One (parent, left col) has "inherited // sharing", look to calling class (right col). running as "without" or omitted = // violation. - "inherited sharing , , without sharing ", - "inherited sharing , , ", + {"inherited sharing "," "," without sharing ",}, + {"inherited sharing "," "," ",}, // when neither Two nor One (center, left cols) have declarations, look to calling // class (right col). no declaration or without sharing means violation - " , , ", - " , , without sharing ", + {" "," "," ",}, + {" "," "," without sharing ",}, // when Two (center col) has "inherited sharing" and it inherits "without sharing" or no // declaration from its calling class (right col), this is a violation - "with sharing , inherited sharing , without sharing ", - "without sharing , inherited sharing , without sharing ", - "inherited sharing , inherited sharing , without sharing ", - " , inherited sharing , without sharing ", - "with sharing , inherited sharing , ", - "without sharing , inherited sharing , ", - "inherited sharing , inherited sharing , ", - " , inherited sharing , ", + {"with sharing "," inherited sharing "," without sharing ",}, + {"without sharing "," inherited sharing "," without sharing ",}, + {"inherited sharing "," inherited sharing "," without sharing ",}, + {" "," inherited sharing "," without sharing ",}, + {"with sharing "," inherited sharing "," ",}, + {"without sharing "," inherited sharing "," ",}, + {"inherited sharing "," inherited sharing "," ",}, + {" "," inherited sharing "," ",}, // when Two runs "without sharing", it's a violation no matter what - "with sharing , without sharing , inherited sharing ", - "without sharing , without sharing , inherited sharing ", - "inherited sharing , without sharing , inherited sharing ", - " , without sharing , inherited sharing ", - "with sharing , without sharing , without sharing ", - "without sharing , without sharing , without sharing ", - "inherited sharing , without sharing , without sharing ", - " , without sharing , without sharing ", - "with sharing , without sharing , with sharing ", - "without sharing , without sharing , with sharing ", - "inherited sharing , without sharing , with sharing ", - " , without sharing , with sharing ", - "with sharing , without sharing , ", - "without sharing , without sharing , ", - "inherited sharing , without sharing , ", - " , without sharing , ", + {"with sharing "," without sharing "," inherited sharing ",}, + {"without sharing "," without sharing "," inherited sharing ",}, + {"inherited sharing "," without sharing "," inherited sharing ",}, + {" "," without sharing "," inherited sharing ",}, + {"with sharing "," without sharing "," without sharing ",}, + {"without sharing "," without sharing "," without sharing ",}, + {"inherited sharing "," without sharing "," without sharing ",}, + {" "," without sharing "," without sharing ",}, + {"with sharing "," without sharing "," with sharing ",}, + {"without sharing "," without sharing "," with sharing ",}, + {"inherited sharing "," without sharing "," with sharing ",}, + {" "," without sharing "," with sharing ",}, + {"with sharing "," without sharing "," ",}, + {"without sharing "," without sharing "," ",}, + {"inherited sharing "," without sharing "," ",}, + {" "," without sharing "," ",}, }; databaseOperations.forEach( operationArg -> { - for (String sharingPolicyCombo : violationSharingPolicyCombos) { - String[] policies = sharingPolicyCombo.split(","); + for (String[] policies : violationSharingPolicyCombos) { sb.add( Arguments.of( operationArg.get()[0], @@ -196,25 +194,24 @@ private static Stream provideWarningParentTests() { Stream.Builder sb = Stream.builder(); Stream databaseOperations = provideSelectDatabaseOperations(); - String[] warningParentSharingPolicyCombos = { + String[][] warningParentSharingPolicyCombos = { // when Two (center col) has no declaration, but it inherits "with sharing" from One // (left col), it runs as "with sharing," but has a warning message of implicit // inheritance from its parent. - "with sharing , , inherited sharing ", - "with sharing , , without sharing ", - "with sharing , , with sharing ", - "with sharing , , ", + {"with sharing "," "," inherited sharing ",}, + {"with sharing "," "," without sharing ",}, + {"with sharing "," "," with sharing ",}, + {"with sharing "," "," ",}, // when Two (center col) has no declaration and One (left col) has "inherited sharing," // and the calling class (right col) has "with sharing" or "inherited sharing," it runs // as "with sharing," but has a warning message of implicit inheritance from its parent. - "inherited sharing , , with sharing ", - "inherited sharing , , inherited sharing ", + {"inherited sharing "," "," with sharing ",}, + {"inherited sharing "," "," inherited sharing ",}, }; databaseOperations.forEach( operationArg -> { - for (String sharingPolicyCombo : warningParentSharingPolicyCombos) { - String[] policies = sharingPolicyCombo.split(","); + for (String[] policies : warningParentSharingPolicyCombos) { sb.add( Arguments.of( operationArg.get()[0], @@ -246,18 +243,17 @@ private static Stream provideWarningCallingTests() { Stream.Builder sb = Stream.builder(); Stream databaseOperations = provideSelectDatabaseOperations(); - String[] warningCallingSharingPolicyCombos = { + String[][] warningCallingSharingPolicyCombos = { // When neither Two nor One (center, left cols) have explicit sharing policies, but they // inherit a safe sharing policy from the calling class (right col), it is safe to run, // but this needs a warning message about implicit inheritance from the calling class. - " , , inherited sharing ", - " , , with sharing ", + {" "," "," inherited sharing ",}, + {" "," "," with sharing ",}, }; databaseOperations.forEach( operationArg -> { - for (String sharingPolicyCombo : warningCallingSharingPolicyCombos) { - String[] policies = sharingPolicyCombo.split(","); + for (String[] policies : warningCallingSharingPolicyCombos) { sb.add( Arguments.of( operationArg.get()[0], diff --git a/sfge/src/test/java/com/salesforce/rules/usewithsharingondatabaseoperation/SharingPolicyInheritanceParentTest.java b/sfge/src/test/java/com/salesforce/rules/usewithsharingondatabaseoperation/SharingPolicyInheritanceParentTest.java index 5cb7bafcd..25bfdfe4d 100644 --- a/sfge/src/test/java/com/salesforce/rules/usewithsharingondatabaseoperation/SharingPolicyInheritanceParentTest.java +++ b/sfge/src/test/java/com/salesforce/rules/usewithsharingondatabaseoperation/SharingPolicyInheritanceParentTest.java @@ -42,25 +42,24 @@ private static Stream provideNoViolationTests() { Stream databaseOperations = provideSelectDatabaseOperations(); // spotless:off - String[] noViolationSharingPolicyCombos = { + String[][] noViolationSharingPolicyCombos = { // anything "inherited sharing" inherits from the calling class, overriding the parent (left column). // In this case, since MyClass is the entrypoint, it runs as "with sharing" (as noted in Apex documentation). - "with sharing , inherited sharing ", - "inherited sharing , inherited sharing ", - "without sharing , inherited sharing ", - " , inherited sharing ", - // anything "with sharing" overrides its parent to be safe. - "with sharing , with sharing ", - "without sharing , with sharing ", - "inherited sharing , with sharing ", - " , with sharing ", + {"with sharing "," inherited sharing ",}, + {"inherited sharing "," inherited sharing ",}, + {"without sharing "," inherited sharing ",}, + {" "," inherited sharing ",}, + // anything "with sharing" overrides its parent to be safe. + {"with sharing "," with sharing ",}, + {"without sharing "," with sharing ",}, + {"inherited sharing "," with sharing ",}, + {" "," with sharing ",}, }; // spotless:on databaseOperations.forEach( operationArg -> { - for (String sharingPolicyCombo : noViolationSharingPolicyCombos) { - String[] policies = sharingPolicyCombo.split(","); + for (String[] policies : noViolationSharingPolicyCombos) { sb.add( Arguments.of( operationArg.get()[0], @@ -87,20 +86,19 @@ private static Stream provideViolationTests() { Stream databaseOperations = provideSelectDatabaseOperations(); // spotless:off - String[] violationSharingPolicyCombos = { - "without sharing , ", - "with sharing , without sharing ", - "without sharing , without sharing ", - "inherited sharing , without sharing ", - " , without sharing ", - " , ", + String[][] violationSharingPolicyCombos = { + {"without sharing "," ",}, + {"with sharing "," without sharing ",}, + {"without sharing "," without sharing ",}, + {"inherited sharing "," without sharing ",}, + {" "," without sharing ",}, + {" "," ",}, }; // spotless:on databaseOperations.forEach( operationArg -> { - for (String sharingPolicyCombo : violationSharingPolicyCombos) { - String[] policies = sharingPolicyCombo.split(","); + for (String[] policies : violationSharingPolicyCombos) { sb.add( Arguments.of( operationArg.get()[0], @@ -130,16 +128,15 @@ private static Stream provideWarningParentTests() { Stream databaseOperations = provideSelectDatabaseOperations(); // spotless:off - String[] warningParentSharingPolicyCombos = { - "with sharing , ", - "inherited sharing , ", + String[][] warningParentSharingPolicyCombos = { + {"with sharing "," ",}, + {"inherited sharing "," ",}, }; // spotless:on databaseOperations.forEach( operationArg -> { - for (String sharingPolicyCombo : warningParentSharingPolicyCombos) { - String[] policies = sharingPolicyCombo.split(","); + for (String[] policies : warningParentSharingPolicyCombos) { sb.add( Arguments.of( operationArg.get()[0],