This is an automated email from the ASF dual-hosted git repository. slachiewicz pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/maven-verifier-plugin.git
commit 5d8ee0dbcfcae42538294e9d17f12c2d757d0fdd Author: Gerd Aschemann <g...@aschemann.net> AuthorDate: Sun Jan 12 14:49:39 2025 +0100 Clean up code with `spotless:apply` which leads to many changes ( Cf. support-and-care/maven-support-and-care#77) --- pom.xml | 24 +- .../verifier/ConsoleVerificationResultPrinter.java | 50 +++-- .../maven/plugins/verifier/VerificationResult.java | 59 +++-- .../verifier/VerificationResultPrinter.java | 25 ++- .../maven/plugins/verifier/VerifierMojo.java | 161 +++++++------- .../maven/plugins/verifier/VerifierMojoTest.java | 245 ++++++++++----------- 6 files changed, 285 insertions(+), 279 deletions(-) diff --git a/pom.xml b/pom.xml index 456ca01..dbed82c 100644 --- a/pom.xml +++ b/pom.xml @@ -1,5 +1,4 @@ -<?xml version='1.0' encoding='UTF-8'?> - +<?xml version="1.0" encoding="UTF-8"?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file @@ -18,13 +17,12 @@ KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> - <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> - <artifactId>maven-plugins</artifactId> <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-plugins</artifactId> <version>43</version> </parent> @@ -42,8 +40,8 @@ under the License. <scm> <connection>scm:git:https://gitbox.apache.org/repos/asf/maven-verifier-plugin.git</connection> <developerConnection>scm:git:https://gitbox.apache.org/repos/asf/maven-verifier-plugin.git</developerConnection> - <url>https://github.com/apache/maven-verifier-plugin/tree/${project.scm.tag}</url> <tag>HEAD</tag> + <url>https://github.com/apache/maven-verifier-plugin/tree/${project.scm.tag}</url> </scm> <issueManagement> <system>JIRA</system> @@ -98,13 +96,19 @@ under the License. <plugin> <groupId>org.codehaus.modello</groupId> <artifactId>modello-maven-plugin</artifactId> + <configuration> + <models> + <model>src/main/mdo/verifications.mdo</model> + </models> + <version>1.0.0</version> + </configuration> <executions> <execution> <id>generate-xsd-site</id> - <phase>pre-site</phase> <goals> <goal>xsd</goal> </goals> + <phase>pre-site</phase> <configuration> <outputDirectory>${project.reporting.outputDirectory}/xsd</outputDirectory> </configuration> @@ -119,18 +123,12 @@ under the License. </execution> <execution> <id>site-docs</id> - <phase>pre-site</phase> <goals> <goal>xdoc</goal> </goals> + <phase>pre-site</phase> </execution> </executions> - <configuration> - <models> - <model>src/main/mdo/verifications.mdo</model> - </models> - <version>1.0.0</version> - </configuration> </plugin> </plugins> </build> diff --git a/src/main/java/org/apache/maven/plugins/verifier/ConsoleVerificationResultPrinter.java b/src/main/java/org/apache/maven/plugins/verifier/ConsoleVerificationResultPrinter.java index 90d20b5..ffb8a3f 100644 --- a/src/main/java/org/apache/maven/plugins/verifier/ConsoleVerificationResultPrinter.java +++ b/src/main/java/org/apache/maven/plugins/verifier/ConsoleVerificationResultPrinter.java @@ -1,3 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 + * + * http://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. + */ package org.apache.maven.plugins.verifier; /* @@ -23,44 +41,36 @@ import org.apache.maven.plugin.logging.Log; import org.apache.maven.plugins.verifier.model.File; /** - * + * */ -public class ConsoleVerificationResultPrinter - implements VerificationResultPrinter -{ +public class ConsoleVerificationResultPrinter implements VerificationResultPrinter { private Log log; /** * @param log {@link Log} */ - public ConsoleVerificationResultPrinter( Log log ) - { + public ConsoleVerificationResultPrinter(Log log) { this.log = log; } /** * {@inheritDoc} */ - public void print( VerificationResult results ) - { - for ( File file : results.getExistenceFailures() ) - { - printMessage( "File not found [" + file.getLocation() + "]" ); + public void print(VerificationResult results) { + for (File file : results.getExistenceFailures()) { + printMessage("File not found [" + file.getLocation() + "]"); } - for ( File file : results.getNonExistenceFailures() ) - { - printMessage( "File should not exist [" + file.getLocation() + "]" ); + for (File file : results.getNonExistenceFailures()) { + printMessage("File should not exist [" + file.getLocation() + "]"); } - for ( File file : results.getContentFailures() ) - { - printMessage( "File [" + file.getLocation() + "] does not match regexp [" + file.getContains() + "]" ); + for (File file : results.getContentFailures()) { + printMessage("File [" + file.getLocation() + "] does not match regexp [" + file.getContains() + "]"); } } - private void printMessage( String message ) - { - this.log.error( "[Verifier] " + message ); + private void printMessage(String message) { + this.log.error("[Verifier] " + message); } } diff --git a/src/main/java/org/apache/maven/plugins/verifier/VerificationResult.java b/src/main/java/org/apache/maven/plugins/verifier/VerificationResult.java index 111468b..c05866a 100644 --- a/src/main/java/org/apache/maven/plugins/verifier/VerificationResult.java +++ b/src/main/java/org/apache/maven/plugins/verifier/VerificationResult.java @@ -1,3 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 + * + * http://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. + */ package org.apache.maven.plugins.verifier; /* @@ -25,10 +43,9 @@ import java.util.List; import org.apache.maven.plugins.verifier.model.File; /** - * + * */ -public class VerificationResult -{ +public class VerificationResult { private List<File> existenceFailures = new ArrayList<>(); private List<File> nonExistenceFailures = new ArrayList<>(); @@ -38,61 +55,55 @@ public class VerificationResult /** * @param file {@link File} */ - public void addExistenceFailure( File file ) - { - existenceFailures.add( file ); + public void addExistenceFailure(File file) { + existenceFailures.add(file); } /** * Added non existence failure. - * + * * @param file {@link File} */ - public void addNonExistenceFailure( File file ) - { - nonExistenceFailures.add( file ); + public void addNonExistenceFailure(File file) { + nonExistenceFailures.add(file); } /** * Add content failure. - * + * * @param file {@link File} */ - public void addContentFailure( File file ) - { - contentFailures.add( file ); + public void addContentFailure(File file) { + contentFailures.add(file); } /** * @return {@link #existenceFailures} */ - public List<File> getExistenceFailures() - { + public List<File> getExistenceFailures() { return existenceFailures; } /** * @return {@link #nonExistenceFailures} */ - public List<File> getNonExistenceFailures() - { + public List<File> getNonExistenceFailures() { return nonExistenceFailures; } /** * @return {@link #contentFailures} */ - public List<File> getContentFailures() - { + public List<File> getContentFailures() { return contentFailures; } /** * @return true if a failures exists false otherwise. */ - public boolean hasFailures() - { - return !getExistenceFailures().isEmpty() || !getNonExistenceFailures().isEmpty() - || !getContentFailures().isEmpty(); + public boolean hasFailures() { + return !getExistenceFailures().isEmpty() + || !getNonExistenceFailures().isEmpty() + || !getContentFailures().isEmpty(); } } diff --git a/src/main/java/org/apache/maven/plugins/verifier/VerificationResultPrinter.java b/src/main/java/org/apache/maven/plugins/verifier/VerificationResultPrinter.java index 13d5db1..920d4ce 100644 --- a/src/main/java/org/apache/maven/plugins/verifier/VerificationResultPrinter.java +++ b/src/main/java/org/apache/maven/plugins/verifier/VerificationResultPrinter.java @@ -1,3 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 + * + * http://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. + */ package org.apache.maven.plugins.verifier; /* @@ -20,12 +38,11 @@ package org.apache.maven.plugins.verifier; */ /** - * + * */ -public interface VerificationResultPrinter -{ +public interface VerificationResultPrinter { /** * @param result {@link VerificationResult} */ - void print( VerificationResult result ); + void print(VerificationResult result); } diff --git a/src/main/java/org/apache/maven/plugins/verifier/VerifierMojo.java b/src/main/java/org/apache/maven/plugins/verifier/VerifierMojo.java index 27b3951..0190a21 100644 --- a/src/main/java/org/apache/maven/plugins/verifier/VerifierMojo.java +++ b/src/main/java/org/apache/maven/plugins/verifier/VerifierMojo.java @@ -1,3 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 + * + * http://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. + */ package org.apache.maven.plugins.verifier; /* @@ -25,6 +43,7 @@ import java.io.IOException; import java.io.Reader; import java.util.regex.Matcher; import java.util.regex.Pattern; + import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.LifecyclePhase; @@ -41,44 +60,41 @@ import org.codehaus.plexus.util.xml.pull.XmlPullParserException; * * @author <a href="vmas...@apache.org">Vincent Massol</a> */ -@Mojo( name = "verify", defaultPhase = LifecyclePhase.INTEGRATION_TEST ) -public class VerifierMojo - extends AbstractMojo -{ +@Mojo(name = "verify", defaultPhase = LifecyclePhase.INTEGRATION_TEST) +public class VerifierMojo extends AbstractMojo { /** * Project base directory (prepended to relative file paths). */ - @Parameter( property = "basedir", required = true ) + @Parameter(property = "basedir", required = true) private File basedir; /** * The file containing the verifications to perform. */ - @Parameter( property = "verifier.verificationFile", defaultValue = "${basedir}/src/test/verifier/verifications.xml", - required = true ) + @Parameter( + property = "verifier.verificationFile", + defaultValue = "${basedir}/src/test/verifier/verifications.xml", + required = true) private File verificationFile; /** * Whether the build will fail on verification errors. */ - @Parameter( property = "verifier.failOnError", defaultValue = "true", required = true ) + @Parameter(property = "verifier.failOnError", defaultValue = "true", required = true) private boolean failOnError; - private VerificationResultPrinter resultPrinter = new ConsoleVerificationResultPrinter( getLog() ); + private VerificationResultPrinter resultPrinter = new ConsoleVerificationResultPrinter(getLog()); /** * {@inheritDoc} */ - public void execute() - throws MojoExecutionException - { + public void execute() throws MojoExecutionException { VerificationResult results = verify(); - resultPrinter.print( results ); + resultPrinter.print(results); // Fail the build if there are errors - if ( this.failOnError && results.hasFailures() ) - { - throw new MojoExecutionException( "There are test failures" ); + if (this.failOnError && results.hasFailures()) { + throw new MojoExecutionException("There are test failures"); } } @@ -87,111 +103,88 @@ public class VerifierMojo * the project's basedir will be prefixed. * @return the absolute file path of the file to check */ - protected File getAbsoluteFileToCheck( File file ) - { + protected File getAbsoluteFileToCheck(File file) { File result = file; - if ( !file.isAbsolute() ) - { - result = new File( basedir, file.getPath() ); + if (!file.isAbsolute()) { + result = new File(basedir, file.getPath()); } return result; } - private VerificationResult verify() - throws MojoExecutionException - { + private VerificationResult verify() throws MojoExecutionException { VerificationResult results = new VerificationResult(); - try ( Reader reader = new FileReader( verificationFile ) ) - { + try (Reader reader = new FileReader(verificationFile)) { VerificationsXpp3Reader xppReader = new VerificationsXpp3Reader(); - Verifications verifications = xppReader.read( reader ); + Verifications verifications = xppReader.read(reader); - for ( org.apache.maven.plugins.verifier.model.File file : verifications.getFiles() ) - { + for (org.apache.maven.plugins.verifier.model.File file : verifications.getFiles()) { // Transform the file to check into an absolute path prefixing the basedir if // the location is relative - if ( file.getLocation() != null ) - { - file.setLocation( getAbsoluteFileToCheck( new File( file.getLocation() ) ).getPath() ); - verifyFile( file, results ); - } - else - { - throw new MojoExecutionException( "Missing <location> element" ); + if (file.getLocation() != null) { + file.setLocation( + getAbsoluteFileToCheck(new File(file.getLocation())).getPath()); + verifyFile(file, results); + } else { + throw new MojoExecutionException("Missing <location> element"); } } - } - catch ( XmlPullParserException | IOException e ) - { - throw new MojoExecutionException( "Error while verifying files", e ); + } catch (XmlPullParserException | IOException e) { + throw new MojoExecutionException("Error while verifying files", e); } return results; } - private boolean verifyFile( org.apache.maven.plugins.verifier.model.File fileCheck, VerificationResult results ) - throws IOException - { + private boolean verifyFile(org.apache.maven.plugins.verifier.model.File fileCheck, VerificationResult results) + throws IOException { boolean result; - result = verifyFileExistence( fileCheck, results ); - if ( result && fileCheck.getContains() != null ) - { - result = result && verifyFileContent( fileCheck, results ); + result = verifyFileExistence(fileCheck, results); + if (result && fileCheck.getContains() != null) { + result = result && verifyFileContent(fileCheck, results); } return result; } - private boolean verifyFileContent( org.apache.maven.plugins.verifier.model.File fileCheck, - VerificationResult results ) - throws IOException - { + private boolean verifyFileContent( + org.apache.maven.plugins.verifier.model.File fileCheck, VerificationResult results) throws IOException { boolean result = false; - getLog().debug( "Verifying contents of " + fileCheck.getLocation() ); + getLog().debug("Verifying contents of " + fileCheck.getLocation()); - Pattern pattern = Pattern.compile( fileCheck.getContains() ); + Pattern pattern = Pattern.compile(fileCheck.getContains()); // Note: Very inefficient way as we load the whole file in memory. If you have a better // idea, please submit it! - Matcher matcher = pattern.matcher( FileUtils.fileRead( new File( fileCheck.getLocation() ) ) ); + Matcher matcher = pattern.matcher(FileUtils.fileRead(new File(fileCheck.getLocation()))); - if ( matcher.find() ) - { + if (matcher.find()) { result = true; - } - else - { - results.addContentFailure( fileCheck ); + } else { + results.addContentFailure(fileCheck); } return result; } - private boolean verifyFileExistence( org.apache.maven.plugins.verifier.model.File fileCheck, - VerificationResult results ) - { + private boolean verifyFileExistence( + org.apache.maven.plugins.verifier.model.File fileCheck, VerificationResult results) { boolean result; - File physicalFile = new File( fileCheck.getLocation() ); - if ( fileCheck.isExists() ) - { - getLog().debug( "Verifying existence of " + physicalFile ); + File physicalFile = new File(fileCheck.getLocation()); + if (fileCheck.isExists()) { + getLog().debug("Verifying existence of " + physicalFile); result = physicalFile.exists(); - if ( !result ) - { - results.addExistenceFailure( fileCheck ); + if (!result) { + results.addExistenceFailure(fileCheck); } - } - else - { - getLog().debug( "Verifying absence of " + physicalFile ); + } else { + getLog().debug("Verifying absence of " + physicalFile); result = !physicalFile.exists(); - if ( !result ) - { - results.addNonExistenceFailure( fileCheck ); + if (!result) { + results.addNonExistenceFailure(fileCheck); } } @@ -201,32 +194,28 @@ public class VerifierMojo /** * @param theBasedir Set the base directory. */ - public void setBaseDir( File theBasedir ) - { + public void setBaseDir(File theBasedir) { this.basedir = theBasedir; } /** * @param file Set the file for verification. */ - public void setVerificationFile( File file ) - { + public void setVerificationFile(File file) { this.verificationFile = file; } /** * @param printer The verification result printer {@link VerificationResultPrinter} */ - public void setVerificationResultPrinter( VerificationResultPrinter printer ) - { + public void setVerificationResultPrinter(VerificationResultPrinter printer) { this.resultPrinter = printer; } /** * @param failOnError true to fail on error false otherwise. */ - public void setFailOnError( boolean failOnError ) - { + public void setFailOnError(boolean failOnError) { this.failOnError = failOnError; } } diff --git a/src/test/java/org/apache/maven/plugins/verifier/VerifierMojoTest.java b/src/test/java/org/apache/maven/plugins/verifier/VerifierMojoTest.java index 0129ee3..c023bfe 100644 --- a/src/test/java/org/apache/maven/plugins/verifier/VerifierMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/verifier/VerifierMojoTest.java @@ -1,3 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 + * + * http://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. + */ package org.apache.maven.plugins.verifier; /* @@ -19,201 +37,164 @@ package org.apache.maven.plugins.verifier; * under the License. */ -import org.apache.maven.plugin.MojoExecutionException; -import org.junit.Test; - import java.io.File; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.nio.charset.StandardCharsets; +import org.apache.maven.plugin.MojoExecutionException; +import org.junit.Test; + import static org.junit.Assert.*; -public class VerifierMojoTest -{ - private File getResourceFile( String name ) throws UnsupportedEncodingException - { - String file = getClass().getResource( name ).getFile(); - String decode = URLDecoder.decode( file, StandardCharsets.UTF_8.toString() ); // necessary for JDK 1.5+, where spaces are escaped to %20 - return new File( decode ); +public class VerifierMojoTest { + private File getResourceFile(String name) throws UnsupportedEncodingException { + String file = getClass().getResource(name).getFile(); + String decode = URLDecoder.decode( + file, StandardCharsets.UTF_8.toString()); // necessary for JDK 1.5+, where spaces are escaped to %20 + return new File(decode); } @Test - public void testPrefixWithBaseDir() - { + public void testPrefixWithBaseDir() { VerifierMojo mojo = new VerifierMojo(); - mojo.setBaseDir( new File( "c:/some/path" ) ); + mojo.setBaseDir(new File("c:/some/path")); - File result = mojo.getAbsoluteFileToCheck( new File( "target/dummy.txt" ) ); + File result = mojo.getAbsoluteFileToCheck(new File("target/dummy.txt")); - File expectedResult = new File( "c:/some/path/target/dummy.txt" ); - assertEquals( expectedResult.getPath(), result.getPath() ); + File expectedResult = new File("c:/some/path/target/dummy.txt"); + assertEquals(expectedResult.getPath(), result.getPath()); } @Test - public void testDoNotPrefixWhenAbsolutePath() - { + public void testDoNotPrefixWhenAbsolutePath() { VerifierMojo mojo = new VerifierMojo(); - mojo.setBaseDir( new File( "/some/path" ).getAbsoluteFile() ); + mojo.setBaseDir(new File("/some/path").getAbsoluteFile()); - File absoluteFile = new File( "/project/target/dummy.txt" ).getAbsoluteFile(); - File result = mojo.getAbsoluteFileToCheck( absoluteFile ); + File absoluteFile = new File("/project/target/dummy.txt").getAbsoluteFile(); + File result = mojo.getAbsoluteFileToCheck(absoluteFile); - assertEquals( absoluteFile.getPath(), result.getPath() ); + assertEquals(absoluteFile.getPath(), result.getPath()); } @Test - public void testCheckFileThatDoesNotExist() - throws Exception - { + public void testCheckFileThatDoesNotExist() throws Exception { VerifierMojo mojo = new VerifierMojo(); - File file = getResourceFile( "/FileDoesNotExist.xml" ); - mojo.setBaseDir( new File( "c:/some/path" ) ); - mojo.setVerificationFile( file ); - mojo.setFailOnError( true ); - mojo.setVerificationResultPrinter( new VerificationResultPrinter() - { - public void print( VerificationResult result ) - { - assertEquals( 1, result.getExistenceFailures().size() ); - assertEquals( 0, result.getNonExistenceFailures().size() ); - assertEquals( 0, result.getContentFailures().size() ); + File file = getResourceFile("/FileDoesNotExist.xml"); + mojo.setBaseDir(new File("c:/some/path")); + mojo.setVerificationFile(file); + mojo.setFailOnError(true); + mojo.setVerificationResultPrinter(new VerificationResultPrinter() { + public void print(VerificationResult result) { + assertEquals(1, result.getExistenceFailures().size()); + assertEquals(0, result.getNonExistenceFailures().size()); + assertEquals(0, result.getContentFailures().size()); } - } ); + }); - try - { + try { mojo.execute(); - fail( "Should have thrown an exception" ); - } - catch ( MojoExecutionException expected ) - { - assertTrue( true ); + fail("Should have thrown an exception"); + } catch (MojoExecutionException expected) { + assertTrue(true); } } @Test - public void testCheckFileThatExists() - throws Exception - { + public void testCheckFileThatExists() throws Exception { VerifierMojo mojo = new VerifierMojo(); - File file = getResourceFile( "/File Exists.xml" ); - mojo.setBaseDir( file.getParentFile() ); - mojo.setVerificationFile( file ); - mojo.setFailOnError( true ); - mojo.setVerificationResultPrinter( new VerificationResultPrinter() - { - public void print( VerificationResult result ) - { - assertEquals( 0, result.getExistenceFailures().size() ); - assertEquals( 0, result.getNonExistenceFailures().size() ); - assertEquals( 0, result.getContentFailures().size() ); + File file = getResourceFile("/File Exists.xml"); + mojo.setBaseDir(file.getParentFile()); + mojo.setVerificationFile(file); + mojo.setFailOnError(true); + mojo.setVerificationResultPrinter(new VerificationResultPrinter() { + public void print(VerificationResult result) { + assertEquals(0, result.getExistenceFailures().size()); + assertEquals(0, result.getNonExistenceFailures().size()); + assertEquals(0, result.getContentFailures().size()); } - } ); + }); mojo.execute(); } @Test - public void testCheckForInexistentFile() - throws Exception - { + public void testCheckForInexistentFile() throws Exception { VerifierMojo mojo = new VerifierMojo(); - File file = getResourceFile( "/InexistentFile.xml" ); - mojo.setBaseDir( new File( "c:/some/path" ) ); - mojo.setVerificationFile( file ); - mojo.setVerificationResultPrinter( new VerificationResultPrinter() - { - public void print( VerificationResult result ) - { - assertEquals( 0, result.getExistenceFailures().size() ); - assertEquals( 0, result.getNonExistenceFailures().size() ); - assertEquals( 0, result.getContentFailures().size() ); + File file = getResourceFile("/InexistentFile.xml"); + mojo.setBaseDir(new File("c:/some/path")); + mojo.setVerificationFile(file); + mojo.setVerificationResultPrinter(new VerificationResultPrinter() { + public void print(VerificationResult result) { + assertEquals(0, result.getExistenceFailures().size()); + assertEquals(0, result.getNonExistenceFailures().size()); + assertEquals(0, result.getContentFailures().size()); } - } ); + }); mojo.execute(); } @Test - public void testCheckForInexistentFileThatExists() - throws Exception - { + public void testCheckForInexistentFileThatExists() throws Exception { VerifierMojo mojo = new VerifierMojo(); - File file = getResourceFile( "/InexistentFileThatExists.xml" ); - mojo.setBaseDir( file.getParentFile() ); - mojo.setVerificationFile( file ); - mojo.setFailOnError( true ); - mojo.setVerificationResultPrinter( new VerificationResultPrinter() - { - public void print( VerificationResult result ) - { - assertEquals( 0, result.getExistenceFailures().size() ); - assertEquals( 1, result.getNonExistenceFailures().size() ); - assertEquals( 0, result.getContentFailures().size() ); + File file = getResourceFile("/InexistentFileThatExists.xml"); + mojo.setBaseDir(file.getParentFile()); + mojo.setVerificationFile(file); + mojo.setFailOnError(true); + mojo.setVerificationResultPrinter(new VerificationResultPrinter() { + public void print(VerificationResult result) { + assertEquals(0, result.getExistenceFailures().size()); + assertEquals(1, result.getNonExistenceFailures().size()); + assertEquals(0, result.getContentFailures().size()); } - } ); + }); - try - { + try { mojo.execute(); - fail( "Should have thrown an exception" ); - } - catch ( MojoExecutionException expected ) - { - assertTrue( true ); + fail("Should have thrown an exception"); + } catch (MojoExecutionException expected) { + assertTrue(true); } } @Test - public void testCheckFileForContent() - throws Exception - { + public void testCheckFileForContent() throws Exception { VerifierMojo mojo = new VerifierMojo(); - File file = getResourceFile( "/FileExistsValidContent.xml" ); - mojo.setBaseDir( file.getParentFile() ); - mojo.setVerificationFile( file ); - mojo.setVerificationResultPrinter( new VerificationResultPrinter() - { - public void print( VerificationResult result ) - { - assertEquals( 0, result.getExistenceFailures().size() ); - assertEquals( 0, result.getNonExistenceFailures().size() ); - assertEquals( 0, result.getContentFailures().size() ); + File file = getResourceFile("/FileExistsValidContent.xml"); + mojo.setBaseDir(file.getParentFile()); + mojo.setVerificationFile(file); + mojo.setVerificationResultPrinter(new VerificationResultPrinter() { + public void print(VerificationResult result) { + assertEquals(0, result.getExistenceFailures().size()); + assertEquals(0, result.getNonExistenceFailures().size()); + assertEquals(0, result.getContentFailures().size()); } - } ); + }); mojo.execute(); } @Test - public void testCheckFileForInvalidContent() - throws Exception - { + public void testCheckFileForInvalidContent() throws Exception { VerifierMojo mojo = new VerifierMojo(); - File file = getResourceFile( "/FileExistsInvalidContent.xml" ); - mojo.setBaseDir( file.getParentFile() ); - mojo.setVerificationFile( file ); - mojo.setFailOnError( true ); - mojo.setVerificationResultPrinter( new VerificationResultPrinter() - { - public void print( VerificationResult result ) - { - assertEquals( 0, result.getExistenceFailures().size() ); - assertEquals( 0, result.getNonExistenceFailures().size() ); - assertEquals( 1, result.getContentFailures().size() ); + File file = getResourceFile("/FileExistsInvalidContent.xml"); + mojo.setBaseDir(file.getParentFile()); + mojo.setVerificationFile(file); + mojo.setFailOnError(true); + mojo.setVerificationResultPrinter(new VerificationResultPrinter() { + public void print(VerificationResult result) { + assertEquals(0, result.getExistenceFailures().size()); + assertEquals(0, result.getNonExistenceFailures().size()); + assertEquals(1, result.getContentFailures().size()); } - } ); + }); - try - { + try { mojo.execute(); - fail( "Should have thrown an exception" ); - } - catch ( MojoExecutionException expected ) - { - assertTrue( true ); + fail("Should have thrown an exception"); + } catch (MojoExecutionException expected) { + assertTrue(true); } } - }