From 82970c0f242f1f6de40b70bb6f73356aaa56656b Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sat, 7 Oct 2023 10:59:16 -0400 Subject: [PATCH 01/19] chore(deps): update plugin com.gradle.enterprise to v3.15.1 (#2606) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- settings.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle.kts b/settings.gradle.kts index 8d354c56dde..d65c9cf83ec 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,5 +1,5 @@ plugins { - id("com.gradle.enterprise") version "3.15" + id("com.gradle.enterprise") version "3.15.1" } include(":eclipsePlugin") From b245f766bf8780852ae89a557bd546519963ef22 Mon Sep 17 00:00:00 2001 From: Guillaume Toison <86775455+gtoison@users.noreply.github.com> Date: Sat, 7 Oct 2023 16:59:49 +0200 Subject: [PATCH 02/19] build: install readthedocs requirements (#2608) The template readthedocs v2 configuration file add the requirements install commented out. Enable it so we install the theme --- .readthedocs.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.readthedocs.yaml b/.readthedocs.yaml index b468076c68e..f6a12ce2d52 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -30,6 +30,6 @@ sphinx: # Optional but recommended, declare the Python requirements required # to build your documentation # See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html -# python: -# install: -# - requirements: docs/requirements.txt +python: + install: + - requirements: docs/requirements.txt From d3b130cc95a38af8ba84cb687d48ba610f487094 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sat, 7 Oct 2023 11:10:19 -0400 Subject: [PATCH 03/19] fix(deps): update dependency org.mockito:mockito-core to v5.6.0 (#2610) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- eclipsePlugin-junit/build.gradle | 2 +- spotbugsTestCases/build.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/eclipsePlugin-junit/build.gradle b/eclipsePlugin-junit/build.gradle index 4db835143b0..97ca15fd50f 100644 --- a/eclipsePlugin-junit/build.gradle +++ b/eclipsePlugin-junit/build.gradle @@ -12,7 +12,7 @@ tasks.named('compileJava', JavaCompile).configure { dependencies { implementation project(':eclipsePlugin') testImplementation 'org.junit.vintage:junit-vintage-engine:5.10.0' - testImplementation 'org.mockito:mockito-core:5.5.0' + testImplementation 'org.mockito:mockito-core:5.6.0' } tasks.named('jacocoTestReport', JacocoReport).configure { diff --git a/spotbugsTestCases/build.gradle b/spotbugsTestCases/build.gradle index a2195117a4e..78f9327e782 100644 --- a/spotbugsTestCases/build.gradle +++ b/spotbugsTestCases/build.gradle @@ -34,7 +34,7 @@ dependencies { implementation project(':spotbugs') api project(':spotbugs-annotations') implementation 'org.apache.groovy:groovy-all:4.0.15' - implementation 'org.mockito:mockito-core:5.5.0' + implementation 'org.mockito:mockito-core:5.6.0' } tasks.withType(JavaCompile).configureEach { From bc6a9d4a606f74cbceef2a6f3fdd0ef029cdc8ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20S=C3=BCli?= Date: Sat, 7 Oct 2023 17:13:07 +0200 Subject: [PATCH 04/19] #2280 Update Eclipse plugin release number to 4.29.0 (#2611) --- buildSrc/src/main/kotlin/eclipse-convention.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildSrc/src/main/kotlin/eclipse-convention.gradle.kts b/buildSrc/src/main/kotlin/eclipse-convention.gradle.kts index d6781284026..0167995e81e 100644 --- a/buildSrc/src/main/kotlin/eclipse-convention.gradle.kts +++ b/buildSrc/src/main/kotlin/eclipse-convention.gradle.kts @@ -7,7 +7,7 @@ val pdeTool by configurations.creating { } eclipseMavenCentral { - release("4.14.0") { + release("4.29.0") { compileOnly("org.eclipse.ant.core") compileOnly("org.eclipse.core.resources") compileOnly("org.eclipse.core.runtime") From d3c49cb360cb2d91b2471cafedacd487c77a7d72 Mon Sep 17 00:00:00 2001 From: nbauma109 Date: Sat, 7 Oct 2023 17:25:08 +0200 Subject: [PATCH 05/19] spell check (#2607) --- spotbugs/etc/messages_fr.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spotbugs/etc/messages_fr.xml b/spotbugs/etc/messages_fr.xml index 98776be4cb8..a904496c754 100644 --- a/spotbugs/etc/messages_fr.xml +++ b/spotbugs/etc/messages_fr.xml @@ -1539,11 +1539,11 @@ public int hashCode() { - Une méthode peut exposer un état interne statique en stockant un objet modifiable dans un champs statique + Une méthode peut exposer un état interne statique en stockant un objet modifiable dans un champ statique La méthode {1} peut exposer un état interne statique en stockant un objet modifiable dans le champs statique {2}
Ce code stocke une référence à un objet modifiable externe dans un champs statique. Si des modifications non vérifiées de l'objet modifiable peuvent compromettre la sécurité ou d'autres propriétés importantes, vous devez faire autre chose. Stocker une copie de l'objet est souvent une meilleur approche.

+

Ce code stocke une référence à un objet modifiable externe dans un champ statique. Si des modifications non vérifiées de l'objet modifiable peuvent compromettre la sécurité ou d'autres propriétés importantes, vous devez faire autre chose. Stocker une copie de l'objet est souvent une meilleur approche.

]]>
@@ -2562,8 +2562,8 @@ public vida foo() { - Auto-alimentation d'un champs - Auto-alimentation du champs {2} dans {1} + Auto-alimentation d'un champ + Auto-alimentation du champ {2} dans {1}
Cette méthode contient un champ s'auto-alimentant; par exemple :

From fe4442beb20b774705f91ff0bbdb95cbb2e9716e Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 8 Oct 2023 11:59:58 -0400 Subject: [PATCH 06/19] chore(deps): update plugin com.github.spotbugs to v6.0.0-beta.4 (#2615) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index c4369524914..bde9eca441e 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ plugins { id "org.sonarqube" version "4.4.1.3373" id "org.gradle.crypto.checksum" version "1.4.0" - id "com.github.spotbugs" version "6.0.0-beta.3" + id "com.github.spotbugs" version "6.0.0-beta.4" id "io.github.gradle-nexus.publish-plugin" version "1.3.0" } From 63618ab7c4c0c66fd89a19e9714d464a1febb449 Mon Sep 17 00:00:00 2001 From: Christoph Loy Date: Mon, 9 Oct 2023 02:05:42 +0200 Subject: [PATCH 07/19] Fix first batch of Gradle buildDir deprecations (#2609) * Fix Gradle buildDir deprecations * Fix errors * Fix another issue --- build.gradle | 8 +-- .../main/kotlin/eclipse-convention.gradle.kts | 5 +- eclipsePlugin/build.gradle | 66 ++++++++++--------- spotbugs-annotations/build.gradle | 2 +- spotbugs-tests/build.gradle | 2 +- spotbugs/build.gradle | 6 +- spotbugsTestCases/build.gradle | 6 +- 7 files changed, 50 insertions(+), 45 deletions(-) diff --git a/build.gradle b/build.gradle index bde9eca441e..e243cbdf1d2 100644 --- a/build.gradle +++ b/build.gradle @@ -71,7 +71,7 @@ def publishTask = tasks.findByName("publish") if (publishTask == null) { publishTask = tasks.findByName("publishToMavenLocal") } -def outputFile = file("$buildDir/release.md") +def outputFile = layout.buildDirectory.file("release.md") def inputFile = subprojects.collect { it.hasProperty('publishing') ? it.publishing.publications.maven.artifacts : [] }.flatten().collect { @@ -103,14 +103,14 @@ createChecksums.configure { dependsOn(":spotbugs:distTar") } createReleaseBody.configure { - inputs.files fileTree("$buildDir/checksums").matching { + inputs.files fileTree(layout.buildDirectory.dir("checksums")).matching { include "*.sha256" } outputs.file outputFile dependsOn createChecksums doLast { - outputFile.delete() + outputFile.get().asFile.delete() outputFile << """SpotBugs ${project.version} ### CHANGELOG @@ -120,7 +120,7 @@ createReleaseBody.configure { | file | checksum (sha256) | | ---- | ----------------- | """ - fileTree("$buildDir/checksums").matching { + fileTree(layout.buildDirectory.dir("checksums")).matching { include "*.sha256" }.sort { it.name diff --git a/buildSrc/src/main/kotlin/eclipse-convention.gradle.kts b/buildSrc/src/main/kotlin/eclipse-convention.gradle.kts index 0167995e81e..a7a546f6940 100644 --- a/buildSrc/src/main/kotlin/eclipse-convention.gradle.kts +++ b/buildSrc/src/main/kotlin/eclipse-convention.gradle.kts @@ -34,13 +34,14 @@ eclipseMavenCentral { /** * Unzip "org.eclipse.pde.build" package into the outputDir. */ +val pdeToolDir = layout.buildDirectory.dir("pdeTool") val unzipPdeTool = tasks.register("unzipPdeTool") { from(zipTree(pdeTool.singleFile)) - into("$buildDir/pdeTool") + into(pdeToolDir) } dependencies { - compileOnly(files("$buildDir/pdeTool/pdebuild.jar"){ + compileOnly(files(pdeToolDir.map { it.file("pdebuild.jar") }){ builtBy(unzipPdeTool) }) } diff --git a/eclipsePlugin/build.gradle b/eclipsePlugin/build.gradle index 2225ee92114..8b92f05c697 100644 --- a/eclipsePlugin/build.gradle +++ b/eclipsePlugin/build.gradle @@ -130,7 +130,7 @@ def updateManifest = tasks.register('updateManifest') { dependsOn ':spotbugs:updateManifest', copyLibsForEclipse doLast { - def manifestSpec = manifest { + def manifestSpec = java.manifest { from "$projectDir/META-INF/MANIFEST-TEMPLATE.MF" attributes 'Bundle-SymbolicName': "$eclipsePluginId; singleton:=true", 'Bundle-Version': project.version, @@ -138,7 +138,7 @@ def updateManifest = tasks.register('updateManifest') { projectDir.toPath().relativize(it.toPath()).toString().replace('\\', '/') }.join(',') } - def distManifestSpec = manifest { + def distManifestSpec = java.manifest { from "$projectDir/META-INF/MANIFEST-TEMPLATE.MF" attributes 'Bundle-SymbolicName': "$eclipsePluginId; singleton:=true", 'Bundle-Version': project.version, @@ -266,20 +266,20 @@ def pluginJar = tasks.register('pluginJar', Zip) { // use Zip task, we already p with distSpec dependsOn jar archiveFileName = "${eclipsePluginId}_${project.version}.jar" - destinationDirectory = file("${buildDir}/site/eclipse/plugins/") + destinationDirectory.set(layout.buildDirectory.dir("site/eclipse/plugins/")) finalizedBy testPluginJar } def pluginCandidateJar = tasks.register('pluginCandidateJar', Copy) { dependsOn pluginJar from pluginJar.map { it.outputs.files } - into "${buildDir}/site/eclipse-candidate/plugins/" + into layout.buildDirectory.dir("site/eclipse-candidate/plugins/") } def pluginDailyJar = tasks.register('pluginDailyJar', Copy) { dependsOn pluginJar from pluginJar.map { it.outputs.files } - into "${buildDir}/site/eclipse-daily/plugins/" + into layout.buildDirectory.dir("site/eclipse-daily/plugins/") mustRunAfter(siteHtml) mustRunAfter(siteXml) } @@ -287,7 +287,7 @@ def pluginDailyJar = tasks.register('pluginDailyJar', Copy) { def pluginStableLatestJar = tasks.register('pluginStableLatestJar', Copy) { dependsOn pluginJar from pluginJar.map { it.outputs.files } - into "${buildDir}/site/eclipse-stable-latest/plugins/" + into layout.buildDirectory.dir("site/eclipse-stable-latest/plugins/") mustRunAfter(siteHtml) mustRunAfter(siteXml) } @@ -310,7 +310,7 @@ def featureJar = tasks.register('featureJar', Zip) { filter(tokens:siteFilterTokens, org.apache.tools.ant.filters.ReplaceTokens) rename { 'p2.inf' } } - destinationDirectory = file("${buildDir}/site/eclipse/features/") + destinationDirectory = layout.buildDirectory.dir("site/eclipse/features/") } def featureCandidateJar = tasks.register('featureCandidateJar', Zip) { @@ -324,7 +324,7 @@ def featureCandidateJar = tasks.register('featureCandidateJar', Zip) { filter(tokens:siteFilterTokens, org.apache.tools.ant.filters.ReplaceTokens) rename { 'p2.inf' } } - destinationDirectory = file("${buildDir}/site/eclipse-candidate/features/") + destinationDirectory = layout.buildDirectory.dir("site/eclipse-candidate/features/") } def featureDailyJar = tasks.register('featureDailyJar', Zip) { @@ -338,7 +338,7 @@ def featureDailyJar = tasks.register('featureDailyJar', Zip) { filter(tokens:siteFilterTokens, org.apache.tools.ant.filters.ReplaceTokens) rename { 'p2.inf' } } - destinationDirectory = file("${buildDir}/site/eclipse-daily/features/") + destinationDirectory = layout.buildDirectory.dir("site/eclipse-daily/features/") } def featureStableLatestJar = tasks.register('featureStableLatestJar', Zip) { @@ -352,7 +352,7 @@ def featureStableLatestJar = tasks.register('featureStableLatestJar', Zip) { filter(tokens:siteFilterTokens, org.apache.tools.ant.filters.ReplaceTokens) rename { 'p2.inf' } } - destinationDirectory = file("${buildDir}/site/eclipse-stable-latest/features/") + destinationDirectory = layout.buildDirectory.dir("site/eclipse-stable-latest/features/") } def siteHtml = tasks.register('siteHtml', Copy) { @@ -360,7 +360,7 @@ def siteHtml = tasks.register('siteHtml', Copy) { 'URL': 'https://spotbugs.github.io/eclipse/' ] + siteFilterTokens, org.apache.tools.ant.filters.ReplaceTokens) from 'plugin_site.html' - destinationDir = file("${buildDir}/site/eclipse") + into layout.buildDirectory.dir("site/eclipse") rename { 'index.html' } outputs.upToDateWhen { // even if we have generated file, we should rerun this task to overwrite it. @@ -375,7 +375,7 @@ def siteCandidateHtml = tasks.register('siteCandidateHtml', Copy) { 'URL': 'https://spotbugs.github.io/eclipse-candidate/' ] + siteFilterTokens, org.apache.tools.ant.filters.ReplaceTokens) from 'plugin_site.html' - destinationDir = file("${buildDir}/site/eclipse-candidate") + into layout.buildDirectory.dir("site/eclipse-candidate") rename { 'index.html' } outputs.upToDateWhen { // even if we have generated file, we should rerun this task to overwrite it. @@ -388,7 +388,7 @@ def siteDailyHtml = tasks.register('siteDailyHtml', Copy) { 'URL': 'https://spotbugs.github.io/eclipse-latest/' ] + siteFilterTokens, org.apache.tools.ant.filters.ReplaceTokens) from 'plugin_site.html' - destinationDir = file("${buildDir}/site/eclipse-daily") + into layout.buildDirectory.dir("site/eclipse-daily") rename { 'index.html' } outputs.upToDateWhen { // even if we have generated file, we should rerun this task to overwrite it. @@ -401,7 +401,7 @@ def siteStableLatestHtml = tasks.register('siteStableLatestHtml', Copy) { 'URL': 'https://spotbugs.github.io/eclipse-stable-latest/' ] + siteFilterTokens, org.apache.tools.ant.filters.ReplaceTokens) from 'plugin_site.html' - destinationDir = file("${buildDir}/site/eclipse-stable-latest") + into layout.buildDirectory.dir("site/eclipse-stable-latest") rename { 'index.html' } outputs.upToDateWhen { // even if we have generated file, we should rerun this task to overwrite it. @@ -412,7 +412,7 @@ def siteStableLatestHtml = tasks.register('siteStableLatestHtml', Copy) { def siteXml = tasks.register('siteXml', Copy) { filter(tokens:siteFilterTokens, org.apache.tools.ant.filters.ReplaceTokens) from 'plugin_site.xml' - destinationDir = file("${buildDir}/site/eclipse") + into layout.buildDirectory.dir("site/eclipse") rename { 'site.xml' } outputs.upToDateWhen { // even if we have generated file, we should rerun this task to overwrite it. @@ -425,7 +425,7 @@ def siteXml = tasks.register('siteXml', Copy) { def siteCandidateXml = tasks.register('siteCandidateXml', Copy) { filter(tokens:siteFilterTokens, org.apache.tools.ant.filters.ReplaceTokens) from 'plugin_site-candidate.xml' - destinationDir = file("${buildDir}/site/eclipse-candidate") + into layout.buildDirectory.dir("site/eclipse-candidate") rename { 'site.xml' } outputs.upToDateWhen { // even if we have generated file, we should rerun this task to overwrite it. @@ -436,7 +436,7 @@ def siteCandidateXml = tasks.register('siteCandidateXml', Copy) { def siteDailyXml = tasks.register('siteDailyXml', Copy) { filter(tokens:siteFilterTokens, org.apache.tools.ant.filters.ReplaceTokens) from 'plugin_site-daily.xml' - destinationDir = file("${buildDir}/site/eclipse-daily") + into layout.buildDirectory.dir("site/eclipse-daily") rename { 'site.xml' } outputs.upToDateWhen { // even if we have generated file, we should rerun this task to overwrite it. @@ -447,7 +447,7 @@ def siteDailyXml = tasks.register('siteDailyXml', Copy) { def siteStableLatestXml = tasks.register('siteStableLatestXml', Copy) { filter(tokens:siteFilterTokens, org.apache.tools.ant.filters.ReplaceTokens) from 'plugin_site-stable_latest.xml' - destinationDir = file("${buildDir}/site/eclipse-stable-latest") + into layout.buildDirectory.dir("site/eclipse-stable-latest") rename { 'site.xml' } outputs.upToDateWhen { // even if we have generated file, we should rerun this task to overwrite it. @@ -489,9 +489,10 @@ def confirmEclipse = tasks.register('confirmEclipse') { def generateP2Metadata = tasks.register('generateP2Metadata', Exec) { doFirst { - project.delete "${buildDir}/site/eclipse/artifacts.xml" - project.delete "${buildDir}/site/eclipse/content.xml" - signJar(file("${buildDir}/site/eclipse")) + def eclipseSiteDir = layout.buildDirectory.dir("site/eclipse") + project.delete eclipseSiteDir.map { it.file("artifacts.xml") } + project.delete eclipseSiteDir.map { it.file("content.xml") } + signJar(eclipseSiteDir.get().asFile) } inputs.file 'local.properties' dependsOn confirmEclipse, pluginJar, featureJar, siteXml, siteHtml @@ -504,9 +505,10 @@ def generateP2Metadata = tasks.register('generateP2Metadata', Exec) { def generateCandidateP2Metadata = tasks.register('generateCandidateP2Metadata', Exec) { doFirst { - project.delete "${buildDir}/site/eclipse-candidate/artifacts.xml" - project.delete "${buildDir}/site/eclipse-candidate/content.xml" - signJar(file("${buildDir}/site/eclipse-candidate")) + def eclipseSiteDir = layout.buildDirectory.dir("site/eclipse-candidate") + project.delete eclipseSiteDir.map { it.file("artifacts.xml") } + project.delete eclipseSiteDir.map { it.file("content.xml") } + signJar(file(eclipseSiteDir.get().asFile)) } inputs.file 'local.properties' dependsOn confirmEclipse, pluginCandidateJar, featureCandidateJar, siteCandidateXml, siteCandidateHtml @@ -519,9 +521,10 @@ def generateCandidateP2Metadata = tasks.register('generateCandidateP2Metadata', def generateP2MetadataDaily = tasks.register('generateP2MetadataDaily', Exec) { doFirst { - project.delete "${buildDir}/site/eclipse-daily/artifacts.xml" - project.delete "${buildDir}/site/eclipse-daily/content.xml" - signJar(file("${buildDir}/site/eclipse-daily")) + def eclipseSiteDir = layout.buildDirectory.dir("site/eclipse-daily") + project.delete eclipseSiteDir.map { it.file("artifacts.xml") } + project.delete eclipseSiteDir.map { it.file("content.xml") } + signJar(eclipseSiteDir.get().asFile) } inputs.file 'local.properties' dependsOn confirmEclipse, pluginDailyJar, featureDailyJar, siteDailyXml, siteDailyHtml @@ -534,9 +537,10 @@ def generateP2MetadataDaily = tasks.register('generateP2MetadataDaily', Exec) { def generateP2MetadataStableLatest = tasks.register('generateP2MetadataStableLatest', Exec) { doFirst { - project.delete "${buildDir}/site/eclipse-stable-latest/artifacts.xml" - project.delete "${buildDir}/site/eclipse-stable-latest/content.xml" - signJar(file("${buildDir}/site/eclipse-stable-latest")) + def eclipseSiteDir = layout.buildDirectory.dir("site/eclipse-stable-latest") + project.delete eclipseSiteDir.map { it.file("artifacts.xml") } + project.delete eclipseSiteDir.map { it.file("content.xml") } + signJar(eclipseSiteDir.get().asFile) } inputs.file 'local.properties' dependsOn confirmEclipse, pluginStableLatestJar, featureStableLatestJar, siteStableLatestXml, siteStableLatestHtml @@ -554,7 +558,7 @@ def eclipseSite = tasks.register('eclipseSite') { // create zip file to upload to GitHub release page def eclipseSiteZip = tasks.register('eclipseSiteZip', Zip) { dependsOn eclipseSite - from("${buildDir}/site/eclipse") + from layout.buildDirectory.dir("site/eclipse") archiveFileName = "eclipsePlugin.zip" } diff --git a/spotbugs-annotations/build.gradle b/spotbugs-annotations/build.gradle index 9870bddfc44..c65feccccd2 100644 --- a/spotbugs-annotations/build.gradle +++ b/spotbugs-annotations/build.gradle @@ -21,7 +21,7 @@ dependencies { api 'com.google.code.findbugs:jsr305:3.0.2' } -def manifestSpec = manifest { +def manifestSpec = java.manifest { attributes 'Bundle-Name': 'spotbugs-annotations', 'Bundle-SymbolicName': 'spotbugs-annotations', 'Bundle-Version': project.version.replace('-', '.'), diff --git a/spotbugs-tests/build.gradle b/spotbugs-tests/build.gradle index 23b16a9bb8e..5defe2da8d2 100644 --- a/spotbugs-tests/build.gradle +++ b/spotbugs-tests/build.gradle @@ -37,7 +37,7 @@ tasks.named('jacocoTestReport', JacocoReport).configure { dependsOn('unstableTest') additionalSourceDirs.setFrom files(project(':spotbugs').sourceSets.main.java.srcDirs) additionalClassDirs.setFrom files(project(':spotbugs').sourceSets.main.output.classesDirs) - executionData.setFrom files("$buildDir/jacoco/unstableTest.exec", "$buildDir/jacoco/test.exec") + executionData.setFrom files(layout.buildDirectory.file("jacoco/unstableTest.exec"), layout.buildDirectory.file("jacoco/test.exec")) } // Tests below fail if executed with other tests diff --git a/spotbugs/build.gradle b/spotbugs/build.gradle index 9a2c47f0c29..f31a82a0874 100644 --- a/spotbugs/build.gradle +++ b/spotbugs/build.gradle @@ -164,7 +164,7 @@ def updateManifest = tasks.register('updateManifest') { outputs.file "$projectDir/META-INF/MANIFEST.MF" dependsOn configurations.runtimeClasspath, copyLibsForEclipse doLast { - def manifestSpec = manifest { + def manifestSpec = java.manifest { from "$projectDir/META-INF/MANIFEST-TEMPLATE.MF" attributes 'Main-Class': 'edu.umd.cs.findbugs.LaunchAppropriateUI', 'Bundle-Version': project.version.replace('-', '.'), @@ -221,7 +221,7 @@ def scripts = tasks.register('scripts', Copy) { into 'experimental' } - destinationDir file("$buildDir/bin") + into(layout.buildDirectory.dir("bin")) duplicatesStrategy DuplicatesStrategy.FAIL fileMode 0755 } @@ -329,7 +329,7 @@ def smokeTest = tasks.register('smokeTest') { timeout:'1800000', outputFile:"${buildDir}/smoketest/findbugscheckAll.xml") { sourcePath(path:'src/main/java:src/gui/main:src/tools') - 'class'(location:project.tasks['compileJava'].destinationDir) + 'class'(location:project.tasks['compileJava'].destinationDirectory.get().asFile) configurations.compileClasspath.each { File file -> auxClasspath(path:file.path) } } } diff --git a/spotbugsTestCases/build.gradle b/spotbugsTestCases/build.gradle index 78f9327e782..9fa81b7cca3 100644 --- a/spotbugsTestCases/build.gradle +++ b/spotbugsTestCases/build.gradle @@ -66,19 +66,19 @@ tasks.named('javadoc', Javadoc).configure { } def classesJava8 = tasks.register('classesJava8', JavaCompile) { - destinationDirectory.set(file("$buildDir/classes/java/java8")) + destinationDirectory.set(layout.buildDirectory.dir("classes/java/java8")) classpath = sourceSets.main.compileClasspath source = file('src/java8') } def classesJava11 = tasks.register('classesJava11', JavaCompile) { - destinationDirectory.set(file("$buildDir/classes/java/java11")) + destinationDirectory.set(layout.buildDirectory.dir("classes/java/java11")) classpath = sourceSets.main.compileClasspath source = file('src/java11') } def classesJava17 = tasks.register('classesJava17', JavaCompile) { - destinationDirectory.set(file("$buildDir/classes/java/java17")) + destinationDirectory.set(layout.buildDirectory.dir("classes/java/java17")) classpath = sourceSets.main.compileClasspath source = file('src/java17') } From cfcf9f2848277fedbf6d1285f9207a5aa588c882 Mon Sep 17 00:00:00 2001 From: Jeremy Landis Date: Sun, 8 Oct 2023 20:06:12 -0400 Subject: [PATCH 08/19] [eclipse-format] No longer supply version to spotless, use same configuration (#2612) far smaller subset of corrections making code easier to read. --- gradle/spotless.gradle | 2 +- .../edu/umd/cs/findbugs/ba/Hierarchy.java | 2 +- .../findbugs/detect/BadResultSetAccess.java | 2 +- .../umd/cs/findbugs/detect/DumbMethods.java | 12 +++---- .../cs/findbugs/detect/EmptyZipFileEntry.java | 2 +- .../findbugs/detect/FindDeadLocalStores.java | 2 +- .../detect/FindFinalizeInvocations.java | 2 +- .../detect/FindInconsistentSync2.java | 2 +- .../detect/FindJSR166LockMonitorenter.java | 2 +- .../detect/FindLocalSelfAssignment2.java | 2 +- .../FindNonSerializableStoreIntoSession.java | 2 +- ...nSerializableValuePassedToWriteObject.java | 4 +-- .../umd/cs/findbugs/detect/FindNullDeref.java | 2 +- .../detect/FindOverridableMethodCall.java | 12 +++---- ...alSecurityCheckBasedOnUntrustedSource.java | 34 +++++++++---------- .../findbugs/detect/FindPublicAttributes.java | 6 ++-- .../umd/cs/findbugs/detect/FindPuzzlers.java | 6 ++-- .../umd/cs/findbugs/detect/FindReturnRef.java | 24 ++++++------- .../detect/FindUnconditionalWait.java | 2 +- .../detect/FindUseOfNonSerializableValue.java | 2 +- .../detect/FindUselessControlFlow.java | 2 +- .../detect/HugeSharedStringConstants.java | 2 +- .../findbugs/detect/InefficientIndexOf.java | 2 +- .../cs/findbugs/detect/InvalidJUnitTest.java | 2 +- .../edu/umd/cs/findbugs/detect/LazyInit.java | 2 +- .../cs/findbugs/detect/MethodReturnCheck.java | 2 +- .../detect/MultithreadedInstanceAccess.java | 6 ++-- .../edu/umd/cs/findbugs/detect/Naming.java | 4 +-- .../cs/findbugs/detect/PermissionsSuper.java | 2 +- .../detect/ReadReturnShouldBeChecked.java | 4 +-- .../ReflectionIncreaseAccessibility.java | 4 +-- .../umd/cs/findbugs/detect/VolatileUsage.java | 2 +- 32 files changed, 79 insertions(+), 79 deletions(-) diff --git a/gradle/spotless.gradle b/gradle/spotless.gradle index 4a906c4401d..2049ed75477 100644 --- a/gradle/spotless.gradle +++ b/gradle/spotless.gradle @@ -4,7 +4,7 @@ spotless { java { removeUnusedImports() trimTrailingWhitespace() - eclipse("4.13").configFile "${rootProject.projectDir}/gradle/eclipse-formatter.xml" + eclipse().configFile "${rootProject.projectDir}/gradle/eclipse-formatter.xml" endWithNewline() } } diff --git a/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/Hierarchy.java b/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/Hierarchy.java index 8b3a9602b37..ec3a0b631f3 100644 --- a/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/Hierarchy.java +++ b/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/Hierarchy.java @@ -853,7 +853,7 @@ public static Set resolveMethodCallTargets(ReferenceType rec if (false && subTypeSet.size() > 500) { new RuntimeException(receiverClassName + " has " + subTypeSet.size() + " subclasses, " + result.size() + " of which implement " + methodName + methodSig + " " + invokeInstruction) - .printStackTrace(System.out); + .printStackTrace(System.out); } } diff --git a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/BadResultSetAccess.java b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/BadResultSetAccess.java index c78d0353c33..97ef3ea3c5f 100644 --- a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/BadResultSetAccess.java +++ b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/BadResultSetAccess.java @@ -100,7 +100,7 @@ public void sawOpcode(int seen) { bugReporter.reportBug(new BugInstance(this, "java/sql/PreparedStatement".equals(clsConstant) ? "SQL_BAD_PREPARED_STATEMENT_ACCESS" : "SQL_BAD_RESULTSET_ACCESS", item.mustBeZero() ? HIGH_PRIORITY : NORMAL_PRIORITY) - .addClassAndMethod(this).addSourceLine(this)); + .addClassAndMethod(this).addSourceLine(this)); } } } diff --git a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/DumbMethods.java b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/DumbMethods.java index 841fbbd8bcd..85b5a3d601b 100644 --- a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/DumbMethods.java +++ b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/DumbMethods.java @@ -208,7 +208,7 @@ public void sawOpcode(int seen) { && "setMaximumPoolSize".equals(getNameConstantOperand())) { accumulator.accumulateBug(new BugInstance(DumbMethods.this, "DMI_FUTILE_ATTEMPT_TO_CHANGE_MAXPOOL_SIZE_OF_SCHEDULED_THREAD_POOL_EXECUTOR", HIGH_PRIORITY) - .addClassAndMethod(DumbMethods.this), DumbMethods.this); + .addClassAndMethod(DumbMethods.this), DumbMethods.this); } } } @@ -756,7 +756,7 @@ public void sawOpcode(int seen) { primitiveType.equals("Z") ? LOW_PRIORITY : primitiveType.equals("B") ? NORMAL_PRIORITY : HIGH_PRIORITY).addClassAndMethod(this).addCalledMethod(this).addMethod(shouldCall) - .describe(MethodAnnotation.SHOULD_CALL); + .describe(MethodAnnotation.SHOULD_CALL); accumulator.accumulateBug(bug, this); } } @@ -1264,7 +1264,7 @@ && getClassConstantOperand().startsWith("javax/swing/") accumulator.accumulateBug(new BugInstance(this, "DMI_CALLING_NEXT_FROM_HASNEXT", item.isInitialParameter() && item.getRegisterNumber() == 0 ? NORMAL_PRIORITY : LOW_PRIORITY).addClassAndMethod(this) - .addCalledMethod(this), this); + .addCalledMethod(this), this); } @@ -1422,9 +1422,9 @@ && getClassConstantOperand().equals(primitiveObjCtorSeen) && dblString.toUpperCase().indexOf('E') == -1; bugReporter.reportBug(new BugInstance(this, "DMI_BIGDECIMAL_CONSTRUCTED_FROM_DOUBLE", scary ? NORMAL_PRIORITY : LOW_PRIORITY).addClassAndMethod(this).addCalledMethod(this) - .addMethod("java.math.BigDecimal", "valueOf", "(D)Ljava/math/BigDecimal;", true) - .describe(MethodAnnotation.METHOD_ALTERNATIVE_TARGET).addString(dblString) - .addString(bigDecimalString).addSourceLine(this)); + .addMethod("java.math.BigDecimal", "valueOf", "(D)Ljava/math/BigDecimal;", true) + .describe(MethodAnnotation.METHOD_ALTERNATIVE_TARGET).addString(dblString) + .addString(bigDecimalString).addSourceLine(this)); } } diff --git a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/EmptyZipFileEntry.java b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/EmptyZipFileEntry.java index 706fdf4cab5..98e10407fb5 100644 --- a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/EmptyZipFileEntry.java +++ b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/EmptyZipFileEntry.java @@ -71,7 +71,7 @@ && getClassConstantOperand().equals(streamType)) { .reportBug(new BugInstance(this, "java/util/zip/ZipOutputStream".equals(streamType) ? "AM_CREATES_EMPTY_ZIP_FILE_ENTRY" : "AM_CREATES_EMPTY_JAR_FILE_ENTRY", NORMAL_PRIORITY).addClassAndMethod(this) - .addSourceLine(this)); + .addSourceLine(this)); } } diff --git a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindDeadLocalStores.java b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindDeadLocalStores.java index 69475d44b72..3b01289a155 100644 --- a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindDeadLocalStores.java +++ b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindDeadLocalStores.java @@ -427,7 +427,7 @@ private void analyzeMethod(ClassContext classContext, Method method) throws Data } BugInstance bugInstance = new BugInstance(this, "DLS_DEAD_STORE_OF_CLASS_LITERAL", Priorities.NORMAL_PRIORITY).addClassAndMethod(methodGen, sourceFileName).add(lvAnnotation) - .addType(initializationOf); + .addType(initializationOf); accumulator.accumulateBug(bugInstance, sourceLineAnnotation); continue; } diff --git a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindFinalizeInvocations.java b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindFinalizeInvocations.java index b4ea2097fca..124d953a983 100644 --- a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindFinalizeInvocations.java +++ b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindFinalizeInvocations.java @@ -91,7 +91,7 @@ public void sawOpcode(int seen) { bugAccumulator.accumulateBug( new BugInstance(this, "FI_EXPLICIT_INVOCATION", "finalize".equals(getMethodName()) && "()V".equals(getMethodSig()) ? HIGH_PRIORITY : NORMAL_PRIORITY).addClassAndMethod(this) - .addCalledMethod(this), this); + .addCalledMethod(this), this); } if (seen == Const.INVOKESPECIAL && "finalize".equals(getNameConstantOperand())) { diff --git a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindInconsistentSync2.java b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindInconsistentSync2.java index eaac08f0fc5..aa3cbb66e6e 100644 --- a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindInconsistentSync2.java +++ b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindInconsistentSync2.java @@ -578,7 +578,7 @@ public void report() { } else { bugInstance = new BugInstance(this, guardedByThis ? "IS_FIELD_NOT_GUARDED" : "IS2_INCONSISTENT_SYNC", Priorities.NORMAL_PRIORITY).addClass(xfield.getClassName()).addField(xfield).addInt(printFreq) - .describe(IntAnnotation.INT_SYNC_PERCENT); + .describe(IntAnnotation.INT_SYNC_PERCENT); } propertySet.decorateBugInstance(bugInstance); diff --git a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindJSR166LockMonitorenter.java b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindJSR166LockMonitorenter.java index cd6b801ed2b..f39aa6b35a7 100644 --- a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindJSR166LockMonitorenter.java +++ b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindJSR166LockMonitorenter.java @@ -233,7 +233,7 @@ private void analyzeMethod(ClassContext classContext, Method method) { if (isSubtype) { bugReporter.reportBug(new BugInstance(this, "JLM_JSR166_LOCK_MONITORENTER", isUtilConcurrentSig ? HIGH_PRIORITY : NORMAL_PRIORITY).addClassAndMethod(classContext.getJavaClass(), method).addType(sig) - .addSourceForTopStackValue(classContext, method, location).addSourceLine(classContext, method, location)); + .addSourceForTopStackValue(classContext, method, location).addSourceLine(classContext, method, location)); } else if (isUtilConcurrentSig) { int priority = "Ljava/util/concurrent/CopyOnWriteArrayList;".equals(sig) ? HIGH_PRIORITY : NORMAL_PRIORITY; diff --git a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindLocalSelfAssignment2.java b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindLocalSelfAssignment2.java index 9fe89b9535b..b5615ba6de7 100644 --- a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindLocalSelfAssignment2.java +++ b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindLocalSelfAssignment2.java @@ -89,7 +89,7 @@ public void sawOpcode(int seen) { if (f.getName().equals(local.getName()) && (f.isStatic() || !getMethod().isStatic())) { bugReporter.reportBug(new BugInstance(this, "SA_LOCAL_SELF_ASSIGNMENT_INSTEAD_OF_FIELD", priority).addClassAndMethod(this).add(local).addField(f) - .describe(FieldAnnotation.DID_YOU_MEAN_ROLE).addSourceLine(this)); + .describe(FieldAnnotation.DID_YOU_MEAN_ROLE).addSourceLine(this)); return; } diff --git a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindNonSerializableStoreIntoSession.java b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindNonSerializableStoreIntoSession.java index f5cf83c5f90..3a9f4621e2e 100644 --- a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindNonSerializableStoreIntoSession.java +++ b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindNonSerializableStoreIntoSession.java @@ -138,7 +138,7 @@ private void analyzeMethod(ClassContext classContext, Method method) throws CFGB bugAccumulator.accumulateBug(new BugInstance(this, "J2EE_STORE_OF_NON_SERIALIZABLE_OBJECT_INTO_SESSION", isSerializable < 0.15 ? HIGH_PRIORITY : isSerializable > 0.5 ? LOW_PRIORITY : NORMAL_PRIORITY) - .addClassAndMethod(methodGen, sourceFile).addType(problem).describe(TypeAnnotation.FOUND_ROLE), + .addClassAndMethod(methodGen, sourceFile).addType(problem).describe(TypeAnnotation.FOUND_ROLE), sourceLineAnnotation); } diff --git a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindNonSerializableValuePassedToWriteObject.java b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindNonSerializableValuePassedToWriteObject.java index 30b442417d6..a6816f906bd 100644 --- a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindNonSerializableValuePassedToWriteObject.java +++ b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindNonSerializableValuePassedToWriteObject.java @@ -146,8 +146,8 @@ private void analyzeMethod(ClassContext classContext, Method method) throws CFGB bugReporter.reportBug(new BugInstance(this, "DMI_NONSERIALIZABLE_OBJECT_WRITTEN", isSerializable < 0.15 ? HIGH_PRIORITY : isSerializable > 0.5 ? LOW_PRIORITY : NORMAL_PRIORITY) - .addClassAndMethod(methodGen, sourceFile).addType(problem).describe(TypeAnnotation.FOUND_ROLE) - .addSourceLine(sourceLineAnnotation)); + .addClassAndMethod(methodGen, sourceFile).addType(problem).describe(TypeAnnotation.FOUND_ROLE) + .addSourceLine(sourceLineAnnotation)); } catch (ClassNotFoundException e) { // ignore diff --git a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindNullDeref.java b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindNullDeref.java index 09d246cc8e3..9d3506e54f2 100644 --- a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindNullDeref.java +++ b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindNullDeref.java @@ -513,7 +513,7 @@ private void examinePutfieldInstruction(Location location, PUTFIELD ins, Constan BugInstance warning = new BugInstance(this, "NP_STORE_INTO_NONNULL_FIELD", tos.isDefinitelyNull() ? HIGH_PRIORITY : NORMAL_PRIORITY).addClassAndMethod(classContext.getJavaClass(), method).addField(field) - .addOptionalAnnotation(variableAnnotation).addSourceLine(classContext, method, location); + .addOptionalAnnotation(variableAnnotation).addSourceLine(classContext, method, location); bugReporter.reportBug(warning); } diff --git a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindOverridableMethodCall.java b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindOverridableMethodCall.java index e964da786e6..9229111950b 100644 --- a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindOverridableMethodCall.java +++ b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindOverridableMethodCall.java @@ -227,7 +227,7 @@ private boolean checkAndRecordCallFromConstructor(XMethod constructor, XMethod c if (overridable != null) { bugAccumulator.accumulateBug(new BugInstance(this, "MC_OVERRIDABLE_METHOD_CALL_IN_CONSTRUCTOR", LOW_PRIORITY) - .addClass(this).addMethod(constructor).addString(overridable.getName()), sourceLine); + .addClass(this).addMethod(constructor).addString(overridable.getName()), sourceLine); return false; } callerConstructors.put(callee, new CallerInfo(constructor, sourceLine)); @@ -240,7 +240,7 @@ private boolean checkAndRecordCallFromClone(XMethod clone, XMethod callee, if (overridable != null) { bugAccumulator.accumulateBug(new BugInstance(this, "MC_OVERRIDABLE_METHOD_CALL_IN_CLONE", NORMAL_PRIORITY) - .addClass(this).addMethod(clone).addString(overridable.getName()), sourceLine); + .addClass(this).addMethod(clone).addString(overridable.getName()), sourceLine); return false; } callerClones.put(callee, new CallerInfo(clone, sourceLine)); @@ -252,7 +252,7 @@ private boolean checkAndRecordCallToOverridable(XMethod caller, XMethod overrida if (constructor != null) { bugAccumulator.accumulateBug(new BugInstance(this, "MC_OVERRIDABLE_METHOD_CALL_IN_CONSTRUCTOR", LOW_PRIORITY) - .addClassAndMethod(constructor.method).addString(overridable.getName()), + .addClassAndMethod(constructor.method).addString(overridable.getName()), constructor.sourceLine); } @@ -260,7 +260,7 @@ private boolean checkAndRecordCallToOverridable(XMethod caller, XMethod overrida if (clone != null) { bugAccumulator.accumulateBug(new BugInstance(this, "MC_OVERRIDABLE_METHOD_CALL_IN_CLONE", NORMAL_PRIORITY) - .addClassAndMethod(clone.method).addString(overridable.getName()), clone.sourceLine); + .addClassAndMethod(clone.method).addString(overridable.getName()), clone.sourceLine); } if (constructor != null || clone != null) { @@ -281,7 +281,7 @@ private boolean checkAndRecordCallBetweenNonOverridableMethods(XMethod caller, X if (constructor != null) { bugAccumulator.accumulateBug(new BugInstance(this, "MC_OVERRIDABLE_METHOD_CALL_IN_CONSTRUCTOR", LOW_PRIORITY) - .addClassAndMethod(constructor.method).addString(overridable.getName()), + .addClassAndMethod(constructor.method).addString(overridable.getName()), constructor.sourceLine); } @@ -289,7 +289,7 @@ private boolean checkAndRecordCallBetweenNonOverridableMethods(XMethod caller, X if (clone != null) { bugAccumulator.accumulateBug(new BugInstance(this, "MC_OVERRIDABLE_METHOD_CALL_IN_CLONE", NORMAL_PRIORITY) - .addClassAndMethod(clone.method).addString(overridable.getName()), + .addClassAndMethod(clone.method).addString(overridable.getName()), clone.sourceLine); } diff --git a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindPotentialSecurityCheckBasedOnUntrustedSource.java b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindPotentialSecurityCheckBasedOnUntrustedSource.java index 30ed6750ae9..f73e337b282 100644 --- a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindPotentialSecurityCheckBasedOnUntrustedSource.java +++ b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindPotentialSecurityCheckBasedOnUntrustedSource.java @@ -334,29 +334,29 @@ private boolean isTheSame(CallerInfo inside, CalleeInfo outside, OpcodeStack.Ite private void reportBug(CallPair callPair) { bugAccumulator.accumulateBug(new BugInstance(this, "USC_POTENTIAL_SECURITY_CHECK_BASED_ON_UNTRUSTED_SOURCE", NORMAL_PRIORITY) - .addClassAndMethod(this) - .addSourceLine(this) - .addClass(callPair.outside.calledClass.getClassName()) - .addCalledMethod(callPair.outside.calledClass.getClassName(), - callPair.outside.calledMethod.getName(), callPair.outside.calledMethod.getSignature(), - callPair.outside.calledMethod.isStatic()) - .addSourceLine(callPair.outside.srcLine) - .addSourceLine(callPair.inside.srcLine), this); + .addClassAndMethod(this) + .addSourceLine(this) + .addClass(callPair.outside.calledClass.getClassName()) + .addCalledMethod(callPair.outside.calledClass.getClassName(), + callPair.outside.calledMethod.getName(), callPair.outside.calledMethod.getSignature(), + callPair.outside.calledMethod.isStatic()) + .addSourceLine(callPair.outside.srcLine) + .addSourceLine(callPair.inside.srcLine), this); } private void reportBug(JavaClass cls, XMethod method, SourceLineAnnotation srcLine, CalleeInfo calleInfo, SourceLineAnnotation insideSrcLine) { bugAccumulator.accumulateBug(new BugInstance(this, "USC_POTENTIAL_SECURITY_CHECK_BASED_ON_UNTRUSTED_SOURCE", NORMAL_PRIORITY) - .addClass(cls) - .addMethod(method) - .addSourceLine(srcLine) - .addClass(calleInfo.calledClass.getClassName()) - .addCalledMethod(calleInfo.calledClass.getClassName(), - calleInfo.calledMethod.getName(), calleInfo.calledMethod.getSignature(), - calleInfo.calledMethod.isStatic()) - .addSourceLine(calleInfo.srcLine) - .addSourceLine(insideSrcLine), this); + .addClass(cls) + .addMethod(method) + .addSourceLine(srcLine) + .addClass(calleInfo.calledClass.getClassName()) + .addCalledMethod(calleInfo.calledClass.getClassName(), + calleInfo.calledMethod.getName(), calleInfo.calledMethod.getSignature(), + calleInfo.calledMethod.isStatic()) + .addSourceLine(calleInfo.srcLine) + .addSourceLine(insideSrcLine), this); } @Override diff --git a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindPublicAttributes.java b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindPublicAttributes.java index 3e58bb0f272..1eef1270214 100644 --- a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindPublicAttributes.java +++ b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindPublicAttributes.java @@ -116,7 +116,7 @@ public void sawOpcode(int seen) { bugReporter.reportBug(new BugInstance(this, "PA_PUBLIC_PRIMITIVE_ATTRIBUTE", NORMAL_PRIORITY) - .addClass(this).addField(field).addSourceLine(sla)); + .addClass(this).addField(field).addSourceLine(sla)); writtenFields.add(field); } else if (seen == Const.AASTORE) { XField field = stack.getStackItem(2).getXField(); @@ -141,7 +141,7 @@ public void sawOpcode(int seen) { bugReporter.reportBug(new BugInstance(this, "PA_PUBLIC_ARRAY_ATTRIBUTE", NORMAL_PRIORITY) - .addClass(this).addField(field).addSourceLine(sla)); + .addClass(this).addField(field).addSourceLine(sla)); writtenFields.add(field); } else if (seen == Const.INVOKEINTERFACE || seen == Const.INVOKEVIRTUAL) { XMethod xmo = getXMethodOperand(); @@ -188,7 +188,7 @@ public void sawOpcode(int seen) { bugReporter.reportBug(new BugInstance(this, "PA_PUBLIC_MUTABLE_OBJECT_ATTRIBUTE", NORMAL_PRIORITY) - .addClass(this).addField(field).addSourceLine(sla)); + .addClass(this).addField(field).addSourceLine(sla)); writtenFields.add(field); } } diff --git a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindPuzzlers.java b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindPuzzlers.java index 0e0d89640f2..beb0db67c11 100644 --- a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindPuzzlers.java +++ b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindPuzzlers.java @@ -391,9 +391,9 @@ && getPrevOpcode(1) == Const.IUSHR && !shiftOfNonnegativeValue valueOfConstantArgumentToShift < 0 ? LOW_PRIORITY : (valueOfConstantArgumentToShift == 32 && "hashCode".equals(getMethodName()) ? NORMAL_PRIORITY : HIGH_PRIORITY)) - .addClassAndMethod(this).addInt(valueOfConstantArgumentToShift).describe( - IntAnnotation.INT_SHIFT) - .addValueSource(stack.getStackItem(1), this), this); + .addClassAndMethod(this).addInt(valueOfConstantArgumentToShift).describe( + IntAnnotation.INT_SHIFT) + .addValueSource(stack.getStackItem(1), this), this); } } if (leftHandSide instanceof Integer && ((Integer) leftHandSide) > 0) { diff --git a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindReturnRef.java b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindReturnRef.java index 4a1e231db7c..e2ddbe878cc 100644 --- a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindReturnRef.java +++ b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindReturnRef.java @@ -145,11 +145,11 @@ public void sawOpcode(int seen) { bugAccumulator.accumulateBug( new BugInstance(this, "EI_EXPOSE_STATIC_" + (capture == CaptureKind.BUF ? "BUF2" : "REP2"), capture == CaptureKind.REP ? NORMAL_PRIORITY : LOW_PRIORITY) - .addClassAndMethod(this) - .addReferencedField(this) - .add(LocalVariableAnnotation.getLocalVariableAnnotation(getMethod(), - top.getRegisterNumber(), - getPC(), getPC() - 1)), this); + .addClassAndMethod(this) + .addReferencedField(this) + .add(LocalVariableAnnotation.getLocalVariableAnnotation(getMethod(), + top.getRegisterNumber(), + getPC(), getPC() - 1)), this); } } if (!staticMethod && seen == Const.PUTFIELD && nonPublicFieldOperand() @@ -161,11 +161,11 @@ public void sawOpcode(int seen) { bugAccumulator.accumulateBug( new BugInstance(this, "EI_EXPOSE_" + (capture == CaptureKind.BUF ? "BUF2" : "REP2"), capture == CaptureKind.REP ? NORMAL_PRIORITY : LOW_PRIORITY) - .addClassAndMethod(this) - .addReferencedField(this) - .add(LocalVariableAnnotation.getLocalVariableAnnotation(getMethod(), - top.getRegisterNumber(), - getPC(), getPC() - 1)), this); + .addClassAndMethod(this) + .addReferencedField(this) + .add(LocalVariableAnnotation.getLocalVariableAnnotation(getMethod(), + top.getRegisterNumber(), + getPC(), getPC() - 1)), this); } } @@ -203,8 +203,8 @@ public void sawOpcode(int seen) { bugAccumulator.accumulateBug(new BugInstance(this, (staticMethod ? "MS" : "EI") + "_EXPOSE_" + (isBuf ? "BUF" : "REP"), (isBuf || isArrayClone) ? LOW_PRIORITY : NORMAL_PRIORITY) - .addClassAndMethod(this).addField(field.getClassName(), field.getName(), - field.getSignature(), field.isStatic()), this); + .addClassAndMethod(this).addField(field.getClassName(), field.getName(), + field.getSignature(), field.isStatic()), this); } diff --git a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindUnconditionalWait.java b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindUnconditionalWait.java index 9735571070e..3231f026b11 100644 --- a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindUnconditionalWait.java +++ b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindUnconditionalWait.java @@ -67,7 +67,7 @@ public void sawOpcode(int seen) { if (seen == Const.INVOKEVIRTUAL && "wait".equals(getNameConstantOperand())) { bugReporter.reportBug(new BugInstance(this, "UW_UNCOND_WAIT", "()V".equals(getSigConstantOperand()) ? NORMAL_PRIORITY : LOW_PRIORITY).addClassAndMethod(this) - .addSourceLine(this)); + .addSourceLine(this)); stage = 2; } break; diff --git a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindUseOfNonSerializableValue.java b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindUseOfNonSerializableValue.java index 547110dec82..d555cd98e10 100644 --- a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindUseOfNonSerializableValue.java +++ b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindUseOfNonSerializableValue.java @@ -213,7 +213,7 @@ private void analyzeMethod(ClassContext classContext, Method method) throws CFGB bugAccumulator.accumulateBug(new BugInstance(this, pattern, isSerializable < 0.15 ? HIGH_PRIORITY : isSerializable > 0.5 ? LOW_PRIORITY : NORMAL_PRIORITY) - .addClassAndMethod(methodGen, sourceFile).addType(problem).describe(TypeAnnotation.FOUND_ROLE), + .addClassAndMethod(methodGen, sourceFile).addType(problem).describe(TypeAnnotation.FOUND_ROLE), sourceLineAnnotation); } diff --git a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindUselessControlFlow.java b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindUselessControlFlow.java index 5c928e88af4..08f130f8bc2 100644 --- a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindUselessControlFlow.java +++ b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindUselessControlFlow.java @@ -108,7 +108,7 @@ public void sawOpcode(int seen) { } bugAccumulator.accumulateBug(new BugInstance(this, priority == HIGH_PRIORITY ? "UCF_USELESS_CONTROL_FLOW_NEXT_LINE" : "UCF_USELESS_CONTROL_FLOW", priority) - .addClassAndMethod(this), this); + .addClassAndMethod(this), this); } } } diff --git a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/HugeSharedStringConstants.java b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/HugeSharedStringConstants.java index 391196a786d..e92ab37b57f 100644 --- a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/HugeSharedStringConstants.java +++ b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/HugeSharedStringConstants.java @@ -110,7 +110,7 @@ public void report() { BugInstance bug = new BugInstance(this, "HSC_HUGE_SHARED_STRING_CONSTANT", overhead > 20 * SIZE_OF_HUGE_CONSTANT ? HIGH_PRIORITY : (overhead > 8 * SIZE_OF_HUGE_CONSTANT ? NORMAL_PRIORITY : LOW_PRIORITY)).addClass(className) - .addField(field).addInt(length).addInt(occursIn.size()).describe(IntAnnotation.INT_OCCURRENCES); + .addField(field).addInt(length).addInt(occursIn.size()).describe(IntAnnotation.INT_OCCURRENCES); for (String c : occursIn) { if (!c.equals(className)) { bug.addClass(c); diff --git a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/InefficientIndexOf.java b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/InefficientIndexOf.java index a86da3f484d..38d6a316588 100644 --- a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/InefficientIndexOf.java +++ b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/InefficientIndexOf.java @@ -77,7 +77,7 @@ public void sawOpcode(int seen) { if (o != null && ((String) o).length() == 1) { bugReporter.reportBug(new BugInstance(this, lastIndexOf ? "IIO_INEFFICIENT_LAST_INDEX_OF" : "IIO_INEFFICIENT_INDEX_OF", LOW_PRIORITY).addClassAndMethod(this) - .describe(StringAnnotation.STRING_MESSAGE).addCalledMethod(this).addSourceLine(this)); + .describe(StringAnnotation.STRING_MESSAGE).addCalledMethod(this).addSourceLine(this)); } } } diff --git a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/InvalidJUnitTest.java b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/InvalidJUnitTest.java index b53828406c3..e55f2cda9a5 100644 --- a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/InvalidJUnitTest.java +++ b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/InvalidJUnitTest.java @@ -196,7 +196,7 @@ public void visit(Code obj) { if (superCode != null && superCode.getCode().length > 3) { bugReporter.reportBug(new BugInstance(this, getMethodName().equals("setUp") ? "IJU_SETUP_NO_SUPER" : "IJU_TEARDOWN_NO_SUPER", NORMAL_PRIORITY).addClassAndMethod(this).addMethod(we, superMethod) - .describe(MethodAnnotation.METHOD_OVERRIDDEN).addSourceLine(this, offset)); + .describe(MethodAnnotation.METHOD_OVERRIDDEN).addSourceLine(this, offset)); } } } diff --git a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/LazyInit.java b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/LazyInit.java index 1f921cbf668..3694417c2d9 100644 --- a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/LazyInit.java +++ b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/LazyInit.java @@ -372,7 +372,7 @@ public void reportMatch(ClassContext classContext, Method method, ByteCodePatter String sourceFile = javaClass.getSourceFileName(); bugReporter.reportBug(new BugInstance(this, sawGetStaticAfterPutStatic ? "LI_LAZY_INIT_UPDATE_STATIC" : "LI_LAZY_INIT_STATIC", priority).addClassAndMethod(methodGen, sourceFile).addField(xfield) - .describe("FIELD_ON").addSourceLine(classContext, methodGen, sourceFile, start, end)); + .describe("FIELD_ON").addSourceLine(classContext, methodGen, sourceFile, start, end)); reported.set(testInstructionHandle.getPosition()); } diff --git a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/MethodReturnCheck.java b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/MethodReturnCheck.java index 5fbb3aded3a..0aa9316bdf0 100644 --- a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/MethodReturnCheck.java +++ b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/MethodReturnCheck.java @@ -102,7 +102,7 @@ public void visitAfter(Code code) { // it's likely that UC_USELESS_VOID_METHOD is just the consequence of the previous report bugAccumulator.accumulateBug(new BugInstance(this, "UC_USELESS_VOID_METHOD", code.getCode().length > 40 ? HIGH_PRIORITY : code.getCode().length > 15 ? NORMAL_PRIORITY : LOW_PRIORITY) - .addClassAndMethod(getMethodDescriptor()), this); + .addClassAndMethod(getMethodDescriptor()), this); } sawExcludedNSECall = false; bugAccumulator.reportAccumulatedBugs(); diff --git a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/MultithreadedInstanceAccess.java b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/MultithreadedInstanceAccess.java index 12a3827bccb..411d22a829f 100644 --- a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/MultithreadedInstanceAccess.java +++ b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/MultithreadedInstanceAccess.java @@ -178,9 +178,9 @@ public void sawField() { bugReporter.reportBug(new BugInstance(this, STRUTS_ACTION_NAME.equals(mtClassName) ? "MTIA_SUSPECT_STRUTS_INSTANCE_FIELD" : "MTIA_SUSPECT_SERVLET_INSTANCE_FIELD", LOW_PRIORITY) - .addField( - new FieldAnnotation(getDottedClassName(), nameCons.getBytes(), typeCons.getBytes(), - false)).addClass(this).addSourceLine(this)); + .addField( + new FieldAnnotation(getDottedClassName(), nameCons.getBytes(), typeCons.getBytes(), + false)).addClass(this).addSourceLine(this)); } break; } diff --git a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/Naming.java b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/Naming.java index 6a86183581e..8c0cd1902da 100644 --- a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/Naming.java +++ b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/Naming.java @@ -431,7 +431,7 @@ public void visit(Field obj) { if (badFieldName(obj)) { bugReporter.reportBug(new BugInstance(this, "NM_FIELD_NAMING_CONVENTION", classIsPublicOrProtected && (obj.isPublic() || obj.isProtected()) && !hasBadFieldNames ? NORMAL_PRIORITY : LOW_PRIORITY) - .addClass(this).addVisitedField(this)); + .addClass(this).addVisitedField(this)); } } @@ -542,7 +542,7 @@ public void visit(Method obj) { } else if (badMethodName(mName)) { bugReporter.reportBug(new BugInstance(this, "NM_METHOD_NAMING_CONVENTION", classIsPublicOrProtected && (obj.isPublic() || obj.isProtected()) && !hasBadMethodNames ? NORMAL_PRIORITY : LOW_PRIORITY) - .addClassAndMethod(this)); + .addClassAndMethod(this)); } if (obj.isAbstract()) { diff --git a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/PermissionsSuper.java b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/PermissionsSuper.java index 17aec737f13..96c5fa9ac27 100644 --- a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/PermissionsSuper.java +++ b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/PermissionsSuper.java @@ -92,7 +92,7 @@ public void sawOpcode(int seen) { } bugAccumulator.accumulateBug(new BugInstance(this, "PERM_SUPER_NOT_CALLED_IN_GETPERMISSIONS", NORMAL_PRIORITY) - .addClassAndMethod(this), this); + .addClassAndMethod(this), this); } } } diff --git a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/ReadReturnShouldBeChecked.java b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/ReadReturnShouldBeChecked.java index 9f7d5c6d1a7..44dd6007b3a 100644 --- a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/ReadReturnShouldBeChecked.java +++ b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/ReadReturnShouldBeChecked.java @@ -154,8 +154,8 @@ && isInputStream()) { accumulator.accumulateBug( new BugInstance(this, "SR_NOT_CHECKED", (wasBufferedInputStream ? HIGH_PRIORITY : recentCallToAvailable ? LOW_PRIORITY : NORMAL_PRIORITY)).addClassAndMethod(this) - .addCalledMethod(lastCallClass, lastCallMethod, lastCallSig, false), SourceLineAnnotation - .fromVisitedInstruction(getClassContext(), this, locationOfCall)); + .addCalledMethod(lastCallClass, lastCallMethod, lastCallSig, false), SourceLineAnnotation + .fromVisitedInstruction(getClassContext(), this, locationOfCall)); } } sawRead = false; diff --git a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/ReflectionIncreaseAccessibility.java b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/ReflectionIncreaseAccessibility.java index 14a53910285..fbfd3955048 100644 --- a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/ReflectionIncreaseAccessibility.java +++ b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/ReflectionIncreaseAccessibility.java @@ -74,7 +74,7 @@ public void sawOpcode(int seen) { "()Ljava/lang/Object;".equals(met.getSignature())) { bugAccumulator.accumulateBug(new BugInstance(this, "REFLC_REFLECTION_MAY_INCREASE_ACCESSIBILITY_OF_CLASS", NORMAL_PRIORITY) - .addClassAndMethod(this), this); + .addClassAndMethod(this), this); } else if ("java.lang.Class".equals(cls.getClassName()) && "getDeclaredField".equals(met.getName()) && "(Ljava/lang/String;)Ljava/lang/reflect/Field;".equals(met.getSignature())) { @@ -86,7 +86,7 @@ public void sawOpcode(int seen) { if (fieldIsFromParam != null && fieldIsFromParam.booleanValue()) { bugAccumulator.accumulateBug(new BugInstance(this, "REFLF_REFLECTION_MAY_INCREASE_ACCESSIBILITY_OF_FIELD", NORMAL_PRIORITY) - .addClassAndMethod(this), this); + .addClassAndMethod(this), this); } } else if ("java.lang.SecurityManager".equals(cls.getClassName()) && "checkPackageAccess".equals(met.getName()) && diff --git a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/VolatileUsage.java b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/VolatileUsage.java index 6ed958dc08a..fe56bdfc4b6 100644 --- a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/VolatileUsage.java +++ b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/VolatileUsage.java @@ -95,7 +95,7 @@ public void sawOpcode(int seen) { if (seen == Const.PUTFIELD && incrementField.equals(getXFieldOperand())) { bugReporter.reportBug(new BugInstance(this, "VO_VOLATILE_INCREMENT", "J".equals(incrementField.getSignature()) ? Priorities.HIGH_PRIORITY : Priorities.NORMAL_PRIORITY) - .addClassAndMethod(this).addField(incrementField).addSourceLine(this)); + .addClassAndMethod(this).addField(incrementField).addSourceLine(this)); } resetIncrementState(); break; From 09d70e11c95cc3856b0c119150e9ee76c124186a Mon Sep 17 00:00:00 2001 From: Christoph Loy Date: Tue, 10 Oct 2023 00:27:24 +0200 Subject: [PATCH 09/19] Fix release (#2616) --- build.gradle | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index e243cbdf1d2..aa2aba66334 100644 --- a/build.gradle +++ b/build.gradle @@ -110,8 +110,9 @@ createReleaseBody.configure { dependsOn createChecksums doLast { - outputFile.get().asFile.delete() - outputFile << """SpotBugs ${project.version} + File outputAsFile = outputFile.get().asFile + outputAsFile.delete() + outputAsFile << """SpotBugs ${project.version} ### CHANGELOG - https://github.com/spotbugs/spotbugs/blob/${project.version}/CHANGELOG.md @@ -127,7 +128,7 @@ createReleaseBody.configure { }.forEach { def name = it.name.replace(".sha256", "") def hash = it as String[] - outputFile << "| ${ name } | ${hash[0]} |\n" + outputFile.get().asFile << "| ${ name } | ${hash[0]} |\n" } } } From 4083f1f494ac5982796ddb506bcf9ec20b4a17ee Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 11 Oct 2023 17:59:23 -0400 Subject: [PATCH 10/19] fix(deps): update dependency com.google.guava:guava to v32.1.3-jre (#2620) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- spotbugsTestCases/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spotbugsTestCases/build.gradle b/spotbugsTestCases/build.gradle index 9fa81b7cca3..e60a48cc38a 100644 --- a/spotbugsTestCases/build.gradle +++ b/spotbugsTestCases/build.gradle @@ -17,7 +17,7 @@ dependencies { implementation 'jakarta.servlet:jakarta.servlet-api:4.0.4' implementation 'jakarta.ejb:jakarta.ejb-api:3.2.6' implementation 'com.google.code.gson:gson:2.10.1' - implementation 'com.google.guava:guava:32.1.2-jre' + implementation 'com.google.guava:guava:32.1.3-jre' implementation libs.guice implementation libs.guice.assistedinject implementation libs.guice.servlet From b6fd746709f05e0198bc28e983c215c3e5d9baf7 Mon Sep 17 00:00:00 2001 From: Jeremy Landis Date: Wed, 11 Oct 2023 20:03:48 -0400 Subject: [PATCH 11/19] Migrate to full junit 5 and add some associated code expected to support junit 5 - fixes #2596 (#2605) * [junit5] Convert to junit 5 * [junit] Apply junit 5 to code that handles junit 3/4 Discovered 'DontAssertInstanceofInTests' when upgrading to junit 5. The others seem to imply same need. While 'TestaseDetector' probably is a no-op, its better to mention both. The dumbMethods seems to need the same check or would benefit. And finally just noting on FindNullDeref that its not needed for junit 5 given junit 5 doesn't do it that way. * [ci] Update change log for junit 5 upgrade * [ci] Update PR on changelog for junit5 * [tests] Per review, cleanup rest of left over publics from tests in other packages * [tests] Add handling around our packaged java tests for java11 or better, add flag to ignore java 8 for java17 or better, add flag to ignore java 8/11 for test that seen failing with java 11, add ignore on java 8/11 Note: We are going to explore showing still building with java 8 separately so this preps based on our coding style here. It does not mean java 8 will work. Further, the reason we are doing this effort is for contributors so they are not scared away by not having a java version to use to test as many are stuck at various points and we get more engagement from developers if they are not so limited. That is a separate effort bot noting as the PR itself has comments in this regard. * [ci] formatting --- CHANGELOG.md | 7 + eclipsePlugin-junit/build.gradle | 2 +- .../ThrottledProgressMonitorTest.java | 8 +- eclipsePlugin-test/build.gradle | 1 + ...tractCreateSuperCallResolutionExample.java | 12 +- .../actions/test/ContextMenuActionsTest.java | 26 ++-- .../actions/test/GroupByActionTest.java | 30 ++-- .../builder/test/FindBugsWorkerTest.java | 26 ++-- .../builder/test/ResourceUtilsTest.java | 28 ++-- .../decorator/test/LabelDecoratorTest.java | 22 +-- .../FindbugsPropertyPageTestSubclass.java | 16 +- .../properties/test/PropertiesPageTest.java | 56 +++---- .../findbugs/quickfix/test/QuickfixMulti.java | 19 ++- .../findbugs/quickfix/test/QuickfixTest.java | 43 +++--- .../quickfix/test/QuickfixWithJUnitTest.java | 19 +-- .../findbugs/reporter/test/JdtUtilTest.java | 29 ++-- .../reporter/test/MarkerUtilTest.java | 37 ++--- .../findbugs/test/AbstractPluginTest.java | 20 +-- .../findbugs/test/AbstractQuickfixTest.java | 26 ++-- .../explorer/test/FilterBugsDialogTest.java | 31 ++-- .../view/explorer/test/TestBugGroup.java | 10 +- .../test/AbstractBugExplorerViewTest.java | 12 +- .../view/test/BugExplorerViewTest.java | 29 ++-- .../BugExplorerViewTwoSrcFoldersTest.java | 21 +-- .../view/test/ExpectedViewBugGroup.java | 16 +- .../view/test/ExpectedViewMarker.java | 6 +- .../view/test/FindBugsPerspectiveTest.java | 27 ++-- .../jdt/testplugin/JavaProjectHelper.java | 6 +- spotbugs-ant/build.gradle | 2 +- .../cs/findbugs/anttask/FindBugsTaskTest.java | 17 ++- .../cs/findbugs/anttask/UnionBugs2Test.java | 15 +- spotbugs-tests/build.gradle | 6 +- .../cs/findbugs/AbstractBugReporterTest.java | 26 ++-- .../cs/findbugs/AbstractIntegrationTest.java | 6 +- .../BugCollectionBugReporterTest.java | 9 +- .../edu/umd/cs/findbugs/BugInstanceTest.java | 60 ++++---- .../edu/umd/cs/findbugs/BugRankerTest.java | 9 +- .../findbugs/BugReporterDispatcherTest.java | 21 ++- .../umd/cs/findbugs/ClassScreenerTest.java | 58 +++---- .../edu/umd/cs/findbugs/CommandLineTest.java | 16 +- .../CurrentThreadExecutorServiceTest.java | 29 ++-- .../edu/umd/cs/findbugs/DetectorsTest.java | 46 +++--- .../ErrorCountingBugReporterTest.java | 9 +- .../edu/umd/cs/findbugs/FindBugsTestCase.java | 3 +- .../umd/cs/findbugs/IntAnnotationTest.java | 8 +- .../umd/cs/findbugs/JUnitDetectorAdapter.java | 1 - .../edu/umd/cs/findbugs/JavaVersionTest.java | 8 +- .../edu/umd/cs/findbugs/ObfuscateTest.java | 12 +- .../umd/cs/findbugs/OpcodeStackItemTest.java | 22 +-- .../findbugs/SAXBugCollectionHandlerTest.java | 30 ++-- .../findbugs/SynchronizedBugReporterTest.java | 10 +- .../cs/findbugs/TextUICommandLineTest.java | 14 +- .../VersionInsensitiveBugComparatorTest.java | 26 ++-- .../umd/cs/findbugs/XDocsBugReporterTest.java | 8 +- .../edu/umd/cs/findbugs/ba/FrameTest.java | 6 +- .../edu/umd/cs/findbugs/ba/Issue1254Test.java | 24 +-- .../edu/umd/cs/findbugs/ba/Issue1338Test.java | 12 +- .../edu/umd/cs/findbugs/ba/Issue1367Test.java | 18 ++- .../edu/umd/cs/findbugs/ba/Issue1464Test.java | 6 +- .../edu/umd/cs/findbugs/ba/Issue2145Test.java | 6 +- .../edu/umd/cs/findbugs/ba/Issue2402Test.java | 6 +- .../edu/umd/cs/findbugs/ba/Issue371Test.java | 6 +- .../edu/umd/cs/findbugs/ba/Issue389Test.java | 6 +- .../edu/umd/cs/findbugs/ba/Issue390Test.java | 8 +- .../edu/umd/cs/findbugs/ba/Issue408Test.java | 37 ++--- .../edu/umd/cs/findbugs/ba/Issue413Test.java | 6 +- .../edu/umd/cs/findbugs/ba/Issue429Test.java | 14 +- .../edu/umd/cs/findbugs/ba/Issue516Test.java | 6 +- .../edu/umd/cs/findbugs/ba/Issue527Test.java | 8 +- .../edu/umd/cs/findbugs/ba/Issue547Test.java | 8 +- .../edu/umd/cs/findbugs/ba/Issue688Test.java | 6 +- .../edu/umd/cs/findbugs/ba/Issue758Test.java | 6 +- .../edu/umd/cs/findbugs/ba/Issue893Test.java | 6 +- .../umd/cs/findbugs/ba/MethodHashTest.java | 48 +++--- .../findbugs/ba/NullnessAnnotationTest.java | 63 ++++---- .../cs/findbugs/ba/SignatureParserTest.java | 42 +++--- .../umd/cs/findbugs/ba/ch/Subtypes2Test.java | 142 ++++++++++-------- .../generic/GenericSignatureParserTest.java | 20 +-- .../ba/generic/GenericUtilitiesTest.java | 28 ++-- .../ba/generic/TestGenericObjectType.java | 26 ++-- .../cs/findbugs/ba/npe/IsNullValueTest.java | 26 ++-- .../ba/npe/NonNullParamPropertyTest.java | 46 +++--- .../findbugs/ba/npe/ReturnPathTypeTest.java | 62 ++++---- .../ba/type/TypeFrameModelingVisitorTest.java | 10 +- .../classfile/TestClassDescriptor.java | 8 +- .../classfile/impl/ClassFactoryTest.java | 36 ++--- .../classfile/impl/ClassPathBuilderTest.java | 21 ++- .../cs/findbugs/config/CommandLineTest.java | 14 +- .../config/ProjectFilterSettingsTest.java | 88 +++++------ .../findbugs/config/UserPreferencesTest.java | 28 ++-- .../cs/findbugs/cwe/WeaknessCatalogTest.java | 24 +-- .../findbugs/detect/ConstructorThrowTest.java | 59 ++++---- .../DontReusePublicIdentifiersTest.java | 21 +-- .../DontUseFloatsAsLoopCountersTest.java | 7 +- .../detect/FindArgumentAssertionsTest.java | 7 +- .../FindAssertionsWithSideEffectsTest.java | 7 +- .../detect/FindBadEndOfStreamCheckTest.java | 9 +- ...stanceLockOnSharedStaticDataCheckTest.java | 14 +- .../detect/FindNonShortCircuitTest.java | 27 ++-- .../detect/FindOverridableMethodCallTest.java | 49 +++--- ...curityCheckBasedOnUntrustedSourceTest.java | 6 +- .../detect/FindPublicAttributesTest.java | 9 +- .../findbugs/detect/FindSqlInjectionTest.java | 12 +- .../detect/FindUnsatisfiedObligationTest.java | 16 +- ...indVulnerableSecurityCheckMethodsTest.java | 53 +++---- .../cs/findbugs/detect/IncompatMaskTest.java | 10 +- ...mparisonInstanceOfPatternMatchingTest.java | 25 ++- .../umd/cs/findbugs/detect/Issue1472Test.java | 7 +- .../umd/cs/findbugs/detect/Issue1498Test.java | 7 +- .../umd/cs/findbugs/detect/Issue1518Test.java | 7 +- .../umd/cs/findbugs/detect/Issue1539Test.java | 37 +++-- .../umd/cs/findbugs/detect/Issue1642Test.java | 7 +- .../umd/cs/findbugs/detect/Issue1759Test.java | 7 +- .../umd/cs/findbugs/detect/Issue1764Test.java | 9 +- .../umd/cs/findbugs/detect/Issue1765Test.java | 7 +- .../umd/cs/findbugs/detect/Issue1771Test.java | 20 +-- .../umd/cs/findbugs/detect/Issue2019Test.java | 6 +- .../umd/cs/findbugs/detect/Issue2114Test.java | 12 +- .../umd/cs/findbugs/detect/Issue2120Test.java | 20 +-- .../umd/cs/findbugs/detect/Issue2142Test.java | 7 +- .../umd/cs/findbugs/detect/Issue2147Test.java | 7 +- .../umd/cs/findbugs/detect/Issue2182Test.java | 20 +-- .../umd/cs/findbugs/detect/Issue2183Test.java | 20 +-- .../umd/cs/findbugs/detect/Issue2184Test.java | 20 +-- .../umd/cs/findbugs/detect/Issue2331Test.java | 6 +- .../umd/cs/findbugs/detect/Issue2370Test.java | 34 ++--- .../umd/cs/findbugs/detect/Issue2436Test.java | 6 +- .../umd/cs/findbugs/detect/Issue2465Test.java | 7 +- .../umd/cs/findbugs/detect/Issue2547Test.java | 7 +- .../umd/cs/findbugs/detect/Issue2552Test.java | 13 +- .../umd/cs/findbugs/detect/Issue374Test.java | 7 +- .../umd/cs/findbugs/detect/Issue463Test.java | 9 +- .../umd/cs/findbugs/detect/Issue484Test.java | 7 +- .../umd/cs/findbugs/detect/Issue500Test.java | 6 +- .../umd/cs/findbugs/detect/Issue560Test.java | 10 +- .../umd/cs/findbugs/detect/Issue582Test.java | 9 +- .../umd/cs/findbugs/detect/Issue595Test.java | 20 +-- .../umd/cs/findbugs/detect/Issue603Test.java | 7 +- .../umd/cs/findbugs/detect/Issue744Test.java | 6 +- .../umd/cs/findbugs/detect/Issue79Test.java | 6 +- .../umd/cs/findbugs/detect/Issue872Test.java | 10 +- .../OverridingMethodMustInvokeSuperTest.java | 6 +- ...sCheckNotNullCanIgnoreReturnValueTest.java | 14 +- ...ntOverwriteOfExternalizableObjectTest.java | 18 +-- .../detect/RegressionIdeas20110722Test.java | 7 +- .../detect/ResolveMethodReferencesTest.java | 14 +- ...ronizationOnSharedBuiltinConstantTest.java | 18 +-- .../umd/cs/findbugs/detect/TestASMTest.java | 7 +- .../detect/ThrowingExceptionsTest.java | 9 +- .../cs/findbugs/detect/UnreadFieldsTest.java | 32 ++-- .../filter/AnnotationMatcherTest.java | 43 +++--- .../umd/cs/findbugs/filter/NameMatchTest.java | 15 +- .../cs/findbugs/filter/NotMatcherTest.java | 29 ++-- .../cs/findbugs/filter/RelationalOpTest.java | 20 ++- .../cs/findbugs/filter/SignatureUtilTest.java | 11 +- .../cs/findbugs/filter/SourceMatcherTest.java | 40 ++--- .../cs/findbugs/gui2/FilterFactoryTest.java | 24 +-- .../umd/cs/findbugs/gui2/SaveTypeTest.java | 8 +- .../FindNullDerefIntegrationTest.java | 8 +- .../SlashedClassNameTest.java | 14 +- .../java/edu/umd/cs/findbugs/io/IOTest.java | 22 +-- .../umd/cs/findbugs/jaif/JAIFScannerTest.java | 28 ++-- .../cs/findbugs/log/ProfileSummaryTest.java | 10 +- .../ml/SplitCamelCaseIdentifierTest.java | 22 +-- .../nullness/AndroidNullabilityTest.java | 28 ++-- .../nullness/AvroNullabilityTest.java | 16 +- .../cs/findbugs/nullness/Issue1338Test.java | 14 +- .../cs/findbugs/nullness/Issue259Test.java | 14 +- .../cs/findbugs/nullness/Issue600Test.java | 38 ++--- .../TestCheckerFrameworkTypeAnnotations.java | 29 ++-- .../sarif/BugCollectionAnalyserTest.java | 13 +- .../cs/findbugs/sarif/GUIDCalculatorTest.java | 13 +- .../edu/umd/cs/findbugs/sarif/LevelTest.java | 23 +-- .../cs/findbugs/sarif/PlaceholderTest.java | 19 +-- .../findbugs/sarif/SarifBugReporterTest.java | 43 +++--- .../umd/cs/findbugs/util/ClassNameTest.java | 69 +++++---- .../cs/findbugs/util/MutableClassesTest.java | 60 ++++---- .../edu/umd/cs/findbugs/util/StringsTest.java | 24 +-- .../visitclass/DismantleBytecodeTest.java | 8 +- .../visitclass/GetNumberArgumentsTest.java | 16 +- .../visitclass/PreorderVisitorTest.java | 8 +- .../cs/findbugs/workflow/FindSeqNumTest.java | 55 +++---- .../findbugs/workflow/UnionResultsTest.java | 13 +- .../umd/cs/findbugs/ba/TestCaseDetector.java | 4 +- .../detect/DontAssertInstanceofInTests.java | 6 +- .../umd/cs/findbugs/detect/DumbMethods.java | 4 +- .../umd/cs/findbugs/detect/FindNullDeref.java | 1 + spotbugsTestCases/build.gradle | 2 +- .../src/java/bugIdeas/Ideas_2008_08_11.java | 27 ++-- .../src/java/bugIdeas/Ideas_2008_11_14.java | 16 +- .../src/java/bugIdeas/Ideas_2009_04_09.java | 8 +- .../src/java/bugIdeas/Ideas_2009_10_29.java | 4 +- .../src/java/bugIdeas/Ideas_2010_01_22.java | 15 +- .../src/java/bugIdeas/Ideas_2010_04_29.java | 4 +- .../src/java/bugIdeas/Ideas_2011_04_24.java | 19 ++- .../src/java/ghIssues/Issue390.java | 2 +- .../src/java/sfBugs/Bug2136033.java | 2 +- .../src/java/sfBugs/Bug2707502.java | 10 +- .../src/java/sfBugs/Bug3474679.java | 2 +- .../umd/cs/findbugs/test/SpotBugsRunner.java | 28 +++- test-harness/build.gradle | 7 +- .../umd/cs/findbugs/test/CountMatcher.java | 2 - .../umd/cs/findbugs/test/SpotBugsRule.java | 110 -------------- .../test/service/ClassFileLocator.java | 10 +- 204 files changed, 1939 insertions(+), 1970 deletions(-) delete mode 100644 test-harness/src/main/java/edu/umd/cs/findbugs/test/SpotBugsRule.java diff --git a/CHANGELOG.md b/CHANGELOG.md index ec72e8f984c..25d57ee744b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -74,6 +74,13 @@ Currently the versioning policy of this project follows [Semantic Versioning v2. - Delete checked in j2ee jar and instead use servlet/ejb apis from jakarta (javax standard) ([#2585](https://github.com/spotbugs/spotbugs/pull/2585)) - Bump Eclipse from 4.14 to 4.29 (latest) ([#2589](https://github.com/spotbugs/spotbugs/pull/2589)) - Cleanup hamcrest imports / used library ([#2600](https://github.com/spotbugs/spotbugs/pull/2600)) +- Migrate entirely to junit 5 ([#2605](https://github.com/spotbugs/spotbugs/pull/2605)) + - Some parts of codebase were junit 3 + - Delete the SpotbugsRule + - Replace custom java determination on build with Junit 5 usage + - Various 'public' methods in tests fixed to 'private' + - Junit 5 styling applied throughout + - Add missing code to the SpotBugsRunner and now use the Extension as replacement of SpotbugsRule ## 4.7.3 - 2022-10-15 ### Fixed diff --git a/eclipsePlugin-junit/build.gradle b/eclipsePlugin-junit/build.gradle index 97ca15fd50f..ff9fdff2424 100644 --- a/eclipsePlugin-junit/build.gradle +++ b/eclipsePlugin-junit/build.gradle @@ -11,7 +11,7 @@ tasks.named('compileJava', JavaCompile).configure { dependencies { implementation project(':eclipsePlugin') - testImplementation 'org.junit.vintage:junit-vintage-engine:5.10.0' + testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.10.0' testImplementation 'org.mockito:mockito-core:5.6.0' } diff --git a/eclipsePlugin-junit/src/test/java/de/tobject/findbugs/reporter/ThrottledProgressMonitorTest.java b/eclipsePlugin-junit/src/test/java/de/tobject/findbugs/reporter/ThrottledProgressMonitorTest.java index d15139a13bb..2a140953d5e 100644 --- a/eclipsePlugin-junit/src/test/java/de/tobject/findbugs/reporter/ThrottledProgressMonitorTest.java +++ b/eclipsePlugin-junit/src/test/java/de/tobject/findbugs/reporter/ThrottledProgressMonitorTest.java @@ -5,11 +5,11 @@ import static org.mockito.Mockito.verify; import org.eclipse.core.runtime.IProgressMonitor; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class ThrottledProgressMonitorTest { +class ThrottledProgressMonitorTest { @Test - public void testSetTaskName() { + void testSetTaskName() { Clock clock = new Clock(); IProgressMonitor delegate = spy(IProgressMonitor.class); ThrottledProgressMonitor throttled = new ThrottledProgressMonitor(delegate, clock::getCurrentTime); @@ -26,7 +26,7 @@ public void testSetTaskName() { } @Test - public void testWorked() { + void testWorked() { Clock clock = new Clock(); IProgressMonitor delegate = spy(IProgressMonitor.class); ThrottledProgressMonitor throttled = new ThrottledProgressMonitor(delegate, clock::getCurrentTime); diff --git a/eclipsePlugin-test/build.gradle b/eclipsePlugin-test/build.gradle index ae65c60d715..57eed2c2ba6 100644 --- a/eclipsePlugin-test/build.gradle +++ b/eclipsePlugin-test/build.gradle @@ -26,6 +26,7 @@ dependencies { } implementation project(':test-harness') + implementation 'org.junit.jupiter:junit-jupiter-engine:5.10.0' implementation 'org.apache.ant:ant:1.10.14' } diff --git a/eclipsePlugin-test/quickfixScenario/AbstractCreateSuperCallResolutionExample.java b/eclipsePlugin-test/quickfixScenario/AbstractCreateSuperCallResolutionExample.java index 621d57a17be..4685c79c226 100644 --- a/eclipsePlugin-test/quickfixScenario/AbstractCreateSuperCallResolutionExample.java +++ b/eclipsePlugin-test/quickfixScenario/AbstractCreateSuperCallResolutionExample.java @@ -1,17 +1,19 @@ -import junit.framework.TestCase; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; -public abstract class AbstractCreateSuperCallResolutionExample extends TestCase { - @Override +public abstract class AbstractCreateSuperCallResolutionExample { + @AfterAll protected void finalize() throws Throwable { this.toString(); } - @Override + @BeforeEach protected void setUp() throws Exception { this.toString(); } - @Override + @AfterEach protected void tearDown() throws Exception { this.toString(); } diff --git a/eclipsePlugin-test/src/de/tobject/findbugs/actions/test/ContextMenuActionsTest.java b/eclipsePlugin-test/src/de/tobject/findbugs/actions/test/ContextMenuActionsTest.java index d170071410f..f49207af6da 100644 --- a/eclipsePlugin-test/src/de/tobject/findbugs/actions/test/ContextMenuActionsTest.java +++ b/eclipsePlugin-test/src/de/tobject/findbugs/actions/test/ContextMenuActionsTest.java @@ -18,16 +18,16 @@ */ package de.tobject.findbugs.actions.test; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.File; import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.ui.IActionDelegate; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import de.tobject.findbugs.FindbugsPlugin; import de.tobject.findbugs.actions.ClearMarkersAction; @@ -40,14 +40,14 @@ * * @author Tomás Pollak */ -public class ContextMenuActionsTest extends AbstractFindBugsTest { - @BeforeClass - public static void setUpClass() throws Exception { +class ContextMenuActionsTest extends AbstractFindBugsTest { + @BeforeAll + static void setUpClass() throws Exception { setUpTestProject(TestScenario.DEFAULT); } - @AfterClass - public static void tearDownClass() throws CoreException { + @AfterAll + static void tearDownClass() throws CoreException { tearDownTestProject(); } @@ -67,7 +67,7 @@ public void tearDown() throws CoreException { } @Test - public void testClearFindBugs() throws CoreException { + void testClearFindBugs() throws CoreException { assertNoBugs(); StructuredSelection selection = new StructuredSelection(getProject()); @@ -89,7 +89,7 @@ public void testClearFindBugs() throws CoreException { } @Test - public void testLoadXML() throws CoreException { + void testLoadXML() throws CoreException { assertNoBugs(); StructuredSelection selection = new StructuredSelection(getProject()); @@ -103,7 +103,7 @@ public void testLoadXML() throws CoreException { } @Test - public void testRunFindBugs() throws CoreException { + void testRunFindBugs() throws CoreException { assertNoBugs(); StructuredSelection selection = new StructuredSelection(getProject()); @@ -117,7 +117,7 @@ public void testRunFindBugs() throws CoreException { } @Test - public void testSaveXML() throws CoreException { + void testSaveXML() throws CoreException { assertNoBugs(); work(createFindBugsWorker()); assertExpectedBugs(); diff --git a/eclipsePlugin-test/src/de/tobject/findbugs/actions/test/GroupByActionTest.java b/eclipsePlugin-test/src/de/tobject/findbugs/actions/test/GroupByActionTest.java index 145f6bdb10c..9cbb27b6c32 100644 --- a/eclipsePlugin-test/src/de/tobject/findbugs/actions/test/GroupByActionTest.java +++ b/eclipsePlugin-test/src/de/tobject/findbugs/actions/test/GroupByActionTest.java @@ -18,7 +18,7 @@ */ package de.tobject.findbugs.actions.test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.Arrays; import java.util.List; @@ -27,9 +27,9 @@ import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IAction; import org.eclipse.ui.PartInitException; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import de.tobject.findbugs.actions.GroupByAction; import de.tobject.findbugs.test.AbstractFindBugsTest; @@ -41,14 +41,14 @@ * * @author Tomás Pollak */ -public class GroupByActionTest extends AbstractFindBugsTest { - @BeforeClass - public static void setUpClass() throws Exception { +class GroupByActionTest extends AbstractFindBugsTest { + @BeforeAll + static void setUpClass() throws Exception { setUpTestProject(TestScenario.DEFAULT); } - @AfterClass - public static void tearDownClass() throws CoreException { + @AfterAll + static void tearDownClass() throws CoreException { tearDownTestProject(); } @@ -85,7 +85,7 @@ public void tearDown() throws CoreException { } @Test - public void testAction_Priority_Category_Project_Package_Class_PatternType_Pattern_Marker() throws PartInitException { + void testAction_Priority_Category_Project_Package_Class_PatternType_Pattern_Marker() throws PartInitException { runAction(PRIORITY_CATEGORY_PROJECT_PACKAGE_CLASS_PATTERN_TYPE_PATTERN_MARKER_ID); assertExpectedGroupTypes(GroupType.Confidence, GroupType.Category, GroupType.Project, GroupType.Package, GroupType.Class, @@ -93,7 +93,7 @@ public void testAction_Priority_Category_Project_Package_Class_PatternType_Patte } @Test - public void testAction_Priority_Category_Project_PatternType_Pattern_Marker() throws PartInitException { + void testAction_Priority_Category_Project_PatternType_Pattern_Marker() throws PartInitException { runAction(PRIORITY_CATEGORY_PROJECT_PATTERN_TYPE_PATTERN_MARKER_ID); assertExpectedGroupTypes(GroupType.Confidence, GroupType.Category, GroupType.Project, GroupType.PatternType, @@ -101,21 +101,21 @@ public void testAction_Priority_Category_Project_PatternType_Pattern_Marker() th } @Test - public void testAction_Priority_Project_Pattern_Marker() throws PartInitException { + void testAction_Priority_Project_Pattern_Marker() throws PartInitException { runAction(PRIORITY_PROJECT_PATTERN_MARKER_ID); assertExpectedGroupTypes(GroupType.Confidence, GroupType.Project, GroupType.Pattern, GroupType.Marker); } @Test - public void testAction_Project_Pattern_Marker() throws PartInitException { + void testAction_Project_Pattern_Marker() throws PartInitException { runAction(PROJECT_PATTERN_MARKER_ID); assertExpectedGroupTypes(GroupType.Project, GroupType.Pattern, GroupType.Marker); } @Test - public void testAction_Project_Priority_Category_PatternType_Pattern_Marker() throws PartInitException { + void testAction_Project_Priority_Category_PatternType_Pattern_Marker() throws PartInitException { runAction(PROJECT_PRIORITY_CATEGORY_PATTERN_TYPE_PATTERN_MARKER_ID); assertExpectedGroupTypes(GroupType.Project, GroupType.Confidence, GroupType.Category, GroupType.PatternType, @@ -123,7 +123,7 @@ public void testAction_Project_Priority_Category_PatternType_Pattern_Marker() th } @Test - public void testAction_Project_Priority_Pattern_Marker() throws PartInitException { + void testAction_Project_Priority_Pattern_Marker() throws PartInitException { runAction(PROJECT_PRIORITY_PATTERN_MARKER_ID); assertExpectedGroupTypes(GroupType.Project, GroupType.Confidence, GroupType.Pattern, GroupType.Marker); diff --git a/eclipsePlugin-test/src/de/tobject/findbugs/builder/test/FindBugsWorkerTest.java b/eclipsePlugin-test/src/de/tobject/findbugs/builder/test/FindBugsWorkerTest.java index 9068863d779..c6022190be5 100644 --- a/eclipsePlugin-test/src/de/tobject/findbugs/builder/test/FindBugsWorkerTest.java +++ b/eclipsePlugin-test/src/de/tobject/findbugs/builder/test/FindBugsWorkerTest.java @@ -18,15 +18,15 @@ */ package de.tobject.findbugs.builder.test; -import static junit.framework.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; import org.eclipse.jdt.core.JavaModelException; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import de.tobject.findbugs.builder.FindBugsWorker; import de.tobject.findbugs.test.AbstractFindBugsTest; @@ -37,13 +37,13 @@ * * @author Tomás Pollak */ -public class FindBugsWorkerTest extends AbstractFindBugsTest { - @BeforeClass +class FindBugsWorkerTest extends AbstractFindBugsTest { + @BeforeAll public static void setUpClass() throws Exception { setUpTestProject(TestScenario.DEFAULT); } - @AfterClass + @AfterAll public static void tearDownClass() throws CoreException { tearDownTestProject(); } @@ -53,7 +53,7 @@ public static void tearDownClass() throws CoreException { private static final String CLASS_A_WORKSPACE_RELATIVE = TEST_PROJECT + "/" + CLASS_A_PROJECT_RELATIVE; @Test - public void testBaselineBugs() throws CoreException { + void testBaselineBugs() throws CoreException { assertNoBugs(); setBaselineBugsFile(true); @@ -64,7 +64,7 @@ public void testBaselineBugs() throws CoreException { } @Test - public void testFilter() throws CoreException { + void testFilter() throws CoreException { assertNoBugs(); setFilterFile(true); @@ -75,7 +75,7 @@ public void testFilter() throws CoreException { } @Test - public void testGetFilterPath() throws JavaModelException { + void testGetFilterPath() throws JavaModelException { IPath classALocation = getClassA().getResource().getLocation(); assertEquals(classALocation, FindBugsWorker.getFilterPath(classALocation.toOSString(), getProject())); assertEquals(classALocation, FindBugsWorker.getFilterPath(CLASS_A_PROJECT_RELATIVE, getProject())); @@ -84,7 +84,7 @@ public void testGetFilterPath() throws JavaModelException { } @Test - public void testLoadXML() throws CoreException { + void testLoadXML() throws CoreException { assertNoBugs(); loadXml(createFindBugsWorker(), getBugsFileLocation()); @@ -93,7 +93,7 @@ public void testLoadXML() throws CoreException { } @Test - public void testRunFindBugs() throws CoreException { + void testRunFindBugs() throws CoreException { assertNoBugs(); work(createFindBugsWorker()); @@ -102,7 +102,7 @@ public void testRunFindBugs() throws CoreException { } @Test - public void testToFilterPath() throws JavaModelException { + void testToFilterPath() throws JavaModelException { String classALocation = getClassA().getResource().getLocation().toOSString(); assertEquals(new Path(CLASS_A_PROJECT_RELATIVE), FindBugsWorker.toFilterPath(classALocation, getProject())); assertEquals(new Path(CLASS_A_WORKSPACE_RELATIVE), FindBugsWorker.toFilterPath(classALocation, null)); diff --git a/eclipsePlugin-test/src/de/tobject/findbugs/builder/test/ResourceUtilsTest.java b/eclipsePlugin-test/src/de/tobject/findbugs/builder/test/ResourceUtilsTest.java index 1762e9cac93..bdbbf667e89 100644 --- a/eclipsePlugin-test/src/de/tobject/findbugs/builder/test/ResourceUtilsTest.java +++ b/eclipsePlugin-test/src/de/tobject/findbugs/builder/test/ResourceUtilsTest.java @@ -18,9 +18,9 @@ */ package de.tobject.findbugs.builder.test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Arrays; import java.util.Collections; @@ -32,9 +32,9 @@ import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jface.viewers.StructuredSelection; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import de.tobject.findbugs.builder.ResourceUtils; import de.tobject.findbugs.builder.WorkItem; @@ -46,19 +46,19 @@ * * @author Tomás Pollak */ -public class ResourceUtilsTest extends AbstractFindBugsTest { - @BeforeClass - public static void setUpClass() throws Exception { +class ResourceUtilsTest extends AbstractFindBugsTest { + @BeforeAll + static void setUpClass() throws Exception { setUpTestProject(TestScenario.DEFAULT); } - @AfterClass - public static void tearDownClass() throws CoreException { + @AfterAll + static void tearDownClass() throws CoreException { tearDownTestProject(); } @Test - public void testGetResourcesPerProject_selectedClasses() throws JavaModelException { + void testGetResourcesPerProject_selectedClasses() throws JavaModelException { // Select classes A and B List classes = Arrays.asList(getClassA(), getClassB()); Map> resourcesPerProject = ResourceUtils @@ -73,7 +73,7 @@ public void testGetResourcesPerProject_selectedClasses() throws JavaModelExcepti } @Test - public void testGetResourcesPerProject_selectedProject() { + void testGetResourcesPerProject_selectedProject() { // Select the project Map> resourcesPerProject = ResourceUtils.getResourcesPerProject(new StructuredSelection( getProject())); @@ -86,7 +86,7 @@ public void testGetResourcesPerProject_selectedProject() { } @Test - public void testGetResourcesPerProject_selectedProjectAndClasses() throws JavaModelException { + void testGetResourcesPerProject_selectedProjectAndClasses() throws JavaModelException { // Select project and classes A and B List classes = Arrays.asList(getProject(), getClassA(), getClassB()); Map> resourcesPerProject = ResourceUtils diff --git a/eclipsePlugin-test/src/de/tobject/findbugs/decorator/test/LabelDecoratorTest.java b/eclipsePlugin-test/src/de/tobject/findbugs/decorator/test/LabelDecoratorTest.java index f93a439d20b..6005c95479d 100644 --- a/eclipsePlugin-test/src/de/tobject/findbugs/decorator/test/LabelDecoratorTest.java +++ b/eclipsePlugin-test/src/de/tobject/findbugs/decorator/test/LabelDecoratorTest.java @@ -18,13 +18,13 @@ */ package de.tobject.findbugs.decorator.test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import org.eclipse.core.runtime.CoreException; import org.eclipse.jdt.core.JavaModelException; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import de.tobject.findbugs.decorators.ResourceBugCountDecorator; import de.tobject.findbugs.test.AbstractFindBugsTest; @@ -35,21 +35,21 @@ * * @author Tomás Pollak */ -public class LabelDecoratorTest extends AbstractFindBugsTest { - @BeforeClass - public static void setUpClass() throws Exception { +class LabelDecoratorTest extends AbstractFindBugsTest { + @BeforeAll + static void setUpClass() throws Exception { setUpTestProject(TestScenario.DEFAULT); } - @AfterClass - public static void tearDownClass() throws CoreException { + @AfterAll + static void tearDownClass() throws CoreException { tearDownTestProject(); } private static final String SOME_LABEL = "label"; @Test - public void testDecorateResourcesWithBugs() throws CoreException { + void testDecorateResourcesWithBugs() throws CoreException { loadXml(createFindBugsWorker(), getBugsFileLocation()); // Class 'A' has no visible bugs @@ -66,7 +66,7 @@ public void testDecorateResourcesWithBugs() throws CoreException { } @Test - public void testDecorateResourcesWithoutBugs() throws JavaModelException { + void testDecorateResourcesWithoutBugs() throws JavaModelException { // Class 'A' doTestDecoratorWithoutBugs(getClassA()); diff --git a/eclipsePlugin-test/src/de/tobject/findbugs/properties/test/FindbugsPropertyPageTestSubclass.java b/eclipsePlugin-test/src/de/tobject/findbugs/properties/test/FindbugsPropertyPageTestSubclass.java index 3a9a4f7ade8..51630316028 100644 --- a/eclipsePlugin-test/src/de/tobject/findbugs/properties/test/FindbugsPropertyPageTestSubclass.java +++ b/eclipsePlugin-test/src/de/tobject/findbugs/properties/test/FindbugsPropertyPageTestSubclass.java @@ -20,7 +20,7 @@ import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.TabFolder; -import org.junit.Assert; +import org.junit.jupiter.api.Assertions; import de.tobject.findbugs.properties.DetectorConfigurationTab; import de.tobject.findbugs.properties.FilterFilesTab; @@ -58,9 +58,9 @@ public void assertProjectControlsVisible(boolean expectsProject) { boolean chkEnableProjectVisible = getEnableProjectCheck() != null; boolean hasProject = getProject() != null; - Assert.assertTrue(expectsProject == hasProject); - Assert.assertTrue(expectsProject == chkEnableFindBugsVisible); - Assert.assertTrue(expectsProject == chkEnableProjectVisible); + Assertions.assertTrue(expectsProject == hasProject); + Assertions.assertTrue(expectsProject == chkEnableFindBugsVisible); + Assertions.assertTrue(expectsProject == chkEnableProjectVisible); } /** @@ -73,10 +73,10 @@ public void assertProjectControlsVisible(boolean expectsProject) { * true if the controls should be enabled, false otherwise */ public void assertProjectSettingsEnabled(boolean enabled) { - Assert.assertEquals(enabled, getDetectorTab().isEnabled()); - Assert.assertEquals(enabled, getReportTab().isEnabled()); - Assert.assertEquals(enabled, getFilterTab().isEnabled()); - Assert.assertEquals(enabled, getEffortViewer().getCombo().isEnabled()); + Assertions.assertEquals(enabled, getDetectorTab().isEnabled()); + Assertions.assertEquals(enabled, getReportTab().isEnabled()); + Assertions.assertEquals(enabled, getFilterTab().isEnabled()); + Assertions.assertEquals(enabled, getEffortViewer().getCombo().isEnabled()); } public void enableFindBugs(boolean enable) { diff --git a/eclipsePlugin-test/src/de/tobject/findbugs/properties/test/PropertiesPageTest.java b/eclipsePlugin-test/src/de/tobject/findbugs/properties/test/PropertiesPageTest.java index 225de3b8e70..bfce442cdcf 100644 --- a/eclipsePlugin-test/src/de/tobject/findbugs/properties/test/PropertiesPageTest.java +++ b/eclipsePlugin-test/src/de/tobject/findbugs/properties/test/PropertiesPageTest.java @@ -18,10 +18,10 @@ */ package de.tobject.findbugs.properties.test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Iterator; import java.util.Map; @@ -30,9 +30,9 @@ import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.PlatformUI; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import de.tobject.findbugs.FindbugsPlugin; import de.tobject.findbugs.properties.FindbugsPropertyPage.Effort; @@ -48,14 +48,14 @@ * * @author Tomás Pollak */ -public class PropertiesPageTest extends AbstractFindBugsTest { - @BeforeClass - public static void setUpClass() throws Exception { +class PropertiesPageTest extends AbstractFindBugsTest { + @BeforeAll + static void setUpClass() throws Exception { setUpTestProject(TestScenario.DEFAULT); } - @AfterClass - public static void tearDownClass() throws CoreException { + @AfterAll + static void tearDownClass() throws CoreException { tearDownTestProject(); } @@ -85,7 +85,7 @@ public void tearDown() throws CoreException { } @Test - public void testAddFileToConflictingFilters() { + void testAddFileToConflictingFilters() { // Check that there are no filter files assertNoFilterFiles(); @@ -105,7 +105,7 @@ public void testAddFileToConflictingFilters() { } @Test - public void testAddFileToExcludeBugsFilter() { + void testAddFileToExcludeBugsFilter() { // Check that there are no filter files assertNoFilterFiles(); @@ -126,7 +126,7 @@ public void testAddFileToExcludeBugsFilter() { } @Test - public void testAddFileToExcludeFilter() { + void testAddFileToExcludeFilter() { // Check that there are no filter files assertNoFilterFiles(); @@ -147,7 +147,7 @@ public void testAddFileToExcludeFilter() { } @Test - public void testAddFileToExcludeFilterTwice() { + void testAddFileToExcludeFilterTwice() { // Check that there are no filter files assertNoFilterFiles(); @@ -169,7 +169,7 @@ public void testAddFileToExcludeFilterTwice() { } @Test - public void testAddFileToIncludeFilter() { + void testAddFileToIncludeFilter() { // Check that there are no filter files assertNoFilterFiles(); @@ -190,7 +190,7 @@ public void testAddFileToIncludeFilter() { } @Test - public void testDeselectAllCategories() { + void testDeselectAllCategories() { // Add all categories addAllBugCategories(); assertAllBugCategoriesSelected(true); @@ -210,7 +210,7 @@ public void testDeselectAllCategories() { } @Test - public void testDisableAllDetectors() { + void testDisableAllDetectors() { // Enable all detectors getProjectPreferences().enableAllDetectors(true); assertAllVisibleDetectorsEnabled(true); @@ -230,7 +230,7 @@ public void testDisableAllDetectors() { } @Test - public void testDisableFindBugs() throws CoreException { + void testDisableFindBugs() throws CoreException { // Set the nature ProjectUtilities.addFindBugsNature(getProject(), new NullProgressMonitor()); assertTrue(ProjectUtilities.hasFindBugsNature(getProject())); @@ -251,7 +251,7 @@ public void testDisableFindBugs() throws CoreException { } @Test - public void testDisableProjectProperties() { + void testDisableProjectProperties() { // Create the properties page and the dialog FindbugsPropertyPageTestSubclass page = createProjectPropertiesPage(); PropertiesTestDialog dialog = createAndOpenProjectPropertiesDialog(page); @@ -287,7 +287,7 @@ public void testDisableProjectProperties() { } @Test - public void testEnableFindBugs() throws CoreException { + void testEnableFindBugs() throws CoreException { // Reset the nature ProjectUtilities.removeFindBugsNature(getProject(), new NullProgressMonitor()); assertFalse(ProjectUtilities.hasFindBugsNature(getProject())); @@ -308,7 +308,7 @@ public void testEnableFindBugs() throws CoreException { } @Test - public void testEnableOneDetector() { + void testEnableOneDetector() { // Disable all detectors getProjectPreferences().enableAllDetectors(false); assertAllVisibleDetectorsEnabled(false); @@ -329,7 +329,7 @@ public void testEnableOneDetector() { } @Test - public void testOpenProjectPreferencePage() { + void testOpenProjectPreferencePage() { // Create the preferences page and the dialog FindbugsPropertyPageTestSubclass page = createProjectPropertiesPage(); PropertiesTestDialog dialog = createAndOpenProjectPropertiesDialog(page); @@ -341,7 +341,7 @@ public void testOpenProjectPreferencePage() { } @Test - public void testOpenWorkspacePreferencePage() { + void testOpenWorkspacePreferencePage() { // Create the preferences page and the dialog FindbugsPropertyPageTestSubclass page = createWorkspacePropertiesPage(); PropertiesTestDialog dialog = createAndOpenWorkspacePreferencesDialog(page); @@ -353,7 +353,7 @@ public void testOpenWorkspacePreferencePage() { } @Test - public void testRemoveFileFromExcludeFilter() throws CoreException { + void testRemoveFileFromExcludeFilter() throws CoreException { // Set the initial preferences with one filter setFilterFile(true); @@ -377,7 +377,7 @@ public void testRemoveFileFromExcludeFilter() throws CoreException { } @Test - public void testSelectOneCategory() { + void testSelectOneCategory() { // Remove all categories removeAllBugCategories(); assertAllBugCategoriesSelected(false); @@ -398,7 +398,7 @@ public void testSelectOneCategory() { } @Test - public void testSetEffort() { + void testSetEffort() { // Reset the effort getProjectPreferences().setEffort(UserPreferences.EFFORT_DEFAULT); assertEquals(UserPreferences.EFFORT_DEFAULT, getProjectPreferences().getEffort()); diff --git a/eclipsePlugin-test/src/de/tobject/findbugs/quickfix/test/QuickfixMulti.java b/eclipsePlugin-test/src/de/tobject/findbugs/quickfix/test/QuickfixMulti.java index 2ec133e9ad9..4a6f5c6d71d 100644 --- a/eclipsePlugin-test/src/de/tobject/findbugs/quickfix/test/QuickfixMulti.java +++ b/eclipsePlugin-test/src/de/tobject/findbugs/quickfix/test/QuickfixMulti.java @@ -18,8 +18,8 @@ */ package de.tobject.findbugs.quickfix.test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; import java.io.IOException; import java.util.ArrayList; @@ -36,8 +36,8 @@ import org.eclipse.jdt.core.JavaModelException; import org.eclipse.ui.IMarkerResolution; import org.eclipse.ui.views.markers.WorkbenchMarkerResolution; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import de.tobject.findbugs.reporter.MarkerUtil; import de.tobject.findbugs.test.AbstractQuickfixTest; @@ -50,16 +50,15 @@ * @author Kevin Lubick * */ -public class QuickfixMulti extends AbstractQuickfixTest { - +class QuickfixMulti extends AbstractQuickfixTest { @Override protected TestScenario getTestScenario() { return TestScenario.MULTIQUICKFIX; } - @BeforeClass - public static void setUpClass() throws Exception { + @BeforeAll + static void setUpClass() throws Exception { setUpTestProject(TestScenario.MULTIQUICKFIX); } @@ -74,7 +73,7 @@ public void setUp() throws Exception { @Test - public void testMultiUseValueOf() throws Exception { + void testMultiUseValueOf() throws Exception { QuickFixTestPackager packager = new QuickFixTestPackager(); packager.addBugPatterns("DM_FP_NUMBER_CTOR", "DM_FP_NUMBER_CTOR", "DM_FP_NUMBER_CTOR", "DM_FP_NUMBER_CTOR", "DM_FP_NUMBER_CTOR", "DM_FP_NUMBER_CTOR"); @@ -103,7 +102,7 @@ protected void doTestMultiQuickfixResolution(IProject project, ListemptySet())); } @Test - public void testRemoveCreateMarkers() throws CoreException { + void testRemoveCreateMarkers() throws CoreException { // Setup the initial state, load bugs from a file loadXml(createFindBugsWorker(), getBugsFileLocation()); assertExpectedMarkers(MarkerUtil.getAllMarkers(getProject())); diff --git a/eclipsePlugin-test/src/de/tobject/findbugs/test/AbstractPluginTest.java b/eclipsePlugin-test/src/de/tobject/findbugs/test/AbstractPluginTest.java index 313b9c293db..8197a9fc6c8 100644 --- a/eclipsePlugin-test/src/de/tobject/findbugs/test/AbstractPluginTest.java +++ b/eclipsePlugin-test/src/de/tobject/findbugs/test/AbstractPluginTest.java @@ -25,8 +25,8 @@ import static org.eclipse.jdt.testplugin.JavaProjectHelper.delete; import static org.eclipse.jdt.testplugin.JavaProjectHelper.importResources; import static org.eclipse.jdt.testplugin.JavaProjectHelper.performDummySearch; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Collections; import java.util.Set; @@ -53,8 +53,8 @@ import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; -import org.junit.After; -import org.junit.Before; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.osgi.framework.Bundle; import de.tobject.findbugs.FindbugsPlugin; @@ -218,7 +218,7 @@ public AbstractPluginTest() { super(); } - @Before + @BeforeEach public void setUp() throws Exception { // Start with a clean FindBugs state clearBugsState(); @@ -233,7 +233,7 @@ public void setUp() throws Exception { processUiEvents(); } - @After + @AfterEach public void tearDown() throws CoreException { // Clean the FindBugs state clearBugsState(); @@ -298,8 +298,8 @@ protected void assertMarkers(String expectedBugType, int expectedBugTypeCount, I seenBugTypeCount++; } } - assertEquals("Expected " + expectedBugTypeCount + " of markers " + expectedBugType + " but seen " + seenBugTypeCount, - expectedBugTypeCount, seenBugTypeCount); + assertEquals(expectedBugTypeCount, seenBugTypeCount, + "Expected " + expectedBugTypeCount + " of markers " + expectedBugType + " but seen " + seenBugTypeCount); } protected void assertNoBugs() throws CoreException { @@ -330,8 +330,8 @@ protected void assertReportedBugs(String expectedBugType, int expectedBugCount, seenBugCount++; } } - assertEquals("Expected " + expectedBugCount + " of bugs " + expectedBugType + " but seen " + seenBugCount, - expectedBugCount, seenBugCount); + assertEquals(expectedBugCount, seenBugCount, + "Expected " + expectedBugCount + " of bugs " + expectedBugType + " but seen " + seenBugCount); } protected void clearBugsState() throws CoreException { diff --git a/eclipsePlugin-test/src/de/tobject/findbugs/test/AbstractQuickfixTest.java b/eclipsePlugin-test/src/de/tobject/findbugs/test/AbstractQuickfixTest.java index 050bbe5d6ed..70756c11274 100644 --- a/eclipsePlugin-test/src/de/tobject/findbugs/test/AbstractQuickfixTest.java +++ b/eclipsePlugin-test/src/de/tobject/findbugs/test/AbstractQuickfixTest.java @@ -18,9 +18,9 @@ */ package de.tobject.findbugs.test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.io.IOException; import java.io.InputStream; @@ -42,9 +42,9 @@ import org.eclipse.jdt.core.JavaModelException; import org.eclipse.ui.IMarkerResolution; import org.eclipse.ui.IMarkerResolutionGenerator2; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; import de.tobject.findbugs.FindbugsPlugin; import de.tobject.findbugs.FindbugsTestPlugin; @@ -63,7 +63,7 @@ public abstract class AbstractQuickfixTest extends AbstractPluginTest { private IMarkerResolutionGenerator2 resolutionGenerator; @Override - @Before + @BeforeEach public void setUp() throws Exception { super.setUp(); @@ -75,7 +75,7 @@ public void setUp() throws Exception { } @Override - @After + @AfterEach public void tearDown() throws CoreException { resolutionGenerator = null; @@ -105,7 +105,7 @@ protected void doTestQuickfixResolution(String classFileName, Class packages, IMar for (int i = 0; i < packages.size(); i++) { int lineNumber = MarkerUtil.findPrimaryLineForMaker(markers[i]); if (packages.get(i).lineNumber != QuickFixTestPackage.LINE_NUMBER_NOT_SPECIFIED) { - assertEquals("Line number should match", packages.get(i).lineNumber, lineNumber); + assertEquals(packages.get(i).lineNumber, lineNumber, "Line number should match"); } } } @@ -234,12 +234,12 @@ protected void assertPresentLabels(List packages, IMarker[] List expectedLabels = new ArrayList<>(packages.get(i).expectedLabels); IMarkerResolution[] resolutions = getResolutionGenerator().getResolutions(marker); - assertEquals("The expected number of resolutions available was wrong", expectedLabels.size(), resolutions.length); + assertEquals(expectedLabels.size(), resolutions.length, "The expected number of resolutions available was wrong"); for (int j = 0; j < resolutions.length; j++) { BugResolution resolution = (BugResolution) resolutions[j]; String label = resolution.getLabel(); - assertTrue("Should have seen label: " + label, expectedLabels.contains(label)); + assertTrue(expectedLabels.contains(label), "Should have seen label: " + label); expectedLabels.remove(label); } } diff --git a/eclipsePlugin-test/src/de/tobject/findbugs/view/explorer/test/FilterBugsDialogTest.java b/eclipsePlugin-test/src/de/tobject/findbugs/view/explorer/test/FilterBugsDialogTest.java index 459d0b3cccb..7f2b33e76ff 100644 --- a/eclipsePlugin-test/src/de/tobject/findbugs/view/explorer/test/FilterBugsDialogTest.java +++ b/eclipsePlugin-test/src/de/tobject/findbugs/view/explorer/test/FilterBugsDialogTest.java @@ -18,8 +18,8 @@ */ package de.tobject.findbugs.view.explorer.test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Collections; import java.util.Set; @@ -27,9 +27,9 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.PlatformUI; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import de.tobject.findbugs.FindbugsPlugin; import de.tobject.findbugs.preferences.FindBugsConstants; @@ -45,14 +45,15 @@ * * @author Tomás Pollak */ -public class FilterBugsDialogTest extends AbstractFindBugsTest { - @BeforeClass - public static void setUpClass() throws Exception { +class FilterBugsDialogTest extends AbstractFindBugsTest { + + @BeforeAll + static void setUpClass() throws Exception { setUpTestProject(TestScenario.DEFAULT); } - @AfterClass - public static void tearDownClass() throws CoreException { + @AfterAll + static void tearDownClass() throws CoreException { tearDownTestProject(); } @@ -74,7 +75,7 @@ public void tearDown() throws CoreException { } @Test - public void testEmptyFilter() { + void testEmptyFilter() { // Open the dialog FilterBugsDialogTestSubclass dialog = openFilterBugsDialog(Collections.emptySet(), Collections.emptySet()); @@ -88,7 +89,7 @@ public void testEmptyFilter() { } @Test - public void testFullFilter() { + void testFullFilter() { // Open the dialog FilterBugsDialogTestSubclass dialog = openFilterBugsDialog(FindbugsPlugin.getKnownPatterns(), FindbugsPlugin.getKnownPatternTypes()); @@ -102,7 +103,7 @@ public void testFullFilter() { } @Test - public void testOnePatternSelectsPattern() { + void testOnePatternSelectsPattern() { // Open the dialog FilterBugsDialogTestSubclass dialog = openFilterBugsDialog(Collections.emptySet(), Collections.emptySet()); @@ -121,7 +122,7 @@ public void testOnePatternSelectsPattern() { } @Test - public void testOnePatternSelectsType() { + void testOnePatternSelectsType() { // Open the dialog FilterBugsDialogTestSubclass dialog = openFilterBugsDialog(Collections.emptySet(), Collections.emptySet()); @@ -141,7 +142,7 @@ public void testOnePatternSelectsType() { } @Test - public void testOneType() { + void testOneType() { // Open the dialog FilterBugsDialogTestSubclass dialog = openFilterBugsDialog(Collections.emptySet(), Collections.emptySet()); diff --git a/eclipsePlugin-test/src/de/tobject/findbugs/view/explorer/test/TestBugGroup.java b/eclipsePlugin-test/src/de/tobject/findbugs/view/explorer/test/TestBugGroup.java index e2c03aed935..ecdd0a255f8 100644 --- a/eclipsePlugin-test/src/de/tobject/findbugs/view/explorer/test/TestBugGroup.java +++ b/eclipsePlugin-test/src/de/tobject/findbugs/view/explorer/test/TestBugGroup.java @@ -18,18 +18,18 @@ */ package de.tobject.findbugs.view.explorer.test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; -import org.junit.Test; +import org.junit.jupiter.api.Test; import de.tobject.findbugs.view.explorer.BugGroup; import de.tobject.findbugs.view.explorer.GroupType; -public class TestBugGroup { +class TestBugGroup { @Test - public void testEquals() { + void testEquals() { BugGroup bg1 = new BugGroup(null, null, GroupType.Marker); BugGroup bg2 = new BugGroup(null, null, GroupType.Marker); assertEquals(bg1, bg2); diff --git a/eclipsePlugin-test/src/de/tobject/findbugs/view/test/AbstractBugExplorerViewTest.java b/eclipsePlugin-test/src/de/tobject/findbugs/view/test/AbstractBugExplorerViewTest.java index 28577a3b447..8430f3e6846 100644 --- a/eclipsePlugin-test/src/de/tobject/findbugs/view/test/AbstractBugExplorerViewTest.java +++ b/eclipsePlugin-test/src/de/tobject/findbugs/view/test/AbstractBugExplorerViewTest.java @@ -18,8 +18,8 @@ */ package de.tobject.findbugs.view.test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import java.util.ArrayList; import java.util.Arrays; @@ -30,8 +30,8 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.ui.PartInitException; -import org.junit.After; -import org.junit.Before; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import de.tobject.findbugs.test.AbstractFindBugsTest; import de.tobject.findbugs.view.BugExplorerView; @@ -51,14 +51,14 @@ protected static Set setOf(T... a) { } @Override - @Before + @BeforeEach public void setUp() throws Exception { resetBugContentProviderInput(); super.setUp(); } @Override - @After + @AfterEach public void tearDown() throws CoreException { super.tearDown(); resetBugContentProviderInput(); diff --git a/eclipsePlugin-test/src/de/tobject/findbugs/view/test/BugExplorerViewTest.java b/eclipsePlugin-test/src/de/tobject/findbugs/view/test/BugExplorerViewTest.java index 33028a45c8b..3ea7eebecf2 100644 --- a/eclipsePlugin-test/src/de/tobject/findbugs/view/test/BugExplorerViewTest.java +++ b/eclipsePlugin-test/src/de/tobject/findbugs/view/test/BugExplorerViewTest.java @@ -18,17 +18,17 @@ */ package de.tobject.findbugs.view.test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import org.eclipse.core.runtime.CoreException; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.ui.IViewPart; import org.eclipse.ui.PartInitException; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import de.tobject.findbugs.test.TestScenario; import de.tobject.findbugs.view.explorer.GroupType; @@ -38,26 +38,27 @@ * * @author Tomás Pollak */ -public class BugExplorerViewTest extends AbstractBugExplorerViewTest { - @BeforeClass - public static void setUpClass() throws Exception { +class BugExplorerViewTest extends AbstractBugExplorerViewTest { + + @BeforeAll + static void setUpClass() throws Exception { setUpTestProject(TestScenario.DEFAULT); } - @AfterClass - public static void tearDownClass() throws CoreException { + @AfterAll + static void tearDownClass() throws CoreException { tearDownTestProject(); } @Test - public void testShowView() throws PartInitException { + void testShowView() throws PartInitException { // Show the view IViewPart view = showBugExplorerView(); assertNotNull(view); } @Test - public void testViewContents_Empty() throws PartInitException { + void testViewContents_Empty() throws PartInitException { // Get the content provider ITreeContentProvider contentProvider = getNavigatorContentProvider(); assertNotNull(contentProvider); @@ -69,7 +70,7 @@ public void testViewContents_Empty() throws PartInitException { } @Test - public void testViewContents_Project_Pattern_Marker() throws CoreException { + void testViewContents_Project_Pattern_Marker() throws CoreException { // Load bugs from a file loadXml(createFindBugsWorker(), getBugsFileLocation()); @@ -85,7 +86,7 @@ public void testViewContents_Project_Pattern_Marker() throws CoreException { } @Test - public void testViewContents_Project_Pattern_Package_Marker() throws CoreException { + void testViewContents_Project_Pattern_Package_Marker() throws CoreException { // Load bugs from a file loadXml(createFindBugsWorker(), getBugsFileLocation()); diff --git a/eclipsePlugin-test/src/de/tobject/findbugs/view/test/BugExplorerViewTwoSrcFoldersTest.java b/eclipsePlugin-test/src/de/tobject/findbugs/view/test/BugExplorerViewTwoSrcFoldersTest.java index e446c5e7ba5..fc6dbb1151f 100644 --- a/eclipsePlugin-test/src/de/tobject/findbugs/view/test/BugExplorerViewTwoSrcFoldersTest.java +++ b/eclipsePlugin-test/src/de/tobject/findbugs/view/test/BugExplorerViewTwoSrcFoldersTest.java @@ -18,13 +18,13 @@ */ package de.tobject.findbugs.view.test; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotNull; import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.viewers.ITreeContentProvider; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import de.tobject.findbugs.test.TestScenario; import de.tobject.findbugs.view.explorer.GroupType; @@ -35,19 +35,20 @@ * * @author Tomás Pollak */ -public class BugExplorerViewTwoSrcFoldersTest extends AbstractBugExplorerViewTest { - @BeforeClass - public static void setUpClass() throws Exception { +class BugExplorerViewTwoSrcFoldersTest extends AbstractBugExplorerViewTest { + + @BeforeAll + static void setUpClass() throws Exception { setUpTestProject(TestScenario.TWO_SRC_FOLDERS); } - @AfterClass - public static void tearDownClass() throws CoreException { + @AfterAll + static void tearDownClass() throws CoreException { tearDownTestProject(); } @Test - public void testViewContents_runTwice_onceOnSrcFolder() throws CoreException { + void testViewContents_runTwice_onceOnSrcFolder() throws CoreException { // Run Findbugs on the entire project work(createFindBugsWorker()); diff --git a/eclipsePlugin-test/src/de/tobject/findbugs/view/test/ExpectedViewBugGroup.java b/eclipsePlugin-test/src/de/tobject/findbugs/view/test/ExpectedViewBugGroup.java index 763eb68c5d0..24a662cde03 100644 --- a/eclipsePlugin-test/src/de/tobject/findbugs/view/test/ExpectedViewBugGroup.java +++ b/eclipsePlugin-test/src/de/tobject/findbugs/view/test/ExpectedViewBugGroup.java @@ -25,7 +25,7 @@ import org.eclipse.core.resources.IMarker; import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.viewers.ITreeContentProvider; -import org.junit.Assert; +import org.junit.jupiter.api.Assertions; import de.tobject.findbugs.view.explorer.BugGroup; import de.tobject.findbugs.view.explorer.GroupType; @@ -35,7 +35,7 @@ * * @author Tomás Pollak */ -public class ExpectedViewBugGroup implements ExpectedViewElement { +class ExpectedViewBugGroup implements ExpectedViewElement { private final GroupType groupType; @@ -55,12 +55,12 @@ public ExpectedViewBugGroup(GroupType groupType, Object data, Set iChildren = children.iterator(); iChildren.hasNext();) { @@ -118,7 +118,7 @@ private Object findActualObjectMatch(ExpectedViewElement child, Object[] bugGrou return bugGroupChildren[i]; } } - Assert.fail("No match found for: " + child + " in " + Arrays.toString(bugGroupChildren)); + Assertions.fail("No match found for: " + child + " in " + Arrays.toString(bugGroupChildren)); return null; } } diff --git a/eclipsePlugin-test/src/de/tobject/findbugs/view/test/ExpectedViewMarker.java b/eclipsePlugin-test/src/de/tobject/findbugs/view/test/ExpectedViewMarker.java index 8e363fb9643..bf8f78be46a 100644 --- a/eclipsePlugin-test/src/de/tobject/findbugs/view/test/ExpectedViewMarker.java +++ b/eclipsePlugin-test/src/de/tobject/findbugs/view/test/ExpectedViewMarker.java @@ -21,7 +21,7 @@ import org.eclipse.core.resources.IMarker; import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.viewers.ITreeContentProvider; -import org.junit.Assert; +import org.junit.jupiter.api.Assertions; import de.tobject.findbugs.marker.FindBugsMarker; @@ -40,10 +40,10 @@ public ExpectedViewMarker(String expectedBugType) { @Override public void assertEquals(Object actual, ITreeContentProvider contentProvider) throws CoreException { - Assert.assertTrue(actual instanceof IMarker); + Assertions.assertTrue(actual instanceof IMarker); IMarker marker = (IMarker) actual; String actualBugType = (String) marker.getAttribute(FindBugsMarker.BUG_TYPE); - Assert.assertEquals(expectedBugType, actualBugType); + Assertions.assertEquals(expectedBugType, actualBugType); } @Override diff --git a/eclipsePlugin-test/src/de/tobject/findbugs/view/test/FindBugsPerspectiveTest.java b/eclipsePlugin-test/src/de/tobject/findbugs/view/test/FindBugsPerspectiveTest.java index 021ee864e12..57456d92a74 100644 --- a/eclipsePlugin-test/src/de/tobject/findbugs/view/test/FindBugsPerspectiveTest.java +++ b/eclipsePlugin-test/src/de/tobject/findbugs/view/test/FindBugsPerspectiveTest.java @@ -18,8 +18,8 @@ */ package de.tobject.findbugs.view.test; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import org.eclipse.core.runtime.CoreException; import org.eclipse.ui.IViewPart; @@ -27,9 +27,9 @@ import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.WorkbenchException; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import de.tobject.findbugs.test.AbstractFindBugsTest; import de.tobject.findbugs.test.AbstractPluginTest; @@ -40,21 +40,22 @@ * * @author Tomás Pollak */ -public class FindBugsPerspectiveTest extends AbstractFindBugsTest { - @BeforeClass - public static void setUpClass() throws Exception { +class FindBugsPerspectiveTest extends AbstractFindBugsTest { + + private static final String FINDBUGS_PERSPECTIVE_ID = "de.tobject.findbugs.FindBugsPerspective"; + + @BeforeAll + static void setUpClass() throws Exception { setUpTestProject(TestScenario.DEFAULT); } - @AfterClass - public static void tearDownClass() throws CoreException { + @AfterAll + static void tearDownClass() throws CoreException { tearDownTestProject(); } - private static final String FINDBUGS_PERSPECTIVE_ID = "de.tobject.findbugs.FindBugsPerspective"; - @Test - public void testShowPerspective() throws WorkbenchException { + void testShowPerspective() throws WorkbenchException { // Show the perspective IWorkbenchPage page = showFindBugsPerspective(); diff --git a/eclipsePlugin-test/src/org/eclipse/jdt/testplugin/JavaProjectHelper.java b/eclipsePlugin-test/src/org/eclipse/jdt/testplugin/JavaProjectHelper.java index 8ab710fa6f0..806d07d5dd7 100644 --- a/eclipsePlugin-test/src/org/eclipse/jdt/testplugin/JavaProjectHelper.java +++ b/eclipsePlugin-test/src/org/eclipse/jdt/testplugin/JavaProjectHelper.java @@ -53,7 +53,7 @@ import org.osgi.framework.Bundle; import de.tobject.findbugs.FindbugsTestPlugin; -import junit.framework.Assert; +import org.junit.jupiter.api.Assertions; /** * Helper methods to set up a IJavaProject. @@ -615,8 +615,8 @@ public static void addToClasspath(IJavaProject jproject, IClasspathEntry cpe) th */ public static IPath[] findRtJar(IPath rtStubsPath) throws CoreException { File rtStubs = FindbugsTestPlugin.getDefault().getFileInPlugin(rtStubsPath); - Assert.assertNotNull(rtStubs); - Assert.assertTrue(rtStubs.exists()); + Assertions.assertNotNull(rtStubs); + Assertions.assertTrue(rtStubs.exists()); return new IPath[] { Path.fromOSString(rtStubs.getPath()), null, null }; } diff --git a/spotbugs-ant/build.gradle b/spotbugs-ant/build.gradle index aef9ebc14d1..c9f8dc08c12 100644 --- a/spotbugs-ant/build.gradle +++ b/spotbugs-ant/build.gradle @@ -8,7 +8,7 @@ dependencies { compileOnly 'org.apache.ant:ant:1.10.14' testImplementation 'org.apache.ant:ant:1.10.14' - testImplementation 'org.junit.vintage:junit-vintage-engine:5.10.0' + testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.10.0' testImplementation 'org.hamcrest:hamcrest:2.2' } diff --git a/spotbugs-ant/src/test/java/edu/umd/cs/findbugs/anttask/FindBugsTaskTest.java b/spotbugs-ant/src/test/java/edu/umd/cs/findbugs/anttask/FindBugsTaskTest.java index 3e71c57216f..405f87a3e24 100644 --- a/spotbugs-ant/src/test/java/edu/umd/cs/findbugs/anttask/FindBugsTaskTest.java +++ b/spotbugs-ant/src/test/java/edu/umd/cs/findbugs/anttask/FindBugsTaskTest.java @@ -1,7 +1,7 @@ package edu.umd.cs.findbugs.anttask; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.Arrays; import java.util.List; @@ -10,11 +10,12 @@ import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.not; -public class FindBugsTaskTest { +class FindBugsTaskTest { + private FindBugsTask task; - @Before - public void setUp() { + @BeforeEach + void setUp() { task = new FindBugsTask(); task.createFindbugsEngine(); } @@ -23,7 +24,7 @@ public void setUp() { * @see */ @Test - public void disableSortByClassWhenXmlIsUsed() { + void disableSortByClassWhenXmlIsUsed() { task.setSort(true); task.setOutput("xml"); @@ -35,7 +36,7 @@ public void disableSortByClassWhenXmlIsUsed() { } @Test - public void enableSortByClassForNullOutput() { + void enableSortByClassForNullOutput() { task.setSort(true); task.setOutput(null); @@ -47,7 +48,7 @@ public void enableSortByClassForNullOutput() { } @Test - public void enableSortByClassWhenTextIsUsed() { + void enableSortByClassWhenTextIsUsed() { task.setSort(true); task.setOutput("text"); diff --git a/spotbugs-ant/src/test/java/edu/umd/cs/findbugs/anttask/UnionBugs2Test.java b/spotbugs-ant/src/test/java/edu/umd/cs/findbugs/anttask/UnionBugs2Test.java index eac4bad50b7..263b5413a7d 100644 --- a/spotbugs-ant/src/test/java/edu/umd/cs/findbugs/anttask/UnionBugs2Test.java +++ b/spotbugs-ant/src/test/java/edu/umd/cs/findbugs/anttask/UnionBugs2Test.java @@ -3,8 +3,8 @@ import org.apache.tools.ant.Project; import org.apache.tools.ant.types.CommandlineJava; import org.apache.tools.ant.types.FileSet; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.io.*; import java.nio.charset.StandardCharsets; @@ -14,9 +14,10 @@ import java.util.Optional; import java.util.stream.Stream; -public class UnionBugs2Test { +class UnionBugs2Test { + @Test - public void testWriteXmlFilePathArgsToTextFile() { + void testWriteXmlFilePathArgsToTextFile() { //Prepare UnionBugs2 unionBugs2 = new UnionBugs2(); unionBugs2.setProject(new Project()); @@ -34,11 +35,11 @@ public void testWriteXmlFilePathArgsToTextFile() { //Verify String[] arguments = commandLine.getJavaCommand().getArguments(); Optional textFileArgument = Stream.of(arguments).filter(s -> s.contains("spotbugs-argument-file") && s.endsWith(".txt")).findFirst(); - Assert.assertTrue("Arguments are supposed to be compiled into text file.", textFileArgument.isPresent()); + Assertions.assertTrue(textFileArgument.isPresent(), "Arguments are supposed to be compiled into text file."); String textFile = textFileArgument.get(); List xmlPaths = readArgumentsFile(textFile); - Assert.assertTrue(xmlPaths.stream().anyMatch(s -> s.contains("findbugsExclusionTest.xml"))); - Assert.assertTrue(xmlPaths.stream().anyMatch(s -> s.contains("findbugsExclusionTest2.xml"))); + Assertions.assertTrue(xmlPaths.stream().anyMatch(s -> s.contains("findbugsExclusionTest.xml"))); + Assertions.assertTrue(xmlPaths.stream().anyMatch(s -> s.contains("findbugsExclusionTest2.xml"))); //Cleanup try { diff --git a/spotbugs-tests/build.gradle b/spotbugs-tests/build.gradle index 5defe2da8d2..7369dc4254e 100644 --- a/spotbugs-tests/build.gradle +++ b/spotbugs-tests/build.gradle @@ -10,8 +10,10 @@ dependencies { api project(':spotbugs-annotations') implementation project(':spotbugsTestCases') implementation project(':test-harness') + implementation project(':test-harness-jupiter') - implementation 'org.junit.vintage:junit-vintage-engine:5.10.0' + implementation 'org.junit.jupiter:junit-jupiter-engine:5.10.0' + implementation 'org.junit.jupiter:junit-jupiter-params:5.10.0' implementation 'org.hamcrest:hamcrest:2.2' implementation 'org.apache.ant:ant:1.10.14' implementation libs.log4j.core @@ -43,6 +45,7 @@ tasks.named('jacocoTestReport', JacocoReport).configure { // Tests below fail if executed with other tests // So we run them before all other tests are executed task unstableTest(type: Test) { + useJUnitPlatform() filter { includeTestsMatching "PlaceholderTest" includeTestsMatching "MutableClassesTest" @@ -54,6 +57,7 @@ task unstableTest(type: Test) { test { dependsOn ':spotbugsTestCases:build', 'unstableTest' + useJUnitPlatform() filter { excludeTestsMatching "PlaceholderTest" excludeTestsMatching "MutableClassesTest" diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/AbstractBugReporterTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/AbstractBugReporterTest.java index 87ae4797b81..ba6c28342f7 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/AbstractBugReporterTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/AbstractBugReporterTest.java @@ -5,20 +5,20 @@ import edu.umd.cs.findbugs.ba.AnalysisContext; import edu.umd.cs.findbugs.classfile.ClassDescriptor; import edu.umd.cs.findbugs.internalAnnotations.DottedClassName; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Test the logic in the reportBug method in all its permutations. */ -public class AbstractBugReporterTest { +class AbstractBugReporterTest { private BugInstance bugInstance; private ObservableBugReporter reporter; - @Before - public void setup() { + @BeforeEach + void setup() { // BugRank = 8, Priority = 2 bugInstance = new BugInstance("NP_NULL_ON_SOME_PATH", Priorities.NORMAL_PRIORITY); reporter = new ObservableBugReporter(); @@ -33,8 +33,8 @@ public boolean isApplicationClass(@DottedClassName String className) { AnalysisContext.setCurrentAnalysisContext(analysisContext); } - @After - public void teardown() { + @AfterEach + void teardown() { AnalysisContext.removeCurrentAnalysisContext(); } @@ -52,11 +52,11 @@ private void assertReported(boolean expectedReport, String message, int rankThre reporter.setRankThreshold(rankThreshold); reporter.reportBug(bugInstance); - Assert.assertEquals(message, expectedReport, reporter.isReportCalled()); + Assertions.assertEquals(expectedReport, reporter.isReportCalled(), message); } @Test - public void verifyPriorityThresholdWorks() { + void verifyPriorityThresholdWorks() { assertReported(false, "Normal bug report blocked on high", BugRanker.VISIBLE_RANK_MAX, Priorities.HIGH_PRIORITY); @@ -68,7 +68,7 @@ public void verifyPriorityThresholdWorks() { } @Test - public void verifyRankThresholdWorks() { + void verifyRankThresholdWorks() { int bugRank = bugInstance.getBugRank(); assertReported(false, "Rank " + bugRank + " bug report blocked on min visible", @@ -82,7 +82,7 @@ public void verifyRankThresholdWorks() { } @Test - public void verifyRelaxedOperationWorks() { + void verifyRelaxedOperationWorks() { reporter.setIsRelaxed(true); assertReported(true, "Relaxed bug reported even when it would not", BugRanker.VISIBLE_RANK_MIN, Priorities.HIGH_PRIORITY); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/AbstractIntegrationTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/AbstractIntegrationTest.java index c586fdbef70..a1e97629286 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/AbstractIntegrationTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/AbstractIntegrationTest.java @@ -19,7 +19,7 @@ package edu.umd.cs.findbugs; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.io.UncheckedIOException; @@ -81,7 +81,7 @@ public abstract class AbstractIntegrationTest { private static Path getFindbugsTestCases() { final Path p = Paths.get(SystemProperties.getProperty("spotbugsTestCases.home", "../spotbugsTestCases")); - assertTrue("'spotbugsTestCases' directory not found", Files.exists(p)); + assertTrue(Files.exists(p), "'spotbugsTestCases' directory not found"); assertTrue(Files.isDirectory(p)); assertTrue(Files.isReadable(p)); @@ -96,7 +96,7 @@ private static Path getFindbugsTestCasesFile(final String path) { .findFirst() .orElseThrow(() -> new AssertionError(path + " not found")); - assertTrue(p + " is not readable", Files.isReadable(p)); + assertTrue(Files.isReadable(p), p + " is not readable"); return p; } diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/BugCollectionBugReporterTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/BugCollectionBugReporterTest.java index 41e18958030..64656565ce9 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/BugCollectionBugReporterTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/BugCollectionBugReporterTest.java @@ -2,14 +2,15 @@ import edu.umd.cs.findbugs.classfile.ClassDescriptor; import edu.umd.cs.findbugs.classfile.DescriptorFactory; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.hamcrest.Matchers.is; import static org.hamcrest.MatcherAssert.assertThat; -public class BugCollectionBugReporterTest { +class BugCollectionBugReporterTest { + @Test - public void reportMissingClassByClassNotFoundException() { + void reportMissingClassByClassNotFoundException() { Project project = new Project(); BugCollectionBugReporter bugReporter = new BugCollectionBugReporter(project); ClassNotFoundException ex = new ClassNotFoundException("Class org.example.Foo cannot be resolved."); @@ -19,7 +20,7 @@ public void reportMissingClassByClassNotFoundException() { } @Test - public void reportMissingClassByClassDescriptor() { + void reportMissingClassByClassDescriptor() { Project project = new Project(); BugCollectionBugReporter bugReporter = new BugCollectionBugReporter(project); ClassDescriptor classDescriptor = DescriptorFactory.createClassDescriptorFromDottedClassName("org.example.Bar"); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/BugInstanceTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/BugInstanceTest.java index f2ab3cf764f..cf9a56d2b80 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/BugInstanceTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/BugInstanceTest.java @@ -10,19 +10,19 @@ import java.util.List; import java.util.NoSuchElementException; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import edu.umd.cs.findbugs.xml.OutputStreamXMLOutput; import edu.umd.cs.findbugs.xml.XMLOutput; -public class BugInstanceTest { +class BugInstanceTest { private BugInstance b; - @Before - public void setUp() { + @BeforeEach + void setUp() { b = new BugInstance("NP_NULL_ON_SOME_PATH", Priorities.NORMAL_PRIORITY); b.setProperty("A", "a"); b.setProperty("B", "b"); @@ -41,7 +41,7 @@ public void setUp() { + ""; @Test - public void testWriteXML() throws Exception { + void testWriteXML() throws Exception { BugInstance bug = new BugInstance("UUF_UNUSED_FIELD", 0); // test all PackageMemberAnnotations String className = "ghIssues.issue543.ImmutableFoobarValue.class"; @@ -62,53 +62,59 @@ public void testWriteXML() throws Exception { } @Test - public void testPropertyIterator() { + void testPropertyIterator() { checkPropertyIterator(b.propertyIterator(), new String[] { "A", "B", "C" }, new String[] { "a", "b", "c" }); } @Test - public void testRemoveThroughIterator1() { + void testRemoveThroughIterator1() { removeThroughIterator(b.propertyIterator(), "A"); checkPropertyIterator(b.propertyIterator(), new String[] { "B", "C" }, new String[] { "b", "c" }); } @Test - public void testRemoveThroughIterator2() { + void testRemoveThroughIterator2() { removeThroughIterator(b.propertyIterator(), "B"); checkPropertyIterator(b.propertyIterator(), new String[] { "A", "C" }, new String[] { "a", "c" }); } @Test - public void testRemoveThroughIterator3() { + void testRemoveThroughIterator3() { removeThroughIterator(b.propertyIterator(), "C"); checkPropertyIterator(b.propertyIterator(), new String[] { "A", "B" }, new String[] { "a", "b" }); } - @Test(expected = NoSuchElementException.class) - public void testIterateTooFar() { + @Test + void testIterateTooFar() { Iterator iter = b.propertyIterator(); get(iter); get(iter); get(iter); - iter.next(); + Assertions.assertThrows(NoSuchElementException.class, () -> { + iter.next(); + }); } - @Test(expected = IllegalStateException.class) - public void testMultipleRemove() { + @Test + void testMultipleRemove() { Iterator iter = b.propertyIterator(); iter.next(); iter.remove(); - iter.remove(); + Assertions.assertThrows(IllegalStateException.class, () -> { + iter.remove(); + }); } - @Test(expected = IllegalStateException.class) - public void testRemoveBeforeNext() { + @Test + void testRemoveBeforeNext() { Iterator iter = b.propertyIterator(); - iter.remove(); + Assertions.assertThrows(IllegalStateException.class, () -> { + iter.remove(); + }); } @Test - public void testRemoveAndAdd() { + void testRemoveAndAdd() { removeThroughIterator(b.propertyIterator(), "C"); b.setProperty("D", "d"); checkPropertyIterator(b.propertyIterator(), new String[] { "A", "B", "D" }, new String[] { "a", "b", "d" }); @@ -117,7 +123,7 @@ public void testRemoveAndAdd() { } @Test - public void testRemoveAll1() { + void testRemoveAll1() { removeThroughIterator(b.propertyIterator(), "A"); checkPropertyIterator(b.propertyIterator(), new String[] { "B", "C" }, new String[] { "b", "c" }); removeThroughIterator(b.propertyIterator(), "B"); @@ -141,7 +147,7 @@ private void get(Iterator iter) { iter.next(); // Good } catch (NoSuchElementException e) { - Assert.assertTrue(false); + Assertions.assertTrue(false); } } @@ -150,17 +156,17 @@ private void checkPropertyIterator(Iterator iter, String[] names, S throw new IllegalArgumentException(); } for (int i = 0; i < names.length; ++i) { - Assert.assertTrue(iter.hasNext()); + Assertions.assertTrue(iter.hasNext()); String name = names[i]; String value = values[i]; checkProperty(iter.next(), name, value); } - Assert.assertFalse(iter.hasNext()); + Assertions.assertFalse(iter.hasNext()); } private void checkProperty(BugProperty property, String name, String value) { - Assert.assertEquals(property.getName(), name); - Assert.assertEquals(property.getValue(), value); + Assertions.assertEquals(property.getName(), name); + Assertions.assertEquals(property.getValue(), value); } private void removeThroughIterator(Iterator iter, String name) { diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/BugRankerTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/BugRankerTest.java index c91cad14dc1..1370a668193 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/BugRankerTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/BugRankerTest.java @@ -1,15 +1,16 @@ package edu.umd.cs.findbugs; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; -import org.junit.Test; +import org.junit.jupiter.api.Test; + +class BugRankerTest { -public class BugRankerTest { /** * @see GitHub issue */ @Test - public void testTrimToMaxRank() { + void testTrimToMaxRank() { SortedBugCollection bugCollection = new SortedBugCollection(); bugCollection.add(new BugInstance("type", Priorities.HIGH_PRIORITY).addClass("the/target/Class")); BugRanker.trimToMaxRank(bugCollection, 0); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/BugReporterDispatcherTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/BugReporterDispatcherTest.java index cf83ceb919b..f283e0d55c8 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/BugReporterDispatcherTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/BugReporterDispatcherTest.java @@ -2,12 +2,14 @@ import edu.umd.cs.findbugs.charsets.UTF8; import edu.umd.cs.findbugs.classfile.DescriptorFactory; -import org.junit.Test; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; import java.io.ByteArrayOutputStream; import java.io.PrintStream; @@ -15,14 +17,17 @@ import java.util.ArrayList; import java.util.Arrays; -public class BugReporterDispatcherTest { - @Test(expected = IllegalArgumentException.class) - public void createWithNoReportToDelegate() { - new BugReportDispatcher(new ArrayList<>()); +class BugReporterDispatcherTest { + + @Test + void createWithNoReportToDelegate() { + Assertions.assertThrows(IllegalArgumentException.class, () -> { + new BugReportDispatcher(new ArrayList<>()); + }); } @Test - public void dispatchingMethod() { + void dispatchingMethod() { SortingBugReporter bugReporter = new SortingBugReporter(); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); bugReporter.setOutputStream(new PrintStream(outStream, false, StandardCharsets.UTF_8)); @@ -52,7 +57,7 @@ public void dispatchingMethod() { } @Test - public void exceptionsAreSuppressed() { + void exceptionsAreSuppressed() { BugReportDispatcher dispatcher = new BugReportDispatcher(Arrays.asList(new BrokenBugReporter(), new BrokenBugReporter())); try { dispatcher.logError("try to throw an error"); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ClassScreenerTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ClassScreenerTest.java index acfd627ee7a..52975932e5a 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ClassScreenerTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ClassScreenerTest.java @@ -19,11 +19,11 @@ package edu.umd.cs.findbugs; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class ClassScreenerTest { +class ClassScreenerTest { private IClassScreener emptyScreener; @@ -65,8 +65,8 @@ private static String makeJarURL(String fileName) { private static final String UNRELATED_THING_CLASS_JARFILENAME = makeJarURL(UNRELATED_THING_CLASS_FILENAME); - @Before - public void setUp() { + @BeforeEach + void setUp() { emptyScreener = new ClassScreener(); particularClassScreener = new ClassScreener(); @@ -80,39 +80,39 @@ public void setUp() { } @Test - public void testEmptyClassScreener() { - Assert.assertTrue(emptyScreener.matches(SOME_CLASS_FILENAME)); - Assert.assertTrue(emptyScreener.matches(SOME_OTHER_CLASS_FILENAME)); - Assert.assertTrue(emptyScreener.matches(UNRELATED_THING_CLASS_FILENAME)); - - Assert.assertTrue(emptyScreener.matches(SOME_CLASS_JARFILENAME)); - Assert.assertTrue(emptyScreener.matches(SOME_OTHER_CLASS_JARFILENAME)); - Assert.assertTrue(emptyScreener.matches(UNRELATED_THING_CLASS_JARFILENAME)); + void testEmptyClassScreener() { + Assertions.assertTrue(emptyScreener.matches(SOME_CLASS_FILENAME)); + Assertions.assertTrue(emptyScreener.matches(SOME_OTHER_CLASS_FILENAME)); + Assertions.assertTrue(emptyScreener.matches(UNRELATED_THING_CLASS_FILENAME)); + + Assertions.assertTrue(emptyScreener.matches(SOME_CLASS_JARFILENAME)); + Assertions.assertTrue(emptyScreener.matches(SOME_OTHER_CLASS_JARFILENAME)); + Assertions.assertTrue(emptyScreener.matches(UNRELATED_THING_CLASS_JARFILENAME)); } @Test - public void testParticularClassScreener() { - Assert.assertTrue(particularClassScreener.matches(SOME_CLASS_FILENAME)); - Assert.assertFalse(particularClassScreener.matches(SOME_OTHER_CLASS_FILENAME)); - Assert.assertFalse(particularClassScreener.matches(UNRELATED_THING_CLASS_FILENAME)); - - Assert.assertTrue(particularClassScreener.matches(SOME_CLASS_JARFILENAME)); - Assert.assertFalse(particularClassScreener.matches(SOME_OTHER_CLASS_JARFILENAME)); - Assert.assertFalse(particularClassScreener.matches(UNRELATED_THING_CLASS_JARFILENAME)); + void testParticularClassScreener() { + Assertions.assertTrue(particularClassScreener.matches(SOME_CLASS_FILENAME)); + Assertions.assertFalse(particularClassScreener.matches(SOME_OTHER_CLASS_FILENAME)); + Assertions.assertFalse(particularClassScreener.matches(UNRELATED_THING_CLASS_FILENAME)); + + Assertions.assertTrue(particularClassScreener.matches(SOME_CLASS_JARFILENAME)); + Assertions.assertFalse(particularClassScreener.matches(SOME_OTHER_CLASS_JARFILENAME)); + Assertions.assertFalse(particularClassScreener.matches(UNRELATED_THING_CLASS_JARFILENAME)); } @Test - public void testParticularPackageScreener() { + void testParticularPackageScreener() { testPackageScreener(particularPackageScreener); testPackageScreener(particularPackageScreener2); } private void testPackageScreener(IClassScreener screener) { - Assert.assertTrue(screener.matches(SOME_CLASS_FILENAME)); - Assert.assertTrue(screener.matches(SOME_OTHER_CLASS_FILENAME)); - Assert.assertFalse(screener.matches(UNRELATED_THING_CLASS_FILENAME)); - Assert.assertTrue(screener.matches(SOME_CLASS_JARFILENAME)); - Assert.assertTrue(screener.matches(SOME_OTHER_CLASS_JARFILENAME)); - Assert.assertFalse(screener.matches(UNRELATED_THING_CLASS_JARFILENAME)); + Assertions.assertTrue(screener.matches(SOME_CLASS_FILENAME)); + Assertions.assertTrue(screener.matches(SOME_OTHER_CLASS_FILENAME)); + Assertions.assertFalse(screener.matches(UNRELATED_THING_CLASS_FILENAME)); + Assertions.assertTrue(screener.matches(SOME_CLASS_JARFILENAME)); + Assertions.assertTrue(screener.matches(SOME_OTHER_CLASS_JARFILENAME)); + Assertions.assertFalse(screener.matches(UNRELATED_THING_CLASS_JARFILENAME)); } } diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/CommandLineTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/CommandLineTest.java index 51649951fef..edc1141aaa3 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/CommandLineTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/CommandLineTest.java @@ -1,8 +1,8 @@ package edu.umd.cs.findbugs; import edu.umd.cs.findbugs.config.CommandLine; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.util.ArrayList; @@ -11,17 +11,17 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; -public class CommandLineTest { +class CommandLineTest { private EmptyCommandLine commandLine; - @Before + @BeforeEach public void createCommandLine() { commandLine = new EmptyCommandLine(); commandLine.addSwitchWithOptionalExtraPart("-xml", "withMessages", ""); } @Test - public void parseOpt() throws CommandLine.HelpRequestedException, IOException { + void parseOpt() throws CommandLine.HelpRequestedException, IOException { commandLine.parse(new String[] { "-xml" }); assertThat(commandLine.options.get(0), is("-xml")); @@ -29,7 +29,7 @@ public void parseOpt() throws CommandLine.HelpRequestedException, IOException { } @Test - public void parseOptWithExtraPart() throws CommandLine.HelpRequestedException, IOException { + void parseOptWithExtraPart() throws CommandLine.HelpRequestedException, IOException { commandLine.parse(new String[] { "-xml:withMessages" }); assertThat(commandLine.options.get(0), is("-xml")); @@ -37,7 +37,7 @@ public void parseOptWithExtraPart() throws CommandLine.HelpRequestedException, I } @Test - public void parseOptWithFilePath() throws CommandLine.HelpRequestedException, IOException { + void parseOptWithFilePath() throws CommandLine.HelpRequestedException, IOException { commandLine.parse(new String[] { "-xml=spotbugs.xml" }); assertThat(commandLine.options.get(0), is("-xml")); @@ -45,7 +45,7 @@ public void parseOptWithFilePath() throws CommandLine.HelpRequestedException, IO } @Test - public void parseOptWithExtraPartAndFilePath() throws CommandLine.HelpRequestedException, IOException { + void parseOptWithExtraPartAndFilePath() throws CommandLine.HelpRequestedException, IOException { commandLine.parse(new String[] { "-xml:withMessages=spotbugs.xml" }); assertThat(commandLine.options.get(0), is("-xml")); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/CurrentThreadExecutorServiceTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/CurrentThreadExecutorServiceTest.java index d534c892b3a..41aefa45e38 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/CurrentThreadExecutorServiceTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/CurrentThreadExecutorServiceTest.java @@ -18,24 +18,21 @@ */ package edu.umd.cs.findbugs; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; -public class CurrentThreadExecutorServiceTest { - @Rule - public ExpectedException expected = ExpectedException.none(); +class CurrentThreadExecutorServiceTest { @Test - public void test() throws InterruptedException { + void testCurrentThread() throws InterruptedException { Thread currentThread = Thread.currentThread(); ExecutorService executorService = new CurrentThreadExecutorService(); AtomicBoolean isCalled = new AtomicBoolean(); @@ -54,19 +51,21 @@ public void test() throws InterruptedException { } @Test - public void testCloseTwice() { + void testCloseTwice() { ExecutorService executorService = new CurrentThreadExecutorService(); List remaining = executorService.shutdownNow(); assertTrue(remaining.isEmpty()); - expected.expect(IllegalStateException.class); - executorService.shutdown(); + Assertions.assertThrows(IllegalStateException.class, () -> { + executorService.shutdown(); + }); } @Test - public void awaitTerminationWithoutShutdown() throws InterruptedException { + void awaitTerminationWithoutShutdown() throws InterruptedException { ExecutorService executorService = new CurrentThreadExecutorService(); - expected.expect(IllegalStateException.class); - executorService.awaitTermination(1, TimeUnit.SECONDS); + Assertions.assertThrows(IllegalStateException.class, () -> { + executorService.awaitTermination(1, TimeUnit.SECONDS); + }); } } diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/DetectorsTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/DetectorsTest.java index 0635771b332..3d1c555d1d9 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/DetectorsTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/DetectorsTest.java @@ -18,7 +18,7 @@ */ package edu.umd.cs.findbugs; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertFalse; import java.io.File; import java.io.IOException; @@ -26,11 +26,11 @@ import java.util.ArrayList; import java.util.List; -import org.junit.After; -import org.junit.Assert; -import org.junit.Assume; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Assumptions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import edu.umd.cs.findbugs.annotations.ExpectWarning; import edu.umd.cs.findbugs.annotations.NoWarning; @@ -52,7 +52,7 @@ // TODO : Rewrite tests using matchers @Deprecated -public class DetectorsTest { +class DetectorsTest { private static final String FB_UNEXPECTED_WARNING = "FB_UNEXPECTED_WARNING"; @@ -67,29 +67,29 @@ public class DetectorsTest { /** detectors which are disabled by default but which must be used in test */ private final String[] enabledDetectors = { "CheckExpectedWarnings", "InefficientMemberAccess", "EmptyZipFileEntry" }; - public File getFindbugsTestCases() { + private File getFindbugsTestCases() { if (spotbugsTestCases != null) { return spotbugsTestCases; } File f = new File(SystemProperties.getProperty("spotbugsTestCases.home", "../spotbugsTestCases")); - Assume.assumeTrue(f.exists()); - Assume.assumeTrue(f.isDirectory()); - Assume.assumeTrue(f.canRead()); + Assumptions.assumeTrue(f.exists()); + Assumptions.assumeTrue(f.isDirectory()); + Assumptions.assumeTrue(f.canRead()); spotbugsTestCases = f; return f; } - public File getFindbugsTestCasesFile(String path) { + private File getFindbugsTestCasesFile(String path) { File f = new File(getFindbugsTestCases(), path); - Assume.assumeTrue(f.exists()); - Assume.assumeTrue(f.canRead()); + Assumptions.assumeTrue(f.exists()); + Assumptions.assumeTrue(f.canRead()); return f; } - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { loadFindbugsPlugin(); } @@ -97,14 +97,14 @@ public void setUp() throws Exception { * Test for expected warnings on javac compiler generated classes */ @Test - public void testAllRegressionFilesJavac() throws IOException, InterruptedException { + void testAllRegressionFilesJavac() throws IOException, InterruptedException { setUpEngine("build/classes/java/main/"); engine.execute(); // If there are zero bugs, then something's wrong - assertFalse("No bugs were reported. Something is wrong with the configuration", bugReporter.getBugCollection() - .getCollection().isEmpty()); + assertFalse(bugReporter.getBugCollection().getCollection().isEmpty(), + "No bugs were reported. Something is wrong with the configuration"); } /** @@ -115,7 +115,7 @@ public void testAllRegressionFilesJavac() throws IOException, InterruptedExcepti * ecj command line compiler and *always* validate both bytecode kinds. */ @Test - public void testAllRegressionFilesEcj() throws IOException, InterruptedException { + void testAllRegressionFilesEcj() throws IOException, InterruptedException { setUpEngine("classesEclipse/"); engine.execute(); @@ -127,8 +127,8 @@ public void testAllRegressionFilesEcj() throws IOException, InterruptedException } } - @After - public void checkForUnexpectedBugs() { + @AfterEach + void checkForUnexpectedBugs() { List unexpectedBugs = new ArrayList<>(); for (BugInstance bug : bugReporter.getBugCollection()) { if (isUnexpectedBug(bug) && bug.getPriority() == Priorities.HIGH_PRIORITY) { @@ -139,7 +139,7 @@ public void checkForUnexpectedBugs() { } if (!unexpectedBugs.isEmpty()) { - Assert.fail("Unexpected bugs (" + unexpectedBugs.size() + "):" + getBugsLocations(unexpectedBugs)); + Assertions.fail("Unexpected bugs (" + unexpectedBugs.size() + "):" + getBugsLocations(unexpectedBugs)); } } diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ErrorCountingBugReporterTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ErrorCountingBugReporterTest.java index 83abb084669..6b4768b43c8 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ErrorCountingBugReporterTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ErrorCountingBugReporterTest.java @@ -2,14 +2,15 @@ import edu.umd.cs.findbugs.classfile.ClassDescriptor; import edu.umd.cs.findbugs.classfile.DescriptorFactory; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.hamcrest.Matchers.is; import static org.hamcrest.MatcherAssert.assertThat; -public class ErrorCountingBugReporterTest { +class ErrorCountingBugReporterTest { + @Test - public void reportMissingClassByClassNotFoundException() { + void reportMissingClassByClassNotFoundException() { PrintingBugReporter realBugReporter = new PrintingBugReporter(); ErrorCountingBugReporter bugReporter = new ErrorCountingBugReporter(realBugReporter); ClassNotFoundException ex = new ClassNotFoundException("Class org.example.Foo cannot be resolved."); @@ -18,7 +19,7 @@ public void reportMissingClassByClassNotFoundException() { } @Test - public void reportMissingClassByClassDescriptor() { + void reportMissingClassByClassDescriptor() { PrintingBugReporter realBugReporter = new PrintingBugReporter(); ErrorCountingBugReporter bugReporter = new ErrorCountingBugReporter(realBugReporter); ClassDescriptor classDescriptor = DescriptorFactory.createClassDescriptorFromDottedClassName("org.example.Bar"); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/FindBugsTestCase.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/FindBugsTestCase.java index d813e02c4b0..291a75a2821 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/FindBugsTestCase.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/FindBugsTestCase.java @@ -25,7 +25,6 @@ import java.io.OutputStream; import edu.umd.cs.findbugs.config.UserPreferences; -import junit.framework.TestCase; /** * Abstract base class for TestCase classes that need to run in the context of a @@ -37,7 +36,7 @@ * * @author David Hovemeyer */ -public abstract class FindBugsTestCase extends TestCase { +public abstract class FindBugsTestCase { /** * Data of an empty class in the default package called "Empty". */ diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/IntAnnotationTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/IntAnnotationTest.java index bbf4b00b4c5..79908650487 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/IntAnnotationTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/IntAnnotationTest.java @@ -19,17 +19,17 @@ package edu.umd.cs.findbugs; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author pugh */ -public class IntAnnotationTest { +class IntAnnotationTest { @Test - public void test() { + void testIntAnnotation() { assertEquals("0xffff", IntAnnotation.getShortInteger(0xffff)); assertEquals("0x1ffff", IntAnnotation.getShortInteger(0x1ffff)); assertEquals("0x1fffffff", IntAnnotation.getShortInteger(0x1fffffff)); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/JUnitDetectorAdapter.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/JUnitDetectorAdapter.java index 1d3f66077c6..1695ef8cb8a 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/JUnitDetectorAdapter.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/JUnitDetectorAdapter.java @@ -105,7 +105,6 @@ public void visitClass(ClassDescriptor classDescriptor) throws CheckedAnalysisEx try { runnableInstance.get().run(); } catch (Throwable e) { - // e.printStackTrace(); throwable = e; } } diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/JavaVersionTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/JavaVersionTest.java index a5394e4d87a..1878f48f1df 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/JavaVersionTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/JavaVersionTest.java @@ -19,11 +19,11 @@ package edu.umd.cs.findbugs; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class JavaVersionTest { +class JavaVersionTest { private static void testJavaVersionString(String version, int maj, int min, String rest) throws JavaVersionException { @@ -38,7 +38,7 @@ private static void testJavaVersionString(String version, int maj, int min, Stri * @throws JavaVersionException if version string cannot be parsed */ @Test - public void testJavaVersionString() throws JavaVersionException { + void testJavaVersionString() throws JavaVersionException { // Historical versions (up to Java 8) testJavaVersionString("1.7", 1, 7, ""); testJavaVersionString("1.7.0", 1, 7, "0"); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ObfuscateTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ObfuscateTest.java index 343495b136e..212a17ee379 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ObfuscateTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ObfuscateTest.java @@ -19,25 +19,25 @@ package edu.umd.cs.findbugs; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author pugh */ -public class ObfuscateTest { +class ObfuscateTest { @Test - public void testMethodSignature() { + void testMethodSignature() { String sig = "([Lcom.google.Search;I)Lcom.google.Money;"; String result = Obfuscate.hashMethodSignature(sig); - assertEquals("hash of " + sig + " gives " + result, result.indexOf("google"), -1); + assertEquals(-1, result.indexOf("google"), "hash of " + sig + " gives " + result); System.out.println(result); } @Test - public void testMethodSignatureDoesntChangeForCoreTypes() { + void testMethodSignatureDoesntChangeForCoreTypes() { String sig = "([Ljava/lang/String;I)Ljava/util/Map;"; String result = Obfuscate.hashMethodSignature(sig); assertEquals(sig, result); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/OpcodeStackItemTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/OpcodeStackItemTest.java index eae10a148c2..5a7a3454635 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/OpcodeStackItemTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/OpcodeStackItemTest.java @@ -19,16 +19,16 @@ package edu.umd.cs.findbugs; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class OpcodeStackItemTest { +class OpcodeStackItemTest { @Test - public void testMergeIntAndZero() { + void testMergeIntAndZero() { OpcodeStack.Item intItem = new OpcodeStack.Item("I"); OpcodeStack.Item zeroItem = new OpcodeStack.Item("I", 0); OpcodeStack.Item m1 = OpcodeStack.Item.merge(intItem, zeroItem); @@ -38,7 +38,7 @@ public void testMergeIntAndZero() { } @Test - public void testMergeTypeOnly() { + void testMergeTypeOnly() { OpcodeStack.Item intOnly = OpcodeStack.Item.typeOnly("I"); OpcodeStack.Item zeroItem = new OpcodeStack.Item("I", 0); @@ -51,19 +51,19 @@ public void testMergeTypeOnly() { private static final String NEW_ITEM_KIND_NAME = "newItemKindName"; @Test - public void testDefineNewItemKind() { + void testDefineNewItemKind() { int defined = OpcodeStack.Item.defineSpecialKind(NEW_ITEM_KIND_NAME); assertEquals(NEW_ITEM_KIND_NAME, OpcodeStack.Item.getSpecialKindName(defined).get()); } @Test - public void testDefinedItemKindIsUsedInToStringMethod() { + void testDefinedItemKindIsUsedInToStringMethod() { int defined = OpcodeStack.Item.defineSpecialKind(NEW_ITEM_KIND_NAME); OpcodeStack.Item intItem = new OpcodeStack.Item("I"); intItem.setSpecialKind(defined); String result = intItem.toString(); - assertTrue("Item.toString() does not use proper name of special kind:" + result, - result.contains(NEW_ITEM_KIND_NAME)); + assertTrue(result.contains(NEW_ITEM_KIND_NAME), + "Item.toString() does not use proper name of special kind:" + result); } } diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/SAXBugCollectionHandlerTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/SAXBugCollectionHandlerTest.java index 069b1f4d4b2..dee3ba7dc34 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/SAXBugCollectionHandlerTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/SAXBugCollectionHandlerTest.java @@ -1,7 +1,7 @@ package edu.umd.cs.findbugs; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.ByteArrayOutputStream; import java.io.StringReader; @@ -12,26 +12,26 @@ import edu.umd.cs.findbugs.classfile.IAnalysisCache; import edu.umd.cs.findbugs.classfile.impl.ClassFactory; import edu.umd.cs.findbugs.classfile.impl.ClassPathImpl; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class SAXBugCollectionHandlerTest { +class SAXBugCollectionHandlerTest { - @Before - public void setUp() { + @BeforeEach + void setUp() { IAnalysisCache analysisCache = ClassFactory.instance().createAnalysisCache(new ClassPathImpl(), new PrintingBugReporter());; Global.setAnalysisCacheForCurrentThread(analysisCache); FindBugs2.registerBuiltInAnalysisEngines(analysisCache); } - @After - public void teardown() { + @AfterEach + void teardown() { Global.removeAnalysisCacheForCurrentThread(); } @Test - public void testBugInstanceXmlPropsNoReviews() throws Exception { + void testBugInstanceXmlPropsNoReviews() throws Exception { SortedBugCollection bc = new SortedBugCollection(); bc.readXML(new StringReader( "" @@ -64,7 +64,7 @@ public void testBugInstanceXmlPropsNoReviews() throws Exception { } @Test - public void testBugInstanceXmlPropsWithReviews() throws Exception { + void testBugInstanceXmlPropsWithReviews() throws Exception { SortedBugCollection bc = new SortedBugCollection(); bc.readXML(new StringReader( "" @@ -96,7 +96,7 @@ public void testBugInstanceXmlPropsWithReviews() throws Exception { } @Test - public void testBugInstanceXmlPropsWithReviewsShouldFix() throws Exception { + void testBugInstanceXmlPropsWithReviewsShouldFix() throws Exception { SortedBugCollection bc = new SortedBugCollection(); bc.readXML(new StringReader( "" @@ -128,7 +128,7 @@ public void testBugInstanceXmlPropsWithReviewsShouldFix() throws Exception { } @Test - public void testReadAndThenStoreXmlProps() throws Exception { + void testReadAndThenStoreXmlProps() throws Exception { SortedBugCollection origBC = new SortedBugCollection(); // read it in origBC.readXML(new StringReader( @@ -170,7 +170,7 @@ public void testReadAndThenStoreXmlProps() throws Exception { } @Test - public void testReadAndThenStoreJasAttribute() throws Exception { + void testReadAndThenStoreJasAttribute() throws Exception { SortedBugCollection origBC = new SortedBugCollection(); // read it in origBC.readXML(new StringReader( diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/SynchronizedBugReporterTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/SynchronizedBugReporterTest.java index 4fc99ff666a..07b15597c89 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/SynchronizedBugReporterTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/SynchronizedBugReporterTest.java @@ -18,16 +18,16 @@ */ package edu.umd.cs.findbugs; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.concurrent.atomic.AtomicBoolean; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class SynchronizedBugReporterTest { +class SynchronizedBugReporterTest { @Test - public void testSetErrorVerbosity() { + void testSetErrorVerbosity() { AtomicBoolean called = new AtomicBoolean(); PrintingBugReporter inner = new PrintingBugReporter() { @Override diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/TextUICommandLineTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/TextUICommandLineTest.java index b4c64fee289..b3107804aca 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/TextUICommandLineTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/TextUICommandLineTest.java @@ -1,6 +1,6 @@ package edu.umd.cs.findbugs; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -10,11 +10,11 @@ import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.is; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; -public class TextUICommandLineTest { +class TextUICommandLineTest { @Test - public void handleOutputFileReturnsRemainingPart() throws IOException { + void handleOutputFileReturnsRemainingPart() throws IOException { Path file = Files.createTempFile("spotbugs", ".xml"); TextUICommandLine commandLine = new TextUICommandLine(); SortingBugReporter reporter = new SortingBugReporter(); @@ -24,7 +24,7 @@ public void handleOutputFileReturnsRemainingPart() throws IOException { } @Test - public void handleOutputFilePathUsesGzip() throws IOException { + void handleOutputFilePathUsesGzip() throws IOException { Path file = Files.createTempFile("spotbugs", ".xml.gz"); TextUICommandLine commandLine = new TextUICommandLine(); SortingBugReporter reporter = new SortingBugReporter(); @@ -37,7 +37,7 @@ public void handleOutputFilePathUsesGzip() throws IOException { } @Test - public void handleOutputFileTruncatesExisting() throws IOException { + void handleOutputFileTruncatesExisting() throws IOException { Path file = Files.createTempFile("spotbugs", ".html"); Files.writeString(file, "content"); TextUICommandLine commandLine = new TextUICommandLine(); @@ -50,7 +50,7 @@ public void handleOutputFileTruncatesExisting() throws IOException { } @Test - public void htmlReportWithOption() throws IOException { + void htmlReportWithOption() throws IOException { Path xmlFile = Files.createTempFile("spotbugs", ".xml"); Path htmlFile = Files.createTempFile("spotbugs", ".html"); Path sarifFile = Files.createTempFile("spotbugs", ".sarif"); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/VersionInsensitiveBugComparatorTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/VersionInsensitiveBugComparatorTest.java index c373b26b13e..4f9baefe26f 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/VersionInsensitiveBugComparatorTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/VersionInsensitiveBugComparatorTest.java @@ -1,14 +1,14 @@ package edu.umd.cs.findbugs; import edu.umd.cs.findbugs.xml.XMLOutput; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.util.LinkedList; import java.util.List; -public class VersionInsensitiveBugComparatorTest { +class VersionInsensitiveBugComparatorTest { static class MyBugAnnotation implements BugAnnotation { private String desc; @@ -72,7 +72,7 @@ public int compareTo(BugAnnotation o) { } @Test - public void compare1() { + void compare1() { BugInstance lbi = new BugInstance("NP_NULL_ON_SOME_PATH", Priorities.NORMAL_PRIORITY); BugInstance rbi = new BugInstance("NP_NULL_ON_SOME_PATH", Priorities.NORMAL_PRIORITY); @@ -89,11 +89,11 @@ public void compare1() { rbi.addAnnotations(rlist); VersionInsensitiveBugComparator cmp = new VersionInsensitiveBugComparator(); - Assert.assertEquals(cmp.compare(lbi, rbi), -cmp.compare(rbi, lbi)); + Assertions.assertEquals(cmp.compare(lbi, rbi), -cmp.compare(rbi, lbi)); } @Test - public void compare2() { + void compare2() { BugInstance bi1 = new BugInstance("NP_NULL_ON_SOME_PATH", Priorities.NORMAL_PRIORITY); BugInstance bi2 = new BugInstance("NP_NULL_ON_SOME_PATH", Priorities.NORMAL_PRIORITY); BugInstance bi3 = new BugInstance("NP_NULL_ON_SOME_PATH", Priorities.NORMAL_PRIORITY); @@ -116,15 +116,15 @@ public void compare2() { VersionInsensitiveBugComparator cmp = new VersionInsensitiveBugComparator(); // Because - Assert.assertTrue(cmp.compare(bi3, bi2) > 0); - Assert.assertTrue(cmp.compare(bi2, bi1) > 0); + Assertions.assertTrue(cmp.compare(bi3, bi2) > 0); + Assertions.assertTrue(cmp.compare(bi2, bi1) > 0); // So - Assert.assertTrue(cmp.compare(bi3, bi1) > 0); + Assertions.assertTrue(cmp.compare(bi3, bi1) > 0); } @Test - public void compare3() { + void compare3() { BugInstance bi1 = new BugInstance("NP_NULL_ON_SOME_PATH", Priorities.NORMAL_PRIORITY); BugInstance bi2 = new BugInstance("NP_NULL_ON_SOME_PATH", Priorities.NORMAL_PRIORITY); BugInstance bi3 = new BugInstance("NP_NULL_ON_SOME_PATH", Priorities.NORMAL_PRIORITY); @@ -148,9 +148,9 @@ public void compare3() { VersionInsensitiveBugComparator cmp = new VersionInsensitiveBugComparator(); // because - Assert.assertTrue(cmp.compare(bi1, bi2) == 0); - Assert.assertTrue(cmp.compare(bi1, bi3) < 0); + Assertions.assertTrue(cmp.compare(bi1, bi2) == 0); + Assertions.assertTrue(cmp.compare(bi1, bi3) < 0); // so - Assert.assertTrue(cmp.compare(bi2, bi3) < 0); + Assertions.assertTrue(cmp.compare(bi2, bi3) < 0); } } diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/XDocsBugReporterTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/XDocsBugReporterTest.java index 20cfd8c7521..f3fcdf78a08 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/XDocsBugReporterTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/XDocsBugReporterTest.java @@ -2,14 +2,14 @@ import edu.umd.cs.findbugs.classfile.ClassDescriptor; import edu.umd.cs.findbugs.classfile.DescriptorFactory; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.hamcrest.Matchers.is; import static org.hamcrest.MatcherAssert.assertThat; -public class XDocsBugReporterTest { +class XDocsBugReporterTest { @Test - public void reportMissingClassByClassNotFoundException() { + void reportMissingClassByClassNotFoundException() { Project project = new Project(); XDocsBugReporter bugReporter = new XDocsBugReporter(project); ClassNotFoundException ex = new ClassNotFoundException("Class org.example.Foo cannot be resolved."); @@ -19,7 +19,7 @@ public void reportMissingClassByClassNotFoundException() { } @Test - public void reportMissingClassByClassDescriptor() { + void reportMissingClassByClassDescriptor() { Project project = new Project(); XDocsBugReporter bugReporter = new XDocsBugReporter(project); ClassDescriptor classDescriptor = DescriptorFactory.createClassDescriptorFromDottedClassName("org.example.Bar"); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/FrameTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/FrameTest.java index e18f66ed612..de1b682f3fa 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/FrameTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/FrameTest.java @@ -4,12 +4,12 @@ import static org.hamcrest.Matchers.is; import static org.hamcrest.MatcherAssert.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class FrameTest { +class FrameTest { @Test - public void testToString() { + void testToString() { Frame frame = new Frame(1) { @Override public String getValue(int n) { diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue1254Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue1254Test.java index 7a1a9752762..77da2f30e4e 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue1254Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue1254Test.java @@ -1,14 +1,11 @@ package edu.umd.cs.findbugs.ba; import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; -import static org.hamcrest.Matchers.greaterThanOrEqualTo; -import static org.hamcrest.Matchers.is; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assume.assumeFalse; -import static org.junit.Assume.assumeThat; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledOnJre; +import org.junit.jupiter.api.condition.JRE; import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.BugCollection; @@ -18,23 +15,17 @@ /** * @see GitHub issue */ -public class Issue1254Test extends AbstractIntegrationTest { +class Issue1254Test extends AbstractIntegrationTest { + // These tests require java 11 or better to run private static final String[] CLASS_LIST = { "../java11/module-info.class", "../java11/Issue1254.class", "../java11/Issue1254$Inner.class", "../java11/Issue1254$1.class", }; - @Before - public void verifyJavaVersion() { - assumeFalse(System.getProperty("java.specification.version").startsWith("1.")); - int javaVersion = Integer.parseInt(System.getProperty("java.specification.version")); - assumeThat(javaVersion, is(greaterThanOrEqualTo(11))); - } - /** * Test that accessing private members of a nested class doesn't result in unresolvable reference problems. */ @Test - public void testUnresolvableReference() { + void testUnresolvableReference() { performAnalysis(CLASS_LIST); BugInstanceMatcher bugTypeMatcher = new BugInstanceMatcherBuilder().bugType("VR_UNRESOLVABLE_REFERENCE") .build(); @@ -45,7 +36,8 @@ public void testUnresolvableReference() { * Test that accessing private members of a nested class doesn't result in uncalled method problems. */ @Test - public void testUncalledPrivateMethod() { + @DisabledOnJre(JRE.JAVA_8) + void testUncalledPrivateMethod() { performAnalysis(CLASS_LIST); BugInstanceMatcher bugTypeMatcher = new BugInstanceMatcherBuilder().bugType("UPM_UNCALLED_PRIVATE_METHOD") .build(); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue1338Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue1338Test.java index 13b0c1349af..766cb89f72e 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue1338Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue1338Test.java @@ -1,9 +1,11 @@ package edu.umd.cs.findbugs.ba; import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledOnJre; +import org.junit.jupiter.api.condition.JRE; import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; @@ -12,15 +14,17 @@ /** * @see GitHub issue */ -public class Issue1338Test extends AbstractIntegrationTest { +class Issue1338Test extends AbstractIntegrationTest { + // These tests require java 11 or better to run private static final String[] CLASS_LIST = { "../java11/module-info.class", "../java11/Issue1338.class", }; /** * Test that calling a method call when initializing a try-with-resource variable doesn't result in redundant nullcheck of nonnull value. */ @Test - public void testMethodCallInTryWithResource() { + @DisabledOnJre(JRE.JAVA_8) + void testMethodCallInTryWithResource() { performAnalysis(CLASS_LIST); BugInstanceMatcher bugTypeMatcher = new BugInstanceMatcherBuilder().bugType("RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE") .build(); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue1367Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue1367Test.java index 999c2c5c611..4151528b1ea 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue1367Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue1367Test.java @@ -1,11 +1,15 @@ package edu.umd.cs.findbugs.ba; import edu.umd.cs.findbugs.BugCollection; -import edu.umd.cs.findbugs.test.SpotBugsRule; +import edu.umd.cs.findbugs.test.SpotBugsExtension; +import edu.umd.cs.findbugs.test.SpotBugsRunner; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; -import org.junit.Rule; -import org.junit.Test; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledOnJre; +import org.junit.jupiter.api.condition.JRE; +import org.junit.jupiter.api.extension.ExtendWith; import java.nio.file.Paths; @@ -15,12 +19,12 @@ /** * @see The related GitHub issue */ -public class Issue1367Test { - @Rule - public SpotBugsRule spotbugs = new SpotBugsRule(); +@ExtendWith(SpotBugsExtension.class) +class Issue1367Test { @Test - public void test() { + @DisabledOnJre({ JRE.JAVA_8, JRE.JAVA_11 }) + void testIssue(SpotBugsRunner spotbugs) { BugCollection bugCollection = spotbugs.performAnalysis(Paths.get("../spotbugsTestCases/build/classes/java/java17/Issue1367.class")); BugInstanceMatcher bugTypeMatcher = new BugInstanceMatcherBuilder().bugType("EQ_UNUSUAL").build(); assertThat(bugCollection, containsExactly(0, bugTypeMatcher)); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue1464Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue1464Test.java index 1fb5a72b662..81903eb6736 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue1464Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue1464Test.java @@ -3,7 +3,7 @@ import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; import static org.hamcrest.MatcherAssert.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; @@ -13,10 +13,10 @@ * @see GitHub issue #1464 */ -public class Issue1464Test extends AbstractIntegrationTest { +class Issue1464Test extends AbstractIntegrationTest { @Test - public void test() { + void testIssue() { performAnalysis("ghIssues/Issue1464.class"); BugInstanceMatcher bugTypeMatcher = new BugInstanceMatcherBuilder().bugType("DMI_RANDOM_USED_ONLY_ONCE").build(); assertThat(getBugCollection(), containsExactly(2, bugTypeMatcher)); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue2145Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue2145Test.java index 198e02920bd..c762d468ae5 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue2145Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue2145Test.java @@ -5,12 +5,12 @@ import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.SortedBugCollection; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class Issue2145Test extends AbstractIntegrationTest { +class Issue2145Test extends AbstractIntegrationTest { @Test - public void test() { + void testIssue() { performAnalysis("ghIssues/Issue2145.class"); SortedBugCollection bugCollection = (SortedBugCollection) getBugCollection(); assertThat(bugCollection.getErrors(), hasSize(0)); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue2402Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue2402Test.java index 4ed22aaf4c9..72304a1c674 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue2402Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue2402Test.java @@ -3,17 +3,17 @@ import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; import static org.hamcrest.MatcherAssert.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; import edu.umd.cs.findbugs.SortedBugCollection; -public class Issue2402Test extends AbstractIntegrationTest { +class Issue2402Test extends AbstractIntegrationTest { @Test - public void test() { + void testIssue() { performAnalysis("ghIssues/issue2402/TestA.class", "ghIssues/issue2402/TestA$UMap.class", "ghIssues/issue2402/TestB.class", diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue371Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue371Test.java index fb4e89b5882..8c9b65fb1d3 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue371Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue371Test.java @@ -3,16 +3,16 @@ import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; import static org.hamcrest.MatcherAssert.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; -public class Issue371Test extends AbstractIntegrationTest { +class Issue371Test extends AbstractIntegrationTest { @Test - public void test() { + void testIssue() { performAnalysis("lambdas/Issue371.class"); final BugInstanceMatcher bugTypeMatcher = new BugInstanceMatcherBuilder() .bugType("NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE").build(); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue389Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue389Test.java index 7412a70ad91..577bf1a9d8f 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue389Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue389Test.java @@ -3,16 +3,16 @@ import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; import static org.hamcrest.MatcherAssert.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; -public class Issue389Test extends AbstractIntegrationTest { +class Issue389Test extends AbstractIntegrationTest { @Test - public void test() { + void testIssue() { performAnalysis("ghIssues/Issue389.class"); BugInstanceMatcher bugTypeMatcher = new BugInstanceMatcherBuilder().bugType("UC_USELESS_VOID_METHOD").build(); assertThat(getBugCollection(), containsExactly(3, bugTypeMatcher)); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue390Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue390Test.java index 44665e43f70..c12e8e6b47f 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue390Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue390Test.java @@ -5,7 +5,7 @@ import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; import org.hamcrest.MatcherAssert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.io.StringWriter; @@ -14,10 +14,10 @@ import static org.hamcrest.Matchers.containsString; import static org.hamcrest.MatcherAssert.assertThat; -public class Issue390Test extends AbstractIntegrationTest { +class Issue390Test extends AbstractIntegrationTest { @Test - public void test() { + void testIssue() { performAnalysis("ghIssues/Issue390.class"); BugInstanceMatcher bugTypeMatcher = new BugInstanceMatcherBuilder().bugType("JUA_DONT_ASSERT_INSTANCEOF_IN_TESTS").build(); MatcherAssert.assertThat(getBugCollection(), containsExactly(1, bugTypeMatcher)); @@ -27,7 +27,7 @@ public void test() { * @see The reported GitHub issue */ @Test - public void testXmlGeneratability() throws IOException { + void testXmlGeneratability() throws IOException { performAnalysis("ghIssues/Issue390.class"); StringWriter writer = new StringWriter(); getBugCollection().setWithMessages(true); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue408Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue408Test.java index c87c06e11ba..3423b28cbc8 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue408Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue408Test.java @@ -3,17 +3,14 @@ import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assume.assumeFalse; -import static org.junit.Assume.assumeThat; import java.io.IOException; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledOnJre; +import org.junit.jupiter.api.condition.JRE; import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; @@ -23,27 +20,21 @@ * @see #408 * @since 3.1 */ -public class Issue408Test extends AbstractIntegrationTest { - @Rule - public ExpectedException expected = ExpectedException.none(); - - @Before - public void verifyJavaVersion() { - assumeFalse(System.getProperty("java.specification.version").startsWith("1.")); - int javaVersion = Integer.parseInt(System.getProperty("java.specification.version")); - assumeThat(javaVersion, is(greaterThanOrEqualTo(11))); - } +class Issue408Test extends AbstractIntegrationTest { @Test - public void testSingleClass() { - expected.expect(AssertionError.class); - expected.expectMessage("Analysis failed with exception"); - expected.expectCause(is(instanceOf(IOException.class))); - performAnalysis("../java11/module-info.class"); + @DisabledOnJre(JRE.JAVA_8) + void testSingleClass() { + Throwable throwable = Assertions.assertThrows(AssertionError.class, () -> { + performAnalysis("../java11/module-info.class"); + }); + Assertions.assertEquals("Analysis failed with exception", throwable.getMessage()); + assertThat(throwable.getCause(), is(instanceOf(IOException.class))); } @Test - public void testFewClasses() { + @DisabledOnJre(JRE.JAVA_8) + void testFewClasses() { performAnalysis("../java11/module-info.class", "../java11/Issue408.class"); BugInstanceMatcher bugTypeMatcher = new BugInstanceMatcherBuilder().build(); assertThat(getBugCollection(), containsExactly(0, bugTypeMatcher)); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue413Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue413Test.java index 92228a773c7..11689b83a6d 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue413Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue413Test.java @@ -3,16 +3,16 @@ import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; import static org.hamcrest.MatcherAssert.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; -public class Issue413Test extends AbstractIntegrationTest { +class Issue413Test extends AbstractIntegrationTest { @Test - public void test() { + void testIssue() { performAnalysis("ghIssues/Issue413.class"); BugInstanceMatcher bugTypeMatcher = new BugInstanceMatcherBuilder().build(); assertThat(getBugCollection(), containsExactly(0, bugTypeMatcher)); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue429Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue429Test.java index 4ffb1826836..9fc87d84188 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue429Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue429Test.java @@ -5,23 +5,23 @@ import java.nio.file.Paths; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import edu.umd.cs.findbugs.BugCollection; -import edu.umd.cs.findbugs.test.SpotBugsRule; +import edu.umd.cs.findbugs.test.SpotBugsExtension; +import edu.umd.cs.findbugs.test.SpotBugsRunner; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; /** * Unit test to reproduce #429. */ -public class Issue429Test { - @Rule - public SpotBugsRule spotbugs = new SpotBugsRule(); +@ExtendWith(SpotBugsExtension.class) +class Issue429Test { @Test - public void test() { + void testIssue(SpotBugsRunner spotbugs) { BugCollection bugCollection = spotbugs.performAnalysis( Paths.get("../spotbugsTestCases/build/classes/java/main/ghIssues/Issue429.class")); BugInstanceMatcher matcher = new BugInstanceMatcherBuilder().bugType("RV_RETURN_VALUE_IGNORED") diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue516Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue516Test.java index 72c0ec61683..9e7a5529d39 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue516Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue516Test.java @@ -3,17 +3,17 @@ import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; import static org.hamcrest.MatcherAssert.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.LocalVariableAnnotation; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; -public class Issue516Test extends AbstractIntegrationTest { +class Issue516Test extends AbstractIntegrationTest { @Test - public void test() { + void testIssue() { performAnalysis("ghIssues/Issue516.class"); // Both ecj/javac compilers as of today do not generate LVT entry for unused variables in some cases. // I would consider this as a compiler bug, so may be it will be fixed some time later. diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue527Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue527Test.java index 4e328049af4..95fc5d79aaf 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue527Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue527Test.java @@ -1,7 +1,7 @@ package edu.umd.cs.findbugs.ba; import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.hamcrest.MatcherAssert.assertThat; import java.util.ArrayList; @@ -9,17 +9,17 @@ import java.util.Iterator; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.SortedBugCollection; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; -public class Issue527Test extends AbstractIntegrationTest { +class Issue527Test extends AbstractIntegrationTest { @Test - public void testSimpleLambdas() { + void testSimpleLambdas() { performAnalysis("lambdas/Issue527.class"); final BugInstanceMatcher bugTypeMatcher = new BugInstanceMatcherBuilder() .bugType("NP_NULL_ON_SOME_PATH").build(); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue547Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue547Test.java index 2e5c31767ea..52f7528c8bb 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue547Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue547Test.java @@ -1,7 +1,7 @@ package edu.umd.cs.findbugs.ba; import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.hamcrest.MatcherAssert.assertThat; import java.util.ArrayList; @@ -9,17 +9,17 @@ import java.util.Iterator; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.SortedBugCollection; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; -public class Issue547Test extends AbstractIntegrationTest { +class Issue547Test extends AbstractIntegrationTest { @Test - public void testLambdas() { + void testLambdas() { performAnalysis("lambdas/Issue547.class"); final BugInstanceMatcher bugTypeMatcher = new BugInstanceMatcherBuilder().build(); SortedBugCollection bugCollection = (SortedBugCollection) getBugCollection(); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue688Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue688Test.java index ed43bbe711f..9f00edd9e5f 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue688Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue688Test.java @@ -21,17 +21,17 @@ import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; import static org.hamcrest.MatcherAssert.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.SortedBugCollection; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; -public class Issue688Test extends AbstractIntegrationTest { +class Issue688Test extends AbstractIntegrationTest { @Test - public void test() { + void testIssue() { performAnalysis("ghIssues/Issue688.class"); final BugInstanceMatcher bugTypeMatcher = new BugInstanceMatcherBuilder().build(); SortedBugCollection bugCollection = (SortedBugCollection) getBugCollection(); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue758Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue758Test.java index f4bf06a3b7b..f4aae1f552b 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue758Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue758Test.java @@ -21,15 +21,15 @@ import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.MatcherAssert.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.SortedBugCollection; -public class Issue758Test extends AbstractIntegrationTest { +class Issue758Test extends AbstractIntegrationTest { @Test - public void test() { + void testIssue() { performAnalysis("ghIssues/Issue758.class"); SortedBugCollection bugCollection = (SortedBugCollection) getBugCollection(); assertThat(bugCollection.getErrors(), hasSize(0)); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue893Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue893Test.java index 947b22b25d5..2289f833745 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue893Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue893Test.java @@ -3,16 +3,16 @@ import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; import static org.hamcrest.MatcherAssert.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; -public class Issue893Test extends AbstractIntegrationTest { +class Issue893Test extends AbstractIntegrationTest { @Test - public void test() { + void testIssue() { performAnalysis("ghIssues/Issue893.class"); BugInstanceMatcher bugTypeMatcher = new BugInstanceMatcherBuilder().build(); assertThat(getBugCollection(), containsExactly(0, bugTypeMatcher)); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/MethodHashTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/MethodHashTest.java index ef1690868d9..9df2072cffa 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/MethodHashTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/MethodHashTest.java @@ -21,14 +21,14 @@ import java.util.Arrays; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * @author David Hovemeyer */ -public class MethodHashTest { +class MethodHashTest { byte[] hash; @@ -44,14 +44,8 @@ public class MethodHashTest { byte[] longerHash; - /* - * (non-Javadoc) - * - * @see junit.framework.TestCase#setUp() - */ - - @Before - public void setUp() { + @BeforeEach + void setUp() { hash = new byte[] { 0x06, 0x04, (byte) 0xDE, (byte) 0xAD, (byte) 0xBE, (byte) 0xEF }; s = "0604deadbeef"; sameHash = new byte[] { 0x06, 0x04, (byte) 0xDE, (byte) 0xAD, (byte) 0xBE, (byte) 0xEF }; @@ -62,40 +56,40 @@ public void setUp() { } @Test - public void testHashToString() { + void testHashToString() { String s2 = ClassHash.hashToString(hash); - Assert.assertEquals(s, s2); + Assertions.assertEquals(s, s2); } @Test - public void testStringToHash() { + void testStringToHash() { byte[] hash2 = ClassHash.stringToHash(s); - Assert.assertTrue(Arrays.equals(hash, hash2)); + Assertions.assertTrue(Arrays.equals(hash, hash2)); } @Test - public void testSame() { - Assert.assertTrue(MethodHash.compareHashes(hash, sameHash) == 0); - Assert.assertTrue(MethodHash.compareHashes(sameHash, hash) == 0); + void testSame() { + Assertions.assertTrue(MethodHash.compareHashes(hash, sameHash) == 0); + Assertions.assertTrue(MethodHash.compareHashes(sameHash, hash) == 0); } @Test - public void testGreater() { - Assert.assertTrue(MethodHash.compareHashes(hash, greaterHash) < 0); + void testGreater() { + Assertions.assertTrue(MethodHash.compareHashes(hash, greaterHash) < 0); } @Test - public void testLesser() { - Assert.assertTrue(MethodHash.compareHashes(hash, lesserHash) > 0); + void testLesser() { + Assertions.assertTrue(MethodHash.compareHashes(hash, lesserHash) > 0); } @Test - public void testShorter() { - Assert.assertTrue(MethodHash.compareHashes(hash, shorterHash) > 0); + void testShorter() { + Assertions.assertTrue(MethodHash.compareHashes(hash, shorterHash) > 0); } @Test - public void testLonger() { - Assert.assertTrue(MethodHash.compareHashes(hash, longerHash) < 0); + void testLonger() { + Assertions.assertTrue(MethodHash.compareHashes(hash, longerHash) < 0); } } diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/NullnessAnnotationTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/NullnessAnnotationTest.java index 0ecd532fbc0..6c2b9dd5d2d 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/NullnessAnnotationTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/NullnessAnnotationTest.java @@ -2,56 +2,51 @@ import static org.hamcrest.Matchers.is; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import java.util.stream.Stream; + +import static org.hamcrest.MatcherAssert.assertThat; + +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.ParameterizedTest; /** * Verifies {@link NullnessAnnotation} parser. * * @author kzaikin */ -@RunWith(Parameterized.class) public class NullnessAnnotationTest { - @Parameterized.Parameters(name = "{0} is {1}") - public static Object[][] parameters() { - return new Object[][] { - { "android.support.annotation.NonNull", NullnessAnnotation.NONNULL }, - { "android.support.annotation.Nullable", NullnessAnnotation.CHECK_FOR_NULL }, + private static Stream parameters() { + return Stream.of( + Arguments.of("android.support.annotation.NonNull", NullnessAnnotation.NONNULL), + Arguments.of("android.support.annotation.Nullable", NullnessAnnotation.CHECK_FOR_NULL), - // there is no such thing as com.google.common.base.NonNull - { "com.google.common.base.Nullable", NullnessAnnotation.CHECK_FOR_NULL }, + // there is no such thing as com.google.common.base.NonNull + Arguments.of("com.google.common.base.Nullable", NullnessAnnotation.CHECK_FOR_NULL), - { "org.eclipse.jdt.annotation.NonNull", NullnessAnnotation.NONNULL }, - { "org.eclipse.jdt.annotation.Nullable", NullnessAnnotation.CHECK_FOR_NULL }, + Arguments.of("org.eclipse.jdt.annotation.NonNull", NullnessAnnotation.NONNULL), + Arguments.of("org.eclipse.jdt.annotation.Nullable", NullnessAnnotation.CHECK_FOR_NULL), - { "org.jetbrains.annotations.NotNull", NullnessAnnotation.NONNULL }, - { "org.jetbrains.annotations.Nullable", NullnessAnnotation.CHECK_FOR_NULL }, + Arguments.of("org.jetbrains.annotations.NotNull", NullnessAnnotation.NONNULL), + Arguments.of("org.jetbrains.annotations.Nullable", NullnessAnnotation.CHECK_FOR_NULL), - { "org.checkerframework.checker.nullness.qual.Nullable", NullnessAnnotation.CHECK_FOR_NULL }, - { "org.checkerframework.checker.nullness.compatqual.NullableDecl", NullnessAnnotation.CHECK_FOR_NULL }, + Arguments.of("org.checkerframework.checker.nullness.qual.Nullable", NullnessAnnotation.CHECK_FOR_NULL), + Arguments.of("org.checkerframework.checker.nullness.compatqual.NullableDecl", NullnessAnnotation.CHECK_FOR_NULL), - { edu.umd.cs.findbugs.annotations.CheckForNull.class.getName(), NullnessAnnotation.CHECK_FOR_NULL }, - { edu.umd.cs.findbugs.annotations.PossiblyNull.class.getName(), NullnessAnnotation.CHECK_FOR_NULL }, + Arguments.of(edu.umd.cs.findbugs.annotations.CheckForNull.class.getName(), NullnessAnnotation.CHECK_FOR_NULL), + Arguments.of(edu.umd.cs.findbugs.annotations.PossiblyNull.class.getName(), NullnessAnnotation.CHECK_FOR_NULL), - { javax.annotation.CheckForNull.class.getName(), NullnessAnnotation.CHECK_FOR_NULL }, - { javax.annotation.Nonnull.class.getName(), NullnessAnnotation.NONNULL }, - { javax.annotation.Nullable.class.getName(), NullnessAnnotation.NULLABLE }, + Arguments.of(javax.annotation.CheckForNull.class.getName(), NullnessAnnotation.CHECK_FOR_NULL), + Arguments.of(javax.annotation.Nonnull.class.getName(), NullnessAnnotation.NONNULL), + Arguments.of(javax.annotation.Nullable.class.getName(), NullnessAnnotation.NULLABLE), - { "something different", null }, - }; + Arguments.of("something different", null)); } - @Parameterized.Parameter(value = 0) - public String annotation; - - @Parameterized.Parameter(value = 1) - public NullnessAnnotation ofType; - - @Test - public void annotationRecognition() { - Assert.assertThat(NullnessAnnotation.Parser.parse(annotation), is(ofType)); + @ParameterizedTest + @MethodSource("parameters") + void annotationRecognition(String annotation, NullnessAnnotation ofType) { + assertThat(NullnessAnnotation.Parser.parse(annotation), is(ofType)); } } diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/SignatureParserTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/SignatureParserTest.java index 5de2a2f8942..d54382a446d 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/SignatureParserTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/SignatureParserTest.java @@ -2,36 +2,36 @@ import java.util.Iterator; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; -public class SignatureParserTest { +class SignatureParserTest { @Test - public void testNoParams() { + void testNoParams() { SignatureParser sut = new SignatureParser("()V"); Iterator i = sut.parameterSignatureIterator(); - Assert.assertFalse(i.hasNext()); + Assertions.assertFalse(i.hasNext()); } @Test - public void testManyParams() { + void testManyParams() { SignatureParser sut = new SignatureParser("(IJFDZLjava/lang/String;B)Ljava/lang/Object;"); Iterator i = sut.parameterSignatureIterator(); - Assert.assertTrue(i.hasNext()); - Assert.assertEquals(i.next(), "I"); - Assert.assertTrue(i.hasNext()); - Assert.assertEquals(i.next(), "J"); - Assert.assertTrue(i.hasNext()); - Assert.assertEquals(i.next(), "F"); - Assert.assertTrue(i.hasNext()); - Assert.assertEquals(i.next(), "D"); - Assert.assertTrue(i.hasNext()); - Assert.assertEquals(i.next(), "Z"); - Assert.assertTrue(i.hasNext()); - Assert.assertEquals(i.next(), "Ljava/lang/String;"); - Assert.assertTrue(i.hasNext()); - Assert.assertEquals(i.next(), "B"); - Assert.assertFalse(i.hasNext()); + Assertions.assertTrue(i.hasNext()); + Assertions.assertEquals(i.next(), "I"); + Assertions.assertTrue(i.hasNext()); + Assertions.assertEquals(i.next(), "J"); + Assertions.assertTrue(i.hasNext()); + Assertions.assertEquals(i.next(), "F"); + Assertions.assertTrue(i.hasNext()); + Assertions.assertEquals(i.next(), "D"); + Assertions.assertTrue(i.hasNext()); + Assertions.assertEquals(i.next(), "Z"); + Assertions.assertTrue(i.hasNext()); + Assertions.assertEquals(i.next(), "Ljava/lang/String;"); + Assertions.assertTrue(i.hasNext()); + Assertions.assertEquals(i.next(), "B"); + Assertions.assertFalse(i.hasNext()); } } diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/ch/Subtypes2Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/ch/Subtypes2Test.java index 7cb2c8741b0..b51ee9618ec 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/ch/Subtypes2Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/ch/Subtypes2Test.java @@ -22,6 +22,9 @@ import org.apache.bcel.generic.ArrayType; import org.apache.bcel.generic.ObjectType; import org.apache.bcel.generic.Type; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import edu.umd.cs.findbugs.FindBugsTestCase; import edu.umd.cs.findbugs.RunnableWithExceptions; @@ -36,7 +39,7 @@ * @author Bill Pugh * @author David Hovemeyer */ -public class Subtypes2Test extends FindBugsTestCase { +class Subtypes2Test extends FindBugsTestCase { ObjectType typeSerializable; @@ -90,14 +93,8 @@ public class Subtypes2Test extends FindBugsTestCase { ObjectType typeParameterString; - /* - * (non-Javadoc) - * - * @see junit.framework.TestCase#setUp() - */ - @Override - protected void setUp() throws Exception { - super.setUp(); + @BeforeEach + void setUp() throws Exception { typeSerializable = ObjectTypeFactory.getInstance("java.io.Serializable"); typeClonable = ObjectTypeFactory.getInstance("java.lang.Cloneable"); typeObject = ObjectTypeFactory.getInstance(Values.DOTTED_JAVA_LANG_OBJECT); @@ -131,7 +128,8 @@ private static Subtypes2 getSubtypes2() { return Global.getAnalysisCache().getDatabase(Subtypes2.class); } - public void testStringSubtypeOfObject() throws Throwable { + @Test + void testStringSubtypeOfObject() throws Throwable { executeFindBugsTest(new RunnableWithExceptions() { /* * (non-Javadoc) @@ -142,12 +140,13 @@ public void testStringSubtypeOfObject() throws Throwable { public void run() throws Throwable { Subtypes2 test = getSubtypes2(); - assertTrue(test.isSubtype(typeString, typeObject)); + Assertions.assertTrue(test.isSubtype(typeString, typeObject)); } }); } - public void testStringSubtypeOfSerializable() throws Throwable { + @Test + void testStringSubtypeOfSerializable() throws Throwable { executeFindBugsTest(new RunnableWithExceptions() { /* * (non-Javadoc) @@ -158,12 +157,13 @@ public void testStringSubtypeOfSerializable() throws Throwable { public void run() throws Throwable { Subtypes2 test = getSubtypes2(); - assertTrue(test.isSubtype(typeString, typeSerializable)); + Assertions.assertTrue(test.isSubtype(typeString, typeSerializable)); } }); } - public void testIdentitySubtype() throws Throwable { + @Test + void testIdentitySubtype() throws Throwable { executeFindBugsTest(new RunnableWithExceptions() { /* * (non-Javadoc) @@ -174,25 +174,27 @@ public void testIdentitySubtype() throws Throwable { public void run() throws Throwable { Subtypes2 test = getSubtypes2(); - assertTrue(test.isSubtype(typeObject, typeObject)); - assertTrue(test.isSubtype(typeSerializable, typeSerializable)); - assertTrue(test.isSubtype(typeArrayClonable, typeArrayClonable)); + Assertions.assertTrue(test.isSubtype(typeObject, typeObject)); + Assertions.assertTrue(test.isSubtype(typeSerializable, typeSerializable)); + Assertions.assertTrue(test.isSubtype(typeArrayClonable, typeArrayClonable)); } }); } - public void testInterfaceIsSubtypeOfObject() throws Throwable { + @Test + void testInterfaceIsSubtypeOfObject() throws Throwable { executeFindBugsTest(new RunnableWithExceptions() { @Override public void run() throws ClassNotFoundException { Subtypes2 test = getSubtypes2(); - assertTrue(test.isSubtype(typeClonable, typeObject)); + Assertions.assertTrue(test.isSubtype(typeClonable, typeObject)); } }); } - public void testArrays() throws Throwable { + @Test + void testArrays() throws Throwable { executeFindBugsTest(new RunnableWithExceptions() { /* * (non-Javadoc) @@ -203,13 +205,14 @@ public void testArrays() throws Throwable { public void run() throws Throwable { Subtypes2 test = getSubtypes2(); - assertTrue(test.isSubtype(typeArrayClonable, typeObject)); - assertTrue(test.isSubtype(typeArrayClonable, typeArrayObject)); + Assertions.assertTrue(test.isSubtype(typeArrayClonable, typeObject)); + Assertions.assertTrue(test.isSubtype(typeArrayClonable, typeArrayObject)); } }); } - public void testUnrelatedTypes() throws Throwable { + @Test + void testUnrelatedTypes() throws Throwable { executeFindBugsTest(new RunnableWithExceptions() { /* * (non-Javadoc) @@ -220,12 +223,13 @@ public void testUnrelatedTypes() throws Throwable { public void run() throws Throwable { Subtypes2 test = getSubtypes2(); - assertFalse(test.isSubtype(typeInteger, typeString)); + Assertions.assertFalse(test.isSubtype(typeInteger, typeString)); } }); } - public void testArraysWrongDimension() throws Throwable { + @Test + void testArraysWrongDimension() throws Throwable { executeFindBugsTest(new RunnableWithExceptions() { /* * (non-Javadoc) @@ -236,12 +240,13 @@ public void testArraysWrongDimension() throws Throwable { public void run() throws Throwable { Subtypes2 test = getSubtypes2(); - assertFalse(test.isSubtype(typeArrayArrayString, typeArrayString)); + Assertions.assertFalse(test.isSubtype(typeArrayArrayString, typeArrayString)); } }); } - public void testMultidimensionalArrayIsSubtypeOfObjectArray() throws Throwable { + @Test + void testMultidimensionalArrayIsSubtypeOfObjectArray() throws Throwable { executeFindBugsTest(new RunnableWithExceptions() { /* * (non-Javadoc) @@ -252,14 +257,15 @@ public void testMultidimensionalArrayIsSubtypeOfObjectArray() throws Throwable { public void run() throws Throwable { Subtypes2 test = getSubtypes2(); - assertTrue(test.isSubtype(typeArrayArrayString, typeArrayObject)); - assertTrue(test.isSubtype(typeArrayArraySerializable, typeArrayObject)); - assertTrue(test.isSubtype(typeArrayArrayInt, typeArrayObject)); + Assertions.assertTrue(test.isSubtype(typeArrayArrayString, typeArrayObject)); + Assertions.assertTrue(test.isSubtype(typeArrayArraySerializable, typeArrayObject)); + Assertions.assertTrue(test.isSubtype(typeArrayArrayInt, typeArrayObject)); } }); } - public void testArrayOfPrimitiveIsSubtypeOfObject() throws Throwable { + @Test + void testArrayOfPrimitiveIsSubtypeOfObject() throws Throwable { executeFindBugsTest(new RunnableWithExceptions() { /* * (non-Javadoc) @@ -270,12 +276,13 @@ public void testArrayOfPrimitiveIsSubtypeOfObject() throws Throwable { public void run() throws Exception { Subtypes2 test = getSubtypes2(); - assertTrue(test.isSubtype(typeArrayInt, typeObject)); + Assertions.assertTrue(test.isSubtype(typeArrayInt, typeObject)); } }); } - public void testSpecialStringSubclasses() throws Exception { + @Test + void testSpecialStringSubclasses() throws Exception { executeFindBugsTest(new RunnableWithExceptions() { /* * (non-Javadoc) @@ -286,14 +293,15 @@ public void testSpecialStringSubclasses() throws Exception { public void run() throws Exception { Subtypes2 test = getSubtypes2(); - assertTrue(test.isSubtype(typeDynamicString, typeString)); - assertTrue(test.isSubtype(typeStaticString, typeString)); - assertTrue(test.isSubtype(typeParameterString, typeString)); + Assertions.assertTrue(test.isSubtype(typeDynamicString, typeString)); + Assertions.assertTrue(test.isSubtype(typeStaticString, typeString)); + Assertions.assertTrue(test.isSubtype(typeParameterString, typeString)); } }); } - public void testEasyFirstCommonSuperclass() throws Exception { + @Test + void testEasyFirstCommonSuperclass() throws Exception { executeFindBugsTest(new RunnableWithExceptions() { /* * (non-Javadoc) @@ -304,18 +312,19 @@ public void testEasyFirstCommonSuperclass() throws Exception { public void run() throws Throwable { Subtypes2 test = getSubtypes2(); - assertEquals(typeObject, test.getFirstCommonSuperclass(typeObject, typeObject)); - assertEquals(typeString, test.getFirstCommonSuperclass(typeString, typeString)); - assertEquals(typeObject, test.getFirstCommonSuperclass(typeString, typeObject)); - assertEquals(typeObject, test.getFirstCommonSuperclass(typeObject, typeString)); + Assertions.assertEquals(typeObject, test.getFirstCommonSuperclass(typeObject, typeObject)); + Assertions.assertEquals(typeString, test.getFirstCommonSuperclass(typeString, typeString)); + Assertions.assertEquals(typeObject, test.getFirstCommonSuperclass(typeString, typeObject)); + Assertions.assertEquals(typeObject, test.getFirstCommonSuperclass(typeObject, typeString)); // Slightly harder one - assertEquals(typeComparable, test.getFirstCommonSuperclass(typeString, typeInteger)); + Assertions.assertEquals(typeComparable, test.getFirstCommonSuperclass(typeString, typeInteger)); } }); } - public void testInterfaceFirstCommonSuperclass() throws Exception { + @Test + void testInterfaceFirstCommonSuperclass() throws Exception { executeFindBugsTest(new RunnableWithExceptions() { /* * (non-Javadoc) @@ -326,16 +335,17 @@ public void testInterfaceFirstCommonSuperclass() throws Exception { public void run() throws Throwable { Subtypes2 test = getSubtypes2(); - assertEquals(typeObject, test.getFirstCommonSuperclass(typeSerializable, typeObject)); - assertEquals(typeObject, test.getFirstCommonSuperclass(typeObject, typeSerializable)); - assertEquals(typeObject, test.getFirstCommonSuperclass(typeSerializable, typeClonable)); + Assertions.assertEquals(typeObject, test.getFirstCommonSuperclass(typeSerializable, typeObject)); + Assertions.assertEquals(typeObject, test.getFirstCommonSuperclass(typeObject, typeSerializable)); + Assertions.assertEquals(typeObject, test.getFirstCommonSuperclass(typeSerializable, typeClonable)); - assertEquals(typeSerializable, test.getFirstCommonSuperclass(typeSerializable, typeSerializable)); + Assertions.assertEquals(typeSerializable, test.getFirstCommonSuperclass(typeSerializable, typeSerializable)); } }); } - public void testArrayFirstCommonSuperclass() throws Exception { + @Test + void testArrayFirstCommonSuperclass() throws Exception { executeFindBugsTest(new RunnableWithExceptions() { /* * (non-Javadoc) @@ -346,50 +356,52 @@ public void testArrayFirstCommonSuperclass() throws Exception { public void run() throws Throwable { Subtypes2 test = getSubtypes2(); - assertEquals(typeObject, test.getFirstCommonSuperclass(typeArrayInteger, typeObject)); - assertEquals(typeObject, test.getFirstCommonSuperclass(typeSerializable, typeArrayClonable)); + Assertions.assertEquals(typeObject, test.getFirstCommonSuperclass(typeArrayInteger, typeObject)); + Assertions.assertEquals(typeObject, test.getFirstCommonSuperclass(typeSerializable, typeArrayClonable)); - assertEquals(typeArrayComparable, test.getFirstCommonSuperclass(typeArrayString, typeArrayInteger)); + Assertions.assertEquals(typeArrayComparable, test.getFirstCommonSuperclass(typeArrayString, typeArrayInteger)); - assertEquals(typeArrayInt, test.getFirstCommonSuperclass(typeArrayInt, typeArrayInt)); - assertEquals(typeObject, test.getFirstCommonSuperclass(typeArrayChar, typeArrayInt)); + Assertions.assertEquals(typeArrayInt, test.getFirstCommonSuperclass(typeArrayInt, typeArrayInt)); + Assertions.assertEquals(typeObject, test.getFirstCommonSuperclass(typeArrayChar, typeArrayInt)); - assertEquals(typeObject, test.getFirstCommonSuperclass(typeArrayString, typeArrayInt)); + Assertions.assertEquals(typeObject, test.getFirstCommonSuperclass(typeArrayString, typeArrayInt)); - assertEquals(typeArrayObject, test.getFirstCommonSuperclass(typeArrayArraySerializable, typeArrayString)); + Assertions.assertEquals(typeArrayObject, test.getFirstCommonSuperclass(typeArrayArraySerializable, typeArrayString)); - assertEquals(typeObject, test.getFirstCommonSuperclass(typeArrayArrayString, typeArrayInt)); + Assertions.assertEquals(typeObject, test.getFirstCommonSuperclass(typeArrayArrayString, typeArrayInt)); } }); } - public void testArrayFirstCommonSuperclassTricky() throws Exception { + @Test + void testArrayFirstCommonSuperclassTricky() throws Exception { executeFindBugsTest(new RunnableWithExceptions() { @Override public void run() throws Throwable { Subtypes2 test = getSubtypes2(); - assertEquals(typeArrayObject, test.getFirstCommonSuperclass(typeArrayArrayInt, typeArrayArrayChar)); - assertEquals(typeArrayObject, test.getFirstCommonSuperclass(typeArrayArrayInt, typeArrayArrayArrayChar)); - assertEquals(typeArrayArrayObject, test.getFirstCommonSuperclass(typeArrayArrayArrayChar, typeArrayArrayArrayInt)); + Assertions.assertEquals(typeArrayObject, test.getFirstCommonSuperclass(typeArrayArrayInt, typeArrayArrayChar)); + Assertions.assertEquals(typeArrayObject, test.getFirstCommonSuperclass(typeArrayArrayInt, typeArrayArrayArrayChar)); + Assertions.assertEquals(typeArrayArrayObject, test.getFirstCommonSuperclass(typeArrayArrayArrayChar, typeArrayArrayArrayInt)); // Sanity check - assertEquals(typeArrayArrayArrayChar, + Assertions.assertEquals(typeArrayArrayArrayChar, test.getFirstCommonSuperclass(typeArrayArrayArrayChar, typeArrayArrayArrayChar)); } }); } - public void testInterfaces() throws Exception { + @Test + void testInterfaces() throws Exception { executeFindBugsTest(new RunnableWithExceptions() { @Override public void run() throws Throwable { Subtypes2 test = getSubtypes2(); - assertEquals(typeCollection, test.getFirstCommonSuperclass(typeCollection, typeHashSet)); - assertEquals(typeCollection, test.getFirstCommonSuperclass(typeHashSet, typeCollection)); - assertEquals(typeCollection, test.getFirstCommonSuperclass(typeList, typeHashSet)); + Assertions.assertEquals(typeCollection, test.getFirstCommonSuperclass(typeCollection, typeHashSet)); + Assertions.assertEquals(typeCollection, test.getFirstCommonSuperclass(typeHashSet, typeCollection)); + Assertions.assertEquals(typeCollection, test.getFirstCommonSuperclass(typeList, typeHashSet)); } }); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/generic/GenericSignatureParserTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/generic/GenericSignatureParserTest.java index b2398ef0e01..5b5f8058a55 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/generic/GenericSignatureParserTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/generic/GenericSignatureParserTest.java @@ -19,33 +19,33 @@ package edu.umd.cs.findbugs.ba.generic; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Iterator; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author pugh */ -public class GenericSignatureParserTest { +class GenericSignatureParserTest { @Test - public void testGenerics() { + void testGenerics() { GenericSignatureParser parser = new GenericSignatureParser( "(Lcom/sleepycat/persist/EntityJoin.JoinForwardCursor;)V"); assertEquals(1, parser.getNumParameters()); } @Test - public void testThrowsGenerics() { + void testThrowsGenerics() { GenericSignatureParser parser = new GenericSignatureParser("(Ljava/lang/String;^TE1;^TE2;^TE3;)V"); assertEquals(1, parser.getNumParameters()); } - public void processTest(String genericSignature, String... substrings) { + private void processTest(String genericSignature, String... substrings) { GenericSignatureParser parser = new GenericSignatureParser(genericSignature); Iterator iter = parser.parameterSignatureIterator(); @@ -57,7 +57,7 @@ public void processTest(String genericSignature, String... substrings) { } @Test - public void testSignatures() { + void testSignatures() { processTest("(Ljava/lang/Comparable;)V", "Ljava/lang/Comparable;"); processTest("(Ljava/lang/Comparable;TE;**[Ljava/lang/Comparable;)V", "Ljava/lang/Comparable;", "TE;", "*", "*", @@ -67,7 +67,7 @@ public void testSignatures() { } @Test - public void testEclipseJDTInvalidSignature() { + void testEclipseJDTInvalidSignature() { GenericSignatureParser parser = new GenericSignatureParser("(!+LHasUniqueKey;)V"); assertEquals(1, parser.getNumParameters()); assertEquals("+LHasUniqueKey;", parser.parameterSignatureIterator().next()); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/generic/GenericUtilitiesTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/generic/GenericUtilitiesTest.java index e9c20feb2bf..eb15a2adfba 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/generic/GenericUtilitiesTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/generic/GenericUtilitiesTest.java @@ -21,34 +21,36 @@ import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; import java.util.List; import org.apache.bcel.generic.ReferenceType; import org.apache.bcel.generic.Type; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author pugh */ -public class GenericUtilitiesTest { +class GenericUtilitiesTest { private static final String SAMPLE_SIGNATURE = "Lcom/sleepycat/persist/EntityJoin.JoinForwardCursor;"; @Test - public void testUnmatchedRightAngleBracket() { + void testUnmatchedRightAngleBracket() { assertEquals(3, GenericUtilities.nextUnmatchedRightAngleBracket(">", 0)); assertEquals(1, GenericUtilities.nextUnmatchedRightAngleBracket("I>", 0)); } - public void notestNestedSignature() { + @Test + void testNestedSignature() { GenericObjectType t = (GenericObjectType) GenericUtilities.getType(SAMPLE_SIGNATURE); assertEquals(1, t.getNumParameters()); } - public void notestNestedSignature2() { + @Test + void testNestedSignature2() { List parameters = GenericUtilities .getTypeParameters("Lcom/google/common/util/WeakIdentityHashMap.IdentityWeakReference;TV;"); @@ -59,20 +61,20 @@ public void notestNestedSignature2() { } @Test - public void testMapSignature() { + void testMapSignature() { GenericObjectType t = (GenericObjectType) GenericUtilities .getType("Ljava/util/Map;"); assertEquals(2, t.getNumParameters()); } @Test - public void testNestedSignatureParser() { + void testNestedSignatureParser() { GenericSignatureParser parser = new GenericSignatureParser("(" + SAMPLE_SIGNATURE + ")V"); assertEquals(1, parser.getNumParameters()); } @Test - public void testOKSignaturesThatHaveCausedProblems() { + void testOKSignaturesThatHaveCausedProblems() { GenericUtilities.getType("[Ljava/util/Map$Entry;"); GenericUtilities.getType("[Ljava/util/Map;"); GenericUtilities.getType( @@ -80,7 +82,7 @@ public void testOKSignaturesThatHaveCausedProblems() { } @Test - public void testEclipseJDTInvalidUpperBoundSignature() { + void testEclipseJDTInvalidUpperBoundSignature() { final Type type = GenericUtilities.getType("!+LHasUniqueKey;"); assertThat(type, instanceOf(GenericObjectType.class)); assertEquals("+", ((GenericObjectType) type).getVariable()); @@ -88,7 +90,7 @@ public void testEclipseJDTInvalidUpperBoundSignature() { } @Test - public void testEclipseJDTInvalidLowerBoundSignature() { + void testEclipseJDTInvalidLowerBoundSignature() { final Type type = GenericUtilities.getType("!-LHasUniqueKey;"); assertThat(type, instanceOf(GenericObjectType.class)); assertEquals("-", ((GenericObjectType) type).getVariable()); @@ -96,7 +98,7 @@ public void testEclipseJDTInvalidLowerBoundSignature() { } @Test - public void testEclipseJDTInvalidWildcardSignature() { + void testEclipseJDTInvalidWildcardSignature() { final Type type = GenericUtilities.getType("!*"); assertThat(type, instanceOf(GenericObjectType.class)); assertEquals("*", ((GenericObjectType) type).getVariable()); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/generic/TestGenericObjectType.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/generic/TestGenericObjectType.java index b3deb689532..8e3e2546340 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/generic/TestGenericObjectType.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/generic/TestGenericObjectType.java @@ -19,11 +19,11 @@ package edu.umd.cs.findbugs.ba.generic; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Arrays; import java.util.List; @@ -32,7 +32,7 @@ import org.apache.bcel.generic.ReferenceType; import org.apache.bcel.generic.Type; -import org.junit.Test; +import org.junit.jupiter.api.Test; import edu.umd.cs.findbugs.ba.generic.GenericUtilities.TypeCategory; import edu.umd.cs.findbugs.util.Values; @@ -40,7 +40,7 @@ /** * @author Nat Ayewah */ -public class TestGenericObjectType { +class TestGenericObjectType { GenericObjectType obj; @@ -58,7 +58,7 @@ public class TestGenericObjectType { List parameters; - public void initTest(String bytecodeSignature, String javaSignature, String underlyingClass, + private void initTest(String bytecodeSignature, String javaSignature, String underlyingClass, GenericUtilities.TypeCategory typeCategory, @Nullable String variable, @Nullable Type extension, @Nullable List parameters) { this.obj = (GenericObjectType) GenericUtilities.getType(bytecodeSignature); @@ -70,7 +70,7 @@ public void initTest(String bytecodeSignature, String javaSignature, String unde this.parameters = parameters; } - public void processTest() { + private void processTest() { assertEquals(obj.toString(true), javaSignature); assertEquals(obj.getClassName(), underlyingClass); assertEquals(obj.getTypeCategory(), typeCategory); @@ -111,14 +111,15 @@ private static void compareTypes(Type a, Type b) { } @Test - public void testParameterizedList() { + void testParameterizedList() { initTest("Ljava/util/List;", "java.util.List", "java.util.List", GenericUtilities.TypeCategory.PARAMETERIZED, null, null, GenericUtilities.getTypeParameters("Ljava/lang/Comparable;")); processTest(); } - public void notestCreateTypes() { + @Test + void testCreateTypes() { initTest("LDummyClass;", "DummyClass", "DummyClass", GenericUtilities.TypeCategory.PARAMETERIZED, null, null, Arrays.asList( (ReferenceType) GenericUtilities.getType("Ljava/lang/Comparable;"), @@ -126,7 +127,8 @@ public void notestCreateTypes() { processTest(); } - public void notestTypeVariables() { + @Test + void testTypeVariables() { initTest("TE;", "E", Values.DOTTED_JAVA_LANG_OBJECT, GenericUtilities.TypeCategory.TYPE_VARIABLE, "E", null, null); processTest(); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/npe/IsNullValueTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/npe/IsNullValueTest.java index 0c4a0d612d1..3de2f9217df 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/npe/IsNullValueTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/npe/IsNullValueTest.java @@ -1,16 +1,16 @@ package edu.umd.cs.findbugs.ba.npe; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; -public class IsNullValueTest { +class IsNullValueTest { @Test - public void testMerge1() { + void testMerge1() { IsNullValue nullValue = IsNullValue.nullValue(); IsNullValue nullExceptionValue = IsNullValue.nullValue().toExceptionValue(); IsNullValue result = IsNullValue.merge(nullValue, nullExceptionValue); @@ -19,7 +19,7 @@ public void testMerge1() { } @Test - public void testMerge2() { + void testMerge2() { IsNullValue nullExceptionValue = IsNullValue.nullValue().toExceptionValue(); IsNullValue nonNullValue = IsNullValue.nonNullValue(); IsNullValue nsp_e = IsNullValue.merge(nonNullValue, nullExceptionValue); @@ -29,7 +29,7 @@ public void testMerge2() { } @Test - public void testMerge3() { + void testMerge3() { IsNullValue nullValue = IsNullValue.nullValue(); IsNullValue nsp_e = IsNullValue.nullOnSimplePathValue().toExceptionValue(); IsNullValue nsp = IsNullValue.merge(nullValue, nsp_e); @@ -39,9 +39,9 @@ public void testMerge3() { @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value = "NP_NONNULL_PARAM_VIOLATION", justification = "Test is disabled, would need to be fixed anyway") - @Ignore + @Disabled @Test - public void testMerge4() { + void testMerge4() { IsNullValue noKaboom = IsNullValue.noKaboomNonNullValue(null); IsNullValue nsp_e = IsNullValue.nullOnSimplePathValue().toExceptionValue(); IsNullValue nsp_e2 = IsNullValue.merge(noKaboom, nsp_e); @@ -50,7 +50,7 @@ public void testMerge4() { } @Test - public void testMerge5() { + void testMerge5() { IsNullValue checkedNonNull = IsNullValue.checkedNonNullValue(); IsNullValue nsp_e = IsNullValue.nullOnSimplePathValue().toExceptionValue(); IsNullValue nsp_e2 = IsNullValue.merge(checkedNonNull, nsp_e); @@ -59,7 +59,7 @@ public void testMerge5() { } @Test - public void testMerge6() { + void testMerge6() { IsNullValue checkedNull_e = IsNullValue.checkedNullValue().toExceptionValue(); IsNullValue unknown = IsNullValue.nonReportingNotNullValue(); IsNullValue nsp_e = IsNullValue.merge(checkedNull_e, unknown); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/npe/NonNullParamPropertyTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/npe/NonNullParamPropertyTest.java index ea94b8ca289..a919bd27824 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/npe/NonNullParamPropertyTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/npe/NonNullParamPropertyTest.java @@ -1,12 +1,12 @@ package edu.umd.cs.findbugs.ba.npe; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import edu.umd.cs.findbugs.ba.interproc.ParameterProperty; -public class NonNullParamPropertyTest { +class NonNullParamPropertyTest { ParameterProperty empty; @@ -14,8 +14,8 @@ public class NonNullParamPropertyTest { ParameterProperty extremes; - @Before - public void setUp() { + @BeforeEach + void setUp() { empty = new ParameterProperty(); nonEmpty = new ParameterProperty(); @@ -28,36 +28,36 @@ public void setUp() { } @Test - public void testEmpty() { + void testEmpty() { for (int i = 0; i < 32; ++i) { - Assert.assertFalse(empty.hasProperty(i)); + Assertions.assertFalse(empty.hasProperty(i)); } } @Test - public void testIsEmpty() { - Assert.assertTrue(empty.isEmpty()); - Assert.assertFalse(nonEmpty.isEmpty()); - Assert.assertFalse(extremes.isEmpty()); + void testIsEmpty() { + Assertions.assertTrue(empty.isEmpty()); + Assertions.assertFalse(nonEmpty.isEmpty()); + Assertions.assertFalse(extremes.isEmpty()); } @Test - public void testNonEmpty() { - Assert.assertTrue(nonEmpty.hasProperty(11)); - Assert.assertTrue(nonEmpty.hasProperty(25)); - Assert.assertFalse(nonEmpty.hasProperty(5)); + void testNonEmpty() { + Assertions.assertTrue(nonEmpty.hasProperty(11)); + Assertions.assertTrue(nonEmpty.hasProperty(25)); + Assertions.assertFalse(nonEmpty.hasProperty(5)); } @Test - public void testExtremes() { - Assert.assertTrue(extremes.hasProperty(0)); - Assert.assertTrue(extremes.hasProperty(31)); - Assert.assertFalse(extremes.hasProperty(10)); + void testExtremes() { + Assertions.assertTrue(extremes.hasProperty(0)); + Assertions.assertTrue(extremes.hasProperty(31)); + Assertions.assertFalse(extremes.hasProperty(10)); } @Test - public void testOutOfBounds() { - Assert.assertFalse(nonEmpty.hasProperty(-1)); - Assert.assertFalse(nonEmpty.hasProperty(32)); + void testOutOfBounds() { + Assertions.assertFalse(nonEmpty.hasProperty(-1)); + Assertions.assertFalse(nonEmpty.hasProperty(32)); } } diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/npe/ReturnPathTypeTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/npe/ReturnPathTypeTest.java index 4e89cdf7ddf..bfa232faa02 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/npe/ReturnPathTypeTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/npe/ReturnPathTypeTest.java @@ -19,9 +19,9 @@ package edu.umd.cs.findbugs.ba.npe; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import edu.umd.cs.findbugs.ba.DataflowAnalysisException; @@ -30,7 +30,7 @@ * * @author David Hovemeyer */ -public class ReturnPathTypeTest { +class ReturnPathTypeTest { ReturnPathType top; @@ -38,8 +38,8 @@ public class ReturnPathTypeTest { ReturnPathType abnormal; - @Before - public void setUp() { + @BeforeEach + void setUp() { top = new ReturnPathType(); normal = new ReturnPathType(); normal.setCanReturnNormally(true); @@ -48,76 +48,76 @@ public void setUp() { } @Test - public void testTop() throws Exception { - Assert.assertFalse(top.isValid()); - Assert.assertTrue(top.isTop()); + void testTop() throws Exception { + Assertions.assertFalse(top.isValid()); + Assertions.assertTrue(top.isTop()); try { top.canReturnNormally();// should throw exception - Assert.assertTrue(false); + Assertions.assertTrue(false); } catch (DataflowAnalysisException e) { // Good } } @Test - public void testCanReturnNormally() throws Exception { - Assert.assertTrue(normal.isValid()); - Assert.assertTrue(normal.canReturnNormally()); + void testCanReturnNormally() throws Exception { + Assertions.assertTrue(normal.isValid()); + Assertions.assertTrue(normal.canReturnNormally()); } @Test - public void testCannotReturnNormally() throws Exception { - Assert.assertTrue(abnormal.isValid()); - Assert.assertFalse(abnormal.canReturnNormally()); + void testCannotReturnNormally() throws Exception { + Assertions.assertTrue(abnormal.isValid()); + Assertions.assertFalse(abnormal.canReturnNormally()); } @Test - public void testMergeWithTop() throws Exception { + void testMergeWithTop() throws Exception { normal.mergeWith(top); - Assert.assertTrue(normal.canReturnNormally()); + Assertions.assertTrue(normal.canReturnNormally()); abnormal.mergeWith(top); - Assert.assertFalse(abnormal.canReturnNormally()); + Assertions.assertFalse(abnormal.canReturnNormally()); } @Test - public void testTopMergeWithNormalReturn() throws Exception { + void testTopMergeWithNormalReturn() throws Exception { top.mergeWith(normal); - Assert.assertTrue(top.canReturnNormally()); + Assertions.assertTrue(top.canReturnNormally()); } @Test - public void testTopMergeWithAbnormalReturn() throws Exception { + void testTopMergeWithAbnormalReturn() throws Exception { top.mergeWith(abnormal); - Assert.assertFalse(top.canReturnNormally()); + Assertions.assertFalse(top.canReturnNormally()); } @Test - public void testNormalMergeWIthAbnormal() throws Exception { + void testNormalMergeWIthAbnormal() throws Exception { normal.mergeWith(abnormal); - Assert.assertTrue(normal.canReturnNormally()); + Assertions.assertTrue(normal.canReturnNormally()); } @Test - public void testAbnormalMergeWithNormal() throws Exception { + void testAbnormalMergeWithNormal() throws Exception { abnormal.mergeWith(normal); - Assert.assertTrue(abnormal.canReturnNormally()); + Assertions.assertTrue(abnormal.canReturnNormally()); } @Test - public void testNormalMergeWithNormal() throws Exception { + void testNormalMergeWithNormal() throws Exception { ReturnPathType otherNormal = new ReturnPathType(); otherNormal.setCanReturnNormally(true); normal.mergeWith(otherNormal); - Assert.assertTrue(normal.canReturnNormally()); + Assertions.assertTrue(normal.canReturnNormally()); } @Test - public void testAbnormalMergeWithAbnormal() throws Exception { + void testAbnormalMergeWithAbnormal() throws Exception { ReturnPathType otherAbnormal = new ReturnPathType(); otherAbnormal.setCanReturnNormally(false); abnormal.mergeWith(otherAbnormal); - Assert.assertFalse(abnormal.canReturnNormally()); + Assertions.assertFalse(abnormal.canReturnNormally()); } } diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/type/TypeFrameModelingVisitorTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/type/TypeFrameModelingVisitorTest.java index ef223dd4897..b93760684e9 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/type/TypeFrameModelingVisitorTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/type/TypeFrameModelingVisitorTest.java @@ -19,17 +19,17 @@ package edu.umd.cs.findbugs.ba.type; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; /** * @author pugh */ -public class TypeFrameModelingVisitorTest { +class TypeFrameModelingVisitorTest { - @Ignore + @Disabled @Test - public void testMapSignaturePattern() { + void testMapSignaturePattern() { // assertTrue(TypeFrameModelingVisitor.mapSignaturePattern.matcher("<") && !sourceSignature.contains("Map")) } } diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/classfile/TestClassDescriptor.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/classfile/TestClassDescriptor.java index c4d6068e7e8..23ce9f011b1 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/classfile/TestClassDescriptor.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/classfile/TestClassDescriptor.java @@ -19,17 +19,17 @@ package edu.umd.cs.findbugs.classfile; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author andrei */ -public class TestClassDescriptor { +class TestClassDescriptor { @Test - public void testSimpleName() { + void testSimpleName() { ClassDescriptor p = DescriptorFactory.createClassDescriptor("com/bla/Parent"); assertEquals("com/bla/Parent", p.getClassName()); assertEquals("com.bla.Parent", p.getDottedClassName()); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/classfile/impl/ClassFactoryTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/classfile/impl/ClassFactoryTest.java index fd5f6e297a2..c221a497b4d 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/classfile/impl/ClassFactoryTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/classfile/impl/ClassFactoryTest.java @@ -19,10 +19,10 @@ package edu.umd.cs.findbugs.classfile.impl; -import static junit.framework.TestCase.assertTrue; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assume.assumeFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assumptions.assumeFalse; import edu.umd.cs.findbugs.classfile.ClassDescriptor; import edu.umd.cs.findbugs.classfile.Global; @@ -32,24 +32,24 @@ import java.nio.charset.StandardCharsets; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class ClassFactoryTest { +class ClassFactoryTest { - @Before - public void setUp() { + @BeforeEach + void setUp() { Global.setAnalysisCacheForCurrentThread(new NoopAnalysisCache()); } - @After - public void tearDown() { + @AfterEach + void tearDown() { Global.setAnalysisCacheForCurrentThread(null); } @Test - public void ignoreNonExistentFile() throws Exception { + void ignoreNonExistentFile() throws Exception { File file = tempFile(); file.delete(); FilesystemCodeBaseLocator locator = buildLocator(file); @@ -57,23 +57,23 @@ public void ignoreNonExistentFile() throws Exception { } @Test - public void ignoreUnreadableFile() throws Exception { + void ignoreUnreadableFile() throws Exception { File file = createZipFile(); file.deleteOnExit(); file.setReadable(false); - assumeFalse("File cannot be marked as unreadable, skipping test.", file.canRead()); + assumeFalse(file.canRead(), "File cannot be marked as unreadable, skipping test."); FilesystemCodeBaseLocator locator = buildLocator(file); assertHasNoCodeBase(ClassFactory.createFilesystemCodeBase(locator)); } @Test - public void ignoreUnknownNonClassFileFormat() throws Exception { + void ignoreUnknownNonClassFileFormat() throws Exception { FilesystemCodeBaseLocator locator = buildLocator(tempFile()); assertHasNoCodeBase(ClassFactory.createFilesystemCodeBase(locator)); } @Test - public void acceptZipFile() throws Exception { + void acceptZipFile() throws Exception { File zipFile = createZipFile(); zipFile.deleteOnExit(); FilesystemCodeBaseLocator locator = buildLocator(zipFile); @@ -112,7 +112,7 @@ private void assertHasCodeBase(IScannableCodeBase codeBase) throws Exception { } @Test - public void acceptConstantDynamic() throws Exception { + void acceptConstantDynamic() throws Exception { String fileName = "../spotbugsTestCases/src/classSamples/recordCompileWithBazel6.2/Foo.clazz"; try (SingleFileCodeBase codeBase = new SingleFileCodeBase(null, fileName)) { diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/classfile/impl/ClassPathBuilderTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/classfile/impl/ClassPathBuilderTest.java index f697a962cc3..1c0bf4bf247 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/classfile/impl/ClassPathBuilderTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/classfile/impl/ClassPathBuilderTest.java @@ -2,23 +2,22 @@ import edu.umd.cs.findbugs.AppVersion; import edu.umd.cs.findbugs.BugCollection; -import edu.umd.cs.findbugs.test.SpotBugsRule; -import org.junit.Rule; -import org.junit.Test; +import edu.umd.cs.findbugs.test.SpotBugsExtension; +import edu.umd.cs.findbugs.test.SpotBugsRunner; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import java.nio.file.Paths; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; -public class ClassPathBuilderTest { - - @Rule - public SpotBugsRule analyzer = new SpotBugsRule(); +@ExtendWith(SpotBugsExtension.class) +class ClassPathBuilderTest { @Test - public void nestedTraversalDisabled() { - BugCollection results = analyzer.performAnalysis((engine) -> { + void nestedTraversalDisabled(SpotBugsRunner spotbugs) { + BugCollection results = spotbugs.performAnalysis((engine) -> { engine.setScanNestedArchives(false); engine.setNoClassOk(true); }, Paths.get("../spotbugsTestCases/archives/nestedArchive.jar")); @@ -27,8 +26,8 @@ public void nestedTraversalDisabled() { } @Test - public void nestedTraversalEnabled() { - BugCollection results = analyzer.performAnalysis((engine) -> engine.setScanNestedArchives(true), + void nestedTraversalEnabled(SpotBugsRunner spotbugs) { + BugCollection results = spotbugs.performAnalysis((engine) -> engine.setScanNestedArchives(true), Paths.get("../spotbugsTestCases/archives/nestedArchive.jar")); AppVersion appInformation = results.getCurrentAppVersion(); assertThat(appInformation.getNumClasses(), equalTo(5)); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/config/CommandLineTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/config/CommandLineTest.java index 5b2692aced9..4ca303999d7 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/config/CommandLineTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/config/CommandLineTest.java @@ -1,41 +1,41 @@ package edu.umd.cs.findbugs.config; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.hamcrest.Matchers.is; import static org.hamcrest.MatcherAssert.assertThat; -public class CommandLineTest { +class CommandLineTest { @Test - public void testNoExtraPart() { + void testNoExtraPart() { CommandLine.Option option = CommandLine.splitOption("-html"); assertThat(option.option, is("-html")); assertThat(option.extraPart, is("")); } @Test - public void testSplitOptionOnLinux() { + void testSplitOptionOnLinux() { CommandLine.Option option = CommandLine.splitOption("-html=/path/to/spotbugs.html"); assertThat(option.option, is("-html")); assertThat(option.extraPart, is("=/path/to/spotbugs.html")); } @Test - public void testSplitOptionWithColonOnLinux() { + void testSplitOptionWithColonOnLinux() { CommandLine.Option option = CommandLine.splitOption("-html:default.xsl=/path/to/spotbugs.html"); assertThat(option.option, is("-html")); assertThat(option.extraPart, is("default.xsl=/path/to/spotbugs.html")); } @Test - public void testSplitOptionOnWindows() { + void testSplitOptionOnWindows() { CommandLine.Option option = CommandLine.splitOption("-html=C:\\path\\to\\spotbugs.html"); assertThat(option.option, is("-html")); assertThat(option.extraPart, is("=C:\\path\\to\\spotbugs.html")); } @Test - public void testSplitOptionWithColonOnWindows() { + void testSplitOptionWithColonOnWindows() { CommandLine.Option option = CommandLine.splitOption("-html:default.xsl=C:\\path\\to\\spotbugs.html"); assertThat(option.option, is("-html")); assertThat(option.extraPart, is("default.xsl=C:\\path\\to\\spotbugs.html")); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/config/ProjectFilterSettingsTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/config/ProjectFilterSettingsTest.java index 40536f5f5b9..b5e721a576a 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/config/ProjectFilterSettingsTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/config/ProjectFilterSettingsTest.java @@ -19,14 +19,14 @@ package edu.umd.cs.findbugs.config; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import edu.umd.cs.findbugs.DetectorFactoryCollection; import edu.umd.cs.findbugs.Priorities; -public class ProjectFilterSettingsTest { +class ProjectFilterSettingsTest { ProjectFilterSettings plain; @@ -40,8 +40,8 @@ public class ProjectFilterSettingsTest { ProjectFilterSettings changed4; - @Before - public void setUp() { + @BeforeEach + void setUp() { plain = ProjectFilterSettings.createDefault(); otherPlain = ProjectFilterSettings.createDefault(); @@ -63,98 +63,98 @@ public void setUp() { } @Test - public void testPlainPrio() { - Assert.assertTrue(plain.getMinPriority().equals(ProjectFilterSettings.DEFAULT_PRIORITY)); + void testPlainPrio() { + Assertions.assertTrue(plain.getMinPriority().equals(ProjectFilterSettings.DEFAULT_PRIORITY)); } @Test - public void testPlainCategories() { + void testPlainCategories() { int count = 0; for (String category : DetectorFactoryCollection.instance().getBugCategories()) { if (!category.equals("NOISE")) { - Assert.assertTrue(plain.containsCategory(category)); + Assertions.assertTrue(plain.containsCategory(category)); ++count; } } - Assert.assertEquals(count, plain.getActiveCategorySet().size()); + Assertions.assertEquals(count, plain.getActiveCategorySet().size()); } @Test - public void testAddCategory() { - Assert.assertTrue(plain.containsCategory("FAKE_CATEGORY")); // unknown + void testAddCategory() { + Assertions.assertTrue(plain.containsCategory("FAKE_CATEGORY")); // unknown // categories // should be // unhidden // by // default plain.addCategory("FAKE_CATEGORY"); - Assert.assertTrue(plain.containsCategory("FAKE_CATEGORY")); + Assertions.assertTrue(plain.containsCategory("FAKE_CATEGORY")); } @Test - public void testRemoveCategory() { - Assert.assertTrue(plain.containsCategory("MALICIOUS_CODE")); + void testRemoveCategory() { + Assertions.assertTrue(plain.containsCategory("MALICIOUS_CODE")); plain.removeCategory("MALICIOUS_CODE"); - Assert.assertFalse(plain.containsCategory("MALICIOUS_CODE")); + Assertions.assertFalse(plain.containsCategory("MALICIOUS_CODE")); } @Test - public void testSetMinPriority() { + void testSetMinPriority() { plain.setMinPriority("High"); - Assert.assertTrue(plain.getMinPriority().equals("High")); - Assert.assertTrue(plain.getMinPriorityAsInt() == Priorities.HIGH_PRIORITY); + Assertions.assertTrue(plain.getMinPriority().equals("High")); + Assertions.assertTrue(plain.getMinPriorityAsInt() == Priorities.HIGH_PRIORITY); plain.setMinPriority("Medium"); - Assert.assertTrue(plain.getMinPriority().equals("Medium")); - Assert.assertTrue(plain.getMinPriorityAsInt() == Priorities.NORMAL_PRIORITY); + Assertions.assertTrue(plain.getMinPriority().equals("Medium")); + Assertions.assertTrue(plain.getMinPriorityAsInt() == Priorities.NORMAL_PRIORITY); plain.setMinPriority("Low"); - Assert.assertTrue(plain.getMinPriority().equals("Low")); - Assert.assertTrue(plain.getMinPriorityAsInt() == Priorities.LOW_PRIORITY); + Assertions.assertTrue(plain.getMinPriority().equals("Low")); + Assertions.assertTrue(plain.getMinPriorityAsInt() == Priorities.LOW_PRIORITY); } @Test - public void testEquals() { - Assert.assertEquals(plain, otherPlain); + void testEquals() { + Assertions.assertEquals(plain, otherPlain); - Assert.assertFalse(plain.equals(changed)); - Assert.assertFalse(changed.equals(plain)); + Assertions.assertFalse(plain.equals(changed)); + Assertions.assertFalse(changed.equals(plain)); - Assert.assertFalse(plain.equals(changed2)); - Assert.assertFalse(changed2.equals(plain)); + Assertions.assertFalse(plain.equals(changed2)); + Assertions.assertFalse(changed2.equals(plain)); // The activeBugCategorySet doesn't matter for equals(), only // the hiddenBugCategorySet does (along with minPriority and // displayFalseWarnings) so 'plain' and 'changed3' should test equal. - Assert.assertTrue(plain.equals(changed3)); - Assert.assertTrue(changed3.equals(plain)); + Assertions.assertTrue(plain.equals(changed3)); + Assertions.assertTrue(changed3.equals(plain)); - Assert.assertFalse(plain.equals(changed4)); - Assert.assertFalse(changed4.equals(plain)); + Assertions.assertFalse(plain.equals(changed4)); + Assertions.assertFalse(changed4.equals(plain)); } @Test - public void testEncodeDecode() { + void testEncodeDecode() { ProjectFilterSettings copyOfPlain = ProjectFilterSettings.fromEncodedString(plain.toEncodedString()); ProjectFilterSettings.hiddenFromEncodedString(copyOfPlain, plain.hiddenToEncodedString()); - Assert.assertEquals(plain, copyOfPlain); + Assertions.assertEquals(plain, copyOfPlain); ProjectFilterSettings copyOfChanged4 = ProjectFilterSettings.fromEncodedString(changed4.toEncodedString()); ProjectFilterSettings.hiddenFromEncodedString(copyOfChanged4, changed4.hiddenToEncodedString()); - Assert.assertEquals(changed4, copyOfChanged4); + Assertions.assertEquals(changed4, copyOfChanged4); } @Test - public void testDisplayFalseWarnings() { - Assert.assertEquals(plain, otherPlain); + void testDisplayFalseWarnings() { + Assertions.assertEquals(plain, otherPlain); - Assert.assertFalse(plain.displayFalseWarnings()); + Assertions.assertFalse(plain.displayFalseWarnings()); plain.setDisplayFalseWarnings(true); - Assert.assertFalse(plain.equals(otherPlain)); + Assertions.assertFalse(plain.equals(otherPlain)); ProjectFilterSettings copyOfPlain = ProjectFilterSettings.fromEncodedString(plain.toEncodedString()); - Assert.assertTrue(copyOfPlain.displayFalseWarnings()); - Assert.assertEquals(copyOfPlain, plain); - Assert.assertEquals(plain, copyOfPlain); + Assertions.assertTrue(copyOfPlain.displayFalseWarnings()); + Assertions.assertEquals(copyOfPlain, plain); + Assertions.assertEquals(plain, copyOfPlain); } } diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/config/UserPreferencesTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/config/UserPreferencesTest.java index 1bd8888f362..f53cdb38e37 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/config/UserPreferencesTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/config/UserPreferencesTest.java @@ -4,58 +4,58 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; -public class UserPreferencesTest { +class UserPreferencesTest { @Test - public void testClone() { + void testClone() { UserPreferences sut = UserPreferences.createDefaultUserPreferences(); UserPreferences clone = sut.clone(); - Assert.assertEquals(sut, clone); - Assert.assertEquals(sut.getClass(), clone.getClass()); + Assertions.assertEquals(sut, clone); + Assertions.assertEquals(sut.getClass(), clone.getClass()); } @Test - public void testReadEffortNoPrefix() throws IOException { + void testReadEffortNoPrefix() throws IOException { String testPrefsString = "effort=max"; UserPreferences userPrefs = UserPreferences.createDefaultUserPreferences(); userPrefs.read(new ByteArrayInputStream(testPrefsString.getBytes(StandardCharsets.ISO_8859_1))); - Assert.assertEquals(UserPreferences.EFFORT_MAX, userPrefs.getEffort()); + Assertions.assertEquals(UserPreferences.EFFORT_MAX, userPrefs.getEffort()); } @Test - public void testReadEffortSpotBugsPrefix() throws IOException { + void testReadEffortSpotBugsPrefix() throws IOException { String testPrefsString = "/instance/com.github.spotbugs.plugin.eclipse/effort=max"; UserPreferences userPrefs = UserPreferences.createDefaultUserPreferences(); userPrefs.read(new ByteArrayInputStream(testPrefsString.getBytes(StandardCharsets.ISO_8859_1))); - Assert.assertEquals(UserPreferences.EFFORT_MAX, userPrefs.getEffort()); + Assertions.assertEquals(UserPreferences.EFFORT_MAX, userPrefs.getEffort()); } @Test - public void testReadEffortFindBugsPrefix() throws IOException { + void testReadEffortFindBugsPrefix() throws IOException { String testPrefsString = "/instance/edu.umd.cs.findbugs.plugin.eclipse/effort=max"; UserPreferences userPrefs = UserPreferences.createDefaultUserPreferences(); userPrefs.read(new ByteArrayInputStream(testPrefsString.getBytes(StandardCharsets.ISO_8859_1))); - Assert.assertEquals(UserPreferences.EFFORT_MAX, userPrefs.getEffort()); + Assertions.assertEquals(UserPreferences.EFFORT_MAX, userPrefs.getEffort()); } @Test - public void testReadEffortUnknownPrefix() throws IOException { + void testReadEffortUnknownPrefix() throws IOException { String testPrefsString = "/instance/test.test.test.test.plugin.eclipse/effort=max"; UserPreferences userPrefs = UserPreferences.createDefaultUserPreferences(); userPrefs.read(new ByteArrayInputStream(testPrefsString.getBytes(StandardCharsets.ISO_8859_1))); - Assert.assertEquals(UserPreferences.EFFORT_DEFAULT, userPrefs.getEffort()); + Assertions.assertEquals(UserPreferences.EFFORT_DEFAULT, userPrefs.getEffort()); } } diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/cwe/WeaknessCatalogTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/cwe/WeaknessCatalogTest.java index 3569257e9a2..36c74a9ffa6 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/cwe/WeaknessCatalogTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/cwe/WeaknessCatalogTest.java @@ -2,21 +2,21 @@ import static org.hamcrest.Matchers.startsWith; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class WeaknessCatalogTest { +class WeaknessCatalogTest { @Test - public void testGetInstanceConstruction() { + void testGetInstanceConstruction() { assertNotNull(WeaknessCatalog.getInstance()); } @Test - public void testGetInstanceCalledTwiceSameInstance() { + void testGetInstanceCalledTwiceSameInstance() { WeaknessCatalog instance1 = WeaknessCatalog.getInstance(); WeaknessCatalog instance2 = WeaknessCatalog.getInstance(); @@ -24,7 +24,7 @@ public void testGetInstanceCalledTwiceSameInstance() { } @Test - public void testGetWeaknessByCweIdOrNullExistingWeakness() { + void testGetWeaknessByCweIdOrNullExistingWeakness() { int cweid = 78; String name = "Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')"; String description = "The product constructs all or part of an OS command using externally-influenced input from an upstream component, but"; @@ -39,7 +39,7 @@ public void testGetWeaknessByCweIdOrNullExistingWeakness() { } @Test - public void testGetWeaknessByCweIdOrNullNonExistingWeakness() { + void testGetWeaknessByCweIdOrNullNonExistingWeakness() { int cweid = Integer.MAX_VALUE; WeaknessCatalog weaknessCatalog = WeaknessCatalog.getInstance(); @@ -49,7 +49,7 @@ public void testGetWeaknessByCweIdOrNullNonExistingWeakness() { } @Test - public void testGetWeaknessByCweIdOrNullNonInvalidCweId() { + void testGetWeaknessByCweIdOrNullNonInvalidCweId() { int cweid = Integer.MIN_VALUE; WeaknessCatalog weaknessCatalog = WeaknessCatalog.getInstance(); @@ -59,7 +59,7 @@ public void testGetWeaknessByCweIdOrNullNonInvalidCweId() { } @Test - public void testGetWeaknessByCweIdOrNullCweIdIsZero() { + void testGetWeaknessByCweIdOrNullCweIdIsZero() { int cweid = 0; WeaknessCatalog weaknessCatalog = WeaknessCatalog.getInstance(); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/ConstructorThrowTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/ConstructorThrowTest.java index 8e6303067bb..3cfe0c2b680 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/ConstructorThrowTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/ConstructorThrowTest.java @@ -3,43 +3,44 @@ import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasItem; -public class ConstructorThrowTest extends AbstractIntegrationTest { +class ConstructorThrowTest extends AbstractIntegrationTest { + @Test - public void testConstructorThrowCheck1() { + void testConstructorThrowCheck1() { performAnalysis("constructorthrow/ConstructorThrowTest1.class"); assertNumOfCTBugs(1); assertCTBugInLine(9); } @Test - public void testConstructorThrowCheck2() { + void testConstructorThrowCheck2() { performAnalysis("constructorthrow/ConstructorThrowTest2.class"); assertNumOfCTBugs(1); assertCTBugInLine(10); } @Test - public void testConstructorThrowCheck3() { + void testConstructorThrowCheck3() { performAnalysis("constructorthrow/ConstructorThrowTest3.class"); assertNumOfCTBugs(1); assertCTBugInLine(9); } @Test - public void testConstructorThrowCheck4() { + void testConstructorThrowCheck4() { performAnalysis("constructorthrow/ConstructorThrowTest4.class"); assertNumOfCTBugs(1); assertCTBugInLine(20); } @Test - public void testConstructorThrowCheck5() { + void testConstructorThrowCheck5() { performAnalysis("constructorthrow/ConstructorThrowTest5.class"); assertNumOfCTBugs(2); assertCTBugInLine(11); @@ -47,144 +48,144 @@ public void testConstructorThrowCheck5() { } @Test - public void testConstructorThrowCheck6() { + void testConstructorThrowCheck6() { performAnalysis("constructorthrow/ConstructorThrowTest6.class"); assertNumOfCTBugs(1); assertCTBugInLine(11); } @Test - public void testConstructorThrowCheck7() { + void testConstructorThrowCheck7() { performAnalysis("constructorthrow/ConstructorThrowTest7.class"); assertNumOfCTBugs(1); assertCTBugInLine(11); // Preferable 12, but 11 is ok. } @Test - public void testConstructorThrowCheck8() { + void testConstructorThrowCheck8() { performAnalysis("constructorthrow/ConstructorThrowTest8.class"); assertNumOfCTBugs(1); assertCTBugInLine(11); // Preferable 12, but 11 is ok. } @Test - public void testConstructorThrowCheck9() { + void testConstructorThrowCheck9() { performAnalysis("constructorthrow/ConstructorThrowTest9.class"); assertNumOfCTBugs(1); assertCTBugInLine(11); // Preferable 12, but 11 is ok. } @Test - public void testConstructorThrowCheck10() { + void testConstructorThrowCheck10() { performAnalysis("constructorthrow/ConstructorThrowTest10.class"); assertNumOfCTBugs(1); assertCTBugInLine(9); } @Test - public void testConstructorThrowCheck11() { + void testConstructorThrowCheck11() { performAnalysis("constructorthrow/ConstructorThrowTest11.class"); assertNumOfCTBugs(1); assertCTBugInLine(15); } @Test - public void testConstructorThrowCheck12() { + void testConstructorThrowCheck12() { performAnalysis("constructorthrow/ConstructorThrowTest12.class"); assertNumOfCTBugs(1); assertCTBugInLine(15); } @Test - public void testConstructorThrowCheck13() { + void testConstructorThrowCheck13() { performAnalysis("constructorthrow/ConstructorThrowTest13.class"); assertNumOfCTBugs(1); assertCTBugInLine(19); } @Test - public void testConstructorThrowCheck14() { + void testConstructorThrowCheck14() { performAnalysis("constructorthrow/ConstructorThrowTest14.class"); assertNumOfCTBugs(1); assertCTBugInLine(24); } @Test - public void testConstructorThrowCheck15() { + void testConstructorThrowCheck15() { performAnalysis("constructorthrow/ConstructorThrowTest15.class"); assertNumOfCTBugs(1); assertCTBugInLine(15); } @Test - public void testConstructorThrowCheck16() { + void testConstructorThrowCheck16() { performAnalysis("constructorthrow/ConstructorThrowTest16.class"); assertNumOfCTBugs(1); assertCTBugInLine(10); } @Test - public void testGoodConstructorThrowCheck1() { + void testGoodConstructorThrowCheck1() { performAnalysis("constructorthrow/ConstructorThrowNegativeTest1.class"); assertNumOfCTBugs(0); } @Test - public void testGoodConstructorThrowCheck2() { + void testGoodConstructorThrowCheck2() { performAnalysis("constructorthrow/ConstructorThrowNegativeTest2.class"); assertNumOfCTBugs(0); } @Test - public void testGoodConstructorThrowCheck3() { + void testGoodConstructorThrowCheck3() { performAnalysis("constructorthrow/ConstructorThrowNegativeTest3.class"); assertNumOfCTBugs(0); } @Test - public void testGoodConstructorThrowCheck4() { + void testGoodConstructorThrowCheck4() { performAnalysis("constructorthrow/ConstructorThrowNegativeTest4.class"); assertNumOfCTBugs(0); } @Test - public void testGoodConstructorThrowCheck5() { + void testGoodConstructorThrowCheck5() { performAnalysis("constructorthrow/ConstructorThrowNegativeTest5.class"); assertNumOfCTBugs(0); } @Test - public void testGoodConstructorThrowCheck6() { + void testGoodConstructorThrowCheck6() { performAnalysis("constructorthrow/ConstructorThrowNegativeTest6.class"); assertNumOfCTBugs(0); } @Test - public void testGoodConstructorThrowCheck7() { + void testGoodConstructorThrowCheck7() { performAnalysis("constructorthrow/ConstructorThrowNegativeTest7.class"); assertNumOfCTBugs(0); } @Test - public void testGoodConstructorThrowCheck8() { + void testGoodConstructorThrowCheck8() { performAnalysis("constructorthrow/ConstructorThrowNegativeTest8.class"); assertNumOfCTBugs(0); } @Test - public void testGoodConstructorThrowCheck9() { + void testGoodConstructorThrowCheck9() { performAnalysis("constructorthrow/ConstructorThrowNegativeTest9.class"); assertNumOfCTBugs(0); } @Test - public void testGoodConstructorThrowCheck10() { + void testGoodConstructorThrowCheck10() { performAnalysis("constructorthrow/ConstructorThrowNegativeTest10.class"); assertNumOfCTBugs(0); } @Test - public void testGoodConstructorThrowCheck11() { + void testGoodConstructorThrowCheck11() { performAnalysis("constructorthrow/ConstructorThrowNegativeTest11.class"); assertNumOfCTBugs(0); } diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/DontReusePublicIdentifiersTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/DontReusePublicIdentifiersTest.java index de986b15686..6afd72b5f41 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/DontReusePublicIdentifiersTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/DontReusePublicIdentifiersTest.java @@ -3,21 +3,22 @@ import edu.umd.cs.findbugs.*; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasItem; -public class DontReusePublicIdentifiersTest extends AbstractIntegrationTest { +class DontReusePublicIdentifiersTest extends AbstractIntegrationTest { + private static final String PI_CLASS_BUG = "PI_DO_NOT_REUSE_PUBLIC_IDENTIFIERS_CLASS_NAMES"; private static final String PI_FIELD_BUG = "PI_DO_NOT_REUSE_PUBLIC_IDENTIFIERS_FIELD_NAMES"; private static final String PI_METHOD_BUG = "PI_DO_NOT_REUSE_PUBLIC_IDENTIFIERS_METHOD_NAMES"; private static final String PI_VARIABLE_BUG = "PI_DO_NOT_REUSE_PUBLIC_IDENTIFIERS_LOCAL_VARIABLE_NAMES"; @Test - public void testShadowedPublicIdentifiersClassNames() { + void testShadowedPublicIdentifiersClassNames() { // check shadowed public identifiers as standalone classes performAnalysis("publicIdentifiers/standalone/InputStream.class"); assertNumOfShadowedPublicIdentifierBugs(PI_CLASS_BUG, 1); @@ -45,7 +46,7 @@ public void testShadowedPublicIdentifiersClassNames() { } @Test - public void testGoodPublicIdentifiersClassNames() { + void testGoodPublicIdentifiersClassNames() { // check good public identifiers as standalone classes performAnalysis("publicIdentifiers/standalone/GoodPublicIdentifiersStandaloneClassNames.class"); assertZeroPublicIdentifierBug(); @@ -68,7 +69,7 @@ public void testGoodPublicIdentifiersClassNames() { } @Test - public void testShadowedPublicIdentifiersFieldNames() { + void testShadowedPublicIdentifiersFieldNames() { performAnalysis("publicIdentifiers/ShadowedPublicIdentifiersFieldNames.class"); assertNumOfShadowedPublicIdentifierBugs(PI_FIELD_BUG, 2); assertShadowedPublicIdentifierFieldBug("String"); @@ -76,13 +77,13 @@ public void testShadowedPublicIdentifiersFieldNames() { } @Test - public void testGoodPublicIdentifiersFieldNames() { + void testGoodPublicIdentifiersFieldNames() { performAnalysis("publicIdentifiers/GoodPublicIdentifiersFieldNames.class"); assertZeroPublicIdentifierBug(); } @Test - public void testShadowedPublicIdentifiersMethodNames() { + void testShadowedPublicIdentifiersMethodNames() { performAnalysis("publicIdentifiers/ShadowedPublicIdentifiersMethodNames.class"); assertNumOfShadowedPublicIdentifierBugs(PI_METHOD_BUG, 3); @@ -92,7 +93,7 @@ public void testShadowedPublicIdentifiersMethodNames() { } @Test - public void testGoodPublicIdentifiersMethodNames() { + void testGoodPublicIdentifiersMethodNames() { performAnalysis("publicIdentifiers/GoodPublicIdentifiersMethodNames.class"); assertZeroPublicIdentifierBug(); @@ -105,7 +106,7 @@ public void testGoodPublicIdentifiersMethodNames() { } @Test - public void testShadowedPublicIdentifiersVariableNames() { + void testShadowedPublicIdentifiersVariableNames() { performAnalysis("publicIdentifiers/ShadowedPublicIdentifiersVariableNames.class"); assertNumOfShadowedPublicIdentifierBugs(PI_VARIABLE_BUG, 3); @@ -115,7 +116,7 @@ public void testShadowedPublicIdentifiersVariableNames() { } @Test - public void testGoodPublicIdentifiersVariableNames() { + void testGoodPublicIdentifiersVariableNames() { performAnalysis("publicIdentifiers/GoodPublicIdentifiersVariableNames.class"); assertZeroPublicIdentifierBug(); } diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/DontUseFloatsAsLoopCountersTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/DontUseFloatsAsLoopCountersTest.java index 269d55adeea..d6ab81dd70c 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/DontUseFloatsAsLoopCountersTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/DontUseFloatsAsLoopCountersTest.java @@ -1,6 +1,6 @@ package edu.umd.cs.findbugs.detect; -import org.junit.Test; +import org.junit.jupiter.api.Test; import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; @@ -10,9 +10,10 @@ import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.MatcherAssert.assertThat; -public class DontUseFloatsAsLoopCountersTest extends AbstractIntegrationTest { +class DontUseFloatsAsLoopCountersTest extends AbstractIntegrationTest { + @Test - public void testChecks() { + void testChecks() { performAnalysis("DontUseFloatsAsLoopCounters.class"); assertNumOfEOSBugs(3); assertBug("test1", 8); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/FindArgumentAssertionsTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/FindArgumentAssertionsTest.java index 555a6a63536..05db6588565 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/FindArgumentAssertionsTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/FindArgumentAssertionsTest.java @@ -4,16 +4,17 @@ import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.MatcherAssert.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.annotations.Confidence; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; -public class FindArgumentAssertionsTest extends AbstractIntegrationTest { +class FindArgumentAssertionsTest extends AbstractIntegrationTest { + @Test - public void testArgumentAssertions() { + void testArgumentAssertions() { performAnalysis("ArgumentAssertions.class"); assertNumOfDABugs(23); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/FindAssertionsWithSideEffectsTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/FindAssertionsWithSideEffectsTest.java index c8f5ab89d7a..b5e2f64749b 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/FindAssertionsWithSideEffectsTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/FindAssertionsWithSideEffectsTest.java @@ -4,16 +4,17 @@ import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.MatcherAssert.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.annotations.Confidence; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; -public class FindAssertionsWithSideEffectsTest extends AbstractIntegrationTest { +class FindAssertionsWithSideEffectsTest extends AbstractIntegrationTest { + @Test - public void testArgumentAssertions() { + void testArgumentAssertions() { performAnalysis("AssertionsWithSideEffects.class", "AssertionsWithSideEffects$ImmutableList.class"); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/FindBadEndOfStreamCheckTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/FindBadEndOfStreamCheckTest.java index 355f249f809..9a82486ad77 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/FindBadEndOfStreamCheckTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/FindBadEndOfStreamCheckTest.java @@ -4,15 +4,16 @@ import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.MatcherAssert.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; -public class FindBadEndOfStreamCheckTest extends AbstractIntegrationTest { +class FindBadEndOfStreamCheckTest extends AbstractIntegrationTest { + @Test - public void testBadEndOfFileChecks() { + void testBadEndOfFileChecks() { performAnalysis("endOfStreamCheck/BadEndOfStreamCheck.class"); assertNumOfEOSBugs(16); @@ -36,7 +37,7 @@ public void testBadEndOfFileChecks() { } @Test - public void testGoodEndOfFileChecks() { + void testGoodEndOfFileChecks() { performAnalysis("endOfStreamCheck/GoodEndOfStreamCheck.class"); assertNumOfEOSBugs(0); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/FindInstanceLockOnSharedStaticDataCheckTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/FindInstanceLockOnSharedStaticDataCheckTest.java index acdbacd21e8..a93e20afc45 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/FindInstanceLockOnSharedStaticDataCheckTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/FindInstanceLockOnSharedStaticDataCheckTest.java @@ -3,16 +3,16 @@ import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasItem; -public class FindInstanceLockOnSharedStaticDataCheckTest extends AbstractIntegrationTest { +class FindInstanceLockOnSharedStaticDataCheckTest extends AbstractIntegrationTest { @Test - public void findSSDBugInClass_InstanceLevelLockOnSharedStaticData() { + void findSSDBugInClass_InstanceLevelLockOnSharedStaticData() { performAnalysis("instanceLockOnSharedStaticData/InstanceLevelLockObject.class"); assertNumOfSSDBugs(1); @@ -21,7 +21,7 @@ public void findSSDBugInClass_InstanceLevelLockOnSharedStaticData() { } @Test - public void findSSDBugInClass_InstanceLevelSynchronizedMethod() { + void findSSDBugInClass_InstanceLevelSynchronizedMethod() { performAnalysis("instanceLockOnSharedStaticData/InstanceLevelSynchronizedMethod.class"); assertNumOfSSDBugs(1); @@ -30,21 +30,21 @@ public void findSSDBugInClass_InstanceLevelSynchronizedMethod() { } @Test - public void findNoSSDBugInClass_StaticLockInsideNotStaticSynchronizedMethod() { + void findNoSSDBugInClass_StaticLockInsideNotStaticSynchronizedMethod() { performAnalysis("instanceLockOnSharedStaticData/StaticLockInsideNotStaticSynchronizedMethod.class"); assertNumOfSSDBugs(0); } @Test - public void findNoSSDBugInClass_LockingOnJavaLangClassObject() { + void findNoSSDBugInClass_LockingOnJavaLangClassObject() { performAnalysis("instanceLockOnSharedStaticData/LockingOnJavaLangClassObject.class"); assertNumOfSSDBugs(0); } @Test - public void findNoSSDBugInClass_StaticLockObjectOnStaticSharedData() { + void findNoSSDBugInClass_StaticLockObjectOnStaticSharedData() { performAnalysis("instanceLockOnSharedStaticData/StaticLockObjectOnStaticSharedData.class"); assertNumOfSSDBugs(0); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/FindNonShortCircuitTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/FindNonShortCircuitTest.java index fb3d262dfe8..160ee93a891 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/FindNonShortCircuitTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/FindNonShortCircuitTest.java @@ -5,18 +5,19 @@ import edu.umd.cs.findbugs.Priorities; import edu.umd.cs.findbugs.Project; import edu.umd.cs.findbugs.ba.AnalysisContext; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; + +class FindNonShortCircuitTest { -public class FindNonShortCircuitTest { private AnalysisContext ctx; private FindNonShortCircuit check; - @Before - public void setup() { + @BeforeEach + void setup() { PrintingBugReporter bugReporter = new PrintingBugReporter(); ctx = AnalysisContext.currentAnalysisContext(); if (ctx == null) { @@ -25,20 +26,20 @@ public void setup() { check = new FindNonShortCircuit(bugReporter); } - @After - public void tearDown() { + @AfterEach + void tearDown() { AnalysisContext.setCurrentAnalysisContext(ctx); } @Test - public void testDefaultBugTypeAndPriority() { + void testDefaultBugTypeAndPriority() { BugInstance bug = check.createBugInstance(); assertEquals(FindNonShortCircuit.NS_NON_SHORT_CIRCUIT, bug.getType()); assertEquals(Priorities.LOW_PRIORITY, bug.getPriority()); } @Test - public void testBugTypeAndPriorityDangerOld() { + void testBugTypeAndPriorityDangerOld() { check.sawDangerOld = true; BugInstance bug = check.createBugInstance(); assertEquals(FindNonShortCircuit.NS_NON_SHORT_CIRCUIT, bug.getType()); @@ -46,7 +47,7 @@ public void testBugTypeAndPriorityDangerOld() { } @Test - public void testBugTypeAndPriorityNullTestOld() { + void testBugTypeAndPriorityNullTestOld() { check.sawDangerOld = true; check.sawNullTestVeryOld = true; BugInstance bug = check.createBugInstance(); @@ -55,7 +56,7 @@ public void testBugTypeAndPriorityNullTestOld() { } @Test - public void testBugTypeAndPriorityMethodCallOld() { + void testBugTypeAndPriorityMethodCallOld() { check.sawDangerOld = true; check.sawMethodCallOld = true; BugInstance bug = check.createBugInstance(); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/FindOverridableMethodCallTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/FindOverridableMethodCallTest.java index c9735309dea..a764a865f21 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/FindOverridableMethodCallTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/FindOverridableMethodCallTest.java @@ -7,121 +7,122 @@ import static org.hamcrest.MatcherAssert.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.annotations.Confidence; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; -public class FindOverridableMethodCallTest extends AbstractIntegrationTest { +class FindOverridableMethodCallTest extends AbstractIntegrationTest { + @Test - public void testDirectCase() { + void testDirectCase() { testCase("DirectCase", 5, 18); } @Test - public void testDirectCaseObject() { + void testDirectCaseObject() { testCase("DirectCaseObject", 5, 13); } @Test - public void testIndirectCase1() { + void testIndirectCase1() { testCase("IndirectCase1", 9, 22); } @Test - public void testIndirectCase2() { + void testIndirectCase2() { testCase("IndirectCase2", 5, 18); } @Test - public void testDoubleIndirectCase1() { + void testDoubleIndirectCase1() { testCase("DoubleIndirectCase1", 16, 29); } @Test - public void testDoubleIndirectCase2() { + void testDoubleIndirectCase2() { testCase("DoubleIndirectCase2", 16, 29); } @Test - public void testDoubleIndirectCase3() { + void testDoubleIndirectCase3() { testCase("DoubleIndirectCase3", 11, 24); } @Test - public void testDoubleIndirectCase4() { + void testDoubleIndirectCase4() { testCase("DoubleIndirectCase4", 10, 23); } @Test - public void testDoubleIndirectCase5() { + void testDoubleIndirectCase5() { testCase("DoubleIndirectCase5", 5, 18); } @Test - public void testDoubleIndirectCase6() { + void testDoubleIndirectCase6() { testCase("DoubleIndirectCase6", 5, 18); } @Test - public void testMethodReference() { + void testMethodReference() { testCase("MethodReference", 11, 20); } @Test - public void testMethodReferenceIndirect1() { + void testMethodReferenceIndirect1() { testCase("MethodReferenceIndirect1", 15, 24); } @Test - public void testMethodReferenceIndirect2() { + void testMethodReferenceIndirect2() { testCase("MethodReferenceIndirect2", 23, 32); } @Test - public void testMethodReferenceIndirect3() { + void testMethodReferenceIndirect3() { testCase("MethodReferenceIndirect3", 23, 32); } @Test - public void testFinalClassDirect() { + void testFinalClassDirect() { testPass("FinalClassDirect"); } @Test - public void testFinalClassIndirect() { + void testFinalClassIndirect() { testPass("FinalClassIndirect"); } @Test - public void testFinalClassDoubleIndirect() { + void testFinalClassDoubleIndirect() { testPass("FinalClassDoubleIndirect"); } @Test - public void testFinalClassMethodReference() { + void testFinalClassMethodReference() { testPass("FinalClassMethodReference"); } @Test - public void testFinalClassInheritedDirect() { + void testFinalClassInheritedDirect() { testPass("FinalClassInheritedDirect"); } @Test - public void testFinalClassInheritedIndirect() { + void testFinalClassInheritedIndirect() { testPass("FinalClassInheritedIndirect"); } @Test - public void testFinalClassInheritedDoubleIndirect() { + void testFinalClassInheritedDoubleIndirect() { testPass("FinalClassInheritedDoubleIndirect"); } @Test - public void testFinalClassInheritedMethodReference() { + void testFinalClassInheritedMethodReference() { testPass("FinalClassInheritedMethodReference"); } diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/FindPotentialSecurityCheckBasedOnUntrustedSourceTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/FindPotentialSecurityCheckBasedOnUntrustedSourceTest.java index 0c0912590f4..62e01148a39 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/FindPotentialSecurityCheckBasedOnUntrustedSourceTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/FindPotentialSecurityCheckBasedOnUntrustedSourceTest.java @@ -4,16 +4,16 @@ import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.MatcherAssert.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; -public class FindPotentialSecurityCheckBasedOnUntrustedSourceTest extends AbstractIntegrationTest { +class FindPotentialSecurityCheckBasedOnUntrustedSourceTest extends AbstractIntegrationTest { @Test - public void test() throws Exception { + void testUntrustedSources() throws Exception { performAnalysis("PotentialSecurityCheckBasedOnUntrustedSource.class", "PotentialSecurityCheckBasedOnUntrustedSource$1.class", "PotentialSecurityCheckBasedOnUntrustedSource$2.class"); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/FindPublicAttributesTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/FindPublicAttributesTest.java index 4829baa3010..25ede461486 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/FindPublicAttributesTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/FindPublicAttributesTest.java @@ -3,19 +3,20 @@ import edu.umd.cs.findbugs.*; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasItem; -public class FindPublicAttributesTest extends AbstractIntegrationTest { +class FindPublicAttributesTest extends AbstractIntegrationTest { + private static final String PRIMITIVE_PUBLIC = "PA_PUBLIC_PRIMITIVE_ATTRIBUTE"; private static final String MUTABLE_PUBLIC = "PA_PUBLIC_MUTABLE_OBJECT_ATTRIBUTE"; private static final String ARRAY_PUBLIC = "PA_PUBLIC_ARRAY_ATTRIBUTE"; @Test - public void testPublicAttributesChecks() { + void testPublicAttributesChecks() { performAnalysis("PublicAttributesTest.class"); assertNumOfBugs(PRIMITIVE_PUBLIC, 3); @@ -33,7 +34,7 @@ public void testPublicAttributesChecks() { } @Test - public void testGoodPublicAttributesChecks() { + void testGoodPublicAttributesChecks() { performAnalysis("PublicAttributesNegativeTest.class"); assertNumOfBugs(PRIMITIVE_PUBLIC, 0); assertNumOfBugs(ARRAY_PUBLIC, 0); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/FindSqlInjectionTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/FindSqlInjectionTest.java index 6bf35b8f70e..dd1296e1048 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/FindSqlInjectionTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/FindSqlInjectionTest.java @@ -19,18 +19,18 @@ package edu.umd.cs.findbugs.detect; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author pugh */ -public class FindSqlInjectionTest { +class FindSqlInjectionTest { @Test - public void testOpenQuote() { + void testOpenQuote() { assertTrue(FindSqlInjection.isOpenQuote("'")); assertTrue(FindSqlInjection.isOpenQuote(" '")); assertTrue(FindSqlInjection.isOpenQuote("='")); @@ -42,7 +42,7 @@ public void testOpenQuote() { } @Test - public void testCloseQuote() { + void testCloseQuote() { assertTrue(FindSqlInjection.isCloseQuote("'")); assertTrue(FindSqlInjection.isCloseQuote("' ")); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/FindUnsatisfiedObligationTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/FindUnsatisfiedObligationTest.java index 02050e48bf5..4f05d28c590 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/FindUnsatisfiedObligationTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/FindUnsatisfiedObligationTest.java @@ -6,22 +6,24 @@ import java.nio.file.Paths; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import edu.umd.cs.findbugs.BugCollection; -import edu.umd.cs.findbugs.test.SpotBugsRule; +import edu.umd.cs.findbugs.test.SpotBugsExtension; +import edu.umd.cs.findbugs.test.SpotBugsRunner; -public class FindUnsatisfiedObligationTest { - @Rule - public SpotBugsRule spotbugs = new SpotBugsRule(); +@ExtendWith(SpotBugsExtension.class) +class FindUnsatisfiedObligationTest { + + public SpotBugsExtension spotbugs = new SpotBugsExtension(); /** * @see GitHub * issue */ @Test - public void testIssue60() { + void testIssue60(SpotBugsRunner spotbugs) { BugCollection bugCollection = spotbugs.performAnalysis(Paths.get("../spotbugsTestCases/build/classes/java/main/lambdas/Issue60.class")); assertThat(bugCollection, is(emptyIterable())); } diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/FindVulnerableSecurityCheckMethodsTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/FindVulnerableSecurityCheckMethodsTest.java index f133fa5f570..df596558c10 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/FindVulnerableSecurityCheckMethodsTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/FindVulnerableSecurityCheckMethodsTest.java @@ -4,16 +4,17 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasItem; -import org.junit.Test; +import org.junit.jupiter.api.Test; import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; -public class FindVulnerableSecurityCheckMethodsTest extends AbstractIntegrationTest { +class FindVulnerableSecurityCheckMethodsTest extends AbstractIntegrationTest { + static String bugType = "VSC_VULNERABLE_SECURITY_CHECK_METHODS"; @Test - public void testingBadCases() { + void testingBadCases() { performAnalysis("vulnerablesecuritycheckmethodstest/FindVulnerableSecurityCheckMethodsTest.class"); BugInstanceMatcher bugInstanceMatcher = new BugInstanceMatcherBuilder() @@ -23,140 +24,140 @@ public void testingBadCases() { } @Test - public void testingBadCase1() { + void testingBadCase1() { performAnalysis("vulnerablesecuritycheckmethodstest/FindVulnerableSecurityCheckMethodsTest.class"); assertVSCBug("badFindVulnerableSecurityCheckMethodsCheck", 23); } @Test - public void testingBadCase2() { + void testingBadCase2() { performAnalysis("vulnerablesecuritycheckmethodstest/FindVulnerableSecurityCheckMethodsTest.class"); assertVSCBug("badFindVulnerableSecurityCheckMethodsCheck2", 37); } @Test - public void testingBadCase3() { + void testingBadCase3() { performAnalysis("vulnerablesecuritycheckmethodstest/FindVulnerableSecurityCheckMethodsTest.class"); assertVSCBug("badFindVulnerableSecurityCheckMethodsCheck3", 53); } @Test - public void testingBadCase4() { + void testingBadCase4() { performAnalysis("vulnerablesecuritycheckmethodstest/FindVulnerableSecurityCheckMethodsTest.class"); assertVSCBug("badFindVulnerableSecurityCheckMethodsCheck4", 94); } @Test - public void testingBadCase5() { + void testingBadCase5() { performAnalysis("vulnerablesecuritycheckmethodstest/FindVulnerableSecurityCheckMethodsTest.class"); assertVSCBug("badFindVulnerableSecurityCheckMethodsCheck6", 128); } @Test - public void testingGoodCase1() { + void testingGoodCase1() { performAnalysis("vulnerablesecuritycheckmethodstest/FindVulnerableSecurityCheckMethodsTest.class"); assertNoVSCBug("goodvulnerablesecuritycheckmethodstestCheck"); } @Test - public void testingGoodCase2() { + void testingGoodCase2() { performAnalysis("vulnerablesecuritycheckmethodstest/FindVulnerableSecurityCheckMethodsTest.class"); assertNoVSCBug("goodVulnerableSecurityCheckMethodsTestCheck2"); } @Test - public void testingGoodCase3() { + void testingGoodCase3() { performAnalysis("vulnerablesecuritycheckmethodstest/FindVulnerableSecurityCheckMethodsTest.class"); assertNoVSCBug("goodVulnerableSecurityCheckMethodsTestCheck4"); } @Test - public void testingGoodCase4() { + void testingGoodCase4() { performAnalysis("vulnerablesecuritycheckmethodstest/FindVulnerableSecurityCheckMethodsTest.class"); assertNoVSCBug("goodVulnerableSecurityCheckMethodsTestCheck5"); } @Test - public void testingGoodCase5() { + void testingGoodCase5() { performAnalysis("vulnerablesecuritycheckmethodstest/GoodVulnerableSecurityCheckMethodsTest.class"); assertNoVSCBug("goodVulnerableSecurityCheckMethodsTestCheck"); } @Test - public void testingGoodCase6() { + void testingGoodCase6() { performAnalysis("vulnerablesecuritycheckmethodstest/GoodVulnerableSecurityCheckMethodsTest.class"); assertNoVSCBug("goodVulnerableSecurityCheckMethodsTestCheck2"); } @Test - public void testingGoodCase7() { + void testingGoodCase7() { performAnalysis("vulnerablesecuritycheckmethodstest/GoodVulnerableSecurityCheckMethodsTest.class"); assertNoVSCBug("goodVulnerableSecurityCheckMethodsTestCheck3"); } @Test - public void testingGoodCase8() { + void testingGoodCase8() { performAnalysis("vulnerablesecuritycheckmethodstest/GoodVulnerableSecurityCheckMethodsTest.class"); assertNoVSCBug("goodVulnerableSecurityCheckMethodsTestCheck4"); } @Test - public void testingGoodCase9() { + void testingGoodCase9() { performAnalysis("vulnerablesecuritycheckmethodstest/GoodVulnerableSecurityCheckMethodsTest.class"); assertNoVSCBug("goodVulnerableSecurityCheckMethodsTestCheck5"); } @Test - public void testingGoodCase10() { + void testingGoodCase10() { performAnalysis("vulnerablesecuritycheckmethodstest/GoodVulnerableSecurityCheckMethodsTest.class"); assertNoVSCBug("badCalled"); } @Test - public void testingGoodCase11() { + void testingGoodCase11() { performAnalysis("vulnerablesecuritycheckmethodstest/GoodVulnerableSecurityCheckMethodsTest.class"); assertNoVSCBug("goodVulnerableSecurityCheckMethodsTestCheck6"); } @Test - public void testingGoodCase12() { + void testingGoodCase12() { performAnalysis("vulnerablesecuritycheckmethodstest/GoodVulnerableSecurityCheckMethodsTest.class"); assertNoVSCBug("goodVulnerableSecurityCheckMethodsTestCheck7"); } @Test - public void testingGoodCase13() { + void testingGoodCase13() { performAnalysis("vulnerablesecuritycheckmethodstest/GoodVulnerableSecurityCheckMethodsTest.class"); assertNoVSCBug("goodFindVulnerableSecurityCheckMethodsCheck5"); } @Test - public void testingGoodCase14() { + void testingGoodCase14() { performAnalysis("vulnerablesecuritycheckmethodstest/GoodVulnerableSecurityCheckMethodsTest.class"); assertNoVSCBug("goodVulnerableSecurityCheckMethodsTestCheck6"); } @Test - public void testingGoodCase15() { + void testingGoodCase15() { performAnalysis("vulnerablesecuritycheckmethodstest/GoodVulnerableSecurityCheckMethodsTest.class"); assertNoVSCBug("goodVulnerableSecurityCheckMethodsTestCheck7"); } @Test - public void testingGoodCase16() { + void testingGoodCase16() { performAnalysis("vulnerablesecuritycheckmethodstest/FindVulnerableSecurityCheckMethodsTest.class"); assertNoVSCBug("goodVulnerableSecurityCheckMethodsTestCheck6"); } @Test - public void testingGoodCase17() { + void testingGoodCase17() { performAnalysis("vulnerablesecuritycheckmethodstest/FindVulnerableSecurityCheckMethodsTest.class"); assertNoVSCBug("goodVulnerableSecurityCheckMethodsTestCheck7"); } @Test - public void testingGoodCase18() { + void testingGoodCase18() { performAnalysis("vulnerablesecuritycheckmethodstest/GoodVulnerableSecurityCheckMethodsTest.class"); assertNoVSCBug("goodVulnerableSecurityCheckMethodsTestCheck8"); } diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/IncompatMaskTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/IncompatMaskTest.java index e91a05f4dbf..0ab427f73c8 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/IncompatMaskTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/IncompatMaskTest.java @@ -19,16 +19,16 @@ package edu.umd.cs.findbugs.detect; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author pugh */ -public class IncompatMaskTest { +class IncompatMaskTest { - void check(long value) { + private void check(long value) { assertEquals(1, IncompatMask.populationCount(value)); boolean isLong = (value >>> 32) != 0; assertEquals(value, IncompatMask.getFlagBits(true, value)); @@ -40,7 +40,7 @@ void check(long value) { } @Test - public void testGetFlagBits() { + void testGetFlagBits() { check(1); check(4); check(0x10000000L); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/IncorrectSelfComparisonInstanceOfPatternMatchingTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/IncorrectSelfComparisonInstanceOfPatternMatchingTest.java index c46d2cb7eff..c288319a028 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/IncorrectSelfComparisonInstanceOfPatternMatchingTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/IncorrectSelfComparisonInstanceOfPatternMatchingTest.java @@ -1,37 +1,32 @@ package edu.umd.cs.findbugs.detect; -import static org.hamcrest.core.Is.is; -import static org.hamcrest.number.OrderingComparison.greaterThanOrEqualTo; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assume.assumeFalse; -import static org.junit.Assume.assumeThat; import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; import java.nio.file.Paths; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledOnJre; +import org.junit.jupiter.api.condition.JRE; +import org.junit.jupiter.api.extension.ExtendWith; import edu.umd.cs.findbugs.BugCollection; -import edu.umd.cs.findbugs.test.SpotBugsRule; +import edu.umd.cs.findbugs.test.SpotBugsExtension; +import edu.umd.cs.findbugs.test.SpotBugsRunner; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; -public class IncorrectSelfComparisonInstanceOfPatternMatchingTest { - @Rule - public SpotBugsRule spotbugs = new SpotBugsRule(); +@ExtendWith(SpotBugsExtension.class) +class IncorrectSelfComparisonInstanceOfPatternMatchingTest { /** * @see GitHub * issue */ @Test - public void testIssue1136() { - assumeFalse(System.getProperty("java.specification.version").startsWith("1.")); - int javaVersion = Integer.parseInt(System.getProperty("java.specification.version")); - assumeThat(javaVersion, is(greaterThanOrEqualTo(14))); - + @DisabledOnJre({ JRE.JAVA_8, JRE.JAVA_11 }) + void testIssue1136(SpotBugsRunner spotbugs) { final BugInstanceMatcher selfComparisonMatcher = new BugInstanceMatcherBuilder() .bugType("SA_LOCAL_SELF_COMPARISON").build(); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue1472Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue1472Test.java index 9e028d97147..8a3ec50432b 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue1472Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue1472Test.java @@ -3,7 +3,7 @@ import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; import static org.hamcrest.MatcherAssert.assertThat; @@ -12,9 +12,10 @@ /** * @see GitHub issue #1472 */ -public class Issue1472Test extends AbstractIntegrationTest { +class Issue1472Test extends AbstractIntegrationTest { + @Test - public void test() { + void testIssue() { performAnalysis("ghIssues/Issue1472.class"); BugInstanceMatcher bugTypeMatcher = new BugInstanceMatcherBuilder() .bugType("SA_LOCAL_SELF_COMPUTATION") diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue1498Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue1498Test.java index dd80fa0c65d..14ef0043641 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue1498Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue1498Test.java @@ -4,13 +4,14 @@ import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; import static org.hamcrest.MatcherAssert.assertThat; -public class Issue1498Test extends AbstractIntegrationTest { +class Issue1498Test extends AbstractIntegrationTest { + @Test - public void test() { + void testIssue() { System.setProperty("frc.debug", "true"); performAnalysis("ghIssues/Issue1498.class"); BugInstanceMatcher bugTypeMatcher = new BugInstanceMatcherBuilder().bugType("IM_MULTIPLYING_RESULT_OF_IREM").build(); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue1518Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue1518Test.java index 3977a9c723c..b1af66c007c 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue1518Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue1518Test.java @@ -3,7 +3,7 @@ import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; import static org.hamcrest.MatcherAssert.assertThat; @@ -11,9 +11,10 @@ /** * @see GitHub issue #1518 */ -public class Issue1518Test extends AbstractIntegrationTest { +class Issue1518Test extends AbstractIntegrationTest { + @Test - public void test() { + void testIssue() { performAnalysis("ghIssues/Issue1518.class"); BugInstanceMatcher bugTypeMatcher = new BugInstanceMatcherBuilder() .bugType("RV_01_TO_INT") diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue1539Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue1539Test.java index be2a533c647..e27c194f2d0 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue1539Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue1539Test.java @@ -3,37 +3,36 @@ import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.ParameterizedTest; import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; import static org.hamcrest.MatcherAssert.assertThat; +import java.util.stream.Stream; + /** * @see PR suggested this test case */ -@RunWith(Parameterized.class) -public class Issue1539Test extends AbstractIntegrationTest { - private final String target; +class Issue1539Test extends AbstractIntegrationTest { - public Issue1539Test(String className) { - this.target = String.format("ghIssues/issue1539/%s.class", className); + private String classLocation(String className) { + return String.format("ghIssues/issue1539/%s.class", className); } - @Parameterized.Parameters - public static String[] data() { - return new String[] { - "Issue1539Instance", - "Issue1539Static", - "Issue1539ThreadLocal", - "Issue1539Argument" - }; + private static Stream classes() { + return Stream.of( + Arguments.of("Issue1539Instance"), + Arguments.of("Issue1539Static"), + Arguments.of("Issue1539ThreadLocal"), + Arguments.of("Issue1539Argument")); } - @Test - public void testInstance() { - performAnalysis(target); + @ParameterizedTest + @MethodSource("classes") + void testInstance(String className) { + performAnalysis(classLocation(className)); BugInstanceMatcher bugTypeMatcher = new BugInstanceMatcherBuilder() .bugType("DMI_RANDOM_USED_ONLY_ONCE") .build(); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue1642Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue1642Test.java index c729adc0735..c65150659f4 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue1642Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue1642Test.java @@ -3,7 +3,7 @@ import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; import static org.hamcrest.MatcherAssert.assertThat; @@ -11,9 +11,10 @@ /** * @see GitHub issue #1472 */ -public class Issue1642Test extends AbstractIntegrationTest { +class Issue1642Test extends AbstractIntegrationTest { + @Test - public void test() { + void testIssue() { performAnalysis("ghIssues/Issue1642.class"); BugInstanceMatcherBuilder builder = new BugInstanceMatcherBuilder() .bugType("NP_NONNULL_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR"); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue1759Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue1759Test.java index 904483ac337..f495cc8b4ee 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue1759Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue1759Test.java @@ -3,14 +3,15 @@ import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; import static org.hamcrest.MatcherAssert.assertThat; -public class Issue1759Test extends AbstractIntegrationTest { +class Issue1759Test extends AbstractIntegrationTest { + @Test - public void test() { + void testIssue() { performAnalysis("ghIssues/Issue1759.class"); BugInstanceMatcher matcher = new BugInstanceMatcherBuilder() .bugType("BC_IMPOSSIBLE_DOWNCAST_OF_TOARRAY").build(); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue1764Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue1764Test.java index 59e8c788613..9aa195b9caf 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue1764Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue1764Test.java @@ -4,16 +4,17 @@ import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; /** * @see GitHub issue */ -public class Issue1764Test extends AbstractIntegrationTest { +class Issue1764Test extends AbstractIntegrationTest { + @Test - public void test() { + void testIssue() { System.setProperty("frc.debug", "true"); performAnalysis("ghIssues/Issue1764.class"); BugInstanceMatcher bugTypeMatcher = new BugInstanceMatcherBuilder() diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue1765Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue1765Test.java index de5fa80838e..0f347e021ec 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue1765Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue1765Test.java @@ -3,14 +3,15 @@ import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; import static org.hamcrest.MatcherAssert.assertThat; -public class Issue1765Test extends AbstractIntegrationTest { +class Issue1765Test extends AbstractIntegrationTest { + @Test - public void test() { + void testIssue() { performAnalysis("ghIssues/Issue1765.class"); BugInstanceMatcher matcher = new BugInstanceMatcherBuilder() .bugType("HE_HASHCODE_USE_OBJECT_EQUALS").build(); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue1771Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue1771Test.java index 30723a1b238..b69a7fa2822 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue1771Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue1771Test.java @@ -1,29 +1,21 @@ package edu.umd.cs.findbugs.detect; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledOnJre; +import org.junit.jupiter.api.condition.JRE; import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; -import static org.junit.Assume.assumeFalse; -import static org.junit.Assume.assumeThat; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.greaterThanOrEqualTo; -public class Issue1771Test extends AbstractIntegrationTest { - @Before - public void verifyJavaVersion() { - assumeFalse(System.getProperty("java.specification.version").startsWith("1.")); - int javaVersion = Integer.parseInt(System.getProperty("java.specification.version")); - assumeThat(javaVersion, is(greaterThanOrEqualTo(11))); - } +class Issue1771Test extends AbstractIntegrationTest { @Test - public void test() { + @DisabledOnJre(JRE.JAVA_8) + void testIssue() { performAnalysis("../java11/ghIssues/Issue1771.class"); BugInstanceMatcher matcher = new BugInstanceMatcherBuilder() .bugType("EI_EXPOSE_REP").build(); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2019Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2019Test.java index 35942acda83..a2ae2142831 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2019Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2019Test.java @@ -1,12 +1,12 @@ package edu.umd.cs.findbugs.detect; import edu.umd.cs.findbugs.AbstractIntegrationTest; -import org.junit.Test; +import org.junit.jupiter.api.Test; +class Issue2019Test extends AbstractIntegrationTest { -public class Issue2019Test extends AbstractIntegrationTest { @Test - public void test() { + void testIssue() { performAnalysis("ghIssues/Issue2019$ATNSimulator.class", "ghIssues/Issue2019$BaseParser.class", "ghIssues/Issue2019$Parser.class", diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2114Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2114Test.java index da57e422200..62689fca22b 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2114Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2114Test.java @@ -1,6 +1,8 @@ package edu.umd.cs.findbugs.detect; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledOnJre; +import org.junit.jupiter.api.condition.JRE; import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; @@ -9,9 +11,11 @@ import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; import static org.hamcrest.MatcherAssert.assertThat; -public class Issue2114Test extends AbstractIntegrationTest { +class Issue2114Test extends AbstractIntegrationTest { + @Test - public void test() { + @DisabledOnJre(JRE.JAVA_8) + void testIssue() { performAnalysis("../java11/Issue2114.class"); assertFoundDefaultEncodingRelianceInMethod("filesReadString"); @@ -21,7 +25,7 @@ public void test() { assertFoundDefaultEncodingRelianceInMethod("filesNewBufferedWriter"); } - public void assertFoundDefaultEncodingRelianceInMethod(String methodName) { + private void assertFoundDefaultEncodingRelianceInMethod(String methodName) { BugInstanceMatcher matcher = new BugInstanceMatcherBuilder() .bugType("DM_DEFAULT_ENCODING") .inMethod(methodName) diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2120Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2120Test.java index 214db484a9d..8b1036a7f4d 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2120Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2120Test.java @@ -1,29 +1,21 @@ package edu.umd.cs.findbugs.detect; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledOnJre; +import org.junit.jupiter.api.condition.JRE; import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; -import static org.junit.Assume.assumeFalse; -import static org.junit.Assume.assumeThat; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.greaterThanOrEqualTo; -public class Issue2120Test extends AbstractIntegrationTest { - @Before - public void verifyJavaVersion() { - assumeFalse(System.getProperty("java.specification.version").startsWith("1.")); - int javaVersion = Integer.parseInt(System.getProperty("java.specification.version")); - assumeThat(javaVersion, is(greaterThanOrEqualTo(11))); - } +class Issue2120Test extends AbstractIntegrationTest { @Test - public void test() { + @DisabledOnJre({ JRE.JAVA_8, JRE.JAVA_11 }) + void testIssue() { performAnalysis("../java17/Issue2120.class", "../java17/Issue2120$1MyEnum.class", "../java17/Issue2120$1MyRecord.class"); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2142Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2142Test.java index abb1267cfa1..b7c40c63d67 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2142Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2142Test.java @@ -1,6 +1,6 @@ package edu.umd.cs.findbugs.detect; -import org.junit.Test; +import org.junit.jupiter.api.Test; import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; @@ -10,9 +10,10 @@ import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.MatcherAssert.assertThat; -public class Issue2142Test extends AbstractIntegrationTest { +class Issue2142Test extends AbstractIntegrationTest { + @Test - public void test() { + void testIssue() { performAnalysis("ghIssues/Issue2142.class", "ghIssues/Issue2142$Inner.class"); BugInstanceMatcher matcher = new BugInstanceMatcherBuilder() diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2147Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2147Test.java index d0d9ff60515..f9e7a709040 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2147Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2147Test.java @@ -1,6 +1,6 @@ package edu.umd.cs.findbugs.detect; -import org.junit.Test; +import org.junit.jupiter.api.Test; import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; @@ -9,9 +9,10 @@ import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; import static org.hamcrest.MatcherAssert.assertThat; -public class Issue2147Test extends AbstractIntegrationTest { +class Issue2147Test extends AbstractIntegrationTest { + @Test - public void test() { + void testIssue() { performAnalysis("ghIssues/Issue2147.class", "ghIssues/Issue2147A.class", "ghIssues/Issue2147B.class", diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2182Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2182Test.java index 06531cdf5cc..4aca4fa24b4 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2182Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2182Test.java @@ -1,29 +1,21 @@ package edu.umd.cs.findbugs.detect; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledOnJre; +import org.junit.jupiter.api.condition.JRE; import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; -import static org.junit.Assume.assumeFalse; -import static org.junit.Assume.assumeThat; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasItem; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.greaterThanOrEqualTo; -public class Issue2182Test extends AbstractIntegrationTest { - @Before - public void verifyJavaVersion() { - assumeFalse(System.getProperty("java.specification.version").startsWith("1.")); - int javaVersion = Integer.parseInt(System.getProperty("java.specification.version")); - assumeThat(javaVersion, is(greaterThanOrEqualTo(11))); - } +class Issue2182Test extends AbstractIntegrationTest { @Test - public void test() { + @DisabledOnJre(JRE.JAVA_8) + void testIssue() { performAnalysis("../java11/ghIssues/Issue2182.class"); BugInstanceMatcher matcher = new BugInstanceMatcherBuilder() .bugType("SBSC_USE_STRINGBUFFER_CONCATENATION") diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2183Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2183Test.java index b353a904e5e..0b37753a01f 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2183Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2183Test.java @@ -1,30 +1,22 @@ package edu.umd.cs.findbugs.detect; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledOnJre; +import org.junit.jupiter.api.condition.JRE; import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.annotations.Confidence; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; -import static org.junit.Assume.assumeFalse; -import static org.junit.Assume.assumeThat; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasItem; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.greaterThanOrEqualTo; -public class Issue2183Test extends AbstractIntegrationTest { - @Before - public void verifyJavaVersion() { - assumeFalse(System.getProperty("java.specification.version").startsWith("1.")); - int javaVersion = Integer.parseInt(System.getProperty("java.specification.version")); - assumeThat(javaVersion, is(greaterThanOrEqualTo(11))); - } +class Issue2183Test extends AbstractIntegrationTest { @Test - public void test() { + @DisabledOnJre(JRE.JAVA_8) + void testIssue() { performAnalysis("../java11/ghIssues/Issue2183.class"); BugInstanceMatcher matcher = new BugInstanceMatcherBuilder() .bugType("SQL_NONCONSTANT_STRING_PASSED_TO_EXECUTE") diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2184Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2184Test.java index f22b9e6a1ef..5fae4413e52 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2184Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2184Test.java @@ -1,29 +1,21 @@ package edu.umd.cs.findbugs.detect; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledOnJre; +import org.junit.jupiter.api.condition.JRE; import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; -import static org.junit.Assume.assumeFalse; -import static org.junit.Assume.assumeThat; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasItem; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.greaterThanOrEqualTo; -public class Issue2184Test extends AbstractIntegrationTest { - @Before - public void verifyJavaVersion() { - assumeFalse(System.getProperty("java.specification.version").startsWith("1.")); - int javaVersion = Integer.parseInt(System.getProperty("java.specification.version")); - assumeThat(javaVersion, is(greaterThanOrEqualTo(14))); - } +class Issue2184Test extends AbstractIntegrationTest { @Test - public void test() { + @DisabledOnJre({ JRE.JAVA_8, JRE.JAVA_11 }) + void testIssue() { performAnalysis("../java17/ghIssues/Issue2184.class"); BugInstanceMatcher matcher = new BugInstanceMatcherBuilder() .bugType("PT_RELATIVE_PATH_TRAVERSAL") diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2331Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2331Test.java index eabd375faf8..1cadf62a8d2 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2331Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2331Test.java @@ -3,15 +3,15 @@ import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; import static org.hamcrest.MatcherAssert.assertThat; -public class Issue2331Test extends AbstractIntegrationTest { +class Issue2331Test extends AbstractIntegrationTest { @Test - public void test() { + void testIssue() { performAnalysis("infiniteLoop/Issue2331.class"); BugInstanceMatcher bugMatcher = new BugInstanceMatcherBuilder() .bugType("IL_INFINITE_LOOP") diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2370Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2370Test.java index ee554a2fd52..122c8e9c490 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2370Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2370Test.java @@ -3,33 +3,31 @@ import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.ParameterizedTest; +import java.util.stream.Stream; import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; import static org.hamcrest.MatcherAssert.assertThat; -@RunWith(Parameterized.class) -public class Issue2370Test extends AbstractIntegrationTest { - private final String target; +class Issue2370Test extends AbstractIntegrationTest { - public Issue2370Test(String className) { - this.target = String.format("ghIssues/issue2370/%s.class", className); + private String classLocation(String className) { + return String.format("ghIssues/issue2370/%s.class", className); } - @Parameterized.Parameters - public static String[] data() { - return new String[] { - "Issue2370Doubles", - "Issue2370Ints", - "Issue2370Longs" - }; + private static Stream classes() { + return Stream.of( + Arguments.of("Issue2370Doubles"), + Arguments.of("Issue2370Ints"), + Arguments.of("Issue2370Longs")); } - @Test - public void testInstance() { - performAnalysis(target); + @ParameterizedTest + @MethodSource("classes") + void testInstance(String className) { + performAnalysis(classLocation(className)); BugInstanceMatcher bugTypeMatcher = new BugInstanceMatcherBuilder() .bugType("DMI_RANDOM_USED_ONLY_ONCE") .build(); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2436Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2436Test.java index 52b533e481e..368e3b80ee3 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2436Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2436Test.java @@ -3,15 +3,15 @@ import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; import static org.hamcrest.MatcherAssert.assertThat; -public class Issue2436Test extends AbstractIntegrationTest { +class Issue2436Test extends AbstractIntegrationTest { @Test - public void test() { + void testIssue() { performAnalysis("ghIssues/Issue2436.class"); BugInstanceMatcher bugMatcher = new BugInstanceMatcherBuilder() .bugType("SE_NO_SERIALVERSIONID") diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2465Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2465Test.java index e54da98c389..a0d6b712b12 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2465Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2465Test.java @@ -3,16 +3,17 @@ import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; import static org.hamcrest.MatcherAssert.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; -public class Issue2465Test extends AbstractIntegrationTest { +class Issue2465Test extends AbstractIntegrationTest { + @Test - public void test() { + public void testIssue() { performAnalysis("ghIssues/Issue2465.class"); // Due to issue #2465 the analysis should fail and we should not get further diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2547Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2547Test.java index 193b73e3a56..1c720328aef 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2547Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2547Test.java @@ -3,7 +3,7 @@ import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; import static org.hamcrest.MatcherAssert.assertThat; @@ -13,9 +13,10 @@ /** * @see GitHub issue #2547 */ -public class Issue2547Test extends AbstractIntegrationTest { +class Issue2547Test extends AbstractIntegrationTest { + @Test - public void test() { + void testIssue() { performAnalysis("ghIssues/issue2547/Issue2547.class", "ghIssues/issue2547/MyEx.class", "ghIssues/issue2547/ExceptionFactory.class"); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2552Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2552Test.java index 24cbed8780d..751c3741412 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2552Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2552Test.java @@ -3,16 +3,19 @@ import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; import static org.hamcrest.MatcherAssert.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledOnJre; +import org.junit.jupiter.api.condition.JRE; import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; +class Issue2552Test extends AbstractIntegrationTest { -public class Issue2552Test extends AbstractIntegrationTest { @Test - public void test() { + @DisabledOnJre({ JRE.JAVA_8, JRE.JAVA_11 }) + public void testIssue() { performAnalysis("../java17/ghIssues/Issue2552.class"); assertBugCount("EI_EXPOSE_REP", 1); @@ -20,7 +23,7 @@ public void test() { assertBugAtLine("EI_EXPOSE_REP", 12); } - public void assertBugCount(String type, int expectedCount) { + private void assertBugCount(String type, int expectedCount) { BugInstanceMatcher bugMatcher = new BugInstanceMatcherBuilder() .bugType(type) .build(); @@ -28,7 +31,7 @@ public void assertBugCount(String type, int expectedCount) { assertThat(getBugCollection(), containsExactly(expectedCount, bugMatcher)); } - public void assertBugAtLine(String type, int line) { + private void assertBugAtLine(String type, int line) { BugInstanceMatcher bugMatcher = new BugInstanceMatcherBuilder() .bugType(type) .atLine(line) diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue374Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue374Test.java index 2babafb432f..9398281f96c 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue374Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue374Test.java @@ -21,7 +21,7 @@ import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; import static org.hamcrest.MatcherAssert.assertThat; @@ -30,9 +30,10 @@ /** * @see GitHub issue */ -public class Issue374Test extends AbstractIntegrationTest { +class Issue374Test extends AbstractIntegrationTest { + @Test - public void test() { + public void testIssue() { performAnalysis( "ghIssues/issue374/package-info.class", "ghIssues/issue374/ClassLevel.class", diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue463Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue463Test.java index b9468770287..75cc8d9d08c 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue463Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue463Test.java @@ -3,7 +3,7 @@ import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; import static org.hamcrest.MatcherAssert.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; @@ -12,9 +12,10 @@ /** * @see GitHub issue */ -public class Issue463Test extends AbstractIntegrationTest { +class Issue463Test extends AbstractIntegrationTest { + @Test - public void testAnnotatedClass() { + void testAnnotatedClass() { performAnalysis("ghIssues/Issue463.class"); BugInstanceMatcher bugTypeMatcher = new BugInstanceMatcherBuilder().bugType("RV_RETURN_VALUE_IGNORED") .atLine(37).build(); @@ -28,7 +29,7 @@ public void testAnnotatedClass() { * @see Issue 582 */ @Test - public void testAnnotatedPackage() { + void testAnnotatedPackage() { performAnalysis("ghIssues/issue463/Issue463.class", "ghIssues/issue463/package-info.class"); BugInstanceMatcher bugTypeMatcher = new BugInstanceMatcherBuilder().bugType("RV_RETURN_VALUE_IGNORED") .atLine(34).build(); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue484Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue484Test.java index f1d37309fc0..c2f2aae72e3 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue484Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue484Test.java @@ -3,7 +3,7 @@ import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; import static org.hamcrest.MatcherAssert.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; @@ -13,9 +13,10 @@ * @see GitHub issue * @since 3.1 */ -public class Issue484Test extends AbstractIntegrationTest { +class Issue484Test extends AbstractIntegrationTest { + @Test - public void test() { + void testIssue() { performAnalysis("ghIssues/Issue484.class"); BugInstanceMatcher bugTypeMatcher = new BugInstanceMatcherBuilder().bugType("NP_NONNULL_PARAM_VIOLATION") .build(); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue500Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue500Test.java index a06e4239589..6d284a80a3d 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue500Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue500Test.java @@ -21,7 +21,7 @@ import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; import static org.hamcrest.MatcherAssert.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; @@ -30,10 +30,10 @@ /** * @author William R. Price */ -public class Issue500Test extends AbstractIntegrationTest { +class Issue500Test extends AbstractIntegrationTest { @Test - public void test() { + void testIssue() { performAnalysis("lambdas/Issue500.class"); BugInstanceMatcher bugMatcher = new BugInstanceMatcherBuilder().build(); assertThat(getBugCollection(), containsExactly(0, bugMatcher)); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue560Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue560Test.java index c4f2040a476..9b0d0236cbc 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue560Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue560Test.java @@ -5,15 +5,15 @@ import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; import static org.hamcrest.MatcherAssert.assertThat; -public class Issue560Test extends AbstractIntegrationTest { +class Issue560Test extends AbstractIntegrationTest { @Test - public void test() { + void testIssue() { performAnalysis("ghIssues/Issue560.class", "ghIssues/Issue560$NotANestedTest.class", "ghIssues/Issue560$NestedTest.class"); @@ -22,7 +22,7 @@ public void test() { assertBugInClass("SIC_INNER_SHOULD_BE_STATIC", "ghIssues.Issue560$NotANestedTest"); } - public void assertBugCount(String type, int expectedCount) { + private void assertBugCount(String type, int expectedCount) { BugInstanceMatcher bugMatcher = new BugInstanceMatcherBuilder() .bugType(type) .build(); @@ -30,7 +30,7 @@ public void assertBugCount(String type, int expectedCount) { assertThat(getBugCollection(), containsExactly(expectedCount, bugMatcher)); } - public void assertBugInClass(String type, String className) { + private void assertBugInClass(String type, String className) { BugInstanceMatcher bugMatcher = new BugInstanceMatcherBuilder() .bugType(type) .inClass(className) diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue582Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue582Test.java index 51dc4eea6de..94bf4c3a346 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue582Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue582Test.java @@ -3,7 +3,7 @@ import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; import static org.hamcrest.MatcherAssert.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; @@ -16,9 +16,10 @@ * @see GitHub issue * @since 3.1.3 */ -public class Issue582Test extends AbstractIntegrationTest { +class Issue582Test extends AbstractIntegrationTest { + @Test - public void testAnnnotatedClass() { + void testAnnnotatedClass() { performAnalysis("ghIssues/Issue582.class"); BugInstanceMatcher bugTypeMatcher = new BugInstanceMatcherBuilder().bugType("RV_RETURN_VALUE_IGNORED") .atLine(35).build(); @@ -26,7 +27,7 @@ public void testAnnnotatedClass() { } @Test - public void testAnnotatedPackage() { + void testAnnotatedPackage() { performAnalysis("ghIssues/issue582/Issue582.class", "ghIssues/issue582/package-info.class"); BugInstanceMatcher bugTypeMatcher = new BugInstanceMatcherBuilder().bugType("RV_RETURN_VALUE_IGNORED") .atLine(34).build(); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue595Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue595Test.java index 2fa652cc465..148435c1a8d 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue595Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue595Test.java @@ -3,11 +3,9 @@ import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; import static org.hamcrest.MatcherAssert.assertThat; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Test; import edu.umd.cs.findbugs.AbstractIntegrationTest; -import edu.umd.cs.findbugs.test.SpotBugsRule; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; @@ -15,12 +13,10 @@ * @see GitHub * issue */ -public class Issue595Test extends AbstractIntegrationTest { - @Rule - public SpotBugsRule spotbugs = new SpotBugsRule(); +class Issue595Test extends AbstractIntegrationTest { @Test - public void testIoOperationOk() { + void testIoOperationOk() { performAnalysis("rangeArray/IoOperationOk.class"); BugInstanceMatcher bugTypeMatcherLength = new BugInstanceMatcherBuilder().bugType("RANGE_ARRAY_LENGTH").build(); BugInstanceMatcher bugTypeMatcherOffset = new BugInstanceMatcherBuilder().bugType("RANGE_ARRAY_OFFSET").build(); @@ -29,21 +25,21 @@ public void testIoOperationOk() { } @Test - public void testIoOperationRangeArrayLengthExpected() { + void testIoOperationRangeArrayLengthExpected() { performAnalysis("rangeArray/IoOperationRangeArrayLengthExpected.class"); BugInstanceMatcher bugTypeMatcherLength = new BugInstanceMatcherBuilder().bugType("RANGE_ARRAY_LENGTH").build(); assertThat(getBugCollection(), containsExactly(5, bugTypeMatcherLength)); } @Test - public void testIoOperationRangeArrayOffsetExpected() { + void testIoOperationRangeArrayOffsetExpected() { performAnalysis("rangeArray/IoOperationRangeArrayOffsetExpected.class"); BugInstanceMatcher bugTypeMatcherOffset = new BugInstanceMatcherBuilder().bugType("RANGE_ARRAY_OFFSET").build(); assertThat(getBugCollection(), containsExactly(2, bugTypeMatcherOffset)); } @Test - public void testStringConstructorOk() { + void testStringConstructorOk() { performAnalysis("rangeArray/StringConstructorOk.class"); BugInstanceMatcher bugTypeMatcherLength = new BugInstanceMatcherBuilder().bugType("RANGE_ARRAY_LENGTH").build(); BugInstanceMatcher bugTypeMatcherOffset = new BugInstanceMatcherBuilder().bugType("RANGE_ARRAY_OFFSET").build(); @@ -52,14 +48,14 @@ public void testStringConstructorOk() { } @Test - public void testStringConstructorRangeArrayLengthExpected() { + void testStringConstructorRangeArrayLengthExpected() { performAnalysis("rangeArray/StringConstructorRangeArrayLengthExpected.class"); BugInstanceMatcher bugTypeMatcherLength = new BugInstanceMatcherBuilder().bugType("RANGE_ARRAY_LENGTH").build(); assertThat(getBugCollection(), containsExactly(5, bugTypeMatcherLength)); } @Test - public void testStringConstructorRangeArrayOffsetExpected() { + void testStringConstructorRangeArrayOffsetExpected() { performAnalysis("rangeArray/StringConstructorRangeArrayOffsetExpected.class"); BugInstanceMatcher bugTypeMatcherOffset = new BugInstanceMatcherBuilder().bugType("RANGE_ARRAY_OFFSET").build(); assertThat(getBugCollection(), containsExactly(2, bugTypeMatcherOffset)); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue603Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue603Test.java index 8fb45f53e48..98318667447 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue603Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue603Test.java @@ -21,7 +21,7 @@ import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; import static org.hamcrest.MatcherAssert.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; @@ -30,9 +30,10 @@ /** * @see GitHub issue */ -public class Issue603Test extends AbstractIntegrationTest { +class Issue603Test extends AbstractIntegrationTest { + @Test - public void test() { + void testIssue() { performAnalysis("ghIssues/Issue603.class"); BugInstanceMatcher bugTypeMatcher = new BugInstanceMatcherBuilder() .bugType("EI_EXPOSE_REP2") diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue744Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue744Test.java index 4c4bc61efc2..31b56a6e01a 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue744Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue744Test.java @@ -3,7 +3,7 @@ import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; import static org.hamcrest.MatcherAssert.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; @@ -12,9 +12,9 @@ /** * @see GitHub issue #744 */ -public class Issue744Test extends AbstractIntegrationTest { +class Issue744Test extends AbstractIntegrationTest { @Test - public void test() { + void testIssue() { performAnalysis("ghIssues/Issue744.class"); BugInstanceMatcher bugTypeMatcher = new BugInstanceMatcherBuilder() .bugType("DM_BOXED_PRIMITIVE_FOR_PARSING") diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue79Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue79Test.java index 074e17c29d6..251451e02e8 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue79Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue79Test.java @@ -3,7 +3,7 @@ import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; import static org.hamcrest.MatcherAssert.assertThat; @@ -16,10 +16,10 @@ * @see GitHub issue * @since 4.1.3 */ -public class Issue79Test extends AbstractIntegrationTest { +class Issue79Test extends AbstractIntegrationTest { @Test - public void test() { + void testIssue() { performAnalysis("ghIssues/Issue79.class"); BugInstanceMatcher bugMatcher = new BugInstanceMatcherBuilder().build(); assertThat(getBugCollection(), containsExactly(0, bugMatcher)); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue872Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue872Test.java index b41c0317033..02ab3413f03 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue872Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue872Test.java @@ -3,15 +3,15 @@ import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; import static org.hamcrest.MatcherAssert.assertThat; -public class Issue872Test extends AbstractIntegrationTest { +class Issue872Test extends AbstractIntegrationTest { @Test - public void test() { + void testIssue() { performAnalysis("ghIssues/Issue872.class", "ghIssues/Issue872$Value.class"); @@ -22,7 +22,7 @@ public void test() { assertBugAtLine("RV_RETURN_VALUE_IGNORED_NO_SIDE_EFFECT", 18); } - public void assertBugCount(String type, int expectedCount) { + private void assertBugCount(String type, int expectedCount) { BugInstanceMatcher bugMatcher = new BugInstanceMatcherBuilder() .bugType(type) .build(); @@ -30,7 +30,7 @@ public void assertBugCount(String type, int expectedCount) { assertThat(getBugCollection(), containsExactly(expectedCount, bugMatcher)); } - public void assertBugAtLine(String type, int line) { + private void assertBugAtLine(String type, int line) { BugInstanceMatcher bugMatcher = new BugInstanceMatcherBuilder() .bugType(type) .atLine(line) diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/OverridingMethodMustInvokeSuperTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/OverridingMethodMustInvokeSuperTest.java index 3051984625b..340f74b8422 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/OverridingMethodMustInvokeSuperTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/OverridingMethodMustInvokeSuperTest.java @@ -3,15 +3,15 @@ import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; import static org.hamcrest.MatcherAssert.assertThat; -public class OverridingMethodMustInvokeSuperTest extends AbstractIntegrationTest { +class OverridingMethodMustInvokeSuperTest extends AbstractIntegrationTest { @Test - public void test() { + void testInvokeSuper() { performAnalysis( "NeedsCallOfSuper.class", "NeedsCallOfSuper$DerivedClass.class", diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/PreconditionsCheckNotNullCanIgnoreReturnValueTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/PreconditionsCheckNotNullCanIgnoreReturnValueTest.java index 0ffd1eafe04..70904e91125 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/PreconditionsCheckNotNullCanIgnoreReturnValueTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/PreconditionsCheckNotNullCanIgnoreReturnValueTest.java @@ -1,9 +1,10 @@ package edu.umd.cs.findbugs.detect; import edu.umd.cs.findbugs.BugCollection; -import edu.umd.cs.findbugs.test.SpotBugsRule; -import org.junit.Rule; -import org.junit.Test; +import edu.umd.cs.findbugs.test.SpotBugsExtension; +import edu.umd.cs.findbugs.test.SpotBugsRunner; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import java.nio.file.Paths; @@ -11,12 +12,11 @@ import static org.hamcrest.core.Is.is; import static org.hamcrest.MatcherAssert.assertThat; -public class PreconditionsCheckNotNullCanIgnoreReturnValueTest { - @Rule - public SpotBugsRule spotbugs = new SpotBugsRule(); +@ExtendWith(SpotBugsExtension.class) +class PreconditionsCheckNotNullCanIgnoreReturnValueTest { @Test - public void testDoNotWarnOnCanIgnoreReturnValue() { + void testDoNotWarnOnCanIgnoreReturnValue(SpotBugsRunner spotbugs) { BugCollection bugCollection = spotbugs.performAnalysis(Paths.get( "../spotbugsTestCases/build/classes/java/main/bugPatterns/RV_RETURN_VALUE_IGNORED_Guava_Preconditions.class")); assertThat(bugCollection, is(emptyIterable())); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/PreventOverwriteOfExternalizableObjectTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/PreventOverwriteOfExternalizableObjectTest.java index 7b0cbabedc9..903a4f52eb9 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/PreventOverwriteOfExternalizableObjectTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/PreventOverwriteOfExternalizableObjectTest.java @@ -1,6 +1,6 @@ package edu.umd.cs.findbugs.detect; -import org.junit.Test; +import org.junit.jupiter.api.Test; import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; @@ -9,10 +9,10 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasItem; -public class PreventOverwriteOfExternalizableObjectTest extends AbstractIntegrationTest { +class PreventOverwriteOfExternalizableObjectTest extends AbstractIntegrationTest { @Test - public void testBadReadExternal() { + void testBadReadExternal() { performAnalysis("externalizable/BadExternalizableTest.class"); assertNumOfBugs(2); @@ -21,7 +21,7 @@ public void testBadReadExternal() { } @Test - public void testBadReadExternal2() { + void testBadReadExternal2() { performAnalysis("externalizable/BadExternalizableTest2.class"); assertNumOfBugs(1); @@ -29,7 +29,7 @@ public void testBadReadExternal2() { } @Test - public void testBadReadExternal3() { + void testBadReadExternal3() { performAnalysis("externalizable/BadExternalizableTest3.class"); assertNumOfBugs(1); @@ -37,7 +37,7 @@ public void testBadReadExternal3() { } @Test - public void testBadReadExternal4() { + void testBadReadExternal4() { performAnalysis("externalizable/BadExternalizableTest4.class"); assertNumOfBugs(1); @@ -45,7 +45,7 @@ public void testBadReadExternal4() { } @Test - public void testBadReadExternal5() { + void testBadReadExternal5() { performAnalysis("externalizable/BadExternalizableTest5.class"); assertNumOfBugs(2); @@ -54,14 +54,14 @@ public void testBadReadExternal5() { } @Test - public void testGoodReadExternal() { + void testGoodReadExternal() { performAnalysis("externalizable/GoodExternalizableTest.class"); assertNumOfBugs(0); } @Test - public void testGoodReadExternal2() { + void testGoodReadExternal2() { performAnalysis("externalizable/GoodExternalizableTest2.class"); assertNumOfBugs(0); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/RegressionIdeas20110722Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/RegressionIdeas20110722Test.java index ec437e058e1..26d9c9b0a62 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/RegressionIdeas20110722Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/RegressionIdeas20110722Test.java @@ -3,15 +3,16 @@ import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasItem; -public class RegressionIdeas20110722Test extends AbstractIntegrationTest { +class RegressionIdeas20110722Test extends AbstractIntegrationTest { + @Test - public void testArgumentAssertions() { + void testArgumentAssertions() { performAnalysis("bugIdeas/Ideas_2011_07_22.class"); assertNumOfBugs("NP_NULL_ON_SOME_PATH", 0); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/ResolveMethodReferencesTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/ResolveMethodReferencesTest.java index 78fa7cc6603..1daa00ee067 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/ResolveMethodReferencesTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/ResolveMethodReferencesTest.java @@ -7,23 +7,23 @@ import java.nio.file.Paths; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import edu.umd.cs.findbugs.BugCollection; import edu.umd.cs.findbugs.SortedBugCollection; -import edu.umd.cs.findbugs.test.SpotBugsRule; +import edu.umd.cs.findbugs.test.SpotBugsExtension; +import edu.umd.cs.findbugs.test.SpotBugsRunner; -public class ResolveMethodReferencesTest { - @Rule - public SpotBugsRule spotbugs = new SpotBugsRule(); +@ExtendWith(SpotBugsExtension.class) +class ResolveMethodReferencesTest { /** * @see GitHub * issue */ @Test - public void testIssue338() { + void testIssue338(SpotBugsRunner spotbugs) { BugCollection bugCollection = spotbugs.performAnalysis(Paths.get("../spotbugsTestCases/build/classes/java/main/lambdas/Issue338.class")); assertThat(bugCollection, is(emptyIterable())); assertThat(bugCollection, instanceOf(SortedBugCollection.class)); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/SynchronizationOnSharedBuiltinConstantTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/SynchronizationOnSharedBuiltinConstantTest.java index 1a55710c688..fe3cba58b15 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/SynchronizationOnSharedBuiltinConstantTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/SynchronizationOnSharedBuiltinConstantTest.java @@ -3,16 +3,16 @@ import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; import static org.hamcrest.MatcherAssert.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; -public class SynchronizationOnSharedBuiltinConstantTest extends AbstractIntegrationTest { +class SynchronizationOnSharedBuiltinConstantTest extends AbstractIntegrationTest { @Test - public void lockOn_noncompliantBooleanLockObject() { + void lockOn_noncompliantBooleanLockObject() { performAnalysis("synchronizationOnSharedBuiltinConstant/SynchronizationOnSharedBuiltinConstantBad.class"); BugInstanceMatcher bugTypeMatcher = new BugInstanceMatcherBuilder() .bugType("DL_SYNCHRONIZATION_ON_BOOLEAN") @@ -22,7 +22,7 @@ public void lockOn_noncompliantBooleanLockObject() { } @Test - public void lockOn_noncompliantBoxedPrimitive() { + void lockOn_noncompliantBoxedPrimitive() { performAnalysis("synchronizationOnSharedBuiltinConstant/SynchronizationOnSharedBuiltinConstantBad.class"); BugInstanceMatcher bugTypeMatcher = new BugInstanceMatcherBuilder() .bugType("DL_SYNCHRONIZATION_ON_BOXED_PRIMITIVE") @@ -32,7 +32,7 @@ public void lockOn_noncompliantBoxedPrimitive() { } @Test - public void lockOn_compliantInteger() { + void lockOn_compliantInteger() { performAnalysis("synchronizationOnSharedBuiltinConstant/SynchronizationOnSharedBuiltinConstantGood.class"); BugInstanceMatcher bugTypeMatcher = new BugInstanceMatcherBuilder() .bugType("DL_SYNCHRONIZATION_ON_BOXED_PRIMITIVE") @@ -42,7 +42,7 @@ public void lockOn_compliantInteger() { } @Test - public void lockOn_noncompliantInternedStringObject() { + void lockOn_noncompliantInternedStringObject() { performAnalysis("synchronizationOnSharedBuiltinConstant/SynchronizationOnSharedBuiltinConstantBad.class"); BugInstanceMatcher bugTypeMatcher = new BugInstanceMatcherBuilder() .bugType("DL_SYNCHRONIZATION_ON_INTERNED_STRING") @@ -52,7 +52,7 @@ public void lockOn_noncompliantInternedStringObject() { } @Test - public void lockOn_noncompliantStringLiteral() { + void lockOn_noncompliantStringLiteral() { performAnalysis("synchronizationOnSharedBuiltinConstant/SynchronizationOnSharedBuiltinConstantBad.class"); BugInstanceMatcher bugTypeMatcher = new BugInstanceMatcherBuilder() .bugType("DL_SYNCHRONIZATION_ON_SHARED_CONSTANT") @@ -62,7 +62,7 @@ public void lockOn_noncompliantStringLiteral() { } @Test - public void lockOn_compliantStringInstance() { + void lockOn_compliantStringInstance() { performAnalysis("synchronizationOnSharedBuiltinConstant/SynchronizationOnSharedBuiltinConstantGood.class"); BugInstanceMatcher bugTypeMatcher = new BugInstanceMatcherBuilder() .bugType("DL_SYNCHRONIZATION_ON_SHARED_CONSTANT") @@ -72,7 +72,7 @@ public void lockOn_compliantStringInstance() { } @Test - public void lockOn_compliantPrivateFinalLockObject() { + void lockOn_compliantPrivateFinalLockObject() { performAnalysis("synchronizationOnSharedBuiltinConstant/SynchronizationOnSharedBuiltinConstantGood.class"); BugInstanceMatcher bugTypeMatcher = new BugInstanceMatcherBuilder() .bugType("DL_SYNCHRONIZATION_ON_BOXED_PRIMITIVE") diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/TestASMTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/TestASMTest.java index 0196d638f7e..b22545e94d4 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/TestASMTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/TestASMTest.java @@ -4,15 +4,16 @@ import edu.umd.cs.findbugs.BugCollection; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasItem; -public class TestASMTest extends AbstractIntegrationTest { +class TestASMTest extends AbstractIntegrationTest { + @Test - public void test() { + void testASM() { performAnalysis("TestASM.class"); assertNumOfBugs(1, "NM_METHOD_NAMING_CONVENTION"); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/ThrowingExceptionsTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/ThrowingExceptionsTest.java index fd4981a0b50..8fbb234c96a 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/ThrowingExceptionsTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/ThrowingExceptionsTest.java @@ -4,15 +4,16 @@ import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.MatcherAssert.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; -public class ThrowingExceptionsTest extends AbstractIntegrationTest { +class ThrowingExceptionsTest extends AbstractIntegrationTest { + @Test - public void throwingExceptionsTests() { + void throwingExceptionsTests() { performAnalysis("MethodsThrowingExceptions.class"); assertNumOfTHROWSBugs("THROWS_METHOD_THROWS_RUNTIMEEXCEPTION", 1); @@ -29,7 +30,7 @@ public void throwingExceptionsTests() { } @Test - public void testNestedInterface() { + void testNestedInterface() { performAnalysis("MethodsThrowingExceptions$ThrowThrowable.class"); assertNumOfTHROWSBugs("THROWS_METHOD_THROWS_CLAUSE_THROWABLE", 1); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/UnreadFieldsTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/UnreadFieldsTest.java index a2927c83fa8..87e84e162e9 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/UnreadFieldsTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/UnreadFieldsTest.java @@ -3,23 +3,23 @@ import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.nio.file.Paths; import java.util.Optional; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import edu.umd.cs.findbugs.BugCollection; import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.Priorities; -import edu.umd.cs.findbugs.test.SpotBugsRule; +import edu.umd.cs.findbugs.test.SpotBugsExtension; +import edu.umd.cs.findbugs.test.SpotBugsRunner; -public class UnreadFieldsTest { - @Rule - public SpotBugsRule spotbugs = new SpotBugsRule(); +@ExtendWith(SpotBugsExtension.class) +class UnreadFieldsTest { /** * {@code UWF_NULL_FIELD} should report the line number of the target field. @@ -27,7 +27,7 @@ public class UnreadFieldsTest { * @see GitHub Issue */ @Test - public void bugInstanceShouldContainLineNumber() { + void bugInstanceShouldContainLineNumber(SpotBugsRunner spotbugs) { BugCollection bugCollection = spotbugs.performAnalysis(Paths.get("../spotbugsTestCases/build/classes/java/main/ghIssues/Issue1368.class")); Optional reportedBug = bugCollection.getCollection().stream() .filter(bug -> "UWF_NULL_FIELD".equals(bug.getBugPattern().getType())) @@ -42,19 +42,19 @@ public void bugInstanceShouldContainLineNumber() { * @see GitHub Issue */ @Test - public void unreadFieldInReflectiveClass() { + void unreadFieldInReflectiveClass(SpotBugsRunner spotbugs) { BugCollection bugCollection = spotbugs.performAnalysis(Paths.get("../spotbugsTestCases/build/classes/java/main/ghIssues/Issue2325.class")); Optional reportedBug = bugCollection.getCollection().stream() .filter(bug -> "UUF_UNUSED_FIELD".equals(bug.getBugPattern().getType())).findAny(); - assertTrue("Expected unused field bug, but got: " + bugCollection.getCollection(), reportedBug.isPresent()); - assertEquals("Expected low priority unused field bug", Priorities.LOW_PRIORITY, - reportedBug.get().getPriority()); + assertTrue(reportedBug.isPresent(), "Expected unused field bug, but got: " + bugCollection.getCollection()); + assertEquals(Priorities.LOW_PRIORITY, reportedBug.get().getPriority(), + "Expected low priority unused field bug"); reportedBug = bugCollection.getCollection().stream() .filter(bug -> "URF_UNREAD_FIELD".equals(bug.getBugPattern().getType())).findAny(); - assertTrue("Expected unread field bug, but got: " + bugCollection.getCollection(), reportedBug.isPresent()); - assertEquals("Expected low priority unread field bug", Priorities.LOW_PRIORITY, - reportedBug.get().getPriority()); + assertTrue(reportedBug.isPresent(), "Expected unread field bug, but got: " + bugCollection.getCollection()); + assertEquals(Priorities.LOW_PRIORITY, reportedBug.get().getPriority(), + "Expected low priority unread field bug"); } } diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/filter/AnnotationMatcherTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/filter/AnnotationMatcherTest.java index 91926a3dfbf..4525ed398ac 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/filter/AnnotationMatcherTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/filter/AnnotationMatcherTest.java @@ -18,9 +18,9 @@ package edu.umd.cs.findbugs.filter; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -29,40 +29,39 @@ import java.util.Arrays; import org.apache.tools.ant.filters.StringInputStream; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import edu.umd.cs.findbugs.BugCollection; import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.ClassAnnotation; import edu.umd.cs.findbugs.ba.AnalysisContext; -import edu.umd.cs.findbugs.test.SpotBugsRule; +import edu.umd.cs.findbugs.test.SpotBugsExtension; +import edu.umd.cs.findbugs.test.SpotBugsRunner; import edu.umd.cs.findbugs.xml.OutputStreamXMLOutput; import edu.umd.cs.findbugs.xml.XMLOutput; -public class AnnotationMatcherTest { - - @Rule - public SpotBugsRule spotbugs = new SpotBugsRule(); +@ExtendWith(SpotBugsExtension.class) +class AnnotationMatcherTest { private String annotationName; - @Before - public void setUp() { + @BeforeEach + void setUp() { annotationName = "org.immutables.value.Generated"; } - @After - public void tearDown() { + @AfterEach + void tearDown() { // Some other test cases fail in case the context is not correctly // cleaned up here. AnalysisContext.removeCurrentAnalysisContext(); } @Test - public void writeXML() throws Exception { + void writeXML() throws Exception { AnnotationMatcher sm = new AnnotationMatcher(annotationName); String xmlOutput = writeXMLAndGetStringOutput(sm, false); @@ -74,7 +73,7 @@ public void writeXML() throws Exception { } @Test - public void testMatchMissingPrimaryAnnotationIsFalse() throws Exception { + void testMatchMissingPrimaryAnnotationIsFalse() throws Exception { Filter filter = readFilterFromXML(); // no primary annotation; should not match BugInstance bug = new BugInstance("UUF_UNUSED_FIELD", 0); @@ -82,7 +81,7 @@ public void testMatchMissingPrimaryAnnotationIsFalse() throws Exception { } @Test - public void testMatchMissingJavaAnnotationIsFalse() throws Exception { + void testMatchMissingJavaAnnotationIsFalse() throws Exception { Filter filter = readFilterFromXML(); // added primary class annotation; should not match b.c. missing java annotation BugInstance bug = new BugInstance("UUF_UNUSED_FIELD", 0); @@ -92,7 +91,7 @@ public void testMatchMissingJavaAnnotationIsFalse() throws Exception { } @Test - public void testMatchOtherJavaAnnotationIsFalse() throws Exception { + void testMatchOtherJavaAnnotationIsFalse() throws Exception { Filter filter = readFilterFromXML(); // added primary class annotation; should not match b.c. other java annotation BugInstance bug = new BugInstance("UUF_UNUSED_FIELD", 0); @@ -103,7 +102,7 @@ public void testMatchOtherJavaAnnotationIsFalse() throws Exception { } @Test - public void testMatchJavaAnnotationIsTrue() throws Exception { + void testMatchJavaAnnotationIsTrue() throws Exception { Filter filter = readFilterFromXML(); // added primary class annotation; should match b.c. has java annotation BugInstance bug = new BugInstance("UUF_UNUSED_FIELD", 0); @@ -130,7 +129,7 @@ private Filter readFilterFromXML() throws IOException { } @Test - public void testPerformAnalysis() throws Exception { + void testPerformAnalysis(SpotBugsRunner spotbugs) throws Exception { BugCollection bugCollection = spotbugs.performAnalysis( Paths.get("../spotbugsTestCases/build/classes/java/main/org/immutables/value/Generated.class"), Paths.get("../spotbugsTestCases/build/classes/java/main/org/immutables/value/Value.class"), diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/filter/NameMatchTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/filter/NameMatchTest.java index 8b887c1778b..fdeea93cdbf 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/filter/NameMatchTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/filter/NameMatchTest.java @@ -18,17 +18,18 @@ */ package edu.umd.cs.findbugs.filter; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @since 3.1 */ -public class NameMatchTest { +class NameMatchTest { + @Test - public void testExactMatch() { + void testExactMatch() { NameMatch match = new NameMatch(SignatureUtil.createMethodSignature("", "void")); assertTrue(match.match("()V")); assertFalse(match.match("(I)V")); @@ -36,7 +37,7 @@ public void testExactMatch() { } @Test - public void testParameterPatternMatch() { + void testParameterPatternMatch() { NameMatch anyParamReturnVoid = new NameMatch(SignatureUtil.createMethodSignature(null, "void")); assertTrue(anyParamReturnVoid.match("()V")); assertTrue(anyParamReturnVoid.match("(I)V")); @@ -45,7 +46,7 @@ public void testParameterPatternMatch() { } @Test - public void testReturnValuePatternMatch() { + void testReturnValuePatternMatch() { NameMatch anyParamReturnVoid = new NameMatch(SignatureUtil.createMethodSignature("", null)); assertTrue(anyParamReturnVoid.match("()V")); assertTrue(anyParamReturnVoid.match("()I")); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/filter/NotMatcherTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/filter/NotMatcherTest.java index 23c5ced7d56..372e6e75fa4 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/filter/NotMatcherTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/filter/NotMatcherTest.java @@ -21,27 +21,28 @@ package edu.umd.cs.findbugs.filter; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.hamcrest.Matchers.containsString; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.nio.charset.StandardCharsets; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.xml.OutputStreamXMLOutput; import edu.umd.cs.findbugs.xml.XMLOutput; -public class NotMatcherTest { +class NotMatcherTest { private final BugInstance bug = new BugInstance("UUF_UNUSED_FIELD", 0); @Test - public void invertsResultsFromWrappedMatcher_doesntMatchWhenWrappedDoesMatch() throws Exception { + void invertsResultsFromWrappedMatcher_doesntMatchWhenWrappedDoesMatch() throws Exception { Matcher wrappedMatcher = new TestMatcher(true); NotMatcher notMatcher = new NotMatcher(); notMatcher.addChild(wrappedMatcher); @@ -50,7 +51,7 @@ public void invertsResultsFromWrappedMatcher_doesntMatchWhenWrappedDoesMatch() t } @Test - public void invertsResultsFromWrappedMatcher_doesMatchWhenWrappedDoesnt() throws Exception { + void invertsResultsFromWrappedMatcher_doesMatchWhenWrappedDoesnt() throws Exception { Matcher wrappedMatcher = new TestMatcher(false); NotMatcher notMatcher = new NotMatcher(); notMatcher.addChild(wrappedMatcher); @@ -59,7 +60,7 @@ public void invertsResultsFromWrappedMatcher_doesMatchWhenWrappedDoesnt() throws } @Test - public void writeXMLOutputAddsNotTagsAroundWrappedMatchersOutput() throws Exception { + void writeXMLOutputAddsNotTagsAroundWrappedMatchersOutput() throws Exception { Matcher wrappedMatcher = new TestMatcher(true); NotMatcher notMatcher = new NotMatcher(); notMatcher.addChild(wrappedMatcher); @@ -73,17 +74,19 @@ public void writeXMLOutputAddsNotTagsAroundWrappedMatchersOutput() throws Except } @Test - public void canReturnChildMatcher() { + void canReturnChildMatcher() { Matcher wrappedMatcher = new TestMatcher(true); NotMatcher notMatcher = new NotMatcher(); notMatcher.addChild(wrappedMatcher); - assertSame("Should return child matcher.", wrappedMatcher, notMatcher.originalMatcher()); + assertSame(wrappedMatcher, notMatcher.originalMatcher(), "Should return child matcher."); } - @Test(expected = IllegalStateException.class) - public void throwsExceptionWhenTryingToGetNonExistentChildMatcher() { - new NotMatcher().originalMatcher(); + @Test + void throwsExceptionWhenTryingToGetNonExistentChildMatcher() { + Assertions.assertThrows(IllegalStateException.class, () -> { + new NotMatcher().originalMatcher(); + }); } private String writeXMLAndGetStringOutput(NotMatcher notMatcher) throws IOException { diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/filter/RelationalOpTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/filter/RelationalOpTest.java index d92c8c3cb8a..24ed90a2b37 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/filter/RelationalOpTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/filter/RelationalOpTest.java @@ -19,19 +19,20 @@ package edu.umd.cs.findbugs.filter; import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * @since 3.1 */ -public class RelationalOpTest { +class RelationalOpTest { @Test - public void test() { + void testRelationalObject() { assertTrue(RelationalOp.byName("EQ").check("A", "A")); assertFalse(RelationalOp.byName("EQ").check("B", "C")); @@ -51,12 +52,15 @@ public void test() { assertFalse(RelationalOp.byName("LEQ").check("E", "D")); } + @Test public void testToString() { assertThat(RelationalOp.EQ.toString(), is("==")); } - @Test(expected = IllegalArgumentException.class) - public void testByName() { - RelationalOp.byName("Unknown"); + @Test + void testByName() { + Assertions.assertThrows(IllegalArgumentException.class, () -> { + RelationalOp.byName("Unknown"); + }); } } diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/filter/SignatureUtilTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/filter/SignatureUtilTest.java index 938ebc442b3..8bb7f7b9bbf 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/filter/SignatureUtilTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/filter/SignatureUtilTest.java @@ -22,17 +22,18 @@ import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.MatcherAssert.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @since 3.1 */ -public class SignatureUtilTest { +class SignatureUtilTest { + /** * Return {@code null} if given parameter is null, otherwise signature of given type. */ @Test - public void testCreateFieldSignature() { + void testCreateFieldSignature() { assertThat(SignatureUtil.createFieldSignature(null), is(nullValue())); assertThat(SignatureUtil.createFieldSignature("int"), is("I")); assertThat(SignatureUtil.createFieldSignature("double[]"), is("[D")); @@ -44,7 +45,7 @@ public void testCreateFieldSignature() { * comma. Even though first parameter contains multiple values, generated signature does not separate them by comma. */ @Test - public void testCreateMethodSignature() { + void testCreateMethodSignature() { assertThat(SignatureUtil.createMethodSignature("", "void"), is("()V")); assertThat(SignatureUtil.createMethodSignature("byte,\r\nchar, \tboolean", "void"), is("(BCZ)V")); assertThat(SignatureUtil.createMethodSignature("float", "java.lang.String[]"), is("(F)[Ljava/lang/String;")); @@ -57,7 +58,7 @@ public void testCreateMethodSignature() { * @see NameMatch This class uses {@code ~} to judge signature is regexp or not. */ @Test - public void testCreateMethodSignatureWithNull() { + void testCreateMethodSignatureWithNull() { assertThat(SignatureUtil.createMethodSignature(null, null), is(nullValue())); assertThat(SignatureUtil.createMethodSignature(null, "long"), is("~\\(.*\\)J")); assertThat(SignatureUtil.createMethodSignature("", null), is("~\\(\\).*")); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/filter/SourceMatcherTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/filter/SourceMatcherTest.java index fc924d84154..0d81678c376 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/filter/SourceMatcherTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/filter/SourceMatcherTest.java @@ -21,9 +21,9 @@ package edu.umd.cs.findbugs.filter; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.ByteArrayOutputStream; import java.util.Collections; @@ -32,9 +32,9 @@ import java.nio.charset.StandardCharsets; import org.apache.tools.ant.filters.StringInputStream; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.ClassAnnotation; @@ -44,26 +44,26 @@ import edu.umd.cs.findbugs.xml.OutputStreamXMLOutput; import edu.umd.cs.findbugs.xml.XMLOutput; -public class SourceMatcherTest { +class SourceMatcherTest { private BugInstance bug; private String fileName; - @Before - public void setUp() { + @BeforeEach + void setUp() { bug = new BugInstance("UUF_UNUSED_FIELD", 0); fileName = "bla.groovy"; } - @After - public void tearDown() { + @AfterEach + void tearDown() { // Some other test cases fail in case the context is not correctly // cleaned up here. AnalysisContext.removeCurrentAnalysisContext(); } @Test - public void writeXML() throws Exception { + void writeXML() throws Exception { SourceMatcher sm = new SourceMatcher(fileName); String xmlOutput = writeXMLAndGetStringOutput(sm, false); @@ -75,7 +75,7 @@ public void writeXML() throws Exception { } @Test - public void readXML() throws Exception { + void readXML() throws Exception { SourceMatcher sm = new SourceMatcher(fileName); String xml = writeXMLAndGetStringOutput(sm, false); @@ -96,7 +96,7 @@ public void readXML() throws Exception { @Test - public void match() throws Exception { + void match() throws Exception { SourceMatcher sm = new SourceMatcher(fileName); // no source set: test incomplete data @@ -131,7 +131,7 @@ public void match() throws Exception { } @Test - public void testRealPathMatchWithRegexpAndProject() throws Exception { + void testRealPathMatchWithRegexpAndProject() throws Exception { // add this test class as the bug target bug.addClass("SourceMatcherTest", null); ClassAnnotation primaryClass = bug.getPrimaryClass(); @@ -149,13 +149,13 @@ public void testRealPathMatchWithRegexpAndProject() throws Exception { // regexp match source folder with project SourceMatcher sm = new SourceMatcher("~.*findbugs.*.java"); - assertTrue("The regex matches the source directory of the given java file", sm.match(bug)); + assertTrue(sm.match(bug), "The regex matches the source directory of the given java file"); sm = new SourceMatcher("~.*notfound.*.java"); - assertFalse("The regex does not match the source directory of the given java file", sm.match(bug)); + assertFalse(sm.match(bug), "The regex does not match the source directory of the given java file"); } @Test - public void testRealPathMatchWithRegexpAndAnalysisContext() throws Exception { + void testRealPathMatchWithRegexpAndAnalysisContext() throws Exception { // add this test class as the bug target bug.addClass("SourceMatcherTest", null); ClassAnnotation primaryClass = bug.getPrimaryClass(); @@ -173,9 +173,9 @@ public void testRealPathMatchWithRegexpAndAnalysisContext() throws Exception { // regexp match source folder with analysis context SourceMatcher sm = new SourceMatcher("~.*findbugs.*.java"); - assertTrue("The regex matches the source directory of the given java file", sm.match(bug)); + assertTrue(sm.match(bug), "The regex matches the source directory of the given java file"); sm = new SourceMatcher("~.*notfound.*.java"); - assertFalse("The regex does not match the source directory of the given java file", sm.match(bug)); + assertFalse(sm.match(bug), "The regex does not match the source directory of the given java file"); } private String writeXMLAndGetStringOutput(SourceMatcher matcher, boolean disabled) throws IOException { diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/gui2/FilterFactoryTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/gui2/FilterFactoryTest.java index a9fb0288017..093a1dbd5b9 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/gui2/FilterFactoryTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/gui2/FilterFactoryTest.java @@ -20,11 +20,11 @@ package edu.umd.cs.findbugs.gui2; import static java.util.Arrays.asList; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; -import org.junit.Test; +import org.junit.jupiter.api.Test; import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.filter.Matcher; @@ -33,28 +33,28 @@ /** * @author Graham Allan (grundlefleck@gmail.com) */ -public class FilterFactoryTest { +class FilterFactoryTest { @Test - public void invertMatcherShouldNegateTheOriginalMatchingResult() { + void invertMatcherShouldNegateTheOriginalMatchingResult() { BugInstance bug = new BugInstance("UUF_UNUSED_FIELD", 0); Matcher originalMatcher = FilterFactory.makeMatcher(asList(Sortables.BUGCODE), bug); - assertTrue("Original matcher should match bug.", originalMatcher.match(bug)); + assertTrue(originalMatcher.match(bug), "Original matcher should match bug."); Matcher notMatcher = FilterFactory.invertMatcher(originalMatcher); - assertTrue("Should return an instance of NotMatcher.", notMatcher instanceof NotMatcher); - assertFalse("Inverted matcher should now not match.", notMatcher.match(bug)); + assertTrue(notMatcher instanceof NotMatcher, "Should return an instance of NotMatcher."); + assertFalse(notMatcher.match(bug), "Inverted matcher should now not match."); } @Test - public void shouldReturnTheOriginalMatcherWhenAskedToInvertANotMatcher() { + void shouldReturnTheOriginalMatcherWhenAskedToInvertANotMatcher() { BugInstance bug = new BugInstance("UUF_UNUSED_FIELD", 0); Matcher originalMatcher = FilterFactory.makeMatcher(asList(Sortables.BUGCODE), bug); Matcher notMatcher = FilterFactory.invertMatcher(originalMatcher); Matcher notNotMatcher = FilterFactory.invertMatcher(notMatcher); - assertSame("Should return the originally wrapped matcher.", originalMatcher, notNotMatcher); - assertTrue("Original matcher should now not match.", notNotMatcher.match(bug)); + assertSame(originalMatcher, notNotMatcher, "Should return the originally wrapped matcher."); + assertTrue(notNotMatcher.match(bug), "Original matcher should now not match."); } } diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/gui2/SaveTypeTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/gui2/SaveTypeTest.java index f5c9a41724c..afb5279a502 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/gui2/SaveTypeTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/gui2/SaveTypeTest.java @@ -19,16 +19,16 @@ package edu.umd.cs.findbugs.gui2; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.File; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Bill Pugh */ -public class SaveTypeTest { +class SaveTypeTest { private void check(SaveType type, String file) { assertEquals(type, SaveType.forFile(new File(file))); @@ -37,7 +37,7 @@ private void check(SaveType type, String file) { @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value = "DMI_HARDCODED_ABSOLUTE_FILENAME", justification = "No actual disk access, just fake paths for testing") @Test - public void testSaveTypes() { + void testSaveTypes() { check(SaveType.HTML_OUTPUT, "/home/pugh/bugs.html"); check(SaveType.HTML_OUTPUT, "/home/pugh/bugs.htm"); check(SaveType.HTML_OUTPUT, "/home/pugh/bugs.HTML"); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/integration/FindNullDerefIntegrationTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/integration/FindNullDerefIntegrationTest.java index d6be38c292a..df75e6ab81a 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/integration/FindNullDerefIntegrationTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/integration/FindNullDerefIntegrationTest.java @@ -25,16 +25,16 @@ import java.io.IOException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; -public class FindNullDerefIntegrationTest extends AbstractIntegrationTest { +class FindNullDerefIntegrationTest extends AbstractIntegrationTest { @Test - public void testNullFromReturnOnLambda() { + void testNullFromReturnOnLambda() { performAnalysis("Elvis.class"); // There should only be 1 issue of this type @@ -52,7 +52,7 @@ public void testNullFromReturnOnLambda() { } @Test - public void testLambdaIssue20() throws IOException, InterruptedException { + void testLambdaIssue20() throws IOException, InterruptedException { performAnalysis("lambdas/Issue20.class"); // There should only be 1 issue of this type diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/internalAnnotations/SlashedClassNameTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/internalAnnotations/SlashedClassNameTest.java index 799fdb77773..97bf29e7faa 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/internalAnnotations/SlashedClassNameTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/internalAnnotations/SlashedClassNameTest.java @@ -19,26 +19,26 @@ package edu.umd.cs.findbugs.internalAnnotations; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.regex.Matcher; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author pugh */ -public class SlashedClassNameTest { +class SlashedClassNameTest { @Test - public void testFoo() { + void testFoo() { Matcher m = SlashedClassName.Checker.simplePattern.matcher("Foo"); assertTrue(m.matches()); } @Test - public void testFooBar() { + void testFooBar() { Matcher m = SlashedClassName.Checker.simplePattern.matcher("foo.Bar"); assertFalse(m.matches()); m = SlashedClassName.Checker.pattern.matcher("foo.Bar"); @@ -46,7 +46,7 @@ public void testFooBar() { } @Test - public void testFoo1Bar2() { + void testFoo1Bar2() { Matcher m = SlashedClassName.Checker.simplePattern.matcher("foo1.Bar2"); assertFalse(m.matches()); m = SlashedClassName.Checker.pattern.matcher("foo1.Bar2"); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/io/IOTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/io/IOTest.java index 1f8f4f05fd3..677a8c34de0 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/io/IOTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/io/IOTest.java @@ -23,13 +23,13 @@ import java.io.IOException; import java.util.Random; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * @author pugh */ -public class IOTest { +class IOTest { Random r = new Random(); @@ -40,42 +40,42 @@ private byte[] randomBytes(int size) { } @Test - public void testReadAllWithCorrectSize() throws IOException { + void testReadAllWithCorrectSize() throws IOException { for (int i = 10; i <= 10000; i *= 10) { byte[] input = randomBytes(i); byte[] output = IO.readAll(new ByteArrayInputStream(input), i); - Assert.assertArrayEquals(input, output); + Assertions.assertArrayEquals(input, output); } } @Test - public void testReadAllWithSmallSize() throws IOException { + void testReadAllWithSmallSize() throws IOException { for (int i = 10; i <= 10000; i *= 10) { byte[] input = randomBytes(i); byte[] output = IO.readAll(new ByteArrayInputStream(input), i - 9); - Assert.assertArrayEquals(input, output); + Assertions.assertArrayEquals(input, output); } } @Test - public void testReadAllWithLargeSize() throws IOException { + void testReadAllWithLargeSize() throws IOException { for (int i = 10; i <= 10000; i *= 10) { byte[] input = randomBytes(i); byte[] output = IO.readAll(new ByteArrayInputStream(input), i + 29); - Assert.assertArrayEquals(input, output); + Assertions.assertArrayEquals(input, output); } } @Test - public void testReadAllWithoutSize() throws IOException { + void testReadAllWithoutSize() throws IOException { for (int i = 10; i <= 10000; i *= 10) { byte[] input = randomBytes(i); byte[] output = IO.readAll(new ByteArrayInputStream(input)); - Assert.assertArrayEquals(input, output); + Assertions.assertArrayEquals(input, output); } } } diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/jaif/JAIFScannerTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/jaif/JAIFScannerTest.java index 8832a3d2bd0..849df2390f6 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/jaif/JAIFScannerTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/jaif/JAIFScannerTest.java @@ -19,13 +19,13 @@ package edu.umd.cs.findbugs.jaif; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.StringReader; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class JAIFScannerTest { +class JAIFScannerTest { private JAIFScanner getScanner(String text) { return new JAIFScanner(new StringReader(text)); @@ -39,14 +39,14 @@ private void checkToken(JAIFScanner scanner, String lexeme, JAIFTokenKind kind) } @Test - public void testScanColon() throws Exception { + void testScanColon() throws Exception { JAIFScanner scanner = getScanner(":"); checkToken(scanner, ":", JAIFTokenKind.COLON); checkToken(scanner, "\n", JAIFTokenKind.NEWLINE); } @Test - public void testScanParens() throws Exception { + void testScanParens() throws Exception { JAIFScanner scanner = getScanner("()"); checkToken(scanner, "(", JAIFTokenKind.LPAREN); @@ -55,7 +55,7 @@ public void testScanParens() throws Exception { } @Test - public void testScanComma() throws Exception { + void testScanComma() throws Exception { JAIFScanner scanner = getScanner(","); checkToken(scanner, ",", JAIFTokenKind.COMMA); @@ -63,7 +63,7 @@ public void testScanComma() throws Exception { } @Test - public void testScanEquals() throws Exception { + void testScanEquals() throws Exception { JAIFScanner scanner = getScanner("="); checkToken(scanner, "=", JAIFTokenKind.EQUALS); @@ -71,7 +71,7 @@ public void testScanEquals() throws Exception { } @Test - public void testScanIdentifier() throws Exception { + void testScanIdentifier() throws Exception { JAIFScanner scanner = getScanner(" \t \t\t@foobar Baz123 ( Boing Boing) @Yum@Yum __123 $plotz"); checkToken(scanner, "@foobar", JAIFTokenKind.IDENTIFIER_OR_KEYWORD); @@ -88,7 +88,7 @@ public void testScanIdentifier() throws Exception { } @Test - public void testScanFloatingPointLiteral() throws Exception { + void testScanFloatingPointLiteral() throws Exception { JAIFScanner scanner = getScanner("1e1f 2.f .3f 0f 3.14f 6.022137e+23f"); checkToken(scanner, "1e1f", JAIFTokenKind.FLOATING_POINT_LITERAL); @@ -101,7 +101,7 @@ public void testScanFloatingPointLiteral() throws Exception { } @Test - public void testScanFloatingPointLiteral2() throws Exception { + void testScanFloatingPointLiteral2() throws Exception { JAIFScanner scanner = getScanner("1e1 2. .3 0.0 3.14 1e-9d 1e137"); checkToken(scanner, "1e1", JAIFTokenKind.FLOATING_POINT_LITERAL); @@ -115,7 +115,7 @@ public void testScanFloatingPointLiteral2() throws Exception { } @Test - public void testScanOctalLiteral() throws Exception { + void testScanOctalLiteral() throws Exception { JAIFScanner scanner = getScanner("0237 01575L 027365l"); checkToken(scanner, "0237", JAIFTokenKind.OCTAL_LITERAL); @@ -125,7 +125,7 @@ public void testScanOctalLiteral() throws Exception { } @Test - public void testScanHexLiteral() throws Exception { + void testScanHexLiteral() throws Exception { JAIFScanner scanner = getScanner("0xDEADbeef 0xcafeBabeL 0X123EEfl"); checkToken(scanner, "0xDEADbeef", JAIFTokenKind.HEX_LITERAL); @@ -135,7 +135,7 @@ public void testScanHexLiteral() throws Exception { } @Test - public void testScanDecimalLiteral() throws Exception { + void testScanDecimalLiteral() throws Exception { JAIFScanner scanner = getScanner("1234 5678L 91919191l"); checkToken(scanner, "1234", JAIFTokenKind.DECIMAL_LITERAL); @@ -145,7 +145,7 @@ public void testScanDecimalLiteral() throws Exception { } @Test - public void testScanStringLiteral() throws Exception { + void testScanStringLiteral() throws Exception { JAIFScanner scanner = getScanner("\"hello\" \"foobie bletch\" \"\\\"\" \"\\\\\\6\\45\\037\" \"\\b\\t\\f\\n\" "); checkToken(scanner, "\"hello\"", JAIFTokenKind.STRING_LITERAL); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/log/ProfileSummaryTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/log/ProfileSummaryTest.java index 4e2b32abf3c..1ea5c88b2d6 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/log/ProfileSummaryTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/log/ProfileSummaryTest.java @@ -28,7 +28,7 @@ import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets; -import org.junit.Test; +import org.junit.jupiter.api.Test; import edu.umd.cs.findbugs.xml.OutputStreamXMLOutput; import edu.umd.cs.findbugs.xml.XMLOutput; @@ -36,10 +36,10 @@ /** * @since 4.0 */ -public class ProfileSummaryTest { +class ProfileSummaryTest { @Test - public void testGetProfile() { + void testGetProfile() { Profiler profiler = new Profiler(); profiler.start(String.class); profiler.end(String.class); @@ -53,7 +53,7 @@ public void testGetProfile() { } @Test - public void testReport() throws UnsupportedEncodingException { + void testReport() throws UnsupportedEncodingException { Profiler profiler = new Profiler(); profiler.start(String.class); profiler.end(String.class); @@ -71,7 +71,7 @@ public void testReport() throws UnsupportedEncodingException { } @Test - public void testWriteXML() throws IOException { + void testWriteXML() throws IOException { Profiler profiler = new Profiler(); Profiler another = new Profiler(); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ml/SplitCamelCaseIdentifierTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ml/SplitCamelCaseIdentifierTest.java index 11dbc8a29b7..fc04a27a34e 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ml/SplitCamelCaseIdentifierTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ml/SplitCamelCaseIdentifierTest.java @@ -2,59 +2,59 @@ import java.util.Collection; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import edu.umd.cs.findbugs.util.SplitCamelCaseIdentifier; -public class SplitCamelCaseIdentifierTest { +class SplitCamelCaseIdentifierTest { @Test - public void testSplitLowerCamelCase() { + void testSplitLowerCamelCase() { SplitCamelCaseIdentifier sut = new SplitCamelCaseIdentifier("displayGUIWindow"); Collection words = sut.split(); checkContents(words, "display", "gui", "window"); } @Test - public void testSplit2() { + void testSplit2() { SplitCamelCaseIdentifier sut = new SplitCamelCaseIdentifier("DisplayGUIWindow"); Collection words = sut.split(); checkContents(words, "display", "gui", "window"); } @Test - public void testSplitLong() { + void testSplitLong() { SplitCamelCaseIdentifier sut = new SplitCamelCaseIdentifier("nowIsTheWINTEROfOURDiscontent"); Collection words = sut.split(); checkContents(words, "now", "is", "the", "winter", "of", "our", "discontent"); } @Test - public void testAllLower() { + void testAllLower() { SplitCamelCaseIdentifier sut = new SplitCamelCaseIdentifier("foobar"); Collection words = sut.split(); checkContents(words, "foobar"); } @Test - public void testAllUpper() { + void testAllUpper() { SplitCamelCaseIdentifier sut = new SplitCamelCaseIdentifier("NSA"); Collection words = sut.split(); checkContents(words, "nsa"); } @Test - public void testCapitalized() { + void testCapitalized() { SplitCamelCaseIdentifier sut = new SplitCamelCaseIdentifier("Maryland"); Collection words = sut.split(); checkContents(words, "maryland"); } private void checkContents(Collection words, String... expected) { - Assert.assertEquals(expected.length, words.size()); + Assertions.assertEquals(expected.length, words.size()); for (String anExpected : expected) { - Assert.assertTrue(words.contains(anExpected)); + Assertions.assertTrue(words.contains(anExpected)); } } } diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/nullness/AndroidNullabilityTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/nullness/AndroidNullabilityTest.java index 2e44e469ce5..f0884719221 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/nullness/AndroidNullabilityTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/nullness/AndroidNullabilityTest.java @@ -6,11 +6,12 @@ import java.nio.file.Paths; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import edu.umd.cs.findbugs.BugCollection; -import edu.umd.cs.findbugs.test.SpotBugsRule; +import edu.umd.cs.findbugs.test.SpotBugsExtension; +import edu.umd.cs.findbugs.test.SpotBugsRunner; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; @@ -19,26 +20,25 @@ * * @author kzaikin */ -public class AndroidNullabilityTest { - @Rule - public SpotBugsRule spotbugs = new SpotBugsRule(); +@ExtendWith(SpotBugsExtension.class) +class AndroidNullabilityTest { @Test - public void objectForNonNullParam_isOk() { + void objectForNonNullParam_isOk(SpotBugsRunner spotbugs) { BugCollection bugCollection = spotbugs.performAnalysis( Paths.get("../spotbugsTestCases/build/classes/java/main/androidAnnotations/ObjectForNonNullParam.class")); assertThat(bugCollection, emptyIterable()); } @Test - public void objectForNonNullParam2_isOk() { + void objectForNonNullParam2_isOk(SpotBugsRunner spotbugs) { BugCollection bugCollection = spotbugs.performAnalysis( Paths.get("../spotbugsTestCases/build/classes/java/main/androidAnnotations/ObjectForNonNullParam2.class")); assertThat(bugCollection, emptyIterable()); } @Test - public void nullForNonNullParam_isDetected() { + void nullForNonNullParam_isDetected(SpotBugsRunner spotbugs) { BugCollection bugCollection = spotbugs.performAnalysis( Paths.get("../spotbugsTestCases/build/classes/java/main/androidAnnotations/NullForNonNullParam.class")); @@ -46,7 +46,7 @@ public void nullForNonNullParam_isDetected() { } @Test - public void nullForNonNullParam2_isDetected() { + void nullForNonNullParam2_isDetected(SpotBugsRunner spotbugs) { BugCollection bugCollection = spotbugs.performAnalysis( Paths.get("../spotbugsTestCases/build/classes/java/main/androidAnnotations/NullForNonNullParam2.class")); @@ -54,21 +54,21 @@ public void nullForNonNullParam2_isDetected() { } @Test - public void checkedNullableReturn_isOk() { + void checkedNullableReturn_isOk(SpotBugsRunner spotbugs) { BugCollection bugCollection = spotbugs.performAnalysis( Paths.get("../spotbugsTestCases/build/classes/java/main/androidAnnotations/CheckedNullableReturn.class")); assertThat(bugCollection, emptyIterable()); } @Test - public void checkedNullableReturn2_isOk() { + void checkedNullableReturn2_isOk(SpotBugsRunner spotbugs) { BugCollection bugCollection = spotbugs.performAnalysis( Paths.get("../spotbugsTestCases/build/classes/java/main/androidAnnotations/CheckedNullableReturn2.class")); assertThat(bugCollection, emptyIterable()); } @Test - public void uncheckedNullableReturn_isDetected() { + void uncheckedNullableReturn_isDetected(SpotBugsRunner spotbugs) { BugCollection bugCollection = spotbugs.performAnalysis( Paths.get("../spotbugsTestCases/build/classes/java/main/androidAnnotations/UncheckedNullableReturn.class")); @@ -76,7 +76,7 @@ public void uncheckedNullableReturn_isDetected() { } @Test - public void uncheckedNullableReturn2_isDetected() { + void uncheckedNullableReturn2_isDetected(SpotBugsRunner spotbugs) { BugCollection bugCollection = spotbugs.performAnalysis( Paths.get("../spotbugsTestCases/build/classes/java/main/androidAnnotations/UncheckedNullableReturn2.class")); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/nullness/AvroNullabilityTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/nullness/AvroNullabilityTest.java index 0896068e9a7..a2a4e2016cd 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/nullness/AvroNullabilityTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/nullness/AvroNullabilityTest.java @@ -1,11 +1,12 @@ package edu.umd.cs.findbugs.nullness; import edu.umd.cs.findbugs.BugCollection; -import edu.umd.cs.findbugs.test.SpotBugsRule; +import edu.umd.cs.findbugs.test.SpotBugsExtension; +import edu.umd.cs.findbugs.test.SpotBugsRunner; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import java.nio.file.Paths; @@ -18,19 +19,18 @@ * * @author HoelzelJon */ -public class AvroNullabilityTest { - @Rule - public SpotBugsRule spotbugs = new SpotBugsRule(); +@ExtendWith(SpotBugsExtension.class) +class AvroNullabilityTest { @Test - public void checkedAvroNullableReturn_isOk() { + void checkedAvroNullableReturn_isOk(SpotBugsRunner spotbugs) { BugCollection bugCollection = spotbugs.performAnalysis( Paths.get("../spotbugsTestCases/build/classes/java/main/CheckedAvroNullableReturn.class")); assertThat(bugCollection, emptyIterable()); } @Test - public void uncheckedAvroNullableReturn_isDetected() { + void uncheckedAvroNullableReturn_isDetected(SpotBugsRunner spotbugs) { BugCollection bugCollection = spotbugs.performAnalysis( Paths.get("../spotbugsTestCases/build/classes/java/main/UncheckedAvroNullableReturn.class")); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/nullness/Issue1338Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/nullness/Issue1338Test.java index 9b244bfd3e6..7a933986146 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/nullness/Issue1338Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/nullness/Issue1338Test.java @@ -1,9 +1,10 @@ package edu.umd.cs.findbugs.nullness; import edu.umd.cs.findbugs.BugCollection; -import edu.umd.cs.findbugs.test.SpotBugsRule; -import org.junit.Rule; -import org.junit.Test; +import edu.umd.cs.findbugs.test.SpotBugsExtension; +import edu.umd.cs.findbugs.test.SpotBugsRunner; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import java.nio.file.Paths; @@ -13,12 +14,11 @@ /** * Unit test to reproduce #1338. */ -public class Issue1338Test { - @Rule - public SpotBugsRule spotbugs = new SpotBugsRule(); +@ExtendWith(SpotBugsExtension.class) +class Issue1338Test { @Test - public void test() { + void testIssue(SpotBugsRunner spotbugs) { BugCollection bugCollection = spotbugs.performAnalysis( Paths.get("../spotbugsTestCases/build/classes/java/main/ghIssues/Issue1338.class")); assertThat(bugCollection, emptyIterable()); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/nullness/Issue259Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/nullness/Issue259Test.java index 67de0b386e9..994f90538f5 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/nullness/Issue259Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/nullness/Issue259Test.java @@ -5,21 +5,21 @@ import java.nio.file.Paths; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import edu.umd.cs.findbugs.BugCollection; -import edu.umd.cs.findbugs.test.SpotBugsRule; +import edu.umd.cs.findbugs.test.SpotBugsExtension; +import edu.umd.cs.findbugs.test.SpotBugsRunner; /** * Unit test to reproduce #259. */ -public class Issue259Test { - @Rule - public SpotBugsRule spotbugs = new SpotBugsRule(); +@ExtendWith(SpotBugsExtension.class) +class Issue259Test { @Test - public void test() { + void testIssue(SpotBugsRunner spotbugs) { BugCollection bugCollection = spotbugs.performAnalysis( Paths.get("../spotbugsTestCases/build/classes/java/main/ghIssues/Issue259.class"), Paths.get("../spotbugsTestCases/build/classes/java/main/ghIssues/Issue259$1.class"), diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/nullness/Issue600Test.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/nullness/Issue600Test.java index d112ac4f8d0..be842c3dce6 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/nullness/Issue600Test.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/nullness/Issue600Test.java @@ -1,11 +1,12 @@ package edu.umd.cs.findbugs.nullness; import edu.umd.cs.findbugs.BugCollection; -import edu.umd.cs.findbugs.test.SpotBugsRule; +import edu.umd.cs.findbugs.test.SpotBugsExtension; +import edu.umd.cs.findbugs.test.SpotBugsRunner; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import java.nio.file.Paths; @@ -15,28 +16,27 @@ /** * Unit tests to reproduce #600. */ -public class Issue600Test { - @Rule - public SpotBugsRule spotbugs = new SpotBugsRule(); +@ExtendWith(SpotBugsExtension.class) +class Issue600Test { @Test - public void testTryWithResourcesSimple() { - assertBugCount("TryWithResourcesSimple", 0); - assertBugCount("TryWithResourcesMultiple", 0); - assertBugCount("TryWithResourcesNested", 0); + void testTryWithResourcesSimple(SpotBugsRunner spotbugs) { + assertBugCount("TryWithResourcesSimple", 0, spotbugs); + assertBugCount("TryWithResourcesMultiple", 0, spotbugs); + assertBugCount("TryWithResourcesNested", 0, spotbugs); } @Test - public void testExplicitNulls() { - assertBugCount("ExplicitNullCheckSimple", 1); - assertBugCount("ExplicitNullCheckNested", 2); - assertBugCount("ExplicitNullCheckMultiple", 2); - assertBugCount("Mixed1", 1); - assertBugCount("Mixed2", 1); + void testExplicitNulls(SpotBugsRunner spotbugs) { + assertBugCount("ExplicitNullCheckSimple", 1, spotbugs); + assertBugCount("ExplicitNullCheckNested", 2, spotbugs); + assertBugCount("ExplicitNullCheckMultiple", 2, spotbugs); + assertBugCount("Mixed1", 1, spotbugs); + assertBugCount("Mixed2", 1, spotbugs); } - private void assertBugCount(String clazz, int count) { - BugCollection bugCollection = analyse(clazz); + private void assertBugCount(String clazz, int count, SpotBugsRunner spotbugs) { + BugCollection bugCollection = analyse(clazz, spotbugs); final BugInstanceMatcher bugTypeMatcher = new BugInstanceMatcherBuilder() .bugType("RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE").build(); @@ -47,7 +47,7 @@ private void assertBugCount(String clazz, int count) { assertThat(bugCollection, containsExactly(0, bugTypeMatcher2)); } - private BugCollection analyse(String clazz) { + private BugCollection analyse(String clazz, SpotBugsRunner spotbugs) { return spotbugs.performAnalysis( Paths.get("../spotbugsTestCases/build/classes/java/main/ghIssues/issue600/" + clazz + ".class"), Paths.get("../spotbugsTestCases/build/classes/java/main/ghIssues/issue600/MyAutocloseable.class"), diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/nullness/TestCheckerFrameworkTypeAnnotations.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/nullness/TestCheckerFrameworkTypeAnnotations.java index 839e0fe910d..9b139b9849b 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/nullness/TestCheckerFrameworkTypeAnnotations.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/nullness/TestCheckerFrameworkTypeAnnotations.java @@ -3,8 +3,8 @@ import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; import static org.hamcrest.MatcherAssert.assertThat; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import edu.umd.cs.findbugs.AbstractIntegrationTest; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; @@ -13,54 +13,55 @@ /** * Checks the effect of CheckerFramework @NonNull annotation on method return value */ -public class TestCheckerFrameworkTypeAnnotations extends AbstractIntegrationTest { - @Before - public void performAnalysis() { +class TestCheckerFrameworkTypeAnnotations extends AbstractIntegrationTest { + + @BeforeEach + void performAnalysis() { performAnalysis("type/annotation/CheckerFrameworkTypeAnnotations.class"); } @Test - public void methodReturns() { + void methodReturns() { assertBugsSpottedCount("NP_NONNULL_RETURN_VIOLATION", 2); } @Test - public void returningNullOnNonNullMethod() { + void returningNullOnNonNullMethod() { assertBugSpotted("NP_NONNULL_RETURN_VIOLATION", "returningNullOnNonNullMethod", 13); } @Test - public void returningNullWithNonNullOnGenerics() { + void returningNullWithNonNullOnGenerics() { assertNoBugSpotted("NP_NONNULL_RETURN_VIOLATION", "returningNullWithNonNullOnGenerics"); } @Test - public void returningNullOnNonNullMethodWithNonNullOnGenerics() { + void returningNullOnNonNullMethodWithNonNullOnGenerics() { assertBugSpotted("NP_NONNULL_RETURN_VIOLATION", "returningNullOnNonNullMethodWithNonNullOnGenerics", 25); } @Test - public void methodParametersTests() { + void methodParametersTests() { assertBugsSpottedCount("NP_NONNULL_PARAM_VIOLATION", 2); } @Test - public void usingNullForNonNullParameter() { + void usingNullForNonNullParameter() { assertBugSpotted("NP_NONNULL_PARAM_VIOLATION", "usingNullForNonNullParameter", 30); } @Test - public void usingNullParameterWithNonNullOnGenerics() { + void usingNullParameterWithNonNullOnGenerics() { assertNoBugSpotted("NP_NONNULL_PARAM_VIOLATION", "usingNullParameterWithNonNullOnGenerics"); } @Test - public void usingNullOnNonNullParameterWithNonNullOnGenerics() { + void usingNullOnNonNullParameterWithNonNullOnGenerics() { assertBugSpotted("NP_NONNULL_PARAM_VIOLATION", "usingNullOnNonNullParameterWithNonNullOnGenerics", 47); } @Test - public void usingNonNullArrayOfNullable() { + void usingNonNullArrayOfNullable() { assertNoBugSpotted("NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE", "usingNonNullArrayOfNullable"); } diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/sarif/BugCollectionAnalyserTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/sarif/BugCollectionAnalyserTest.java index 11f43789282..528c3e92769 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/sarif/BugCollectionAnalyserTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/sarif/BugCollectionAnalyserTest.java @@ -4,7 +4,7 @@ import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.MatcherAssert.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; import com.google.gson.JsonArray; import com.google.gson.JsonObject; @@ -16,9 +16,10 @@ import edu.umd.cs.findbugs.SortedBugCollection; import edu.umd.cs.findbugs.SourceLineAnnotation; -public class BugCollectionAnalyserTest { +class BugCollectionAnalyserTest { + @Test - public void testGetRulesGetResultsGetCweTaxonomyNoBug() { + void testGetRulesGetResultsGetCweTaxonomyNoBug() { BugCollection bugCollection = new SortedBugCollection(); BugCollectionAnalyser analyser = new BugCollectionAnalyser(bugCollection); @@ -34,7 +35,7 @@ public void testGetRulesGetResultsGetCweTaxonomyNoBug() { } @Test - public void testGetRulesGetResultsGetCweTaxonomyOneBugWithCwe() { + void testGetRulesGetResultsGetCweTaxonomyOneBugWithCwe() { int cweid = 78; String type = "TYPE"; @@ -81,7 +82,7 @@ public void testGetRulesGetResultsGetCweTaxonomyOneBugWithCwe() { } @Test - public void testGetRulesGetResultsGetCweTaxonomyOneBugNoCweId() { + void testGetRulesGetResultsGetCweTaxonomyOneBugNoCweId() { String type = "TYPE"; BugPattern bugPattern = new BugPattern(type, "abbrev", "category", false, "shortDescription", @@ -117,7 +118,7 @@ public void testGetRulesGetResultsGetCweTaxonomyOneBugNoCweId() { } @Test - public void testGetRulesGetResultsGetCweTaxonomyMultipleBugsWithAndWithoutCweId() { + void testGetRulesGetResultsGetCweTaxonomyMultipleBugsWithAndWithoutCweId() { BugPattern bugPattern = new BugPattern("TYPE_NO_CWE", "abbrev", "category", false, "shortDescription", "longDescription", "detailText", "https://example.com/help.html", 0); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/sarif/GUIDCalculatorTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/sarif/GUIDCalculatorTest.java index 630c7dc379b..6eccd9bc48e 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/sarif/GUIDCalculatorTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/sarif/GUIDCalculatorTest.java @@ -5,11 +5,12 @@ import java.util.UUID; -import org.junit.Test; +import org.junit.jupiter.api.Test; + +class GUIDCalculatorTest { -public class GUIDCalculatorTest { @Test - public void testGuidFromNamespaceUsingAsciiChars() { + void testGuidFromNamespaceUsingAsciiChars() { // output of: uuid -v 5 '6ba7b811-9dad-11d1-80b4-00c04fd430c8' '22' UUID expectedUUID = UUID.fromString("51e4ac9a-92ed-5ca5-95ab-f9260e15f813"); @@ -20,7 +21,7 @@ public void testGuidFromNamespaceUsingAsciiChars() { } @Test - public void testGuidFromNamespaceUsingSmiley() { + void testGuidFromNamespaceUsingSmiley() { // output of: uuid -v 5 '6ba7b811-9dad-11d1-80b4-00c04fd430c8' '😀' UUID expectedUUID = UUID.fromString("f0793165-4aab-598c-9164-4efc598481b2"); @@ -31,7 +32,7 @@ public void testGuidFromNamespaceUsingSmiley() { } @Test - public void testGuidFromStringUsingAsciiChars() { + void testGuidFromStringUsingAsciiChars() { UUID expectedUUID = UUID.fromString("12c6fc06-c99a-5623-b5ee-b3f43dfd832b"); UUID actualGUID = GUIDCalculator.fromString("22"); @@ -41,7 +42,7 @@ public void testGuidFromStringUsingAsciiChars() { @Test - public void testGuidFromStringUsingSmiley() { + void testGuidFromStringUsingSmiley() { UUID expectedUUID = UUID.fromString("9c533688-a979-5858-8bd6-a43c9f91aba6"); UUID actualGUID = GUIDCalculator.fromString("😀"); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/sarif/LevelTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/sarif/LevelTest.java index 33fdb73f4e2..947dc0f66b9 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/sarif/LevelTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/sarif/LevelTest.java @@ -3,16 +3,17 @@ import static org.hamcrest.Matchers.is; import static org.hamcrest.MatcherAssert.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; import com.google.gson.Gson; import com.google.gson.JsonObject; import edu.umd.cs.findbugs.cwe.WeaknessSeverity; -public class LevelTest { +class LevelTest { + @Test - public void testToJsonString() { + void testToJsonString() { Gson gson = new Gson(); JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("level", Level.WARNING.toJsonString()); @@ -20,42 +21,42 @@ public void testToJsonString() { } @Test - public void testMapHighestRankToError() { + void testMapHighestRankToError() { assertThat(Level.fromBugRank(1), is(Level.ERROR)); } @Test - public void testMapHighRankToError() { + void testMapHighRankToError() { assertThat(Level.fromBugRank(9), is(Level.ERROR)); } @Test - public void testMapLowRankToWarning() { + void testMapLowRankToWarning() { assertThat(Level.fromBugRank(14), is(Level.WARNING)); } @Test - public void testMapLowestRankToNote() { + void testMapLowestRankToNote() { assertThat(Level.fromBugRank(20), is(Level.NOTE)); } @Test - public void testMapWeaknessSeverityLevelHighToError() { + void testMapWeaknessSeverityLevelHighToError() { assertThat(Level.fromWeaknessSeverity(WeaknessSeverity.HIGH), is(Level.ERROR)); } @Test - public void testMapWeaknessSeverityLevelMediumToWarning() { + void testMapWeaknessSeverityLevelMediumToWarning() { assertThat(Level.fromWeaknessSeverity(WeaknessSeverity.MEDIUM), is(Level.WARNING)); } @Test - public void testMapWeaknessSeverityLevelLowToNote() { + void testMapWeaknessSeverityLevelLowToNote() { assertThat(Level.fromWeaknessSeverity(WeaknessSeverity.LOW), is(Level.NOTE)); } @Test - public void testMapWeaknessSeverityLevelNoneToNone() { + void testMapWeaknessSeverityLevelNoneToNone() { assertThat(Level.fromWeaknessSeverity(WeaknessSeverity.NONE), is(Level.NONE)); } } diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/sarif/PlaceholderTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/sarif/PlaceholderTest.java index 4a22621cf0b..ec03709679f 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/sarif/PlaceholderTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/sarif/PlaceholderTest.java @@ -18,9 +18,9 @@ import com.google.gson.Gson; import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.io.PrintWriter; import java.io.StringWriter; @@ -29,12 +29,13 @@ import static org.hamcrest.Matchers.is; import static org.hamcrest.MatcherAssert.assertThat; -public class PlaceholderTest { +class PlaceholderTest { + private SarifBugReporter reporter; private StringWriter writer; - @Before - public void setup() { + @BeforeEach + void setup() { Project project = new Project(); reporter = new SarifBugReporter(project); writer = new StringWriter(); @@ -53,14 +54,14 @@ public boolean isApplicationClass(@DottedClassName String className) { AnalysisContext.setCurrentAnalysisContext(analysisContext); } - @After - public void teardown() { + @AfterEach + void teardown() { AnalysisContext.removeCurrentAnalysisContext(); Global.removeAnalysisCacheForCurrentThread(); } @Test - public void testFormatWithKey() throws ClassNotFoundException { + void testFormatWithKey() throws ClassNotFoundException { BugPattern bugPattern = new BugPattern("BUG_TYPE", "abbrev", "category", false, "describing about this bug type...", "describing about this bug type with value {0.givenClass} and {1.name}", "detailText", null, 0); DetectorFactoryCollection.instance().registerBugPattern(bugPattern); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/sarif/SarifBugReporterTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/sarif/SarifBugReporterTest.java index 66756b211a5..29f8d0e9646 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/sarif/SarifBugReporterTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/sarif/SarifBugReporterTest.java @@ -3,8 +3,8 @@ import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.startsWith; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.File; import java.io.IOException; @@ -17,9 +17,9 @@ import java.util.Locale; import java.util.Optional; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import com.google.gson.Gson; import com.google.gson.JsonArray; @@ -45,12 +45,13 @@ import edu.umd.cs.findbugs.classfile.impl.ClassPathImpl; import edu.umd.cs.findbugs.internalAnnotations.DottedClassName; -public class SarifBugReporterTest { +class SarifBugReporterTest { + private SarifBugReporter reporter; private StringWriter writer; - @Before - public void setup() { + @BeforeEach + void setup() { Project project = new Project(); reporter = new SarifBugReporter(project); writer = new StringWriter(); @@ -70,8 +71,8 @@ public boolean isApplicationClass(@DottedClassName String className) { AnalysisContext.setCurrentAnalysisContext(analysisContext); } - @After - public void teardown() { + @AfterEach + void teardown() { AnalysisContext.removeCurrentAnalysisContext(); Global.removeAnalysisCacheForCurrentThread(); } @@ -81,7 +82,7 @@ public void teardown() { * Root object also should have {@code "$schema"} field that points the JSON schema provided by SARIF community. */ @Test - public void testVersionAndSchema() { + void testVersionAndSchema() { reporter.finish(); String json = writer.toString(); @@ -99,7 +100,7 @@ public void testVersionAndSchema() { * A toolComponent object MAY contain a {@code "language"} property (§3.19.21). */ @Test - public void testDriver() { + void testDriver() { final String EXPECTED_VERSION = Version.VERSION_STRING; final String EXPECTED_LANGUAGE = "ja"; @@ -123,7 +124,7 @@ public void testDriver() { } @Test - public void testRuleWithArguments() { + void testRuleWithArguments() { // given final String EXPECTED_BUG_TYPE = "BUG_TYPE"; final int EXPECTED_PRIORITY = Priorities.NORMAL_PRIORITY; @@ -160,7 +161,7 @@ public void testRuleWithArguments() { } @Test - public void testMissingClassNotification() { + void testMissingClassNotification() { ClassDescriptor classDescriptor = DescriptorFactory.instance().getClassDescriptor("com/github/spotbugs/MissingClass"); reporter.reportMissingClass(classDescriptor); reporter.finish(); @@ -181,7 +182,7 @@ public void testMissingClassNotification() { } @Test - public void testErrorNotification() { + void testErrorNotification() { reporter.logError("Unexpected Error"); reporter.finish(); @@ -200,7 +201,7 @@ public void testErrorNotification() { } @Test - public void testExceptionNotification() { + void testExceptionNotification() { reporter.getProject().getSourceFinder().setSourceBaseList(Collections.singletonList(new File("src/test/java").getAbsolutePath())); reporter.logError("Unexpected Error", new Exception("Unexpected Problem")); reporter.finish(); @@ -224,7 +225,7 @@ public void testExceptionNotification() { } @Test - public void testExceptionNotificationWithoutMessage() { + void testExceptionNotificationWithoutMessage() { reporter.logError("Unexpected Error", new Exception()); reporter.finish(); @@ -243,7 +244,7 @@ public void testExceptionNotificationWithoutMessage() { } @Test - public void testHelpUriAndTags() { + void testHelpUriAndTags() { BugPattern bugPattern = new BugPattern("TYPE", "abbrev", "category", false, "shortDescription", "longDescription", "detailText", "https://example.com/help.html", 0); DetectorFactoryCollection.instance().registerBugPattern(bugPattern); @@ -266,7 +267,7 @@ public void testHelpUriAndTags() { } @Test - public void testExtensions() throws PluginException { + void testExtensions() throws PluginException { PluginLoader pluginLoader = DetectorFactoryCollection.instance().getCorePlugin().getPluginLoader(); Plugin plugin = new Plugin("pluginId", "version", null, pluginLoader, true, false); DetectorFactoryCollection dfc = new DetectorFactoryCollection(plugin); @@ -291,7 +292,7 @@ public void testExtensions() throws PluginException { } @Test - public void testSourceLocation() throws IOException { + void testSourceLocation() throws IOException { Path tmpDir = Files.createTempDirectory("spotbugs"); new File(tmpDir.toFile(), "SampleClass.java").createNewFile(); SourceFinder sourceFinder = reporter.getProject().getSourceFinder(); @@ -324,7 +325,7 @@ public void testSourceLocation() throws IOException { } @Test - public void testCweTaxonomy() throws IOException { + void testCweTaxonomy() throws IOException { String type = "TYPE_WITH_CWE"; int cweid = 502; diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/util/ClassNameTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/util/ClassNameTest.java index 6f10826df22..f9fcd66093e 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/util/ClassNameTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/util/ClassNameTest.java @@ -19,20 +19,21 @@ package edu.umd.cs.findbugs.util; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.Arrays; import java.util.List; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; /** * @author pugh */ -public class ClassNameTest { +class ClassNameTest { @Test - public void testExtractPackagePrefix() { + void testExtractPackagePrefix() { assertEquals("", ClassName.extractPackagePrefix("org.apache.ant.subpkg.sub2", 0)); assertEquals("org", ClassName.extractPackagePrefix("org", 1)); assertEquals("org.apache.ant", ClassName.extractPackagePrefix("org.apache.ant.subpkg.sub2", 3)); @@ -41,7 +42,7 @@ public void testExtractPackagePrefix() { } @Test - public void testExtractClassName() { + void testExtractClassName() { assertEquals("java/lang/Integer", ClassName.extractClassName("Ljava/lang/Integer;")); assertEquals("java/lang/Integer", ClassName.extractClassName("[Ljava/lang/Integer;")); assertEquals("java/lang/Integer", ClassName.extractClassName("[[Ljava/lang/Integer;")); @@ -50,7 +51,7 @@ public void testExtractClassName() { } @Test - public void testGetPrimitiveType() { + void testGetPrimitiveType() { assertEquals("I", ClassName.getPrimitiveType("java/lang/Integer")); assertEquals("F", ClassName.getPrimitiveType("java/lang/Float")); assertEquals("D", ClassName.getPrimitiveType("java/lang/Double")); @@ -63,21 +64,23 @@ public void testGetPrimitiveType() { assertNull(ClassName.getPrimitiveType("java/util/HashMap")); } - @Test(expected = IllegalArgumentException.class) - public void testExtractClassNameBad() { - ClassName.extractClassName("L[Ljava/lang/Integer;"); + @Test + void testExtractClassNameBad() { + Assertions.assertThrows(IllegalArgumentException.class, () -> { + ClassName.extractClassName("L[Ljava/lang/Integer;"); + }); } @Test - public void testMatchedPrefix() { + void testMatchedPrefix() { List negativeCases = Arrays.asList( new String[] { "foobar" }, new String[] { "" }, new String[] { "testObject" }); for (String[] searchString : negativeCases) { - assertFalse("com.text.TestClass should not be matched by " + Arrays.toString(searchString), - ClassName.matchedPrefixes(searchString, "com.test.TestClass")); + Assertions.assertFalse(ClassName.matchedPrefixes(searchString, "com.test.TestClass"), + "com.text.TestClass should not be matched by " + Arrays.toString(searchString)); } List positiveCases = Arrays.asList( @@ -91,105 +94,105 @@ public void testMatchedPrefix() { new String[] { "bastClass" }); for (String[] searchString : positiveCases) { - assertTrue("com.text.TestClass should be matched by " + Arrays.toString(searchString), - ClassName.matchedPrefixes(searchString, "com.test.TestClass")); + assertTrue(ClassName.matchedPrefixes(searchString, "com.test.TestClass"), + "com.text.TestClass should be matched by " + Arrays.toString(searchString)); } } @Test - public void testSimpleBinaryClassNameIsValidClassName() { + void testSimpleBinaryClassNameIsValidClassName() { assertTrue(ClassName.isValidClassName("com/bla/Parent")); } @Test - public void testSimpleDottedClassNameIsValidClassName() { + void testSimpleDottedClassNameIsValidClassName() { assertTrue(ClassName.isValidClassName("com.bla.Parent")); } @Test - public void testInnerClassBinaryClassNameIsValidClassName() { + void testInnerClassBinaryClassNameIsValidClassName() { assertTrue(ClassName.isValidClassName("com/bla/Parent$Child")); } @Test - public void testInnerClassDottedClassNameIsValidClassName() { + void testInnerClassDottedClassNameIsValidClassName() { assertTrue(ClassName.isValidClassName("com.bla.Parent$Child")); } @Test - public void testJavaStyleAnonymousInnerClassBinaryClassNameIsValidClassName() { + void testJavaStyleAnonymousInnerClassBinaryClassNameIsValidClassName() { assertTrue(ClassName.isValidClassName("com/bla/Parent$Child$1")); } @Test - public void testJavaStyleAnonymousInnerClassDottedClassNameIsValidClassName() { + void testJavaStyleAnonymousInnerClassDottedClassNameIsValidClassName() { assertTrue(ClassName.isValidClassName("com.bla.Parent$Child$1")); } @Test - public void testKotlinStyleAnonymousInnerClassBinaryClassNameIsValidClassName() { + void testKotlinStyleAnonymousInnerClassBinaryClassNameIsValidClassName() { assertTrue(ClassName.isValidClassName("com/bla/Parent$function$variable$1")); } @Test - public void testKotlinStyleAnonymousInnerClassDottedClassNameIsValidClassName() { + void testKotlinStyleAnonymousInnerClassDottedClassNameIsValidClassName() { assertTrue(ClassName.isValidClassName("com.bla.Parent$function$variable$1")); } @Test - public void testBinaryClassNameContainingAllowedSpecialCharactersIsValidClassName() { + void testBinaryClassNameContainingAllowedSpecialCharactersIsValidClassName() { assertTrue(ClassName.isValidClassName("com/bla/Parent$function!@#%^&*,?{}]()$variable$1")); } @Test - public void testDottedClassNameContainingAllowedSpecialCharactersIsValidClassName() { + void testDottedClassNameContainingAllowedSpecialCharactersIsValidClassName() { assertTrue(ClassName.isValidClassName("com.bla.Parent$function!@#%^&*,?{}]()$variable$1")); } @Test - public void testFieldDescriptorClassNameIsValidClassName() { + void testFieldDescriptorClassNameIsValidClassName() { assertTrue(ClassName.isValidClassName("Lcom/bla/Parent;")); } @Test - public void testFieldDescriptorOneDimensionalArrayClassNameIsValidClassName() { + void testFieldDescriptorOneDimensionalArrayClassNameIsValidClassName() { assertTrue(ClassName.isValidClassName("[Lcom/bla/Parent;")); } @Test - public void testFieldDescriptorOneDimensionalPrimitiveArrayClassNameIsValidClassName() { + void testFieldDescriptorOneDimensionalPrimitiveArrayClassNameIsValidClassName() { assertTrue(ClassName.isValidClassName("[I")); } @Test - public void testFieldDescriptorTwoDimensionalArrayClassNameIsValidClassName() { + void testFieldDescriptorTwoDimensionalArrayClassNameIsValidClassName() { assertTrue(ClassName.isValidClassName("[[Lcom/bla/Parent;")); } @Test - public void testFieldDescriptorClassNameContainingAllowedSpecialCharactersIsValidClassName() { + void testFieldDescriptorClassNameContainingAllowedSpecialCharactersIsValidClassName() { assertTrue(ClassName.isValidClassName("[[Lcom/bla/Parent$function!@#%^&*,?{}]()$variable$1;")); } @Test - public void testFieldDescriptorClassNameContainingDotsIsInvalidClassName() { + void testFieldDescriptorClassNameContainingDotsIsInvalidClassName() { assertFalse(ClassName.isValidClassName("Lcom.bla.Parent;")); } @Test - public void testClassNameContainingBothSlashesAndDotsIsInvalidClassName() { + void testClassNameContainingBothSlashesAndDotsIsInvalidClassName() { assertFalse(ClassName.isValidClassName("com.bla/Parent")); } @Test - public void testBinaryClassNameContainingDisallowedSpecialCharactersIsInvalidClassName() { + void testBinaryClassNameContainingDisallowedSpecialCharactersIsInvalidClassName() { assertFalse(ClassName.isValidClassName("com/bla/Parent$function$variable$1;")); assertFalse(ClassName.isValidClassName("com/bla/Parent$function;$variable$1")); assertFalse(ClassName.isValidClassName("com/bla/Parent$function[$variable$1")); } @Test - public void testEmptyStringIsInvalidClassName() { + void testEmptyStringIsInvalidClassName() { assertFalse(ClassName.isValidClassName((""))); } } diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/util/MutableClassesTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/util/MutableClassesTest.java index 4d35f656ace..917db4ebb9d 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/util/MutableClassesTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/util/MutableClassesTest.java @@ -2,8 +2,10 @@ import javax.annotation.concurrent.Immutable; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledOnJre; +import org.junit.jupiter.api.condition.JRE; @Immutable class Annotated { @@ -19,36 +21,37 @@ void set(int n) { } } -public class MutableClassesTest { +class MutableClassesTest { + @Test - public void TestKnownMutable() { - Assert.assertTrue(MutableClasses.mutableSignature("Ljava/util/Date;")); + void testKnownMutable() { + Assertions.assertTrue(MutableClasses.mutableSignature("Ljava/util/Date;")); } @Test - public void TestKnownImmutablePackage() { - Assert.assertFalse(MutableClasses.mutableSignature("Ljava/time/LocalTime;")); + void testKnownImmutablePackage() { + Assertions.assertFalse(MutableClasses.mutableSignature("Ljava/time/LocalTime;")); } @Test - public void TestKnownImmutable() { - Assert.assertFalse(MutableClasses.mutableSignature("Ljava/lang/String;")); - Assert.assertFalse(MutableClasses.mutableSignature("Ljava/util/regex/Pattern;")); + void testKnownImmutable() { + Assertions.assertFalse(MutableClasses.mutableSignature("Ljava/lang/String;")); + Assertions.assertFalse(MutableClasses.mutableSignature("Ljava/util/regex/Pattern;")); } @Test - public void TestLocale() { - Assert.assertFalse(MutableClasses.mutableSignature("Ljava/util/Locale;")); + void testLocale() { + Assertions.assertFalse(MutableClasses.mutableSignature("Ljava/util/Locale;")); } @Test - public void TestArray() { - Assert.assertTrue(MutableClasses.mutableSignature("[I")); + void testArray() { + Assertions.assertTrue(MutableClasses.mutableSignature("[I")); } @Test - public void TestAnnotatedImmutable() { - Assert.assertFalse(MutableClasses.mutableSignature("Ledu/umd/cs/findbugs/util/Annotated;")); + void testAnnotatedImmutable() { + Assertions.assertFalse(MutableClasses.mutableSignature("Ledu/umd/cs/findbugs/util/Annotated;")); } public static class Mutable { @@ -68,8 +71,8 @@ public int getN() { } @Test - public void TestMutable() { - Assert.assertTrue(MutableClasses.mutableSignature("Ledu/umd/cs/findbugs/util/MutableClassesTest$Mutable;")); + void testMutable() { + Assertions.assertTrue(MutableClasses.mutableSignature("Ledu/umd/cs/findbugs/util/MutableClassesTest$Mutable;")); } public static class Immutable { @@ -98,14 +101,17 @@ public static void setImmutable(Immutable imm) { } @Test - public void TestImmutable() { - Assert.assertFalse(MutableClasses.mutableSignature("Ledu/umd/cs/findbugs/util/MutableClassesTest$Immutable;")); + void testImmutable() { + Assertions.assertFalse(MutableClasses.mutableSignature("Ledu/umd/cs/findbugs/util/MutableClassesTest$Immutable;")); } + // This tests fails on java 8/11, so disable it and only run on java 17+ unless its determined how to fix @Test - public void TestImmutableValuedBased() { + @DisabledOnJre({ JRE.JAVA_8, JRE.JAVA_11 }) + void testImmutableValuedBased() { // Annotated with @jdk.internal.ValueBased and has "setValue", which should normally trip detection - Assert.assertFalse(MutableClasses.mutableSignature("Ljava/util/KeyValueHolder;")); + System.out.println("starting....."); + Assertions.assertFalse(MutableClasses.mutableSignature("Ljava/util/KeyValueHolder;")); } @com.google.errorprone.annotations.Immutable @@ -122,8 +128,8 @@ public void writeOther() { } @Test - public void TestEnumsAreImmutable() { - Assert.assertFalse(MutableClasses.mutableSignature("Ledu/umd/cs/findbugs/util/MutableClassesTest$ImmutableTestEnum;")); + void testEnumsAreImmutable() { + Assertions.assertFalse(MutableClasses.mutableSignature("Ledu/umd/cs/findbugs/util/MutableClassesTest$ImmutableTestEnum;")); } public enum ImmutableTestEnum { @@ -136,10 +142,10 @@ public void write() { } @Test - public void TestErrorProneImmutable() { - Assert.assertFalse(MutableClasses.mutableSignature( + void testErrorProneImmutable() { + Assertions.assertFalse(MutableClasses.mutableSignature( "Ledu/umd/cs/findbugs/util/MutableClassesTest$ErrorProneImmutable;")); - Assert.assertFalse(MutableClasses.mutableSignature( + Assertions.assertFalse(MutableClasses.mutableSignature( "Ledu/umd/cs/findbugs/util/MutableClassesTest$ErrorProneImmutableSubclass;")); } } diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/util/StringsTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/util/StringsTest.java index 8cc2240e63f..5145050d4a9 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/util/StringsTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/util/StringsTest.java @@ -19,14 +19,14 @@ package edu.umd.cs.findbugs.util; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; -public class StringsTest { +class StringsTest { - public static String[] escapedStrings = { + private static String[] escapedStrings = { // mixed entities/unicode escape sequences "a b c 1 2 3 & < > " ' \\u0005 \\u0013 λ \\\\u0007", // *even* series of prefixed slashes + \\u -> do escape @@ -45,24 +45,24 @@ public class StringsTest { // an empty string should be safe too "", }; - public static String[] unescapedStrings = { "a b c 1 2 3 & < > \" ' \u0005 \u0013 \u03BB \\\\u0007", "a b c \\\\\u0005", + private static String[] unescapedStrings = { "a b c 1 2 3 & < > \" ' \u0005 \u0013 \u03BB \\\\u0007", "a b c \\\\\u0005", "a b c \\\\\\\\u0005", "a b c \\\\\u0005 \\\\\\\\u0013", "\\\\\\", "a b c 1 2 3 & < > \" ' \u0005 \u0013 \u03BB \\\\u0007 a b c 1 2 3", null, "", }; @Test - public void testEscapeXml() { + void testEscapeXml() { assert (escapedStrings.length == unescapedStrings.length); for (int i = 0; i < unescapedStrings.length; i++) { if (unescapedStrings[i] == null) { assert (Strings.escapeXml(unescapedStrings[i]) == null); } else { - Assert.assertEquals(escapedStrings[i], Strings.escapeXml(unescapedStrings[i])); + Assertions.assertEquals(escapedStrings[i], Strings.escapeXml(unescapedStrings[i])); } } } @Test - public void testUnescapeXml() { + void testUnescapeXml() { assert (escapedStrings.length == unescapedStrings.length); for (int i = 0; i < escapedStrings.length; i++) { if (escapedStrings[i] == null) { @@ -73,12 +73,12 @@ public void testUnescapeXml() { } } - public void checkEscapeLFCRBackSlash(String expected, String argument) { - assertEquals(argument, expected, Strings.escapeLFCRBackSlash(argument)); + private void checkEscapeLFCRBackSlash(String expected, String argument) { + assertEquals(expected, Strings.escapeLFCRBackSlash(argument), argument); } @Test - public void testEscapeLFCRBackSlash() { + void testEscapeLFCRBackSlash() { checkEscapeLFCRBackSlash("abc", "abc"); checkEscapeLFCRBackSlash("\\n", "\n"); checkEscapeLFCRBackSlash("\\r", "\r"); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/visitclass/DismantleBytecodeTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/visitclass/DismantleBytecodeTest.java index 360472597d2..d049bf83de7 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/visitclass/DismantleBytecodeTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/visitclass/DismantleBytecodeTest.java @@ -19,18 +19,18 @@ package edu.umd.cs.findbugs.visitclass; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import org.apache.bcel.Const; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author pugh */ -public class DismantleBytecodeTest { +class DismantleBytecodeTest { @Test - public void testAreOppositeBranches() { + void testAreOppositeBranches() { assertTrue(DismantleBytecode.areOppositeBranches(Const.IF_ACMPEQ, Const.IF_ACMPNE)); assertTrue(DismantleBytecode.areOppositeBranches(Const.IF_ICMPEQ, Const.IF_ICMPNE)); assertTrue(DismantleBytecode.areOppositeBranches(Const.IF_ICMPLT, Const.IF_ICMPGE)); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/visitclass/GetNumberArgumentsTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/visitclass/GetNumberArgumentsTest.java index 946e794512c..993fdf59ef3 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/visitclass/GetNumberArgumentsTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/visitclass/GetNumberArgumentsTest.java @@ -19,34 +19,34 @@ package edu.umd.cs.findbugs.visitclass; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author pugh */ -public class GetNumberArgumentsTest { +class GetNumberArgumentsTest { static String[] simpleTypes = "I J B C D F I S Z".split(" "); @Test - public void testSimpleWithVoidReturnType() { + void testSimpleWithVoidReturnType() { for (String s : simpleTypes) { assertEquals(1, PreorderVisitor.getNumberArguments("(" + s + ")V")); } } @Test - public void testSimpleWithVoidIntegerType() { + void testSimpleWithVoidIntegerType() { for (String s : simpleTypes) { assertEquals(1, PreorderVisitor.getNumberArguments("(" + s + ")I")); } } @Test - public void testArrays() { + void testArrays() { for (String s : simpleTypes) { assertEquals(1, PreorderVisitor.getNumberArguments("([" + s + ")V")); assertEquals(1, PreorderVisitor.getNumberArguments("([[" + s + ")I")); @@ -54,7 +54,7 @@ public void testArrays() { } @Test - public void testStringArguments() { + void testStringArguments() { for (String s : simpleTypes) { assertEquals(2, PreorderVisitor.getNumberArguments("([Ljava/lang/String;" + s + ")V")); assertEquals(2, PreorderVisitor.getNumberArguments("([[" + s + "Ljava/lang/String;)I")); @@ -62,7 +62,7 @@ public void testStringArguments() { } @Test - public void testSimpleObjectArgument() { + void testSimpleObjectArgument() { assertEquals(1, PreorderVisitor.getNumberArguments("(Ledu/umd/cs/findbugs/ba/ClassContext;)V")); } } diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/visitclass/PreorderVisitorTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/visitclass/PreorderVisitorTest.java index a5ddd6b1fdf..feb7d1cc63d 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/visitclass/PreorderVisitorTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/visitclass/PreorderVisitorTest.java @@ -19,17 +19,17 @@ package edu.umd.cs.findbugs.visitclass; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author bill.pugh */ -public class PreorderVisitorTest { +class PreorderVisitorTest { @Test - public void testGetNumberArguments() { + void testGetNumberArguments() { assertEquals(0, PreorderVisitor.getNumberArguments("()V")); assertEquals(0, PreorderVisitor.getNumberArguments("()I")); assertEquals(0, PreorderVisitor.getNumberArguments("()J")); diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/workflow/FindSeqNumTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/workflow/FindSeqNumTest.java index f14cde908b6..6928fd2f78b 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/workflow/FindSeqNumTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/workflow/FindSeqNumTest.java @@ -1,7 +1,6 @@ package edu.umd.cs.findbugs.workflow; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.text.SimpleDateFormat; import java.util.HashMap; @@ -12,18 +11,19 @@ import java.util.SortedMap; import java.util.TreeMap; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import edu.umd.cs.findbugs.AppVersion; -public class FindSeqNumTest { +class FindSeqNumTest { Map versionNames; SortedMap timeStamps; - @Before + @BeforeEach public void setUp() throws Exception { versionNames = new HashMap<>(); timeStamps = new TreeMap<>(); @@ -40,93 +40,94 @@ public void setUp() throws Exception { } @Test - public void test0() { + void test0() { assertEquals(0, Filter.FilterCommandLine.getVersionNum(versionNames, timeStamps, "0", true, 3)); } @Test - public void testminusOne() { + void testminusOne() { assertEquals(3, Filter.FilterCommandLine.getVersionNum(versionNames, timeStamps, "-1", true, 3)); } @Test - public void testminusTwo() { + void testminusTwo() { assertEquals(2, Filter.FilterCommandLine.getVersionNum(versionNames, timeStamps, "-2", true, 3)); } @Test - public void testLast() { + void testLast() { assertEquals(3, Filter.FilterCommandLine.getVersionNum(versionNames, timeStamps, "last", true, 3)); } @Test - public void testlastVersion() { + void testlastVersion() { assertEquals(3, Filter.FilterCommandLine.getVersionNum(versionNames, timeStamps, "lastVersion", true, 3)); } @Test - public void test1() { + void test1() { assertEquals(1, Filter.FilterCommandLine.getVersionNum(versionNames, timeStamps, "1", true, 3)); } @Test - public void testV1_0() { + void testV1_0() { assertEquals(0, Filter.FilterCommandLine.getVersionNum(versionNames, timeStamps, "v1.0", true, 3)); } @Test - public void testV1_1() { + void testV1_1() { assertEquals(1, Filter.FilterCommandLine.getVersionNum(versionNames, timeStamps, "v1.1", true, 3)); } @Test - public void testV2_0() { + void testV2_0() { assertEquals(2, Filter.FilterCommandLine.getVersionNum(versionNames, timeStamps, "v2.0", true, 3)); } - @Test(expected = IllegalArgumentException.class) - public void testV2_1() { - Filter.FilterCommandLine.getVersionNum(versionNames, timeStamps, "v2.1", true, 0); - fail("Should have rejected version number 2.1"); + @Test + void testV2_1() { + Assertions.assertThrows(IllegalArgumentException.class, () -> { + Filter.FilterCommandLine.getVersionNum(versionNames, timeStamps, "v2.1", true, 0); + }); } @Test - public void testAfterMay5() { + void testAfterMay5() { assertEquals(0, Filter.FilterCommandLine.getVersionNum(versionNames, timeStamps, "5/5/2005", true, 3)); } @Test - public void testAfterJune5() { + void testAfterJune5() { assertEquals(1, Filter.FilterCommandLine.getVersionNum(versionNames, timeStamps, "6/5/2005", true, 3)); } @Test - public void testAfterJune15() { + void testAfterJune15() { assertEquals(2, Filter.FilterCommandLine.getVersionNum(versionNames, timeStamps, "June 15, 2005", true, 3)); } @Test - public void testAfterJune25() { + void testAfterJune25() { assertEquals(Long.MAX_VALUE, Filter.FilterCommandLine.getVersionNum(versionNames, timeStamps, "June 25, 2005", true, 3)); } @Test - public void testBeforeMay5() { + void testBeforeMay5() { assertEquals(Long.MIN_VALUE, Filter.FilterCommandLine.getVersionNum(versionNames, timeStamps, "5/5/2005", false, 3)); } @Test - public void testBeforeJune5() { + void testBeforeJune5() { assertEquals(0, Filter.FilterCommandLine.getVersionNum(versionNames, timeStamps, "6/5/2005", false, 3)); } @Test - public void testBeforeJune15() { + void testBeforeJune15() { assertEquals(1, Filter.FilterCommandLine.getVersionNum(versionNames, timeStamps, "June 15, 2005", false, 3)); } @Test - public void testBeforeJune25() { + void testBeforeJune25() { assertEquals(2, Filter.FilterCommandLine.getVersionNum(versionNames, timeStamps, "June 25, 2005", false, 3)); } } diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/workflow/UnionResultsTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/workflow/UnionResultsTest.java index 9d1a55ccbef..6926c16a7f8 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/workflow/UnionResultsTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/workflow/UnionResultsTest.java @@ -3,8 +3,8 @@ import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.SortedBugCollection; import edu.umd.cs.findbugs.SourceLineAnnotation; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.io.*; import java.nio.file.Files; @@ -12,9 +12,10 @@ import java.util.ArrayList; import java.util.List; -public class UnionResultsTest { +class UnionResultsTest { + @Test - public void testMain() throws IOException { + void testMain() throws IOException { //Prepare String fileName = createBugFile(); File outputFile = new File("src/test/resources/output.xml"); @@ -24,8 +25,8 @@ public void testMain() throws IOException { //Verify List output = readOutPut(outputFile.getAbsolutePath()); - Assert.assertTrue(output.stream().anyMatch(line -> line.contains("(Lorg/test/TestClass;Ljava/util/List;)V"))); - Assert.assertTrue(output.stream().anyMatch(line -> line.contains("(Lorg/test/TestClass2;Ljava/util/List;)V"))); + Assertions.assertTrue(output.stream().anyMatch(line -> line.contains("(Lorg/test/TestClass;Ljava/util/List;)V"))); + Assertions.assertTrue(output.stream().anyMatch(line -> line.contains("(Lorg/test/TestClass2;Ljava/util/List;)V"))); //Cleanup Files.deleteIfExists(new File(fileName).toPath()); diff --git a/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/TestCaseDetector.java b/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/TestCaseDetector.java index 6ecd244f9d9..df4bce13775 100644 --- a/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/TestCaseDetector.java +++ b/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/TestCaseDetector.java @@ -28,12 +28,14 @@ */ public class TestCaseDetector { + private static final ClassDescriptor JUNIT5TEST = DescriptorFactory.createClassDescriptor("org/junit/jupiter/api/Test"); + private static final ClassDescriptor JUNIT4TEST = DescriptorFactory.createClassDescriptor("org/junit/Test"); private static final ClassDescriptor JUNIT3TESTCASE = DescriptorFactory.createClassDescriptor("junit/framework/TestCase"); public static boolean likelyTestCase(XMethod m) { - if (m.getAnnotation(JUNIT4TEST) != null) { + if (m.getAnnotation(JUNIT4TEST) != null || m.getAnnotation(JUNIT5TEST) != null) { return true; } diff --git a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/DontAssertInstanceofInTests.java b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/DontAssertInstanceofInTests.java index 30459d8ed90..694c4ce775e 100644 --- a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/DontAssertInstanceofInTests.java +++ b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/DontAssertInstanceofInTests.java @@ -33,8 +33,10 @@ public void visitMethod(Method obj) { isTest = false; for (AnnotationEntry entry : obj.getAnnotationEntries()) { String entryType = entry.getAnnotationType(); - // Visit the method only if it's a JUnit test. + // Visit the method only if it's a JUnit4 test. isTest |= "Lorg/junit/Test;".equals(entryType); + // Visit the method only if it's a JUnit5 test. + isTest |= "Lorg/junit/jupiter/api/Test;".equals(entryType); } } @@ -60,7 +62,7 @@ public void sawOpcode(int seen) { String ciOp = getClassConstantOperand(); String ncOp = getNameConstantOperand(); - if ("org/junit/Assert".equals(ciOp) && + if (("org/junit/Assert".equals(ciOp) || "org/junit/jupiter/api/Assertion".equals(ciOp)) && "assertTrue".equals(ncOp)) { // This condition only triggers if the previous opcode was instanceof, // so currBug is guaranteed to be a new BugInstance. diff --git a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/DumbMethods.java b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/DumbMethods.java index 85b5a3d601b..17b33035c5c 100644 --- a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/DumbMethods.java +++ b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/DumbMethods.java @@ -169,8 +169,8 @@ public void sawOpcode(int seen) { } if (seen == Const.INVOKESTATIC && ("junit/framework/Assert".equals(getClassConstantOperand()) || "org/junit/Assert".equals( - getClassConstantOperand())) - && "assertNotNull".equals(getNameConstantOperand())) { + getClassConstantOperand()) || "org/junit/jupiter/api/Assertion".equals(getClassConstantOperand()) + && "assertNotNull".equals(getNameConstantOperand()))) { OpcodeStack.Item item = stack.getStackItem(0); Object o = item.getConstant(); diff --git a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindNullDeref.java b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindNullDeref.java index 9d3506e54f2..8186a6ddc2d 100644 --- a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindNullDeref.java +++ b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindNullDeref.java @@ -246,6 +246,7 @@ private void analyzeMethod(ClassContext classContext, Method method) throws Data XMethod xMethod = XFactory.createXMethod(classContext.getJavaClass(), method); + // For junit 4 only (does not apply to junit 5) ClassDescriptor junitTestAnnotation = DescriptorFactory.createClassDescriptor("org/junit/Test"); AnnotationValue av = xMethod.getAnnotation(junitTestAnnotation); if (av != null) { diff --git a/spotbugsTestCases/build.gradle b/spotbugsTestCases/build.gradle index e60a48cc38a..386b8b096e5 100644 --- a/spotbugsTestCases/build.gradle +++ b/spotbugsTestCases/build.gradle @@ -28,7 +28,7 @@ dependencies { compileOnly 'jakarta.annotation:jakarta.annotation-api:1.3.5' implementation 'org.checkerframework:checker-qual:3.39.0' - implementation 'org.junit.vintage:junit-vintage-engine:5.10.0' + implementation 'org.junit.jupiter:junit-jupiter-engine:5.10.0' implementation 'org.testng:testng:7.8.0' implementation project(':spotbugs') diff --git a/spotbugsTestCases/src/java/bugIdeas/Ideas_2008_08_11.java b/spotbugsTestCases/src/java/bugIdeas/Ideas_2008_08_11.java index c5129739b79..4947eb9c0a6 100644 --- a/spotbugsTestCases/src/java/bugIdeas/Ideas_2008_08_11.java +++ b/spotbugsTestCases/src/java/bugIdeas/Ideas_2008_08_11.java @@ -3,37 +3,36 @@ import java.util.HashMap; import java.util.HashSet; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Assertions; -import junit.framework.TestCase; - -public class Ideas_2008_08_11 extends TestCase { +public class Ideas_2008_08_11 { @Test public void fooBar() throws Exception { - assertFalse(Boolean.TRUE.equals(5)); + Assertions.assertFalse(Boolean.TRUE.equals(5)); HashMap map = new HashMap(); map.put("a", 1); - assertFalse(map.containsKey(1)); - assertNull(map.get(1)); + Assertions.assertFalse(map.containsKey(1)); + Assertions.assertNull(map.get(1)); } @Test public void fooBar2() throws Exception { - assertFalse(Boolean.TRUE.equals(5)); + Assertions.assertFalse(Boolean.TRUE.equals(5)); HashSet set = new HashSet(); set.add("a"); - assertFalse(set.contains(1)); - assertFalse(set.remove(1)); + Assertions.assertFalse(set.contains(1)); + Assertions.assertFalse(set.remove(1)); } public void testFoo() throws Exception { - assertFalse(Boolean.TRUE.equals(5)); + Assertions.assertFalse(Boolean.TRUE.equals(5)); HashMap map = new HashMap(); map.put("a", 1); - assertFalse(map.containsKey(1)); - assertNull(map.get(1)); - assertNull(map.remove(1)); + Assertions.assertFalse(map.containsKey(1)); + Assertions.assertNull(map.get(1)); + Assertions.assertNull(map.remove(1)); } } diff --git a/spotbugsTestCases/src/java/bugIdeas/Ideas_2008_11_14.java b/spotbugsTestCases/src/java/bugIdeas/Ideas_2008_11_14.java index 4b0875a3955..0766742ac42 100644 --- a/spotbugsTestCases/src/java/bugIdeas/Ideas_2008_11_14.java +++ b/spotbugsTestCases/src/java/bugIdeas/Ideas_2008_11_14.java @@ -5,18 +5,20 @@ import java.util.Map; import java.util.Set; -import junit.framework.TestCase; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; -public class Ideas_2008_11_14 extends TestCase { +public class Ideas_2008_11_14 { + @Test public void testOne() { HashMap m = new HashMap(); m.put("a", "a"); - assertFalse(m.containsKey(1)); - assertFalse(m.containsValue(1)); - assertFalse(m.entrySet().contains(1)); - assertFalse(m.keySet().contains(1)); - assertFalse(m.values().contains(1)); + Assertions.assertFalse(m.containsKey(1)); + Assertions.assertFalse(m.containsValue(1)); + Assertions.assertFalse(m.entrySet().contains(1)); + Assertions.assertFalse(m.keySet().contains(1)); + Assertions.assertFalse(m.values().contains(1)); } HashMap m = new HashMap(); diff --git a/spotbugsTestCases/src/java/bugIdeas/Ideas_2009_04_09.java b/spotbugsTestCases/src/java/bugIdeas/Ideas_2009_04_09.java index d92dd538e2e..49d83721be2 100644 --- a/spotbugsTestCases/src/java/bugIdeas/Ideas_2009_04_09.java +++ b/spotbugsTestCases/src/java/bugIdeas/Ideas_2009_04_09.java @@ -1,15 +1,17 @@ package bugIdeas; -import junit.framework.TestCase; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; -public class Ideas_2009_04_09 extends TestCase { +public class Ideas_2009_04_09 { + @Test public void testBad() { try { shouldThrowAssertion(); - fail(); + Assertions.fail(); } catch (AssertionError e) { } diff --git a/spotbugsTestCases/src/java/bugIdeas/Ideas_2009_10_29.java b/spotbugsTestCases/src/java/bugIdeas/Ideas_2009_10_29.java index 87408522c4c..40879a9d3d8 100644 --- a/spotbugsTestCases/src/java/bugIdeas/Ideas_2009_10_29.java +++ b/spotbugsTestCases/src/java/bugIdeas/Ideas_2009_10_29.java @@ -2,9 +2,7 @@ import java.util.Random; -import junit.framework.TestCase; - -public class Ideas_2009_10_29 extends TestCase { +public class Ideas_2009_10_29 { Random r = new Random(); diff --git a/spotbugsTestCases/src/java/bugIdeas/Ideas_2010_01_22.java b/spotbugsTestCases/src/java/bugIdeas/Ideas_2010_01_22.java index a047033b388..13ac3f7d7f6 100644 --- a/spotbugsTestCases/src/java/bugIdeas/Ideas_2010_01_22.java +++ b/spotbugsTestCases/src/java/bugIdeas/Ideas_2010_01_22.java @@ -2,7 +2,8 @@ import javax.annotation.Nonnull; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class Ideas_2010_01_22 { @@ -14,14 +15,18 @@ public int needsNonnull2(@Nonnull Object x) { return 17; } - @Test(expected = NullPointerException.class) + @Test public void testNeedsNonnull() { - needsNonnull(null); + Assertions.assertThrows(NullPointerException.class, () -> { + needsNonnull(null); + }); } - @Test(expected = NullPointerException.class) + @Test public void testNeedsNonnull2() { - needsNonnull2(null); + Assertions.assertThrows(NullPointerException.class, () -> { + needsNonnull2(null); + }); } @Test diff --git a/spotbugsTestCases/src/java/bugIdeas/Ideas_2010_04_29.java b/spotbugsTestCases/src/java/bugIdeas/Ideas_2010_04_29.java index b668285df3e..d9aceb4a3a0 100644 --- a/spotbugsTestCases/src/java/bugIdeas/Ideas_2010_04_29.java +++ b/spotbugsTestCases/src/java/bugIdeas/Ideas_2010_04_29.java @@ -5,7 +5,7 @@ import java.sql.DriverManager; import java.sql.SQLException; -import org.junit.Assert; +import org.junit.jupiter.api.Assertions; import edu.umd.cs.findbugs.annotations.ExpectWarning; import edu.umd.cs.findbugs.annotations.NoWarning; @@ -138,7 +138,7 @@ public void test8(boolean fail) throws Exception { throw new IOException(); } } catch (IOException e) { - Assert.assertEquals("Hello", v.toString()); + Assertions.assertEquals("Hello", v.toString()); } } diff --git a/spotbugsTestCases/src/java/bugIdeas/Ideas_2011_04_24.java b/spotbugsTestCases/src/java/bugIdeas/Ideas_2011_04_24.java index a81d8acbb0a..4a8114469ca 100644 --- a/spotbugsTestCases/src/java/bugIdeas/Ideas_2011_04_24.java +++ b/spotbugsTestCases/src/java/bugIdeas/Ideas_2011_04_24.java @@ -1,8 +1,9 @@ package bugIdeas; -import junit.framework.TestCase; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; -public class Ideas_2011_04_24 extends TestCase { +public class Ideas_2011_04_24 { public double getDouble() { @@ -18,12 +19,14 @@ public String getFoo() { public boolean b(String s) { return s.length() == 0 || s == null; } + + @Test public void testBusted() { - assertSame(17, getDouble() ); - assertEquals(42.0, getDouble() ); - assertEquals(17, getDouble() ); - assertEquals(42.0, getInt() ); - assertEquals(42, getFoo() ); - assertEquals(42.0, getFoo() ); + Assertions.assertSame(17, getDouble() ); + Assertions.assertEquals(42.0, getDouble() ); + Assertions.assertEquals(17, getDouble() ); + Assertions.assertEquals(42.0, getInt() ); + Assertions.assertEquals(42, getFoo() ); + Assertions.assertEquals(42.0, getFoo() ); } } diff --git a/spotbugsTestCases/src/java/ghIssues/Issue390.java b/spotbugsTestCases/src/java/ghIssues/Issue390.java index 59f29c32a8c..003356ab9e4 100644 --- a/spotbugsTestCases/src/java/ghIssues/Issue390.java +++ b/spotbugsTestCases/src/java/ghIssues/Issue390.java @@ -1,6 +1,6 @@ package ghIssues; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.junit.Assert.assertTrue; diff --git a/spotbugsTestCases/src/java/sfBugs/Bug2136033.java b/spotbugsTestCases/src/java/sfBugs/Bug2136033.java index a6141b5c159..38ff548b3e0 100644 --- a/spotbugsTestCases/src/java/sfBugs/Bug2136033.java +++ b/spotbugsTestCases/src/java/sfBugs/Bug2136033.java @@ -6,7 +6,7 @@ import java.io.IOException; import java.io.OutputStream; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * diff --git a/spotbugsTestCases/src/java/sfBugs/Bug2707502.java b/spotbugsTestCases/src/java/sfBugs/Bug2707502.java index ebbfa5f7d47..6d737b4ac22 100644 --- a/spotbugsTestCases/src/java/sfBugs/Bug2707502.java +++ b/spotbugsTestCases/src/java/sfBugs/Bug2707502.java @@ -1,13 +1,17 @@ package sfBugs; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; class Bug2707502 { - @Test(expected = NullPointerException.class) + @Test public int foo() { Object x = null; - return x.hashCode(); + Assertions.assertThrows(NullPointerException.class, () -> { + x.hashCode(); + }); + return -1; } } diff --git a/spotbugsTestCases/src/java/sfBugs/Bug3474679.java b/spotbugsTestCases/src/java/sfBugs/Bug3474679.java index 48bd803e479..4419087f051 100644 --- a/spotbugsTestCases/src/java/sfBugs/Bug3474679.java +++ b/spotbugsTestCases/src/java/sfBugs/Bug3474679.java @@ -2,7 +2,7 @@ import java.math.BigDecimal; -import org.junit.Test; +import org.junit.jupiter.api.Test; import edu.umd.cs.findbugs.annotations.ExpectWarning; import edu.umd.cs.findbugs.annotations.NoWarning; diff --git a/test-harness-jupiter/src/main/java/edu/umd/cs/findbugs/test/SpotBugsRunner.java b/test-harness-jupiter/src/main/java/edu/umd/cs/findbugs/test/SpotBugsRunner.java index e21f9961204..fb79de97fbf 100644 --- a/test-harness-jupiter/src/main/java/edu/umd/cs/findbugs/test/SpotBugsRunner.java +++ b/test-harness-jupiter/src/main/java/edu/umd/cs/findbugs/test/SpotBugsRunner.java @@ -1,9 +1,12 @@ package edu.umd.cs.findbugs.test; import java.nio.file.Path; +import java.util.function.Consumer; import javax.annotation.Nonnull; +import edu.umd.cs.findbugs.IFindBugsEngine; + import edu.umd.cs.findbugs.BugCollection; /** @@ -22,13 +25,15 @@ public class SpotBugsRunner { *

* Add an entry to aux classpath of SpotBugs analysis. *

+ * @param engineCustomization + * A customization of the engine to apply before running engine#execute * @param path * A path of the target class file or jar file. Non-null. * @return callee itself, so caller can chain another method in fluent interface. */ // TODO let users specify "groupId:artifactId:packaging:version:classifier" like Grape in Groovy @Nonnull - public SpotBugsRunner addAuxClasspathEntry(Path path) { + public SpotBugsRunner addAuxClasspathEntry(Consumer engineCustomization, Path path) { if (runner == null) { throw new IllegalStateException( "Please call this addAuxClasspathEntry() method in @Before method or test method"); @@ -41,16 +46,33 @@ public SpotBugsRunner addAuxClasspathEntry(Path path) { *

* Run SpotBugs under given condition, and return its result. *

+ * @param engineCustomization + * A customization of the engine to apply before running engine#execute * @param paths * Paths of target class files * @return a {@link BugCollection} which contains all detected bugs. */ // TODO let users specify SlashedClassName, then find its file path automatically @Nonnull - public BugCollection performAnalysis(Path... paths) { + public BugCollection performAnalysis(Consumer engineCustomization, Path... paths) { if (runner == null) { throw new IllegalStateException("Please call this performAnalysis() method in test method"); } - return runner.run(paths).getBugCollection(); + return runner.run(engineCustomization, paths).getBugCollection(); + } + + /** + *

+ * Run SpotBugs under given condition, and return its result. + *

+ * @param paths + * Paths of target class files + * @return a {@link BugCollection} which contains all detected bugs. + */ + // TODO let users specify SlashedClassName, then find its file path automatically + @Nonnull + public BugCollection performAnalysis(Path... paths) { + return performAnalysis(e -> { + }, paths); } } diff --git a/test-harness/build.gradle b/test-harness/build.gradle index 98f426629aa..3392c12cd57 100644 --- a/test-harness/build.gradle +++ b/test-harness/build.gradle @@ -3,7 +3,8 @@ apply from: "$rootDir/gradle/javadoc.gradle" apply from: "$rootDir/gradle/maven.gradle" dependencies { - compileOnly 'org.junit.vintage:junit-vintage-engine:5.10.0' + compileOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.0' + compileOnly 'org.hamcrest:hamcrest:2.2' testImplementation project(':spotbugs') api project(':test-harness-core') } @@ -15,8 +16,8 @@ java { publishing.publications.maven { pom { - name = 'JUnit 4 Test Harness for SpotBugs Plugin' - description = 'A test harness library for SpotBugs plugin developers to test on JUnit4' + name = 'JUnit 5 Test Harness for SpotBugs Plugin' + description = 'A test harness library for SpotBugs plugin developers to test on JUnit5' } } diff --git a/test-harness/src/main/java/edu/umd/cs/findbugs/test/CountMatcher.java b/test-harness/src/main/java/edu/umd/cs/findbugs/test/CountMatcher.java index 755091b1a46..d3d85ef8786 100644 --- a/test-harness/src/main/java/edu/umd/cs/findbugs/test/CountMatcher.java +++ b/test-harness/src/main/java/edu/umd/cs/findbugs/test/CountMatcher.java @@ -1,7 +1,6 @@ package edu.umd.cs.findbugs.test; import org.hamcrest.Description; -import org.hamcrest.Factory; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeMatcher; @@ -33,7 +32,6 @@ public CountMatcher(int count, Matcher matcher) { * How many times the {@code matcher} must match. * @return new matcher instance */ - @Factory public static Matcher> containsExactly(final int count, final Matcher matcher) { return new CountMatcher<>(count, matcher); } diff --git a/test-harness/src/main/java/edu/umd/cs/findbugs/test/SpotBugsRule.java b/test-harness/src/main/java/edu/umd/cs/findbugs/test/SpotBugsRule.java deleted file mode 100644 index b98048941af..00000000000 --- a/test-harness/src/main/java/edu/umd/cs/findbugs/test/SpotBugsRule.java +++ /dev/null @@ -1,110 +0,0 @@ -package edu.umd.cs.findbugs.test; - -import java.nio.file.Path; -import java.util.function.Consumer; - -import javax.annotation.Nonnull; -import javax.annotation.ParametersAreNonnullByDefault; - -import edu.umd.cs.findbugs.IFindBugsEngine; -import org.junit.rules.ExternalResource; - -import edu.umd.cs.findbugs.BugCollection; - -/** - *

- * A JUnit rule to execute integration test for SpotBugs. This is basically - * designed to help SpotBugs plugin developer to test their product. Basic usage: - *

- *

- * public class MyIntegrationTest {
- *     @Rule
- *     public SpotBugsRule spotbugs = new SpotBugsRule();
- *     @Test
- *     public void testIssuesAreFound() {
- *         Path path = Paths.get("target/classes/my/company/AnalyzedClass.class")
- *         BugCollection bugCollection = spotbugs.performAnalysis(path);
- *
- *         // There should only be exactly 1 issue of this type
- *         final BugInstanceMatcher bugTypeMatcher = new BugInstanceMatcherBuilder()
- *                 .bugType("NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE").build();
- *         assertThat(bugCollection, CountMatcher.containsExactly(1, bugTypeMatcher));
- *
- *         final BugInstanceMatcher bugInstanceMatcher = new BugInstanceMatcherBuilder()
- *                 .bugType("NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE")
- *                 .inClass("AnalyzedClass")
- *                 .atLine(25)
- *                 .build();
- *         assertThat(bugCollection, hasItem(bugInstanceMatcher));
- *     }
- * }
- * 
- * @since 3.1 - */ -@ParametersAreNonnullByDefault -public class SpotBugsRule extends ExternalResource { - private AnalysisRunner runner; - - @Override - protected void before() throws Throwable { - runner = new AnalysisRunner(); - } - - @Override - protected void after() { - runner = null; - } - - /** - *

- * Add an entry to aux classpath of SpotBugs analysis. - *

- * @param path - * A path of the target class file or jar file. Non-null. - * @return callee itself, so caller can chain another method in fluent interface. - */ - // TODO let users specify "groupId:artifactId:packaging:version:classifier" like Grape in Groovy - @Nonnull - public SpotBugsRule addAuxClasspathEntry(Path path) { - if (runner == null) { - throw new IllegalStateException( - "Please call this addAuxClasspathEntry() method in @Before method or test method"); - } - runner.addAuxClasspathEntry(path); - return this; - } - - /** - *

- * Run SpotBugs under given condition, and return its result. - *

- * @param engineCustomization - * A customization of the engine to apply before running engine#execute - * @param paths - * Paths of target class files - * @return a {@link BugCollection} which contains all detected bugs. - */ - // TODO let users specify SlashedClassName, then find its file path automatically - @Nonnull - public BugCollection performAnalysis(Consumer engineCustomization, Path... paths) { - if (runner == null) { - throw new IllegalStateException("Please call this performAnalysis() method in test method"); - } - return runner.run(engineCustomization, paths).getBugCollection(); - } - - /** - *

- * Run SpotBugs under given condition, and return its result. - *

- * @param paths - * Paths of target class files - * @return a {@link BugCollection} which contains all detected bugs. - */ - // TODO let users specify SlashedClassName, then find its file path automatically - @Nonnull - public BugCollection performAnalysis(Path... paths) { - return performAnalysis(e -> { - }, paths); - } -} diff --git a/test-harness/src/main/java/edu/umd/cs/findbugs/test/service/ClassFileLocator.java b/test-harness/src/main/java/edu/umd/cs/findbugs/test/service/ClassFileLocator.java index b7af870f777..5ffea6d8c77 100644 --- a/test-harness/src/main/java/edu/umd/cs/findbugs/test/service/ClassFileLocator.java +++ b/test-harness/src/main/java/edu/umd/cs/findbugs/test/service/ClassFileLocator.java @@ -17,8 +17,8 @@ */ package edu.umd.cs.findbugs.test.service; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; import java.net.URISyntaxException; import java.net.URL; @@ -38,7 +38,7 @@ public String getClassFilePath(String path) { return getFilenameFromUrl(url); } url = cl.getResource(path); - assertNotNull("No class found for the path = " + path, url); + assertNotNull(url, "No class found for the path = " + path); return getFilenameFromUrl(url); } @@ -52,14 +52,14 @@ public String getJspFilePath(String path) { url = cl.getResource("org/apache/jsp/" + generatedClassName + ".class"); } - assertNotNull("No jsp file found for the path = " + path, url); + assertNotNull(url, "No jsp file found for the path = " + path); return getFilenameFromUrl(url); } public String getJarFilePath(String path) { ClassLoader cl = getClass().getClassLoader(); URL url = cl.getResource(path); - assertNotNull("No jar found for the path = " + path, url); + assertNotNull(url, "No jar found for the path = " + path); return getFilenameFromUrl(url); } From b8c498cc05dced2c6f101c6e838aa32dca993d6c Mon Sep 17 00:00:00 2001 From: Jeremy Landis Date: Sat, 30 Sep 2023 22:39:46 -0400 Subject: [PATCH 12/19] release v4.8.0 --- CHANGELOG.md | 2 +- build.gradle | 2 +- docs/conf.py | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 25d57ee744b..294a6b69350 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ This is the changelog for SpotBugs. This follows [Keep a Changelog v1.0.0](http: Currently the versioning policy of this project follows [Semantic Versioning v2.0.0](http://semver.org/spec/v2.0.0.html). -## Unreleased 4.8.0 - 2023-??-?? +## 4.8.0 - 2023-10-11 ### Changed - Bump up Apache Commons BCEL to the version 6.6.1 ([#2223](https://github.com/spotbugs/spotbugs/pull/2223)) diff --git a/build.gradle b/build.gradle index aa2aba66334..defadc37781 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { } group = 'com.github.spotbugs' -version = '4.8.0-SNAPSHOT' +version = '4.8.0' apply from: "$rootDir/gradle/java.gradle" apply from: "$rootDir/gradle/jacoco.gradle" diff --git a/docs/conf.py b/docs/conf.py index 1df390fc516..a11c1865fb5 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -16,10 +16,10 @@ import os html_context = { - 'version' : '4.7', - 'full_version' : '4.7.3', - 'maven_plugin_version' : '4.7.2.1', - 'gradle_plugin_version' : '5.0.12', + 'version' : '4.8', + 'full_version' : '4.8.0', + 'maven_plugin_version' : '4.8.0.0', + 'gradle_plugin_version' : '6.0.0-beta.5', 'archetype_version' : '0.2.3' } From d5d5a87f900fd320083b733e44c80ef7eda7268b Mon Sep 17 00:00:00 2001 From: Jeremy Landis Date: Wed, 11 Oct 2023 21:29:09 -0400 Subject: [PATCH 13/19] prepare for next release --- CHANGELOG.md | 2 ++ build.gradle | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 294a6b69350..985045d703a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ This is the changelog for SpotBugs. This follows [Keep a Changelog v1.0.0](http: Currently the versioning policy of this project follows [Semantic Versioning v2.0.0](http://semver.org/spec/v2.0.0.html). +## Unreleased - 2022-??-?? + ## 4.8.0 - 2023-10-11 ### Changed diff --git a/build.gradle b/build.gradle index defadc37781..b95cfdf4c3a 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { } group = 'com.github.spotbugs' -version = '4.8.0' +version = '4.8.1-SNAPSHOT' apply from: "$rootDir/gradle/java.gradle" apply from: "$rootDir/gradle/jacoco.gradle" From 4f344965a808c09c3741df0c16c7f84afa9da816 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 12 Oct 2023 09:35:59 -0400 Subject: [PATCH 14/19] fix(deps): update dependency org.springframework:spring-core to v6.0.13 (#2626) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- spotbugsTestCases/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spotbugsTestCases/build.gradle b/spotbugsTestCases/build.gradle index 386b8b096e5..84765d9babf 100644 --- a/spotbugsTestCases/build.gradle +++ b/spotbugsTestCases/build.gradle @@ -24,7 +24,7 @@ dependencies { implementation 'com.google.truth:truth:1.1.5' implementation 'joda-time:joda-time:2.12.5' api 'com.github.stephenc.jcip:jcip-annotations:1.0-1' - implementation 'org.springframework:spring-core:6.0.12' + implementation 'org.springframework:spring-core:6.0.13' compileOnly 'jakarta.annotation:jakarta.annotation-api:1.3.5' implementation 'org.checkerframework:checker-qual:3.39.0' From 4b46444c2d7ae76f3ef65729d4891f9dcad19a43 Mon Sep 17 00:00:00 2001 From: NeetigyaPod <47060152+NeetigyaPod@users.noreply.github.com> Date: Fri, 13 Oct 2023 04:14:00 +0530 Subject: [PATCH 15/19] fix: Schema Location to a dead end (#2625) --- CHANGELOG.md | 3 +++ spotbugs/etc/findbugsfilter.xsd | 1 + 2 files changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 985045d703a..b44679217a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ Currently the versioning policy of this project follows [Semantic Versioning v2. ## Unreleased - 2022-??-?? +### Fixed +- Fixed schema location for findbugsfilter.xsd ([[#1416](https://github.com/spotbugs/spotbugs/issues/1416)]) + ## 4.8.0 - 2023-10-11 ### Changed diff --git a/spotbugs/etc/findbugsfilter.xsd b/spotbugs/etc/findbugsfilter.xsd index d7ecd1b56a8..af8286a6098 100644 --- a/spotbugs/etc/findbugsfilter.xsd +++ b/spotbugs/etc/findbugsfilter.xsd @@ -1,5 +1,6 @@ From 9400f3ce8a7355cc73bfe5f255ae482f93236dbe Mon Sep 17 00:00:00 2001 From: Judit Knoll <123470644+JuditKnoll@users.noreply.github.com> Date: Sun, 15 Oct 2023 01:31:13 +0200 Subject: [PATCH 16/19] Add missing null checks (#2630) * Fix missing null checks * add changelog entry --- CHANGELOG.md | 1 + .../cs/findbugs/detect/FindArgumentAssertions.java | 14 ++++++++------ .../detect/FindAssertionsWithSideEffects.java | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b44679217a1..86c85ab490e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ Currently the versioning policy of this project follows [Semantic Versioning v2. ### Fixed - Fixed schema location for findbugsfilter.xsd ([[#1416](https://github.com/spotbugs/spotbugs/issues/1416)]) +- Fixed missing null checks ([[#2629](https://github.com/spotbugs/spotbugs/issues/2629)]) ## 4.8.0 - 2023-10-11 diff --git a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindArgumentAssertions.java b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindArgumentAssertions.java index 1ac3cdaaf0c..cd8db31acd5 100644 --- a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindArgumentAssertions.java +++ b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindArgumentAssertions.java @@ -56,12 +56,14 @@ public void visitClassContext(ClassContext classContext) { */ private boolean isInitialArg() { XMethod m = getXMethodOperand(); - int numPar = m.getNumParams(); - // Get values from the stack - for (int i = 0; i < numPar; i++) { - Item item = stack.getStackItem(i); - if (item.isInitialParameter()) - return true; + if (m != null) { + int numPar = m.getNumParams(); + // Get values from the stack + for (int i = 0; i < numPar; i++) { + Item item = stack.getStackItem(i); + if (item.isInitialParameter()) + return true; + } } return false; } diff --git a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindAssertionsWithSideEffects.java b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindAssertionsWithSideEffects.java index 431baa46572..bf9ff39c295 100644 --- a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindAssertionsWithSideEffects.java +++ b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindAssertionsWithSideEffects.java @@ -61,7 +61,7 @@ private boolean checkSeen(int seen) { */ @Override protected void detect(int seen) { - if (isMethodCall(seen)) { + if (isMethodCall(seen) && getXClassOperand() != null && getXMethodOperand() != null) { String retSig = new SignatureParser(getXMethodOperand().getSignature()).getReturnTypeSignature(); String classSig = getXClassOperand().getSourceSignature(); if (MutableClasses.mutableSignature("L" + getClassConstantOperand() + ";") && From 6f981430c0fccbe76ce587fb6adcbbf3ffece2ed Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 15 Oct 2023 20:39:33 -0400 Subject: [PATCH 17/19] chore(deps): update plugin com.github.spotbugs to v6.0.0-beta.5 (#2635) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index b95cfdf4c3a..c19574b1901 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ plugins { id "org.sonarqube" version "4.4.1.3373" id "org.gradle.crypto.checksum" version "1.4.0" - id "com.github.spotbugs" version "6.0.0-beta.4" + id "com.github.spotbugs" version "6.0.0-beta.5" id "io.github.gradle-nexus.publish-plugin" version "1.3.0" } From 3db5c681bd42f0ec2db971065e35aab197a4f3c8 Mon Sep 17 00:00:00 2001 From: gtoison Date: Mon, 16 Oct 2023 07:38:33 +0200 Subject: [PATCH 18/19] Disabled DontReusePublicIdentifiers due to false positives rate Fixes #2627 --- CHANGELOG.md | 1 + spotbugs/etc/findbugs.xml | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 86c85ab490e..8a861e8e946 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ Currently the versioning policy of this project follows [Semantic Versioning v2. ### Fixed - Fixed schema location for findbugsfilter.xsd ([[#1416](https://github.com/spotbugs/spotbugs/issues/1416)]) - Fixed missing null checks ([[#2629](https://github.com/spotbugs/spotbugs/issues/2629)]) +- Disabled DontReusePublicIdentifiers due to the high false positives rate ([[#2627](https://github.com/spotbugs/spotbugs/issues/2627)]) ## 4.8.0 - 2023-10-11 diff --git a/spotbugs/etc/findbugs.xml b/spotbugs/etc/findbugs.xml index 494f914fc3d..7754486391e 100644 --- a/spotbugs/etc/findbugs.xml +++ b/spotbugs/etc/findbugs.xml @@ -680,7 +680,8 @@ + reports="PI_DO_NOT_REUSE_PUBLIC_IDENTIFIERS_CLASS_NAMES,PI_DO_NOT_REUSE_PUBLIC_IDENTIFIERS_FIELD_NAMES,PI_DO_NOT_REUSE_PUBLIC_IDENTIFIERS_METHOD_NAMES,PI_DO_NOT_REUSE_PUBLIC_IDENTIFIERS_LOCAL_VARIABLE_NAMES" + disabled="true"/>