org.sonar.squidbridge.checks.CheckMessagesVerifier Java Examples

The following examples show how to use org.sonar.squidbridge.checks.CheckMessagesVerifier. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LineLengthCheckTest.java    From sonar-lua with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void test() {
	LineLengthCheck check = new LineLengthCheck();
	check.maximumLineLength = 80;

	SourceFile file = LuaAstScanner.scanSingleFile(new File(
			"src/test/resources/checks/lineLength.lua"), check);
	CheckMessagesVerifier
			.verify(file.getCheckMessages())
			
			
			.next().atLine(5).withMessage("Split this 94 characters long line (which is greater than 80 authorized).")
			.next().atLine(29).withMessage("Split this 99 characters long line (which is greater than 80 authorized).")
			 .next().atLine(30).withMessage("Split this 99 characters long line (which is greater than 80 authorized).")
			.noMore();
}
 
Example #2
Source File: DeeplyNestedIfStmtsCheckTest.java    From enforce-sonarqube-plugin with MIT License 6 votes vote down vote up
/**
 * Exceeds if-then limit of 3 four times.
 * @throws Exception
 */
@Test
public void testMessyIfElse() throws Exception{
	sourceFile = scanFile(new File("src/test/resources/checks/messyIfElse.cls"), check);
	CheckMessagesVerifier.verify(sourceFile.getCheckMessages())
	.next().atLine(7).withMessage("Avoid creating deeply nested if-then statements since they are harder to read and error-prone to maintain, limit to "+check.DEFAULT_IF_DEPTH+".")
	.next().atLine(11).withMessage("Avoid creating deeply nested if-then statements since they are harder to read and error-prone to maintain, limit to "+check.DEFAULT_IF_DEPTH+".")
	.next().atLine(15).withMessage("Avoid creating deeply nested if-then statements since they are harder to read and error-prone to maintain, limit to "+check.DEFAULT_IF_DEPTH+".")
	.next().atLine(17).withMessage("Avoid creating deeply nested if-then statements since they are harder to read and error-prone to maintain, limit to "+check.DEFAULT_IF_DEPTH+".")
	.next().atLine(28).withMessage("Avoid creating deeply nested if-then statements since they are harder to read and error-prone to maintain, limit to "+check.DEFAULT_IF_DEPTH+".")
	.next().atLine(32).withMessage("Avoid creating deeply nested if-then statements since they are harder to read and error-prone to maintain, limit to "+check.DEFAULT_IF_DEPTH+".")
	.next().atLine(36).withMessage("Avoid creating deeply nested if-then statements since they are harder to read and error-prone to maintain, limit to "+check.DEFAULT_IF_DEPTH+".")
	.next().atLine(38).withMessage("Avoid creating deeply nested if-then statements since they are harder to read and error-prone to maintain, limit to "+check.DEFAULT_IF_DEPTH+".")
	.next().atLine(45).withMessage("Avoid creating deeply nested if-then statements since they are harder to read and error-prone to maintain, limit to "+check.DEFAULT_IF_DEPTH+".")
	.noMore();
}
 
Example #3
Source File: DeprecatedMethodCheckTest.java    From enforce-sonarqube-plugin with MIT License 5 votes vote down vote up
@Test
public void testIncorrectDMLDeclarationCorrect() throws Exception {
    deprecatedMethodCheck = new DeprecatedMethodCheck();
    sourceFile = scanFile(new File("src/test/resources/checks/clazzCorrect.cls"), deprecatedMethodCheck);
    CheckMessagesVerifier.verify(sourceFile.getCheckMessages())
            .noMore();
}
 
Example #4
Source File: XPathCheckTest.java    From sonar-lua with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void parseError() {
  check.xpathQuery = "//STATEMENT";

  SourceFile file = LuaAstScanner.scanSingleFile(new File("src/test/resources/checks/xPath.lua"), check);
  CheckMessagesVerifier.verify(file.getCheckMessages())
  .next().atLine(2).withMessage("The XPath expression matches this piece of code")
  .next().atLine(3).withMessage("The XPath expression matches this piece of code")
  .next().atLine(4).withMessage("The XPath expression matches this piece of code")
   .noMore();
}
 
