Skip to content

Adding CustomAssert class#344

Merged
codefriar merged 1 commit intomainfrom
feat/addCustomAssert
Jun 8, 2025
Merged

Adding CustomAssert class#344
codefriar merged 1 commit intomainfrom
feat/addCustomAssert

Conversation

@codefriar
Copy link
Owner

@codefriar codefriar commented Jun 8, 2025

Adds CustomAssert Class

Summary by CodeRabbit

  • New Feature: Introduced the CustomAssert class, enhancing our testing capabilities. This class provides custom assertion methods for various use cases such as comparing datetimes with a leeway, checking string prefixes and suffixes, validating list contents and sizes, deserializing JSON strings, and handling exceptions. This will improve the robustness of our test suites and ensure more accurate results.

@github-actions
Copy link

github-actions bot commented Jun 8, 2025

Image description CodeRabbit

Walkthrough

This update introduces the CustomAssert class, a powerful utility for enhancing test assertions in Apex. It provides custom methods for various checks such as datetime comparisons, string prefix/suffix validations, list content and size verifications, JSON deserialization, and exception handling.

Changes

File Summary
force-app/main/default/classes/test utilities/CustomAssert.cls, force-app/main/default/classes/test utilities/CustomAssert.cls-meta.xml Added a new CustomAssert class with custom assertion methods for testing. The class is set to Active with API version 63.0.

🐇💻

In the land of code where the shadows lie,
A rabbit hops forth, its gaze held high.
With each line it pens, the bugs do flee,
For in its wake, only quality shall be.

A new class born, under the moon's soft glow,
CustomAssert, a name you should know.
It tests, it checks, it validates with glee,
Ensuring your code, as perfect as can be. 🌟


Uplevel your code reviews with CodeRabbit Pro

CodeRabbit Pro

If you like this project, please support us by purchasing the Pro version. The Pro version has advanced context, superior noise reduction and several proprietary improvements compared to the open source version. Moreover, CodeRabbit Pro is free for open source projects.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Image description CodeRabbit

Commits Files that changed from the base of the PR and between 6fb568c and fdac5ff commits.
Files selected (2)
  • force-app/main/default/classes/test utilities/CustomAssert.cls (1)
  • force-app/main/default/classes/test utilities/CustomAssert.cls-meta.xml (1)
Files skipped from review due to trivial changes (1)
  • force-app/main/default/classes/test utilities/CustomAssert.cls-meta.xml
Review comments generated (17)
  • Review: 2
  • LGTM: 15

Tips

Chat with Image description CodeRabbit Bot (@coderabbitai)

  • Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
  • Invite the bot into a review comment chain by tagging @coderabbitai in a reply.

Code suggestions

  • The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
  • You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.

Pausing incremental reviews

  • Add @coderabbitai: ignore anywhere in the PR description to pause further reviews from the bot.

Comment on lines +77 to +95

/**
* @description An assertion that validates a list contains at least one of the items in the other list passed in
* @param listToCheck List<Object> the list to check
* @param listToCheckAgainst List<Object> the list to check against
* @param msg String the message to display if the assertion fails
*/
public static void contains(
List<Object> listToCheck,
List<Object> listToCheckAgainst,
String msg
) {
contains(
new Set<Object>(listToCheck),
new Set<Object>(listToCheckAgainst),
msg
);
System.Assert.fail(msg);
}
Copy link

Choose a reason for hiding this comment

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

Image description CodeRabbit

There seems to be an issue with the contains method. The System.Assert.fail(msg); on line 94 will always be executed, causing the test to fail every time this method is called, regardless of whether the condition in the contains method on line 89-93 is met or not. This line should be removed.

- System.Assert.fail(msg);

Comment on lines +96 to +112

/**
* @description 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.
* @param listToCheck List<Object> to check for containing at least one item from the set
* @param setToCheckAgainst Set<Object> the set of items to check for in the list
* @param msg String the message to display if the assertion fails
*/
public static void contains(
List<Object> listToCheck,
Set<Object> setToCheckAgainst,
String msg
) {
Set<Object> listSet = new Set<Object>(listToCheck);
contains(setToCheckAgainst, listSet, msg);
System.Assert.fail(msg);
}
Copy link

Choose a reason for hiding this comment

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

Image description CodeRabbit

Similar to the previous comment, there's a misplaced System.Assert.fail(msg); on line 111 which will cause the test to fail every time this method is called. This line should be removed.

- System.Assert.fail(msg);

@codefriar codefriar merged commit 1e34e3f into main Jun 8, 2025
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant