This is an automated email from the ASF dual-hosted git repository. khmarbaise pushed a commit to branch MNG-6825 in repository https://gitbox.apache.org/repos/asf/maven.git
commit 3df04847a9fbb7e0f45a4a4693210a5a4eea5029 Author: Karl Heinz Marbaise <khmarba...@apache.org> AuthorDate: Sun Dec 15 04:02:46 2019 +0100 WIP - Continued. --- maven-artifact/pom.xml | 5 + maven-embedder/pom.xml | 11 + .../transfer/AbstractMavenTransferListener.java | 146 +++++----- .../java/org/apache/maven/cli/CLIManagerTest.java | 26 +- .../apache/maven/cli/CLIReportingUtilsTest.java | 29 +- .../org/apache/maven/cli/CleanArgumentTest.java | 24 +- .../maven/cli/transfer/FileSizeFormatTest.java | 324 +++++++++++---------- maven-model-builder/pom.xml | 10 + .../maven/model/building/FileModelSourceTest.java | 36 ++- .../interpolation/MavenBuildTimestampTest.java | 13 +- maven-utils/pom.xml | 4 - .../java/org/apache/maven/utils/Precondition.java | 75 +++-- .../org/apache/maven/utils/PreconditionTest.java | 5 +- pom.xml | 17 ++ 14 files changed, 405 insertions(+), 320 deletions(-) diff --git a/maven-artifact/pom.xml b/maven-artifact/pom.xml index 9dd4fe9..24bee1d 100644 --- a/maven-artifact/pom.xml +++ b/maven-artifact/pom.xml @@ -41,6 +41,11 @@ under the License. <groupId>org.apache.maven</groupId> <artifactId>maven-utils</artifactId> </dependency> + <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-lang3</artifactId> + <version>3.9</version> + </dependency> </dependencies> <build> diff --git a/maven-embedder/pom.xml b/maven-embedder/pom.xml index 1754eb2..92acd77 100644 --- a/maven-embedder/pom.xml +++ b/maven-embedder/pom.xml @@ -175,6 +175,17 @@ under the License. <groupId>org.apache.maven</groupId> <artifactId>maven-utils</artifactId> </dependency> + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter-engine</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + <scope>test</scope> + </dependency> + </dependencies> <build> diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/transfer/AbstractMavenTransferListener.java b/maven-embedder/src/main/java/org/apache/maven/cli/transfer/AbstractMavenTransferListener.java index 72bffc3..899e086 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/transfer/AbstractMavenTransferListener.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/transfer/AbstractMavenTransferListener.java @@ -24,7 +24,7 @@ import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.util.Locale; -import org.apache.commons.lang3.Validate; +import org.apache.maven.utils.Precondition; import org.eclipse.aether.transfer.AbstractTransferListener; import org.eclipse.aether.transfer.TransferCancelledException; import org.eclipse.aether.transfer.TransferEvent; @@ -33,20 +33,19 @@ import org.eclipse.aether.transfer.TransferResource; /** * AbstractMavenTransferListener */ -public abstract class AbstractMavenTransferListener - extends AbstractTransferListener +public abstract class AbstractMavenTransferListener extends AbstractTransferListener { // CHECKSTYLE_OFF: LineLength + /** - * Formats file size with the associated <a href="https://en.wikipedia.org/wiki/Metric_prefix">SI</a> prefix - * (GB, MB, kB) and using the patterns <code>#0.0</code> for numbers between 1 and 10 - * and <code>###0</code> for numbers between 10 and 1000+ by default. + * Formats file size with the associated <a href="https://en.wikipedia.org/wiki/Metric_prefix">SI</a> prefix (GB, + * MB, kB) and using the patterns <code>#0.0</code> for numbers between 1 and 10 and <code>###0</code> for numbers + * between 10 and 1000+ by default. * * @see <a href="https://en.wikipedia.org/wiki/Metric_prefix">https://en.wikipedia.org/wiki/Metric_prefix</a> * @see <a href="https://en.wikipedia.org/wiki/Binary_prefix">https://en.wikipedia.org/wiki/Binary_prefix</a> - * @see <a - * href="https://en.wikipedia.org/wiki/Octet_%28computing%29">https://en.wikipedia.org/wiki/Octet_(computing)</a> + * @see <a href="https://en.wikipedia.org/wiki/Octet_%28computing%29">https://en.wikipedia.org/wiki/Octet_(computing)</a> */ // CHECKSTYLE_ON: LineLength // TODO Move me to Maven Shared Utils @@ -55,68 +54,67 @@ public abstract class AbstractMavenTransferListener enum ScaleUnit { BYTE - { - @Override - public long bytes() - { - return 1L; - } - - @Override - public String symbol() - { - return "B"; - } - }, + { + @Override + public long bytes() + { + return 1L; + } + + @Override + public String symbol() + { + return "B"; + } + }, KILOBYTE - { - @Override - public long bytes() - { - return 1000L; - } - - @Override - public String symbol() - { - return "kB"; - } - }, + { + @Override + public long bytes() + { + return 1000L; + } + + @Override + public String symbol() + { + return "kB"; + } + }, MEGABYTE - { - @Override - public long bytes() - { - return KILOBYTE.bytes() * KILOBYTE.bytes(); - } - - @Override - public String symbol() - { - return "MB"; - } - }, + { + @Override + public long bytes() + { + return KILOBYTE.bytes() * KILOBYTE.bytes(); + } + + @Override + public String symbol() + { + return "MB"; + } + }, GIGABYTE - { - @Override - public long bytes() - { - return MEGABYTE.bytes() * KILOBYTE.bytes(); - }; - - @Override - public String symbol() - { - return "GB"; - } - }; - - public abstract long bytes(); - public abstract String symbol(); + { + @Override + public long bytes() + { + return MEGABYTE.bytes() * KILOBYTE.bytes(); + } + + ; + + @Override + public String symbol() + { + return "GB"; + } + }; public static ScaleUnit getScaleUnit( long size ) { - Validate.isTrue( size >= 0L, "file size cannot be negative: %s", size ); + Precondition.greaterOrEqualToZero( size, "file size cannot be negative: %s", size ); if ( size >= GIGABYTE.bytes() ) { @@ -135,6 +133,10 @@ public abstract class AbstractMavenTransferListener return BYTE; } } + + public abstract long bytes(); + + public abstract String symbol(); } private DecimalFormat smallFormat; @@ -159,7 +161,7 @@ public abstract class AbstractMavenTransferListener @SuppressWarnings( "checkstyle:magicnumber" ) public String format( long size, ScaleUnit unit, boolean omitSymbol ) { - Validate.isTrue( size >= 0L, "file size cannot be negative: %s", size ); + Precondition.greaterOrEqualToZero( size, "file size cannot be negative: %s", size ); if ( unit == null ) { @@ -191,9 +193,10 @@ public abstract class AbstractMavenTransferListener public String formatProgress( long progressedSize, long size ) { - Validate.isTrue( progressedSize >= 0L, "progressed file size cannot be negative: %s", progressedSize ); - Validate.isTrue( size < 0L || progressedSize <= size, - "progressed file size cannot be greater than size: %s > %s", progressedSize, size ); + Precondition.greaterOrEqualToZero( progressedSize, "progressed file size cannot be negative: %s", + progressedSize ); + Precondition.isTrue( size >= 0L && progressedSize <= size || size < 0L, + "progressed file size cannot be greater than size: %s > %s", progressedSize, size ); if ( size >= 0L && progressedSize != size ) { @@ -233,13 +236,12 @@ public abstract class AbstractMavenTransferListener } @Override - public void transferCorrupted( TransferEvent event ) - throws TransferCancelledException + public void transferCorrupted( TransferEvent event ) throws TransferCancelledException { TransferResource resource = event.getResource(); // TODO This needs to be colorized - out.println( "[WARNING] " + event.getException().getMessage() + " from " + resource.getRepositoryId() + " for " - + resource.getRepositoryUrl() + resource.getResourceName() ); + out.println( "[WARNING] " + event.getException().getMessage() + " from " + resource + .getRepositoryId() + " for " + resource.getRepositoryUrl() + resource.getResourceName() ); } @Override diff --git a/maven-embedder/src/test/java/org/apache/maven/cli/CLIManagerTest.java b/maven-embedder/src/test/java/org/apache/maven/cli/CLIManagerTest.java index dbb3879..e663d23 100644 --- a/maven-embedder/src/test/java/org/apache/maven/cli/CLIManagerTest.java +++ b/maven-embedder/src/test/java/org/apache/maven/cli/CLIManagerTest.java @@ -19,32 +19,30 @@ package org.apache.maven.cli; * under the License. */ -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; - import org.apache.commons.cli.CommandLine; -import org.junit.Before; -import org.junit.Test; +import org.apache.commons.cli.ParseException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; -public class CLIManagerTest +class CLIManagerTest { private CLIManager cliManager; - @Before - public void setup() + @BeforeEach + void beforeEach() { cliManager = new CLIManager(); } @Test - public void spacedOptions() - throws Exception + void spacedOptions() throws ParseException { CommandLine cmdLine = cliManager.parse( "-X -Dx=1 -D y=2 test".split( " " ) ); - assertTrue( cmdLine.hasOption( CLIManager.DEBUG ) ); - assertThat( cmdLine.getOptionValues( CLIManager.SET_SYSTEM_PROPERTY )[0], is( "x=1" ) ); - assertThat( cmdLine.getOptionValues( CLIManager.SET_SYSTEM_PROPERTY )[1], is( "y=2" ) ); + assertThat( cmdLine.hasOption( CLIManager.DEBUG ) ).isTrue(); + assertThat( cmdLine.getOptionValues( CLIManager.SET_SYSTEM_PROPERTY )[0] ).isEqualTo( "x=1" ); + assertThat( cmdLine.getOptionValues( CLIManager.SET_SYSTEM_PROPERTY )[1] ).isEqualTo( "y=2" ); } } diff --git a/maven-embedder/src/test/java/org/apache/maven/cli/CLIReportingUtilsTest.java b/maven-embedder/src/test/java/org/apache/maven/cli/CLIReportingUtilsTest.java index 65488c7..1a79971 100644 --- a/maven-embedder/src/test/java/org/apache/maven/cli/CLIReportingUtilsTest.java +++ b/maven-embedder/src/test/java/org/apache/maven/cli/CLIReportingUtilsTest.java @@ -19,22 +19,23 @@ package org.apache.maven.cli; * under the License. */ -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; -public class CLIReportingUtilsTest - extends TestCase -{ +import static org.assertj.core.api.Assertions.assertThat; - public void testFormatDuration() +class CLIReportingUtilsTest +{ + @Test + void testFormatDuration() { - assertEquals( "0.001 s", CLIReportingUtils.formatDuration( 1 ) ); - assertEquals( "0.999 s", CLIReportingUtils.formatDuration( 1000 - 1 ) ); - assertEquals( "1.000 s", CLIReportingUtils.formatDuration( 1000 ) ); - assertEquals( "59.999 s", CLIReportingUtils.formatDuration( 60 * 1000 - 1 ) ); - assertEquals( "01:00 min", CLIReportingUtils.formatDuration( 60 * 1000 ) ); - assertEquals( "59:59 min", CLIReportingUtils.formatDuration( 60 * 60 * 1000 - 1 ) ); - assertEquals( "01:00 h", CLIReportingUtils.formatDuration( 60 * 60 * 1000 ) ); - assertEquals( "23:59 h", CLIReportingUtils.formatDuration( 24 * 60 * 60 * 1000 - 1 ) ); - assertEquals( "1 d 00:00 h", CLIReportingUtils.formatDuration( 24 * 60 * 60 * 1000 ) ); + assertThat( CLIReportingUtils.formatDuration( 1 ) ).isEqualTo( "0.001 s" ); + assertThat( CLIReportingUtils.formatDuration( 1000 - 1 ) ).isEqualTo( "0.999 s" ); + assertThat( CLIReportingUtils.formatDuration( 1000 ) ).isEqualTo( "1.000 s" ); + assertThat( CLIReportingUtils.formatDuration( 60 * 1000 - 1 ) ).isEqualTo( "59.999 s" ); + assertThat( CLIReportingUtils.formatDuration( 60 * 1000 ) ).isEqualTo( "01:00 min" ); + assertThat( CLIReportingUtils.formatDuration( 60 * 60 * 1000 - 1 ) ).isEqualTo( "59:59 min" ); + assertThat( CLIReportingUtils.formatDuration( 60 * 60 * 1000 ) ).isEqualTo( "01:00 h" ); + assertThat( CLIReportingUtils.formatDuration( 24 * 60 * 60 * 1000 - 1 ) ).isEqualTo( "23:59 h" ); + assertThat( CLIReportingUtils.formatDuration( 24 * 60 * 60 * 1000 ) ).isEqualTo( "1 d 00:00 h" ); } } diff --git a/maven-embedder/src/test/java/org/apache/maven/cli/CleanArgumentTest.java b/maven-embedder/src/test/java/org/apache/maven/cli/CleanArgumentTest.java index 7e2b489..550a280 100644 --- a/maven-embedder/src/test/java/org/apache/maven/cli/CleanArgumentTest.java +++ b/maven-embedder/src/test/java/org/apache/maven/cli/CleanArgumentTest.java @@ -19,33 +19,33 @@ package org.apache.maven.cli; * under the License. */ -import static org.junit.Assert.assertEquals; +import org.junit.jupiter.api.Test; -import org.junit.Test; +import static org.assertj.core.api.Assertions.assertThat; /** * @author Karl Heinz Marbaise */ -public class CleanArgumentTest +class CleanArgumentTest { @Test - public void cleanArgsShouldRemoveWrongSurroundingQuotes() + void cleanArgsShouldRemoveWrongSurroundingQuotes() { String[] args = { "\"-Dfoo=bar", "\"-Dfoo2=bar two\"" }; String[] cleanArgs = CleanArgument.cleanArgs( args ); - assertEquals( args.length, cleanArgs.length ); - assertEquals( "-Dfoo=bar", cleanArgs[0] ); - assertEquals( "-Dfoo2=bar two", cleanArgs[1] ); + assertThat( cleanArgs.length ).isEqualTo( args.length ); + assertThat( cleanArgs[0] ).isEqualTo( "-Dfoo=bar" ); + assertThat( cleanArgs[1] ).isEqualTo( "-Dfoo2=bar two" ); } @Test - public void testCleanArgsShouldNotTouchCorrectlyQuotedArgumentsUsingDoubleQuotes() + void testCleanArgsShouldNotTouchCorrectlyQuotedArgumentsUsingDoubleQuotes() { String information = "-Dinformation=\"The Information is important.\""; String[] args = { information }; String[] cleanArgs = CleanArgument.cleanArgs( args ); - assertEquals( args.length, cleanArgs.length ); - assertEquals( information, cleanArgs[0] ); + assertThat( cleanArgs.length ).isEqualTo( args.length ); + assertThat( cleanArgs[0] ).isEqualTo( information ); } @Test @@ -54,8 +54,8 @@ public class CleanArgumentTest String information = "-Dinformation='The Information is important.'"; String[] args = { information }; String[] cleanArgs = CleanArgument.cleanArgs( args ); - assertEquals( args.length, cleanArgs.length ); - assertEquals( information, cleanArgs[0] ); + assertThat( cleanArgs.length ).isEqualTo( args.length ); + assertThat( cleanArgs[0] ).isEqualTo( information ); } } diff --git a/maven-embedder/src/test/java/org/apache/maven/cli/transfer/FileSizeFormatTest.java b/maven-embedder/src/test/java/org/apache/maven/cli/transfer/FileSizeFormatTest.java index e595ace..75885ce 100644 --- a/maven-embedder/src/test/java/org/apache/maven/cli/transfer/FileSizeFormatTest.java +++ b/maven-embedder/src/test/java/org/apache/maven/cli/transfer/FileSizeFormatTest.java @@ -23,280 +23,286 @@ import java.util.Locale; import org.apache.maven.cli.transfer.AbstractMavenTransferListener.FileSizeFormat; import org.apache.maven.cli.transfer.AbstractMavenTransferListener.FileSizeFormat.ScaleUnit; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; -public class FileSizeFormatTest { +class FileSizeFormatTest +{ - @Test( expected = IllegalArgumentException.class ) - public void testNegativeSize() + @Test + void testNegativeSize() { FileSizeFormat format = new FileSizeFormat( Locale.ENGLISH ); long negativeSize = -100L; - format.format( negativeSize ); + assertThatIllegalArgumentException().isThrownBy( () -> format.format( negativeSize ) ).withMessage( + "file size cannot be negative: -100" ); } @Test - public void testSize() + void testSize() { FileSizeFormat format = new FileSizeFormat( Locale.ENGLISH ); long _0_bytes = 0L; - assertEquals( "0 B", format.format( _0_bytes ) ); + assertThat( format.format( _0_bytes ) ).isEqualTo( "0 B" ); long _5_bytes = 5L; - assertEquals( "5 B", format.format( _5_bytes ) ); + assertThat( format.format( _5_bytes ) ).isEqualTo( "5 B" ); long _10_bytes = 10L; - assertEquals( "10 B", format.format( _10_bytes ) ); + assertThat( format.format( _10_bytes ) ).isEqualTo( "10 B" ); long _15_bytes = 15L; - assertEquals( "15 B", format.format( _15_bytes ) ); + assertThat( format.format( _15_bytes ) ).isEqualTo( "15 B" ); long _999_bytes = 999L; - assertEquals( "999 B", format.format( _999_bytes ) ); + assertThat( format.format( _999_bytes ) ).isEqualTo( "999 B" ); long _1000_bytes = 1000L; - assertEquals( "1.0 kB", format.format( _1000_bytes ) ); + assertThat( format.format( _1000_bytes ) ).isEqualTo( "1.0 kB" ); long _5500_bytes = 5500L; - assertEquals( "5.5 kB", format.format( _5500_bytes ) ); + assertThat( format.format( _5500_bytes ) ).isEqualTo( "5.5 kB" ); long _10_kilobytes = 10L * 1000L; - assertEquals( "10 kB", format.format( _10_kilobytes ) ); + assertThat( format.format( _10_kilobytes ) ).isEqualTo( "10 kB" ); long _15_kilobytes = 15L * 1000L; - assertEquals( "15 kB", format.format( _15_kilobytes ) ); + assertThat( format.format( _15_kilobytes ) ).isEqualTo( "15 kB" ); long _999_kilobytes = 999L * 1000L; - assertEquals( "999 kB", format.format( _999_kilobytes ) ); + assertThat( format.format( _999_kilobytes ) ).isEqualTo( "999 kB" ); long _1000_kilobytes = 1000L * 1000L; - assertEquals( "1.0 MB", format.format( _1000_kilobytes ) ); + assertThat( format.format( _1000_kilobytes ) ).isEqualTo( "1.0 MB" ); long _5500_kilobytes = 5500L * 1000L; - assertEquals( "5.5 MB", format.format( _5500_kilobytes ) ); + assertThat( format.format( _5500_kilobytes ) ).isEqualTo( "5.5 MB" ); long _10_megabytes = 10L * 1000L * 1000L; - assertEquals( "10 MB", format.format( _10_megabytes ) ); + assertThat( format.format( _10_megabytes ) ).isEqualTo( "10 MB" ); long _15_megabytes = 15L * 1000L * 1000L; - assertEquals( "15 MB", format.format( _15_megabytes ) ); + assertThat( format.format( _15_megabytes ) ).isEqualTo( "15 MB" ); long _999_megabytes = 999L * 1000L * 1000L; - assertEquals( "999 MB", format.format( _999_megabytes ) ); + assertThat( format.format( _999_megabytes ) ).isEqualTo( "999 MB" ); long _1000_megabytes = 1000L * 1000L * 1000L; - assertEquals( "1.0 GB", format.format( _1000_megabytes ) ); + assertThat( format.format( _1000_megabytes ) ).isEqualTo( "1.0 GB" ); long _5500_megabytes = 5500L * 1000L * 1000L; - assertEquals( "5.5 GB", format.format( _5500_megabytes ) ); + assertThat( format.format( _5500_megabytes ) ).isEqualTo( "5.5 GB" ); long _10_gigabytes = 10L * 1000L * 1000L * 1000L; - assertEquals( "10 GB", format.format( _10_gigabytes ) ); + assertThat( format.format( _10_gigabytes ) ).isEqualTo( "10 GB" ); long _15_gigabytes = 15L * 1000L * 1000L * 1000L; - assertEquals( "15 GB", format.format( _15_gigabytes ) ); + assertThat( format.format( _15_gigabytes ) ).isEqualTo( "15 GB" ); long _1000_gigabytes = 1000L * 1000L * 1000L * 1000L; - assertEquals( "1000 GB", format.format( _1000_gigabytes ) ); + assertThat( format.format( _1000_gigabytes ) ).isEqualTo( "1000 GB" ); } @Test - public void testSizeWithSelectedScaleUnit() + void testSizeWithSelectedScaleUnit() { FileSizeFormat format = new FileSizeFormat( Locale.ENGLISH ); long _0_bytes = 0L; - assertEquals( "0 B", format.format( _0_bytes ) ); - assertEquals( "0 B", format.format( _0_bytes, ScaleUnit.BYTE ) ); - assertEquals( "0 kB", format.format( _0_bytes, ScaleUnit.KILOBYTE ) ); - assertEquals( "0 MB", format.format( _0_bytes, ScaleUnit.MEGABYTE ) ); - assertEquals( "0 GB", format.format( _0_bytes, ScaleUnit.GIGABYTE ) ); + assertThat( format.format( _0_bytes ) ).isEqualTo( "0 B" ); + assertThat( format.format( _0_bytes, ScaleUnit.BYTE ) ).isEqualTo( "0 B" ); + assertThat( format.format( _0_bytes, ScaleUnit.KILOBYTE ) ).isEqualTo( "0 kB" ); + assertThat( format.format( _0_bytes, ScaleUnit.MEGABYTE ) ).isEqualTo( "0 MB" ); + assertThat( format.format( _0_bytes, ScaleUnit.GIGABYTE ) ).isEqualTo( "0 GB" ); long _5_bytes = 5L; - assertEquals( "5 B", format.format( _5_bytes ) ); - assertEquals( "5 B", format.format( _5_bytes, ScaleUnit.BYTE ) ); - assertEquals( "0 kB", format.format( _5_bytes, ScaleUnit.KILOBYTE ) ); - assertEquals( "0 MB", format.format( _5_bytes, ScaleUnit.MEGABYTE ) ); - assertEquals( "0 GB", format.format( _5_bytes, ScaleUnit.GIGABYTE ) ); + assertThat( format.format( _5_bytes ) ).isEqualTo( "5 B" ); + assertThat( format.format( _5_bytes, ScaleUnit.BYTE ) ).isEqualTo( "5 B" ); + assertThat( format.format( _5_bytes, ScaleUnit.KILOBYTE ) ).isEqualTo( "0 kB" ); + assertThat( format.format( _5_bytes, ScaleUnit.MEGABYTE ) ).isEqualTo( "0 MB" ); + assertThat( format.format( _5_bytes, ScaleUnit.GIGABYTE ) ).isEqualTo( "0 GB" ); long _49_bytes = 49L; - assertEquals( "49 B", format.format( _49_bytes ) ); - assertEquals( "49 B", format.format( _49_bytes, ScaleUnit.BYTE ) ); - assertEquals( "0 kB", format.format( _49_bytes, ScaleUnit.KILOBYTE ) ); - assertEquals( "0 MB", format.format( _49_bytes, ScaleUnit.MEGABYTE ) ); - assertEquals( "0 GB", format.format( _49_bytes, ScaleUnit.GIGABYTE ) ); + assertThat( format.format( _49_bytes ) ).isEqualTo( "49 B" ); + assertThat( format.format( _49_bytes, ScaleUnit.BYTE ) ).isEqualTo( "49 B" ); + assertThat( format.format( _49_bytes, ScaleUnit.KILOBYTE ) ).isEqualTo( "0 kB" ); + assertThat( format.format( _49_bytes, ScaleUnit.MEGABYTE ) ).isEqualTo( "0 MB" ); + assertThat( format.format( _49_bytes, ScaleUnit.GIGABYTE ) ).isEqualTo( "0 GB" ); long _50_bytes = 50L; - assertEquals( "50 B", format.format( _50_bytes ) ); - assertEquals( "50 B", format.format( _50_bytes, ScaleUnit.BYTE ) ); - assertEquals( "0.1 kB", format.format( _50_bytes, ScaleUnit.KILOBYTE ) ); - assertEquals( "0 MB", format.format( _50_bytes, ScaleUnit.MEGABYTE ) ); - assertEquals( "0 GB", format.format( _50_bytes, ScaleUnit.GIGABYTE ) ); + assertThat( format.format( _50_bytes ) ).isEqualTo( "50 B" ); + assertThat( format.format( _50_bytes, ScaleUnit.BYTE ) ).isEqualTo( "50 B" ); + assertThat( format.format( _50_bytes, ScaleUnit.KILOBYTE ) ).isEqualTo( "0.1 kB" ); + assertThat( format.format( _50_bytes, ScaleUnit.MEGABYTE ) ).isEqualTo( "0 MB" ); + assertThat( format.format( _50_bytes, ScaleUnit.GIGABYTE ) ).isEqualTo( "0 GB" ); long _999_bytes = 999L; - assertEquals( "999 B", format.format( _999_bytes ) ); - assertEquals( "999 B", format.format( _999_bytes, ScaleUnit.BYTE ) ); - assertEquals( "1.0 kB", format.format( _999_bytes, ScaleUnit.KILOBYTE ) ); - assertEquals( "0 MB", format.format( _999_bytes, ScaleUnit.MEGABYTE ) ); - assertEquals( "0 GB", format.format( _999_bytes, ScaleUnit.GIGABYTE ) ); + assertThat( format.format( _999_bytes ) ).isEqualTo( "999 B" ); + assertThat( format.format( _999_bytes, ScaleUnit.BYTE ) ).isEqualTo( "999 B" ); + assertThat( format.format( _999_bytes, ScaleUnit.KILOBYTE ) ).isEqualTo( "1.0 kB" ); + assertThat( format.format( _999_bytes, ScaleUnit.MEGABYTE ) ).isEqualTo( "0 MB" ); + assertThat( format.format( _999_bytes, ScaleUnit.GIGABYTE ) ).isEqualTo( "0 GB" ); long _1000_bytes = 1000L; - assertEquals( "1.0 kB", format.format( _1000_bytes ) ); - assertEquals( "1000 B", format.format( _1000_bytes, ScaleUnit.BYTE ) ); - assertEquals( "1.0 kB", format.format( _1000_bytes, ScaleUnit.KILOBYTE ) ); - assertEquals( "0 MB", format.format( _1000_bytes, ScaleUnit.MEGABYTE ) ); - assertEquals( "0 GB", format.format( _1000_bytes, ScaleUnit.GIGABYTE ) ); + assertThat( format.format( _1000_bytes ) ).isEqualTo( "1.0 kB" ); + assertThat( format.format( _1000_bytes, ScaleUnit.BYTE ) ).isEqualTo( "1000 B" ); + assertThat( format.format( _1000_bytes, ScaleUnit.KILOBYTE ) ).isEqualTo( "1.0 kB" ); + assertThat( format.format( _1000_bytes, ScaleUnit.MEGABYTE ) ).isEqualTo( "0 MB" ); + assertThat( format.format( _1000_bytes, ScaleUnit.GIGABYTE ) ).isEqualTo( "0 GB" ); long _49_kilobytes = 49L * 1000L; - assertEquals( "49 kB", format.format( _49_kilobytes ) ); - assertEquals( "49000 B", format.format( _49_kilobytes, ScaleUnit.BYTE ) ); - assertEquals( "49 kB", format.format( _49_kilobytes, ScaleUnit.KILOBYTE ) ); - assertEquals( "0 MB", format.format( _49_kilobytes, ScaleUnit.MEGABYTE ) ); - assertEquals( "0 GB", format.format( _49_kilobytes, ScaleUnit.GIGABYTE ) ); + assertThat( format.format( _49_kilobytes ) ).isEqualTo( "49 kB" ); + assertThat( format.format( _49_kilobytes, ScaleUnit.BYTE ) ).isEqualTo( "49000 B" ); + assertThat( format.format( _49_kilobytes, ScaleUnit.KILOBYTE ) ).isEqualTo( "49 kB" ); + assertThat( format.format( _49_kilobytes, ScaleUnit.MEGABYTE ) ).isEqualTo( "0 MB" ); + assertThat( format.format( _49_kilobytes, ScaleUnit.GIGABYTE ) ).isEqualTo( "0 GB" ); long _50_kilobytes = 50L * 1000L; - assertEquals( "50 kB", format.format( _50_kilobytes ) ); - assertEquals( "50000 B", format.format( _50_kilobytes, ScaleUnit.BYTE ) ); - assertEquals( "50 kB", format.format( _50_kilobytes, ScaleUnit.KILOBYTE ) ); - assertEquals( "0.1 MB", format.format( _50_kilobytes, ScaleUnit.MEGABYTE ) ); - assertEquals( "0 GB", format.format( _50_kilobytes, ScaleUnit.GIGABYTE ) ); + assertThat( format.format( _50_kilobytes ) ).isEqualTo( "50 kB" ); + assertThat( format.format( _50_kilobytes, ScaleUnit.BYTE ) ).isEqualTo( "50000 B" ); + assertThat( format.format( _50_kilobytes, ScaleUnit.KILOBYTE ) ).isEqualTo( "50 kB" ); + assertThat( format.format( _50_kilobytes, ScaleUnit.MEGABYTE ) ).isEqualTo( "0.1 MB" ); + assertThat( format.format( _50_kilobytes, ScaleUnit.GIGABYTE ) ).isEqualTo( "0 GB" ); long _999_kilobytes = 999L * 1000L; - assertEquals( "999 kB", format.format( _999_kilobytes ) ); - assertEquals( "999000 B", format.format( _999_kilobytes, ScaleUnit.BYTE ) ); - assertEquals( "999 kB", format.format( _999_kilobytes, ScaleUnit.KILOBYTE ) ); - assertEquals( "1.0 MB", format.format( _999_kilobytes, ScaleUnit.MEGABYTE ) ); - assertEquals( "0 GB", format.format( _999_kilobytes, ScaleUnit.GIGABYTE ) ); + assertThat( format.format( _999_kilobytes ) ).isEqualTo( "999 kB" ); + assertThat( format.format( _999_kilobytes, ScaleUnit.BYTE ) ).isEqualTo( "999000 B" ); + assertThat( format.format( _999_kilobytes, ScaleUnit.KILOBYTE ) ).isEqualTo( "999 kB" ); + assertThat( format.format( _999_kilobytes, ScaleUnit.MEGABYTE ) ).isEqualTo( "1.0 MB" ); + assertThat( format.format( _999_kilobytes, ScaleUnit.GIGABYTE ) ).isEqualTo( "0 GB" ); long _1000_kilobytes = 1000L * 1000L; - assertEquals( "1.0 MB", format.format( _1000_kilobytes ) ); - assertEquals( "1000000 B", format.format( _1000_kilobytes, ScaleUnit.BYTE ) ); - assertEquals( "1000 kB", format.format( _1000_kilobytes, ScaleUnit.KILOBYTE ) ); - assertEquals( "1.0 MB", format.format( _1000_kilobytes, ScaleUnit.MEGABYTE ) ); - assertEquals( "0 GB", format.format( _1000_kilobytes, ScaleUnit.GIGABYTE ) ); + assertThat( format.format( _1000_kilobytes ) ).isEqualTo( "1.0 MB" ); + assertThat( format.format( _1000_kilobytes, ScaleUnit.BYTE ) ).isEqualTo( "1000000 B" ); + assertThat( format.format( _1000_kilobytes, ScaleUnit.KILOBYTE ) ).isEqualTo( "1000 kB" ); + assertThat( format.format( _1000_kilobytes, ScaleUnit.MEGABYTE ) ).isEqualTo( "1.0 MB" ); + assertThat( format.format( _1000_kilobytes, ScaleUnit.GIGABYTE ) ).isEqualTo( "0 GB" ); long _49_megabytes = 49L * 1000L * 1000L; - assertEquals( "49 MB", format.format( _49_megabytes ) ); - assertEquals( "49000000 B", format.format( _49_megabytes, ScaleUnit.BYTE ) ); - assertEquals( "49000 kB", format.format( _49_megabytes, ScaleUnit.KILOBYTE ) ); - assertEquals( "49 MB", format.format( _49_megabytes, ScaleUnit.MEGABYTE ) ); - assertEquals( "0 GB", format.format( _49_megabytes, ScaleUnit.GIGABYTE ) ); + assertThat( format.format( _49_megabytes ) ).isEqualTo( "49 MB" ); + assertThat( format.format( _49_megabytes, ScaleUnit.BYTE ) ).isEqualTo( "49000000 B" ); + assertThat( format.format( _49_megabytes, ScaleUnit.KILOBYTE ) ).isEqualTo( "49000 kB" ); + assertThat( format.format( _49_megabytes, ScaleUnit.MEGABYTE ) ).isEqualTo( "49 MB" ); + assertThat( format.format( _49_megabytes, ScaleUnit.GIGABYTE ) ).isEqualTo( "0 GB" ); long _50_megabytes = 50L * 1000L * 1000L; - assertEquals( "50 MB", format.format( _50_megabytes ) ); - assertEquals( "50000000 B", format.format( _50_megabytes, ScaleUnit.BYTE ) ); - assertEquals( "50000 kB", format.format( _50_megabytes, ScaleUnit.KILOBYTE ) ); - assertEquals( "50 MB", format.format( _50_megabytes, ScaleUnit.MEGABYTE ) ); - assertEquals( "0.1 GB", format.format( _50_megabytes, ScaleUnit.GIGABYTE ) ); + assertThat( format.format( _50_megabytes ) ).isEqualTo( "50 MB" ); + assertThat( format.format( _50_megabytes, ScaleUnit.BYTE ) ).isEqualTo( "50000000 B" ); + assertThat( format.format( _50_megabytes, ScaleUnit.KILOBYTE ) ).isEqualTo( "50000 kB" ); + assertThat( format.format( _50_megabytes, ScaleUnit.MEGABYTE ) ).isEqualTo( "50 MB" ); + assertThat( format.format( _50_megabytes, ScaleUnit.GIGABYTE ) ).isEqualTo( "0.1 GB" ); long _999_megabytes = 999L * 1000L * 1000L; - assertEquals( "999 MB", format.format( _999_megabytes ) ); - assertEquals( "999000000 B", format.format( _999_megabytes, ScaleUnit.BYTE ) ); - assertEquals( "999000 kB", format.format( _999_megabytes, ScaleUnit.KILOBYTE ) ); - assertEquals( "999 MB", format.format( _999_megabytes, ScaleUnit.MEGABYTE ) ); - assertEquals( "1.0 GB", format.format( _999_megabytes, ScaleUnit.GIGABYTE ) ); + assertThat( format.format( _999_megabytes ) ).isEqualTo( "999 MB" ); + assertThat( format.format( _999_megabytes, ScaleUnit.BYTE ) ).isEqualTo( "999000000 B" ); + assertThat( format.format( _999_megabytes, ScaleUnit.KILOBYTE ) ).isEqualTo( "999000 kB" ); + assertThat( format.format( _999_megabytes, ScaleUnit.MEGABYTE ) ).isEqualTo( "999 MB" ); + assertThat( format.format( _999_megabytes, ScaleUnit.GIGABYTE ) ).isEqualTo( "1.0 GB" ); long _1000_megabytes = 1000L * 1000L * 1000L; - assertEquals( "1.0 GB", format.format( _1000_megabytes ) ); - assertEquals( "1000000000 B", format.format( _1000_megabytes, ScaleUnit.BYTE ) ); - assertEquals( "1000000 kB", format.format( _1000_megabytes, ScaleUnit.KILOBYTE ) ); - assertEquals( "1000 MB", format.format( _1000_megabytes, ScaleUnit.MEGABYTE ) ); - assertEquals( "1.0 GB", format.format( _1000_megabytes, ScaleUnit.GIGABYTE ) ); + assertThat( format.format( _1000_megabytes ) ).isEqualTo( "1.0 GB" ); + assertThat( format.format( _1000_megabytes, ScaleUnit.BYTE ) ).isEqualTo( "1000000000 B" ); + assertThat( format.format( _1000_megabytes, ScaleUnit.KILOBYTE ) ).isEqualTo( "1000000 kB" ); + assertThat( format.format( _1000_megabytes, ScaleUnit.MEGABYTE ) ).isEqualTo( "1000 MB" ); + assertThat( format.format( _1000_megabytes, ScaleUnit.GIGABYTE ) ).isEqualTo( "1.0 GB" ); } - @Test( expected = IllegalArgumentException.class ) - public void testNegativeProgressedSize() + @Test + void testNegativeProgressedSize() { FileSizeFormat format = new FileSizeFormat( Locale.ENGLISH ); long negativeProgressedSize = -100L; - format.formatProgress( negativeProgressedSize, 10L ); + assertThatIllegalArgumentException().isThrownBy( () -> format.formatProgress( negativeProgressedSize, 10L ) ) + .withMessage( "progressed file size cannot be negative: -100" ); } - @Test( expected = IllegalArgumentException.class ) - public void testNegativeProgressedSizeBiggerThanSize() + @Test + void testNegativeProgressedSizeBiggerThanSize() { FileSizeFormat format = new FileSizeFormat( Locale.ENGLISH ); - format.formatProgress( 100L, 10L ); + assertThatIllegalArgumentException().isThrownBy( () -> format.formatProgress( 100L, 10L ) ).withMessage( + "progressed file size cannot be greater than size: 100 > 10" ); } @Test - public void testProgressedSizeWithoutSize() + void testProgressedSizeWithoutSize() { - FileSizeFormat format = new FileSizeFormat( Locale.ENGLISH ); + FileSizeFormat format = new FileSizeFormat( Locale.ENGLISH ); - long _0_bytes = 0L; - assertEquals( "0 B", format.formatProgress( _0_bytes, -1L ) ); + long _0_bytes = 0L; + assertThat( format.formatProgress( _0_bytes, -1L ) ).isEqualTo( "0 B" ); - long _1000_bytes = 1000L; - assertEquals( "1.0 kB", format.formatProgress( _1000_bytes, -1L ) ); + long _1000_bytes = 1000L; + assertThat( format.formatProgress( _1000_bytes, -1L ) ).isEqualTo( "1.0 kB" ); - long _1000_kilobytes = 1000L * 1000L; - assertEquals( "1.0 MB", format.formatProgress( _1000_kilobytes, -1L ) ); + long _1000_kilobytes = 1000L * 1000L; + assertThat( format.formatProgress( _1000_kilobytes, -1L ) ).isEqualTo( "1.0 MB" ); - long _1000_megabytes = 1000L * 1000L * 1000L; - assertEquals( "1.0 GB", format.formatProgress( _1000_megabytes, -1L ) ); + long _1000_megabytes = 1000L * 1000L * 1000L; + assertThat( format.formatProgress( _1000_megabytes, -1L ) ).isEqualTo( "1.0 GB" ); } @Test - public void testProgressedBothZero() + void testProgressedBothZero() { - FileSizeFormat format = new FileSizeFormat( Locale.ENGLISH ); + FileSizeFormat format = new FileSizeFormat( Locale.ENGLISH ); - long _0_bytes = 0L; - assertEquals( "0 B", format.formatProgress( _0_bytes, _0_bytes ) ); + long _0_bytes = 0L; + assertThat( format.formatProgress( _0_bytes, _0_bytes ) ).isEqualTo( "0 B" ); } @Test - public void testProgressedSizeWithSize() + void testProgressedSizeWithSize() { - FileSizeFormat format = new FileSizeFormat( Locale.ENGLISH ); - - long _0_bytes = 0L; - long _400_bytes = 400L; - long _800_bytes = 2L * _400_bytes; - assertEquals( "0/800 B", format.formatProgress( _0_bytes, _800_bytes ) ); - assertEquals( "400/800 B", format.formatProgress( _400_bytes, _800_bytes ) ); - assertEquals( "800 B", format.formatProgress( _800_bytes, _800_bytes ) ); - - long _4000_bytes = 4000L; - long _8000_bytes = 2L * _4000_bytes; - long _50_kilobytes = 50000L; - assertEquals( "0/8.0 kB", format.formatProgress( _0_bytes, _8000_bytes ) ); - assertEquals( "0.4/8.0 kB", format.formatProgress( _400_bytes, _8000_bytes ) ); - assertEquals( "4.0/8.0 kB", format.formatProgress( _4000_bytes, _8000_bytes ) ); - assertEquals( "8.0 kB", format.formatProgress( _8000_bytes, _8000_bytes ) ); - assertEquals( "8.0/50 kB", format.formatProgress( _8000_bytes, _50_kilobytes ) ); - assertEquals( "16/50 kB", format.formatProgress( 2L * _8000_bytes, _50_kilobytes ) ); - assertEquals( "50 kB", format.formatProgress( _50_kilobytes, _50_kilobytes ) ); - - long _500_kilobytes = 500000L; - long _1000_kilobytes = 2L * _500_kilobytes;; - long _5000_kilobytes = 5L * _1000_kilobytes; - long _15_megabytes = 3L * _5000_kilobytes; - assertEquals( "0/5.0 MB", format.formatProgress( _0_bytes, _5000_kilobytes ) ); - assertEquals( "0.5/5.0 MB", format.formatProgress( _500_kilobytes, _5000_kilobytes ) ); - assertEquals( "1.0/5.0 MB", format.formatProgress( _1000_kilobytes, _5000_kilobytes ) ); - assertEquals( "5.0 MB", format.formatProgress( _5000_kilobytes, _5000_kilobytes ) ); - assertEquals( "5.0/15 MB", format.formatProgress( _5000_kilobytes, _15_megabytes ) ); - assertEquals( "15 MB", format.formatProgress( _15_megabytes, _15_megabytes ) ); - - long _500_megabytes = 500000000L; - long _1000_megabytes = 2L * _500_megabytes; - long _5000_megabytes = 5L * _1000_megabytes; - long _15_gigabytes = 3L * _5000_megabytes; - assertEquals( "0/500 MB", format.formatProgress( _0_bytes, _500_megabytes ) ); - assertEquals( "1.0/5.0 GB", format.formatProgress( _1000_megabytes, _5000_megabytes ) ); - assertEquals( "5.0 GB", format.formatProgress( _5000_megabytes, _5000_megabytes ) ); - assertEquals( "5.0/15 GB", format.formatProgress( _5000_megabytes, _15_gigabytes ) ); - assertEquals( "15 GB", format.formatProgress( _15_gigabytes, _15_gigabytes ) ); + FileSizeFormat format = new FileSizeFormat( Locale.ENGLISH ); + + long _0_bytes = 0L; + long _400_bytes = 400L; + long _800_bytes = 2L * _400_bytes; + assertThat( format.formatProgress( _0_bytes, _800_bytes ) ).isEqualTo( "0/800 B" ); + assertThat( format.formatProgress( _400_bytes, _800_bytes ) ).isEqualTo( "400/800 B" ); + assertThat( format.formatProgress( _800_bytes, _800_bytes ) ).isEqualTo( "800 B" ); + + long _4000_bytes = 4000L; + long _8000_bytes = 2L * _4000_bytes; + long _50_kilobytes = 50000L; + assertThat( format.formatProgress( _0_bytes, _8000_bytes ) ).isEqualTo( "0/8.0 kB" ); + assertThat( format.formatProgress( _400_bytes, _8000_bytes ) ).isEqualTo( "0.4/8.0 kB" ); + assertThat( format.formatProgress( _4000_bytes, _8000_bytes ) ).isEqualTo( "4.0/8.0 kB" ); + assertThat( format.formatProgress( _8000_bytes, _8000_bytes ) ).isEqualTo( "8.0 kB" ); + assertThat( format.formatProgress( _8000_bytes, _50_kilobytes ) ).isEqualTo( "8.0/50 kB" ); + assertThat( format.formatProgress( 2L * _8000_bytes, _50_kilobytes ) ).isEqualTo( "16/50 kB" ); + assertThat( format.formatProgress( _50_kilobytes, _50_kilobytes ) ).isEqualTo( "50 kB" ); + + long _500_kilobytes = 500000L; + long _1000_kilobytes = 2L * _500_kilobytes; + ; + long _5000_kilobytes = 5L * _1000_kilobytes; + long _15_megabytes = 3L * _5000_kilobytes; + assertThat( format.formatProgress( _0_bytes, _5000_kilobytes ) ).isEqualTo( "0/5.0 MB" ); + assertThat( format.formatProgress( _500_kilobytes, _5000_kilobytes ) ).isEqualTo( "0.5/5.0 MB" ); + assertThat( format.formatProgress( _1000_kilobytes, _5000_kilobytes ) ).isEqualTo( "1.0/5.0 MB" ); + assertThat( format.formatProgress( _5000_kilobytes, _5000_kilobytes ) ).isEqualTo( "5.0 MB" ); + assertThat( format.formatProgress( _5000_kilobytes, _15_megabytes ) ).isEqualTo( "5.0/15 MB" ); + assertThat( format.formatProgress( _15_megabytes, _15_megabytes ) ).isEqualTo( "15 MB" ); + + long _500_megabytes = 500000000L; + long _1000_megabytes = 2L * _500_megabytes; + long _5000_megabytes = 5L * _1000_megabytes; + long _15_gigabytes = 3L * _5000_megabytes; + assertThat( format.formatProgress( _0_bytes, _500_megabytes ) ).isEqualTo( "0/500 MB" ); + assertThat( format.formatProgress( _1000_megabytes, _5000_megabytes ) ).isEqualTo( "1.0/5.0 GB" ); + assertThat( format.formatProgress( _5000_megabytes, _5000_megabytes ) ).isEqualTo( "5.0 GB" ); + assertThat( format.formatProgress( _5000_megabytes, _15_gigabytes ) ).isEqualTo( "5.0/15 GB" ); + assertThat( format.formatProgress( _15_gigabytes, _15_gigabytes ) ).isEqualTo( "15 GB" ); } } \ No newline at end of file diff --git a/maven-model-builder/pom.xml b/maven-model-builder/pom.xml index a2145d2..36e76ff 100644 --- a/maven-model-builder/pom.xml +++ b/maven-model-builder/pom.xml @@ -89,6 +89,16 @@ under the License. <artifactId>powermock-reflect</artifactId> <scope>test</scope> </dependency> + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter-engine</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + <scope>test</scope> + </dependency> </dependencies> <build> diff --git a/maven-model-builder/src/test/java/org/apache/maven/model/building/FileModelSourceTest.java b/maven-model-builder/src/test/java/org/apache/maven/model/building/FileModelSourceTest.java index 9b0ecd9..b694bf1 100644 --- a/maven-model-builder/src/test/java/org/apache/maven/model/building/FileModelSourceTest.java +++ b/maven-model-builder/src/test/java/org/apache/maven/model/building/FileModelSourceTest.java @@ -18,51 +18,49 @@ package org.apache.maven.model.building; * specific language governing permissions and limitations * under the License. */ + import java.io.File; import java.io.IOException; -import static junit.framework.TestCase.assertFalse; -import static junit.framework.TestCase.assertTrue; -import org.apache.commons.lang3.SystemUtils; -import static org.junit.Assume.assumeTrue; -import org.junit.Test; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.EnabledOnOs; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.condition.OS.WINDOWS; /** * Test that validate the solution of MNG-6261 issue - * */ -public class FileModelSourceTest +class FileModelSourceTest { /** * Test of equals method, of class FileModelSource. */ @Test - public void testEquals() - throws Exception + void testEquals() throws Exception { File tempFile = createTempFile( "pomTest" ); FileModelSource instance = new FileModelSource( tempFile ); - assertFalse( instance.equals( null ) ); - assertFalse( instance.equals( new Object() ) ); - assertTrue( instance.equals( instance ) ); - assertTrue( instance.equals( new FileModelSource( tempFile ) ) ); + assertThat(instance.equals( null )).isFalse(); + assertThat( instance.equals( new Object() ) ).isFalse(); + assertThat( instance.equals( instance ) ).isTrue(); + assertThat( instance.equals( new FileModelSource( tempFile ) ) ).isTrue(); } @Test - public void testWindowsPaths() - throws Exception + @EnabledOnOs( WINDOWS ) + void testWindowsPaths() throws Exception { - assumeTrue( SystemUtils.IS_OS_WINDOWS ); - File upperCaseFile = createTempFile( "TESTE" ); String absolutePath = upperCaseFile.getAbsolutePath(); File lowerCaseFile = new File( absolutePath.toLowerCase() ); - + FileModelSource upperCaseFileSouce = new FileModelSource( upperCaseFile ); FileModelSource lowerCaseFileSouce = new FileModelSource( lowerCaseFile ); - assertTrue( upperCaseFileSouce.equals( lowerCaseFileSouce ) ); + assertThat( upperCaseFileSouce.equals( lowerCaseFileSouce ) ).isTrue(); } private File createTempFile( String name ) throws IOException diff --git a/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/MavenBuildTimestampTest.java b/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/MavenBuildTimestampTest.java index 8af32fc..3067753 100644 --- a/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/MavenBuildTimestampTest.java +++ b/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/MavenBuildTimestampTest.java @@ -22,17 +22,20 @@ package org.apache.maven.model.interpolation; import java.util.Date; import java.util.Properties; -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; -public class MavenBuildTimestampTest - extends TestCase +import static org.assertj.core.api.Assertions.assertThat; + +class MavenBuildTimestampTest { - public void testMavenBuildTimestampUsesUTC() + @Test + void testMavenBuildTimestampUsesUTC() { Properties interpolationProperties = new Properties(); interpolationProperties.setProperty( "maven.build.timestamp.format", "yyyyMMdd'T'HHmm'Z'" ); MavenBuildTimestamp timestamp = new MavenBuildTimestamp( new Date(), interpolationProperties ); String formattedTimestamp = timestamp.formattedTimestamp(); - assertTrue( "We expect the UTC marker at the end of the timestamp.", formattedTimestamp.endsWith( "Z" ) ); + assertThat( formattedTimestamp ).describedAs( "We expect the UTC marker at the end of the timestamp." ) + .endsWith( "Z" ); } } diff --git a/maven-utils/pom.xml b/maven-utils/pom.xml index 0472794..36a5710 100644 --- a/maven-utils/pom.xml +++ b/maven-utils/pom.xml @@ -37,19 +37,15 @@ under the License. <dependency> <groupId>org.apiguardian</groupId> <artifactId>apiguardian-api</artifactId> - <version>1.1.0</version> </dependency> - <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-engine</artifactId> <scope>test</scope> - <version>5.5.2</version> </dependency> <dependency> <groupId>org.assertj</groupId> <artifactId>assertj-core</artifactId> - <version>3.14.0</version> <scope>test</scope> </dependency> diff --git a/maven-utils/src/main/java/org/apache/maven/utils/Precondition.java b/maven-utils/src/main/java/org/apache/maven/utils/Precondition.java index 677d3fb..258e5a2 100644 --- a/maven-utils/src/main/java/org/apache/maven/utils/Precondition.java +++ b/maven-utils/src/main/java/org/apache/maven/utils/Precondition.java @@ -37,24 +37,6 @@ public final class Precondition { // no-op } -/* - int c = str != null && str.length() > 0 ? str.charAt( 0 ) : 0; - if ( ( c < '0' || c > '9' ) && ( c < 'a' || c > 'z' ) ) - { - Validate.notBlank( str, message ); - } -*/ - public static boolean notBlank(String str, String message) - { - for ( int i = 0; i < str.length(); i++ ) - { - if ( !Character.isWhitespace( str.charAt( i ) ) ) - { - return false; - } - } - throw new IllegalArgumentException( message ); - } /** * assert that the given {@code obj} is not {@code null}. @@ -101,6 +83,20 @@ public final class Precondition throw new IllegalArgumentException( message ); } + if ( longValue < 0 ) + { + throw new IllegalArgumentException( message ); + } + return longValue; + } + + public static Long requireGreaterOrEqualZero(Long longValue, String message) + { + if ( longValue == null ) + { + throw new IllegalArgumentException( message ); + } + if ( longValue <= 0 ) { throw new IllegalArgumentException( message ); @@ -124,6 +120,19 @@ public final class Precondition } } + public static Long greaterOrEqualToZero(Long currentValue, String message, final long value) { + if ( currentValue == null ) + { + throw new IllegalArgumentException( String.format( message, value ) ); + } + + if ( currentValue < 0 ) + { + throw new IllegalArgumentException( String.format( message, value ) ); + } + return currentValue; + } + public static Long requireGreaterThanZero(Long longValue, String message, final long value) { if ( longValue == null ) { @@ -199,6 +208,19 @@ public final class Precondition return true; } + public static boolean notBlank(String str, String message) + { + for ( int i = 0; i < str.length(); i++ ) + { + if ( !Character.isWhitespace( str.charAt( i ) ) ) + { + return false; + } + } + throw new IllegalArgumentException( message ); + } + + public static boolean isBlank(String str, String message) { if ( str == null || str.trim().isEmpty() ) @@ -212,6 +234,23 @@ public final class Precondition return cs == null || cs.length() == 0; } + public static boolean isDigits(final String str) { + return isNumeric(str); + } + + public static boolean isNumeric(final CharSequence cs) { + if (isEmpty(cs)) { + return false; + } + final int sz = cs.length(); + for (int i = 0; i < sz; i++) { + if (!Character.isDigit(cs.charAt(i))) { + return false; + } + } + return true; + } + } diff --git a/maven-utils/src/test/java/org/apache/maven/utils/PreconditionTest.java b/maven-utils/src/test/java/org/apache/maven/utils/PreconditionTest.java index 5a157b3..18811c5 100644 --- a/maven-utils/src/test/java/org/apache/maven/utils/PreconditionTest.java +++ b/maven-utils/src/test/java/org/apache/maven/utils/PreconditionTest.java @@ -22,14 +22,13 @@ package org.apache.maven.utils; import org.junit.jupiter.api.Test; import static org.apache.maven.utils.Precondition.notBlank; -import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; +import static org.assertj.core.api.Assertions.assertThatCode; class PreconditionTest { @Test void first() { - assertThatIllegalArgumentException() - .isThrownBy( () -> notBlank( "x", "Message" ) ); + assertThatCode( () -> notBlank( "x", "Message" ) ).doesNotThrowAnyException(); } } \ No newline at end of file diff --git a/pom.xml b/pom.xml index 6c203d6..5b9c2f1 100644 --- a/pom.xml +++ b/pom.xml @@ -442,6 +442,23 @@ under the License. <version>2.2</version> <scope>test</scope> </dependency> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + <version>3.14.0</version> + </dependency> + <dependency> + <groupId>org.apiguardian</groupId> + <artifactId>apiguardian-api</artifactId> + <version>1.1.0</version> + </dependency> + <dependency> + <groupId>org.junit</groupId> + <artifactId>junit-bom</artifactId> + <version>5.6.0-M1</version> + <scope>import</scope> + <type>pom</type> + </dependency> </dependencies> <!--bootstrap-start-comment--> </dependencyManagement>