Example #5
Source File: LocalFunctionComplexityCheckTest.java    From sonar-lua with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void test() {
 LocalFunctionComplexityCheck check = new LocalFunctionComplexityCheck();
  check.setMaximumFunctionComplexityThreshold(0);

  SourceFile file = LuaAstScanner.scanSingleFile(new File("src/test/resources/checks/localFunctionComplexity.lua"), check);

  CheckMessagesVerifier.verify(file.getCheckMessages())

     .next().atLine(1).withMessage("LocalFunction has a complexity of 6 which is greater than 0 authorized.") 
        .next().atLine(2).withMessage("LocalFunction has a complexity of 3 which is greater than 0 authorized.")
     
      .noMore();
}
 
Example #6
Source File: LocalFunctionNameCheckTest.java    From sonar-lua with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void defaultFormat() {
  SourceFile file = LuaAstScanner.scanSingleFile(new File("src/test/resources/checks/localFunctionName.lua"), check);
  CheckMessagesVerifier.verify(file.getCheckMessages())

 //.next().atLine(1).withMessage("Rename this \"SOMETHING\" function to match the regular expression " + check.format)
  .next().atLine(1).withMessage("Rename this \"_Test\" function to match the regular expression " + check.format)
 // .next().atLine(13).withMessage("Rename this \"d_Test\" function to match the regular expression " + check.format)
  .noMore();
}
 
Example #7
Source File: LocalFunctionNameCheckTest.java    From sonar-lua with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void custom() {
  check.format = "^[a-z][a-z_A-Z0-9]*$";
 


  SourceFile file = LuaAstScanner.scanSingleFile(new File("src/test/resources/checks/localFunctionName.lua"), check);
  CheckMessagesVerifier.verify(file.getCheckMessages())
  //.next().atLine(1).withMessage("Rename this \"SOMETHING\" function to match the regular expression " + check.format)
    .next().atLine(1).withMessage("Rename this \"_Test\" function to match the regular expression " + check.format)
   // .next().atLine(13).withMessage("Rename this \"d_Test\" function to match the regular expression " + check.format)
    .noMore();
}
 
Example #8
Source File: TooManyLinesInFileCheckTest.java    From sonar-lua with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void test_positive() {
 TooManyLinesInFileCheck check = new TooManyLinesInFileCheck();
   check.maximum = 2;
  SourceFile file = LuaAstScanner.scanSingleFile(new File("src/test/resources/checks/tooManyLinesInFile.lua"), check);
  CheckMessagesVerifier.verify(file.getCheckMessages())
    .next().withMessage(
      "File \"tooManyLinesInFile.lua\" has 5 lines, which is greater than 2 authorized. Split it into smaller files.")
    .noMore();
}
 
Example #9
Source File: TableWithTooManyFieldsCheckTest.java    From sonar-lua with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void defaults() {
  SourceFile file = LuaAstScanner.scanSingleFile(new File("src/test/resources/checks/tableWithTooManyFields.lua"), check);
  CheckMessagesVerifier.verify(file.getCheckMessages())
    .next().atLine(1).withMessage("This table has 6 fields, which is greater than the 5 authorized.")
   
    .noMore();
}
 
Example #10
Source File: FunctionNameCheckTest.java    From sonar-lua with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void custom() {
  check.format = "^[A-Z][a-zA-Z0-9]*$";
  SourceFile file = LuaAstScanner.scanSingleFile(new File("src/test/resources/checks/functionName.lua"), check);
  CheckMessagesVerifier.verify(file.getCheckMessages())
    .next().atLine(1).withMessage("Rename this \"add\" function to match the regular expression " + check.format)
    .next().atLine(10).withMessage("Rename this \"_sara\" function to match the regular expression " + check.format)
    .next().atLine(15).withMessage("Rename this \"d_Test\" function to match the regular expression " + check.format)
    .noMore();
}
 
