Skip to content

Commit

Permalink
mojohaus#760: Fixing the reported number of updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jarmoniuk committed Oct 15, 2022
1 parent 954a853 commit f8c36bb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,8 @@ public final int getSegmentCount( ArtifactVersion v )
*/
public final ArtifactVersion incrementSegment( ArtifactVersion v, Segment segment ) throws InvalidSegmentException
{
if ( VersionComparators.isSnapshot( v ) )
{
return VersionComparators.copySnapshot( v, innerIncrementSegment( VersionComparators.stripSnapshot( v ),
segment ) );
}
int segmentCount = getSegmentCount( v );
if ( segment.value() >= segmentCount )
{
throw new InvalidSegmentException( segment, segmentCount, v );
}
return innerIncrementSegment( v, segment );
return VersionComparators.copySnapshot( v, innerIncrementSegment( VersionComparators.stripSnapshot( v ),
segment ) );
}

protected abstract ArtifactVersion innerIncrementSegment( ArtifactVersion v, Segment segment )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.matchesPattern;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -307,4 +308,25 @@ public void testDependenciesShouldOverrideDependencyManagement() throws IOExcept
String output = os.toString().replaceAll( "\n", "" );
assertThat( output, Matchers.stringContainsInOrder( "artifactB" ) );
}

@Test
public void testWrongReportBounds() throws IOException, MavenReportException
{
OutputStream os = new ByteArrayOutputStream();
SinkFactory sinkFactory = new Xhtml5SinkFactory();
new TestDependencyUpdatesReportMojo()
.withOnlyUpgradable( true )
.withDependencies(
dependencyOf( "test-artifact" ) )
.withArtifactMetadataSource( mockArtifactMetadataSource( new HashMap<String, String[]>()
{{
put( "test-artifact", new String[] { "1.0.0", "2.0.0-M1", "2.0.0-beta1", "2.0.0-rc2" } );
}} ) )
.generate( sinkFactory.createSink( os ), sinkFactory, Locale.getDefault() );

String output = os.toString().replaceAll( "\n", "" );
assertThat( output, allOf(
matchesPattern( ".*<td>report.overview.numNewerMajorAvailable</td>\\s*<td>1</td>.*" ),
matchesPattern( ".*<td>report.overview.numUpToDate</td>\\s*<td>0</td>.*" ) ) );
}
}

0 comments on commit f8c36bb

Please sign in to comment.