Skip to content

Commit

Permalink
Merge pull request spotbugs#745 from hazendaz/thorough-cleanup
Browse files Browse the repository at this point in the history
Thorough cleanup of integration tests
  • Loading branch information
hazendaz authored Dec 31, 2023
2 parents 0d3f105 + f6be5bc commit 2906403
Show file tree
Hide file tree
Showing 71 changed files with 769 additions and 828 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@

/**
* Hello world!
*
*/
public class App implements Cloneable {

public static void main( String[] args ) {
System.out.println( "Hello World!" );
public static void main(String[] args) {
System.out.println("Hello World!");
}

public Object clone() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,13 @@
* Hello world!
*
*/
public class App implements Cloneable
{
public class App implements Cloneable {

public static void main( String[] args )
{
System.out.println( "Hello World!" );
public static void main(String[] args) {
System.out.println("Hello World!");
}

public Object clone()
{
public Object clone() {
return null; // Does not call 'super.clone()'.
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,21 @@ import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;

String[] paths =
{
"target/site/spotbugs.html",
"target/site/xref/index.html",
};
String[] paths = [ "target/site/spotbugs.html", "target/site/xref/index.html" ]

// Spotbugs and JXR reports
for ( String path : paths ) {
File file = new File( basedir, path );
System.out.println( "Checking for existence of " + file );
if ( !file.isFile() ) {
throw new FileNotFoundException( "Missing: " + file.getAbsolutePath() );
for (String path : paths) {
File file = new File(basedir, path)
System.out.println("Checking for existence of " + file)
if (!file.isFile()) {
throw new FileNotFoundException("Missing: " + file.getAbsolutePath())
}
}

File report = new File( basedir, "target/site/spotbugs.html" );
String content = new String(Files.readAllBytes(report.toPath()), StandardCharsets.UTF_8);
if ( content.indexOf( "<a href=\"./xref/org/codehaus/mojo/spotbugsmavenplugin/it/mfindbugs145/App.html#L32\">" ) < 0 ) {
throw new IOException( "XRef link not generated." );
File report = new File(basedir, "target/site/spotbugs.html")
String content = new String(Files.readAllBytes(report.toPath()), StandardCharsets.UTF_8)
if (content.indexOf("<a href=\"./xref/org/codehaus/mojo/spotbugsmavenplugin/it/mfindbugs145/App.html#L29\">") < 0) {
throw new IOException("XRef link not generated.")
}

return true;
return true
19 changes: 19 additions & 0 deletions src/it/MFINDBUGS-178/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright 2005-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Check no missing classes

File buildLog = new File(basedir, 'build.log')
assert buildLog.text.contains('Error size is 0')
35 changes: 16 additions & 19 deletions src/it/basic-1/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
* limitations under the License.
*/
import groovy.xml.XmlSlurper

String effortLevel = 'default'

import groovy.xml.slurpersupport.GPathResult;

File spotbugsHtml = new File(basedir, 'target/site/spotbugs.html')
assert spotbugsHtml.exists()
Expand All @@ -27,43 +25,42 @@ assert spotbugXdoc.exists()
File spotbugXml = new File(basedir, 'target/spotbugsXml.xml')
assert spotbugXml.exists()

println '******************'
println 'Checking HTML file'
println '******************'

println '***************************'
println "Checking HTML file"
println '***************************'
String effortLevel = 'default'

assert spotbugsHtml.text.contains( "<i>" + effortLevel + "</i>" )
assert spotbugsHtml.text.contains("<i>" + effortLevel + "</i>")

XmlSlurper xhtmlParser = new XmlSlurper();
xhtmlParser.setFeature("http://apache.org/xml/features/disallow-doctype-decl", false)
xhtmlParser.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false)
def path = xhtmlParser.parse( spotbugsHtml )

GPathResult path = xhtmlParser.parse(spotbugsHtml)
int spotbugsErrors = path.body.'**'.find {main -> main.@id == 'bodyColumn'}.section[1].table.tr[1].td[1].toInteger()
println "Error Count is ${spotbugsErrors}"


println '**********************************'
println "Checking Spotbugs Native XML file"
println '**********************************'
println '*********************************'
println 'Checking Spotbugs Native XML file'
println '*********************************'

path = new XmlSlurper().parse(spotbugXml)

allNodes = path.depthFirst().collect{ it }
def allNodes = path.depthFirst().collect{ it }
int spotbugsXmlErrors = allNodes.findAll {it.name() == 'BugInstance'}.size()
println "BugInstance size is ${spotbugsXmlErrors}"

assert spotbugsErrors == spotbugsXmlErrors

println '***************************'
println "Checking xDoc file"
println '***************************'
println '******************'
println 'Checking xDoc file'
println '******************'

path = new XmlSlurper().parse(spotbugXdoc)

allNodes = path.depthFirst().collect{ it }
int xdocErrors = allNodes.findAll {it.name() == 'BugInstance'}.size()
println "BugInstance size is ${xdocErrors}"


assert xdocErrors == spotbugsXmlErrors

assert spotbugsErrors == spotbugsXmlErrors
13 changes: 6 additions & 7 deletions src/it/change-xml-filename/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,19 @@
* limitations under the License.
*/
import groovy.xml.XmlSlurper
import groovy.xml.slurpersupport.GPathResult;

File spotbugXml = new File(basedir, 'target/findbugsXml.xml')
assert spotbugXml.exists()

println '*********************************'
println 'Checking Spotbugs Native XML file'
println '*********************************'

println '**********************************'
println "Checking Spotbugs Native XML file"
println '**********************************'
GPathResult path = new XmlSlurper().parse(spotbugXml)

path = new XmlSlurper().parse(spotbugXml)

allNodes = path.depthFirst().collect{ it }
def allNodes = path.depthFirst().collect{ it }
int spotbugsXmlErrors = allNodes.findAll {it.name() == 'BugInstance'}.size()
println "BugInstance size is ${spotbugsXmlErrors}"


assert spotbugsXmlErrors > 0
15 changes: 8 additions & 7 deletions src/it/check-bug-file-multi-list/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/
import groovy.xml.XmlSlurper
import groovy.xml.slurpersupport.GPathResult;

File spotbugXdoc = new File(basedir, 'target/spotbugs.xml')
assert spotbugXdoc.exists()
Expand All @@ -22,19 +23,20 @@ File spotbugXml = new File(basedir, 'target/spotbugsXml.xml')
assert spotbugXml.exists()

println '**********************************'
println "Checking Spotbugs Native XML file"
println 'Checking Spotbugs Native XML file '
println '**********************************'

path = new XmlSlurper().parse(spotbugXml)
GPathResult path = new XmlSlurper().parse(spotbugXml)

allNodes = path.depthFirst().collect{ it }
def allNodes = path.depthFirst().collect{ it }
int spotbugsXmlErrors = allNodes.findAll {it.name() == 'BugInstance'}.size()
println "BugInstance size is ${spotbugsXmlErrors}"

assert spotbugsXmlErrors == 0

println '***************************'
println "Checking xDoc file"
println '***************************'
println '******************'
println 'Checking xDoc file'
println '******************'

path = new XmlSlurper().parse(spotbugXdoc)

Expand All @@ -43,4 +45,3 @@ int xdocErrors = allNodes.findAll {it.name() == 'BugInstance'}.size()
println "BugInstance size is ${xdocErrors}"

assert xdocErrors == 0
assert spotbugsXmlErrors == 0
19 changes: 10 additions & 9 deletions src/it/check-bug-file-multi/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,29 @@
* limitations under the License.
*/
import groovy.xml.XmlSlurper
import groovy.xml.slurpersupport.GPathResult;

File spotbugXdoc = new File(basedir, 'target/spotbugs.xml')
assert spotbugXdoc.exists()

File spotbugXml = new File(basedir, 'target/spotbugsXml.xml')
assert spotbugXml.exists()

println '**********************************'
println "Checking Spotbugs Native XML file"
println '**********************************'
println '*********************************'
println 'Checking Spotbugs Native XML file'
println '*********************************'

path = new XmlSlurper().parse(spotbugXml)
GPathResult path = new XmlSlurper().parse(spotbugXml)

allNodes = path.depthFirst().collect{ it }
def allNodes = path.depthFirst().collect{ it }
int spotbugsXmlErrors = allNodes.findAll {it.name() == 'BugInstance'}.size()
println "BugInstance size is ${spotbugsXmlErrors}"

assert spotbugsXmlErrors == 0

println '***************************'
println "Checking xDoc file"
println '***************************'
println '******************'
println 'Checking xDoc file'
println '******************'

path = new XmlSlurper().parse(spotbugXdoc)

Expand All @@ -43,4 +45,3 @@ int xdocErrors = allNodes.findAll {it.name() == 'BugInstance'}.size()
println "BugInstance size is ${xdocErrors}"

assert xdocErrors == 0
assert spotbugsXmlErrors == 0
19 changes: 10 additions & 9 deletions src/it/check-bug-file/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,29 @@
* limitations under the License.
*/
import groovy.xml.XmlSlurper
import groovy.xml.slurpersupport.GPathResult;

File spotbugXdoc = new File(basedir, 'target/spotbugs.xml')
assert spotbugXdoc.exists()

File spotbugXml = new File(basedir, 'target/spotbugsXml.xml')
assert spotbugXml.exists()

println '**********************************'
println "Checking Spotbugs Native XML file"
println '**********************************'
println '*********************************'
println 'Checking Spotbugs Native XML file'
println '*********************************'

path = new XmlSlurper().parse(spotbugXml)
GPathResult path = new XmlSlurper().parse(spotbugXml)

allNodes = path.depthFirst().collect{ it }
def allNodes = path.depthFirst().collect{ it }
int spotbugsXmlErrors = allNodes.findAll {it.name() == 'BugInstance'}.size()
println "BugInstance size is ${spotbugsXmlErrors}"

assert spotbugsXmlErrors == 0

println '***************************'
println "Checking xDoc file"
println '***************************'
println '******************'
println 'Checking xDoc file'
println '******************'

path = new XmlSlurper().parse(spotbugXdoc)

Expand All @@ -43,4 +45,3 @@ int xdocErrors = allNodes.findAll {it.name() == 'BugInstance'}.size()
println "BugInstance size is ${xdocErrors}"

assert xdocErrors == 0
assert spotbugsXmlErrors == 0
4 changes: 2 additions & 2 deletions src/it/check-bug-only-test-sources/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
File buildLog = new File( basedir, 'build.log' )
assert buildLog.text.contains( 'BugInstance size is 2' )
File buildLog = new File(basedir, 'build.log')
assert buildLog.text.contains('BugInstance size is 2')
4 changes: 2 additions & 2 deletions src/it/check-fail/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
File buildLog = new File( basedir, 'build.log' )
assert buildLog.text.contains( '[ERROR] High: Found reliance on default encoding in UserMistakes' )
File buildLog = new File(basedir, 'build.log')
assert buildLog.text.contains('[ERROR] High: Found reliance on default encoding in UserMistakes')
6 changes: 3 additions & 3 deletions src/it/check-failThreshold/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
File buildLog = new File( basedir, 'build.log' )
assert buildLog.text.contains( '[INFO] Medium: Unused public or protected field:' )
assert buildLog.text.contains( '[ERROR] High: Found reliance on default encoding in UserMistakes' )
File buildLog = new File(basedir, 'build.log')
assert buildLog.text.contains('[INFO] Medium: Unused public or protected field:')
assert buildLog.text.contains('[ERROR] High: Found reliance on default encoding in UserMistakes')
22 changes: 11 additions & 11 deletions src/it/check-jvmargs/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,31 @@
* limitations under the License.
*/
import groovy.xml.XmlSlurper
import groovy.xml.slurpersupport.GPathResult;

File spotbugXdoc = new File(basedir, 'target/spotbugs.xml')
assert spotbugXdoc.exists()

File spotbugXml = new File(basedir, 'target/spotbugsXml.xml')
assert spotbugXml.exists()

println '*********************************'
println 'Checking Spotbugs Native XML file'
println '*********************************'

println '**********************************'
println "Checking Spotbugs Native XML file"
println '**********************************'
GPathResult path = new XmlSlurper().parse(spotbugXml)

path = new XmlSlurper().parse(spotbugXml)

allNodes = path.depthFirst().collect{ it }
def allNodes = path.depthFirst().collect{ it }
int spotbugsXmlErrors = allNodes.findAll {it.name() == 'BugInstance'}.size()
println "BugInstance size is ${spotbugsXmlErrors}"

println '***************************'
println "Checking xDoc file"
println '***************************'
println '******************'
println 'Checking xDoc file'
println '******************'

def path = new XmlSlurper().parse(spotbugXdoc)
path = new XmlSlurper().parse(spotbugXdoc)

def allNodes = path.depthFirst().collect{ it }
allNodes = path.depthFirst().collect{ it }
int xdocErrors = allNodes.findAll {it.name() == 'BugInstance'}.size()
println "BugInstance size is ${xdocErrors}"

Expand Down
6 changes: 2 additions & 4 deletions src/it/check-multi-filter-dups/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@
*/
// check module 1

File spotbugXmlInModule = new File(basedir, "module1/src/main/config/spotbugs-exclude-filters.xml")
File spotbugXmlInModule = new File(basedir, 'module1/src/main/config/spotbugs-exclude-filters.xml')
assert !spotbugXmlInModule.exists()


// check module 2

spotbugXmlInModule = new File(basedir, "module2/src/main/config/spotbugs-exclude-filters.xml")
spotbugXmlInModule = new File(basedir, 'module2/src/main/config/spotbugs-exclude-filters.xml')
assert !spotbugXmlInModule.exists()

Loading

0 comments on commit 2906403

Please sign in to comment.