Example #11
Source File: FunctionNameCheckTest.java    From sonar-lua with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void defaultFormat() {
  SourceFile file = LuaAstScanner.scanSingleFile(new File("src/test/resources/checks/functionName.lua"), check);
  CheckMessagesVerifier.verify(file.getCheckMessages())

  .next().atLine(6).withMessage("Rename this \"Add\" function to match the regular expression " + check.format)
  .next().atLine(10).withMessage("Rename this \"_sara\" function to match the regular expression " + check.format)
  .next().atLine(15).withMessage("Rename this \"d_Test\" function to match the regular expression " + check.format)
  .noMore();
}
 
Example #12
Source File: MethodComplexityCheckTest.java    From sonar-lua with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void test() {
  MethodComplexityCheck check = new MethodComplexityCheck();
  check.setMaximumFunctionComplexityThreshold(0);

  SourceFile file = LuaAstScanner.scanSingleFile(new File("src/test/resources/checks/methodComplexity.lua"), check);

  CheckMessagesVerifier.verify(file.getCheckMessages())
     .next().atLine(1).withMessage("Method has a complexity of 6 which is greater than 0 authorized.")
      .next().atLine(3).withMessage("Method has a complexity of 2 which is greater than 0 authorized.") 
        .next().atLine(4).withMessage("Method has a complexity of 1 which is greater than 0 authorized.")
     .next().atLine(11).withMessage("Method has a complexity of 1 which is greater than 0 authorized.")

      .noMore();
}
 
Example #13
Source File: XPathCheckTest.java    From sonar-lua with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void check() {
  check.xpathQuery = "//STATEMENT";
  check.message = "Avoid statements :)";

  SourceFile file = LuaAstScanner.scanSingleFile(new File("src/test/resources/checks/xPath.lua"), check);
  CheckMessagesVerifier.verify(file.getCheckMessages())
      .next().atLine(2).withMessage("Avoid statements :)")
      .next().atLine(3).withMessage("Avoid statements :)")
      .next().atLine(4).withMessage("Avoid statements :)")
      .noMore();
}
 
Example #14
Source File: DmlInWhileCheckTest.java    From enforce-sonarqube-plugin with MIT License 5 votes vote down vote up
@Test
public void testIncorrectDMLDeclarationIncorrectInsert() throws Exception {
    dmlCheckInWhile = new DmlInWhileCheck();
    sourceFile = scanFile(new File("src/test/resources/checks/clazzError.cls"), dmlCheckInWhile);
    CheckMessagesVerifier.verify(sourceFile.getCheckMessages()).
            next().atLine(4).withMessage(
            "The DML statement \"insert\", can not be inside a while loop.");
}
 
Example #15
Source File: DmlInWhileCheckTest.java    From enforce-sonarqube-plugin with MIT License 5 votes vote down vote up
@Test
public void testIncorrectDMLDeclarationCorrect() throws Exception {
    dmlCheckInWhile = new DmlInWhileCheck();
    sourceFile = scanFile(new File("src/test/resources/checks/clazzCorrect.cls"), dmlCheckInWhile);
    CheckMessagesVerifier.verify(sourceFile.getCheckMessages())
            .noMore();
}
 
Example #16
Source File: DmlInConstructorCheckTest.java    From enforce-sonarqube-plugin with MIT License 5 votes vote down vote up
@Test
public void testIncorrectDMLDeclarationCorrect() throws Exception {
    dmlCheckInConstructor = new DmlInConstructorCheck();
    sourceFile = scanFile(new File("src/test/resources/checks/clazzCorrect.cls"), dmlCheckInConstructor);
    CheckMessagesVerifier.verify(sourceFile.getCheckMessages())
            .noMore();
}
 
Example #17
Source File: ErrorRecoveryCheckTest.java    From enforce-sonarqube-plugin with MIT License 5 votes vote down vote up
@Test
public void testFileWithErrors() {
    sourceFile = scanFile(new File("src/test/resources/checks/recoveryClass.cls"), check);
    Assert.assertFalse(sourceFile.getCheckMessages().isEmpty());
    CheckMessagesVerifier.verify(sourceFile.getCheckMessages())
            .next().atLine(8).withMessage("Parsing error found, the block was skipped during the analysis.")
            .next().atLine(16).withMessage("Parsing error found, the block was skipped during the analysis.")
            .noMore();
}
 
