apex.lang.best-practice.ncino.tests.useassertclass.use-assert-class

profile photo of semgrepsemgrep
Author
unknown
Download Count*

Assert methods in the System class have been replaced with the Assert class: https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_System_Assert.htm

Run Locally

Run in CI

Defintion

rules:
  - id: use-assert-class
    min-version: 1.44.0
    severity: WARNING
    languages:
      - generic
    metadata:
      category: best-practice
      references:
        - https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_System_Assert.htm
      technology:
        - salesforce
      license: Commons Clause License Condition v1.0[LGPL-2.1-only]
    message: "Assert methods in the System class have been replaced with the Assert
      class:
      https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/ap\
      ex_class_System_Assert.htm"
    pattern-regex: System\.assert
    paths:
      include:
        - "*.cls"
        - UseAssertClass.cls

Examples

UseAssertClass.cls

public class UseAssertClass {
	// ruleid: use-assert-class
	System.assert(true);

	// ruleid: use-assert-class
	System.assertEquals(1,1);

	// ruleid: use-assert-class
	System.assertNotEquals(1,1);

	// ok: use-assert-class
	Assert.areEqual(1,1);
}