Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/custom assertions #110

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/project-scratch-def.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"orgName": "ApexKit Company",
"description": "ApexKitV2.5",
"edition": "Developer",

"hasSampleData": true,
"features": [
"EinsteinGPTForDevelopers",
Expand Down
204 changes: 204 additions & 0 deletions docs/CAssert.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
`APIVERSION: 58`

`STATUS: ACTIVE`

## Methods

### `public static void areEqual(Datetime expectedDatetime, Datetime actualDatetime, Integer timeVarianceSeconds, String msg)`

`SUPPRESSWARNINGS`

Assertion method to validate that two Datetime objects are equal within a given leeway

#### Parameters

| Param | Description |
| --------------------- | ------------------------------------------------------ |
| `expectedDatetime` | Datetime - the expected Datetime |
| `actualDatetime` | Datetime - the actual Datetime |
| `timeVarianceSeconds` | Integer - the number of seconds of leeway to allow |
| `msg` | String - the message to display if the assertion fails |

### `public static void startsWith(String str, String prefix, String msg)`

Assertion method to validate that a string starts with the given string

#### Parameters

| Param | Description |
| -------- | ------------------------------------------------------ |
| `str` | String - the string to validate |
| `prefix` | String - the prefix the string must start with |
| `msg` | String - the message to display if the assertion fails |

### `public static void startsWithIgnoreCase(String str, String prefix, String msg)`

Assertion method to validate that a string starts with the given string (case insensitive)

#### Parameters

| Param | Description |
| -------- | ----------------------------------------------------------------- |
| `str` | String - the string to validate |
| `prefix` | String - the prefix the string must start with (case insensitive) |
| `msg` | String - the message to display if the assertion fails |

### `public static void endsWith(String str, String suffix, String msg)`

Assertion method to validate that a string ends with the given string

#### Parameters

| Param | Description |
| -------- | ------------------------------------------------------ |
| `str` | String - the string to validate |
| `suffix` | String - the suffix the string must end with |
| `msg` | String - the message to display if the assertion fails |

### `public static void endsWithIgnoreCase(String str, String suffix, String msg)`

Assertion method to validate that a string ends with the given string (case insensitive)

#### Parameters

| Param | Description |
| -------- | ------------------------------------------------------ |
| `str` | String - the string to validate (case insensitive) |
| `suffix` | String - the suffix the string must end with |
| `msg` | String - the message to display if the assertion fails |

### `public static void contains(List<Object> listToCheck, List<Object> listToCheckAgainst, String msg)`

An assertion that validates a list contains at least one of the items in the other list passed in

#### Parameters

| Param | Description |
| -------------------- | ---------------------------------------------------- |
| `listToCheck` | List<Object> the list to check |
| `listToCheckAgainst` | List<Object> the list to check against |
| `msg` | String the message to display if the assertion fails |

### `public static void contains(List<Object> listToCheck, Set<Object> setToCheckAgainst, String msg)`

An assertion that validates the passed in list contains at least one of the items in the set. Ultimately defers to the contains assertion below comparing two sets.

#### Parameters

| Param | Description |
| ------------------- | ------------------------------------------------------------------- |
| `listToCheck` | List<Object> to check for containing at least one item from the set |
| `setToCheckAgainst` | Set<Object> the set of items to check for in the list |
| `msg` | String the message to display if the assertion fails |

### `public static void contains(Set<Object> setToCheck, Set<Object> setToCheckAgainst, String msg)`

Checks to see if a set contains any of the items in another set.

#### Parameters

| Param | Description |
| ------------------- | ---------------------------------------------------- |
| `setToCheck` | Set<Object> the set to check |
| `setToCheckAgainst` | Set<Object> the set to check against |
| `msg` | String the message to display if the assertion fails |

### `public static void isNotJanky(String msg)`

Look, this is a quasi inside joke method. If you have to ask if it's janky, it is. For more information, ask

#### Parameters

| Param | Description |
| ----- | ---------------------------------------------------- |
| `msg` | String the message you want in your failure response |

**JeffKrantz** over on SFDC Discord.

### `public static void listMeetsMinimumSize(List<Object> collection, Integer minSize, String msg)`

An assertion that validates a list is at least a certain size

#### Parameters

| Param | Description |
| ------------ | ------------------------------------------------------ |
| `collection` | List<Object> - the list to validate |
| `minSize` | Integer - the minimum size the list must be |
| `msg` | String - the message to display if the assertion fails |

### `public static void stringIsDeserializableAsUntypedJson(String jsonString, String msg)`

An assertion that validates a string is deserializable to untyped JSON

#### Parameters

| Param | Description |
| ------------ | ------------------------------------------------------ |
| `jsonString` | String - the string to validate |
| `msg` | String - the message to display if the assertion fails |

### `public static void isSObject(Object obj, String msg)`

An assertion to validate that the object is an SObject

#### Parameters

| Param | Description |
| ----- | ------------------------------------------------------ |
| `obj` | Object - the object to validate |
| `msg` | String - the message to display if the assertion fails |

### `public static void caughtExpectedException(Exception incomingException, Type expectedExceptionType, String msg)`

An assertion to validate that the exception is of the expected type

#### Parameters

| Param | Description |
| ----------------------- | ------------------------------------------------------ |
| `incomingException` | Exception - the exception to validate |
| `expectedExceptionType` | Type - the expected type of the exception |
| `msg` | String - the message to display if the assertion fails |

### `public static void caughtExpectedException(Exception incomingException, Type expectedExceptionType, String expectedExceptionMessage, String msg)`

An assertion to validate that the exception is of the expected type and contains the expected message

#### Parameters

| Param | Description |
| -------------------------- | -------------------------------------------------------------------- |
| `incomingException` | Exception - the exception to validate |
| `expectedExceptionType` | Type - the expected type of the exception |
| `expectedExceptionMessage` | String - A string that must exist in the resulting exception message |
| `msg` | String - the message to display if the assertion fails |

### `public static void isInRange(Integer value, Integer min, Integer max, String msg)`

An assertion that validates the given value is within a given range

#### Parameters

| Param | Description |
| ------- | ------------------------------------------------------ |
| `value` | Integer - the value to validate |
| `min` | Integer - the minimum value the value must be |
| `max` | Integer - the maximum value the value must be |
| `msg` | String - the message to display if the assertion fails |

### `public static void logsWereGenerated(String msg)`

An Assertion that validates that LogEvent\_\_c records were generated. Note: this relies on the Log class that's part of ApexKit

#### Parameters

| Param | Description |
| ----- | ------------------------------------------------------ |
| `msg` | String - the message to display if the assertion fails |

### `public static void logsWereGenerated()`

An assertion that validates that LogEvent\_\_c records were generated. Note this relies on the Log class that's part of ApexKit. This method override accepts no parameters but delegates to the variant above by specifying a default message.

---
2 changes: 2 additions & 0 deletions docs/home.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ AsyncRestApi calls

Provides a similar interface to Callable, but bulkified to handle multiple sets of parameters.

### [CAssert](https://github.com/codefriar/ApexKit/wiki/Miscellaneous/CAssert)

Comment on lines +14 to +15

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

The new CAssert class is mentioned in the documentation, but there's no description provided for it. It would be helpful to include a brief explanation of what this class does and how it can be used.

### [CAssert](https://github.com/codefriar/ApexKit/wiki/Miscellaneous/CAssert)
+ A 'shadow' Assert class that facilitates developers adding custom assertion methods that can still be cleanly read as `Assert.methodName`.

 ### [CachePartitionType](https://github.com/codefriar/ApexKit/wiki/Miscellaneous/CachePartitionType)

### [CachePartitionType](https://github.com/codefriar/ApexKit/wiki/Miscellaneous/CachePartitionType)

Enum for partition type.
Expand Down
Loading