Example #18
Source File: ClassNameCheckTest.java    From enforce-sonarqube-plugin with MIT License 5 votes vote down vote up
@Test
public void testErrorClassName() throws Exception {
    classNameCheck = new ClassNameCheck();
    sourceFile = scanFile(new File("src/test/resources/checks/clazzError.cls"), classNameCheck);
    CheckMessagesVerifier.verify(sourceFile.getCheckMessages())
            .next().atLine(1).withMessage(
            "Rename class \"someDraftArticle\" to match the regular expression ^[A-Z_][a-zA-Z0-9]+$.");
}
 
Example #19
Source File: ClassNameCheckTest.java    From enforce-sonarqube-plugin with MIT License 5 votes vote down vote up
@Test
public void testCorrectClassName_() throws Exception {
    classNameCheck = new ClassNameCheck();
    sourceFile = scanFile(new File("src/test/resources/checks/clazzCorrect_.cls"), classNameCheck);
    CheckMessagesVerifier.verify(sourceFile.getCheckMessages())
            .noMore();
}
 
Example #20
Source File: ClassNameCheckTest.java    From enforce-sonarqube-plugin with MIT License 5 votes vote down vote up
@Test
public void testCorrectClassName() throws Exception {
    classNameCheck = new ClassNameCheck();
    sourceFile = scanFile(new File("src/test/resources/checks/clazzCorrect.cls"), classNameCheck);
    CheckMessagesVerifier.verify(sourceFile.getCheckMessages())
            .noMore();
}
 
Example #21
Source File: AsyncMethodsCheckTest.java    From enforce-sonarqube-plugin with MIT License 5 votes vote down vote up
@Test
public void testAsyncMethodCheck() throws Exception {
    asyncMethodCheck = new AsyncMethodsCheck();
    sourceFile = scanFile(new File("src/test/resources/checks/asyncMethodTestClass.cls"), asyncMethodCheck);
    CheckMessagesVerifier.verify(sourceFile.getCheckMessages())
            .next().atLine(11).withMessage(
            "Method \"execAsyncMethod\" is Async, should not be called within a loop.")
            .next().atLine(17).withMessage(
            "Method \"execAsyncMethod\" is Async, should not be called within a loop.")
            .next().atLine(22).withMessage(
            "Method \"execAnotherAsyncMethod\" is Async, should not be called within a loop.")
            .next().atLine(25).withMessage(
            "Method \"execAnotherAsyncMethod\" is Async, should not be called within a loop.")
            .noMore();
}
 
Example #22
Source File: MethodNameAsClassNameCheckTest.java    From enforce-sonarqube-plugin with MIT License 5 votes vote down vote up
@Test
public void testErrorMethodName() throws Exception {
	methodNameAsClassNameCheck = new MethodNameAsClassNameCheck();
    sourceFile = scanFile(new File("src/test/resources/checks/MethodNameAsClassNameCheckErrorClass.cls"), methodNameAsClassNameCheck);
    CheckMessagesVerifier.verify(sourceFile.getCheckMessages())
            .next().atLine(17).withMessage( "Non-constructor methods should not have the same name as the enclosing class.")
            .next().atLine(29).withMessage( "Non-constructor methods should not have the same name as the enclosing class.");
}
 
Example #23
Source File: TableComplexityCheckTest.java    From sonar-lua with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void test() {
  TableComplexityCheck check = new TableComplexityCheck();
  check.setMaximumTableComplexityThreshold(0);

  SourceFile file = LuaAstScanner.scanSingleFile(new File("src/test/resources/checks/tableComplexity.lua"), check);

  CheckMessagesVerifier.verify(file.getCheckMessages())
     .next().atLine(1).withMessage("Table has a complexity of 1 which is greater than 0 authorized.")
     
      .noMore();
}
 
Example #24
Source File: TestAssertionsAndTestMethodKeywordCheckTest.java    From enforce-sonarqube-plugin with MIT License 5 votes vote down vote up
@Test
public void testTestShouldHaveAssertions() {
    File file = new File("src/test/resources/checks/testsClassAssertions.cls");
    SourceFile sourceFile = ApexAstScanner.scanFile(file, check);
    CheckMessagesVerifier.verify(sourceFile.getCheckMessages())
            .next()
            .atLine(7)
            .withMessage("Test method \"testSampleMethod\" should have at least one assertion.")
            .next()
            .atLine(58)
            .withMessage("Test method \"testNoKeywordWithAssertionLogic\" must have \"testMethod\" keyword.")
            .noMore();
}
 
