Skip to content

Commit 5becb99

Browse files
committed
SONARJAVA-1212 Migrates test to JavaCheckVerifier
1 parent a16aee5 commit 5becb99

2 files changed

Lines changed: 7 additions & 35 deletions

File tree

java-checks/src/test/files/checks/DeprecatedHashAlgorithmCheck.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
class A {
66
void myMethod(String algorithm) {
77
MessageDigest md = null;
8-
md = MessageDigest.getInstance("MD5"); // Noncompliant
9-
md = MessageDigest.getInstance("SHA-1"); // Noncompliant
8+
md = MessageDigest.getInstance("MD5"); // Noncompliant {{Use a stronger encryption algorithm than MD5.}}
9+
md = MessageDigest.getInstance("SHA-1"); // Noncompliant {{Use a stronger encryption algorithm than SHA-1.}}
1010
md = MessageDigest.getInstance("SHA-256");
1111
md = org.apache.commons.codec.digest.DigestUtils.getDigest("MD5"); // Noncompliant
1212
md = DigestUtils.getDigest("SHA-1"); // Noncompliant
@@ -25,9 +25,9 @@ void myMethod(String algorithm) {
2525
DigestUtils.sha256Hex("");
2626
md = MessageDigest.getInstance(algorithm);
2727
md = DigestUtils.getDigest(algorithm);
28-
md5Hex("");
29-
com.google.common.hash.Hashing.md5();
30-
com.google.common.hash.Hashing.sha1();
28+
md5Hex(""); // Noncompliant
29+
com.google.common.hash.Hashing.md5(); // Noncompliant
30+
com.google.common.hash.Hashing.sha1(); // Noncompliant
3131
com.google.common.hash.Hashing.sha256();
3232
}
3333

java-checks/src/test/java/org/sonar/java/checks/DeprecatedHashAlgorithmCheckTest.java

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,42 +19,14 @@
1919
*/
2020
package org.sonar.java.checks;
2121

22-
import com.google.common.collect.ImmutableList;
23-
import org.junit.Rule;
2422
import org.junit.Test;
25-
import org.sonar.java.ast.JavaAstScanner;
26-
import org.sonar.java.model.VisitorsBridge;
27-
import org.sonar.squidbridge.api.SourceFile;
28-
import org.sonar.squidbridge.checks.CheckMessagesVerifierRule;
29-
30-
import java.io.File;
23+
import org.sonar.java.checks.verifier.JavaCheckVerifier;
3124

3225
public class DeprecatedHashAlgorithmCheckTest {
3326

34-
@Rule
35-
public CheckMessagesVerifierRule checkMessagesVerifier = new CheckMessagesVerifierRule();
36-
3727
@Test
3828
public void test() {
39-
SourceFile file = JavaAstScanner.scanSingleFile(new File("src/test/files/checks/DeprecatedHashAlgorithmCheck.java"),
40-
new VisitorsBridge(new DeprecatedHashAlgorithmCheck(), ImmutableList.of(new File("target/test-classes"))));
41-
checkMessagesVerifier.verify(file.getCheckMessages())
42-
.next().atLine(8).withMessage("Use a stronger encryption algorithm than MD5.")
43-
.next().atLine(9).withMessage("Use a stronger encryption algorithm than SHA-1.")
44-
.next().atLine(11).withMessage("Use a stronger encryption algorithm than MD5.")
45-
.next().atLine(12).withMessage("Use a stronger encryption algorithm than SHA-1.")
46-
.next().atLine(14).withMessage("Use a stronger encryption algorithm than MD5.")
47-
.next().atLine(15).withMessage("Use a stronger encryption algorithm than SHA-1.")
48-
.next().atLine(16).withMessage("Use a stronger encryption algorithm than SHA-1.")
49-
.next().atLine(18).withMessage("Use a stronger encryption algorithm than MD5.")
50-
.next().atLine(19).withMessage("Use a stronger encryption algorithm than MD5.")
51-
.next().atLine(20).withMessage("Use a stronger encryption algorithm than SHA-1.")
52-
.next().atLine(21).withMessage("Use a stronger encryption algorithm than SHA-1.")
53-
.next().atLine(22).withMessage("Use a stronger encryption algorithm than SHA-1.")
54-
.next().atLine(23).withMessage("Use a stronger encryption algorithm than SHA-1.")
55-
.next().atLine(28).withMessage("Use a stronger encryption algorithm than MD5.")
56-
.next().atLine(29).withMessage("Use a stronger encryption algorithm than MD5.")
57-
.next().atLine(30).withMessage("Use a stronger encryption algorithm than SHA-1.");
29+
JavaCheckVerifier.verify("src/test/files/checks/DeprecatedHashAlgorithmCheck.java", new DeprecatedHashAlgorithmCheck());
5830
}
5931

6032
}

0 commit comments

Comments
 (0)