Example #25
Source File: MethodLengthCheckTest.java    From enforce-sonarqube-plugin with MIT License 5 votes vote down vote up
@Test
public void testErrorMethodLength() throws Exception {
	methodLengthCheck = new MethodLengthCheck();
    sourceFile = scanFile(new File("src/test/resources/checks/ClassLengthError.cls"), methodLengthCheck);
    CheckMessagesVerifier chkMsgVerify = CheckMessagesVerifier.verify(sourceFile.getCheckMessages());
    
    chkMsgVerify.next().withMessage("The maximum number of statements in method is: "+ methodLengthCheck.DEFAULT_METHOD_LENGTH+".");
    
}
 
Example #26
Source File: MethodLengthCheckTest.java    From enforce-sonarqube-plugin with MIT License 5 votes vote down vote up
@Test
public void testCorrectMethodLength() throws Exception {
	methodLengthCheck = new MethodLengthCheck();
    sourceFile = scanFile(new File("src/test/resources/checks/clazzCorrect.cls"), methodLengthCheck);
    CheckMessagesVerifier.verify(sourceFile.getCheckMessages())
            .noMore();
}
 
Example #27
Source File: HardcodingIdsCheckTest.java    From enforce-sonarqube-plugin with MIT License 5 votes vote down vote up
@Test
public void testHardcodedIdsInMethodsAndConstructors() {
    String filePath = "src/test/resources/checks/hardcodingIdsInMethodsAndConstructors.cls";
    scanFilesWithCheck(filePath, new HardcodingIdsInMethodsAndConstructorsCheck());

    CheckMessagesVerifier.verify(sourceFile.getCheckMessages())
            .next().atLine(4).withMessage(FIRST_EXPRESSION_ERROR_MESSAGE)
            .next().atLine(15).withMessage(SECOND_EXPRESSION_ERROR_MESSAGE)
            .noMore();
}
 
Example #28
Source File: HardcodingIdsCheckTest.java    From enforce-sonarqube-plugin with MIT License 5 votes vote down vote up
@Test
public void testHardcodedIdsInVariables() {
    String filePath = "src/test/resources/checks/hardcodedIdsInVariables.cls";
    scanFilesWithCheck(filePath, new HardcodingIdsCheckInVariables());

    CheckMessagesVerifier.verify(sourceFile.getCheckMessages())
            .next().atLine(3).withMessage(FIRST_VARIABLE_ERROR)
            .next().atLine(10).withMessage(SECOND_VARIABLE_ERROR)
            .next().atLine(12).withMessage(THIRD_VARIABLE_ERROR)
            .noMore();
}
 
Example #29
Source File: FunctionWithTooManyParametersCheckTest.java    From sonar-lua with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void defaults() {
  SourceFile file = LuaAstScanner.scanSingleFile(new File("src/test/resources/checks/functionWithTooManyParameters.lua"), check);
  CheckMessagesVerifier.verify(file.getCheckMessages())
    .next().atLine(1).withMessage("This function/method has 8 parameters, which is greater than the 7 authorized.")
    .next().atLine(7).withMessage("This function/method has 8 parameters, which is greater than the 7 authorized.")
    .next().atLine(10).withMessage("This function/method has 9 parameters, which is greater than the 7 authorized.")
    .noMore();
}
 
Example #30
Source File: CommentRegularExpressionCheckTest.java    From sonar-lua with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void test() {
  CommentRegularExpressionCheck check = new CommentRegularExpressionCheck();

  check.regularExpression = "(?i).*TODO.*";
  check.message = "Avoid TODO";

  SourceFile file = LuaAstScanner.scanSingleFile(new File("src/test/resources/checks/commentRegularExpression.lua"), check);
  CheckMessagesVerifier.verify(file.getCheckMessages())
      .next().atLine(2).withMessage("Avoid TODO")
      .noMore();
}