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
andrzejj0 committed Oct 15, 2022
1 parent 954a853 commit 45d70f0
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 35 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" } );
}} ) )
.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>.*" ) ) );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ public void testSegmentCounting()
@Test
public void testSegmentIncrementing() throws InvalidSegmentException
{
assertIncrement( "6", "5", MAJOR );
assertIncrement( "6.0", "5.0", MAJOR );
assertIncrement( "5.1", "5.0", MINOR );
assertIncrement( "5.1.0", "5.0.1", MINOR );
assertIncrement( "5.alpha.2", "5.alpha.1", MAJOR );
assertIncrement( "5.alpha-1.2", "5.alpha-1.1", MAJOR );
assertIncrement( "5.alpha-1.ba", "5.alpha-1.az", MAJOR );
assertIncrement( "5.alpha-wins.2", "5.alpha-wins.1", MAJOR );
assertIncrement( "6-SNAPSHOT", "5", MAJOR );
assertIncrement( "6.0-SNAPSHOT", "5.0", MAJOR );
assertIncrement( "5.1-SNAPSHOT", "5.0", MINOR );
assertIncrement( "5.1.0-SNAPSHOT", "5.0.1", MINOR );
assertIncrement( "5.alpha.2-SNAPSHOT", "5.alpha.1", MAJOR );
assertIncrement( "5.alpha-1.2-SNAPSHOT", "5.alpha-1.1", MAJOR );
assertIncrement( "5.alpha-1.ba-SNAPSHOT", "5.alpha-1.az", MAJOR );
assertIncrement( "5.alpha-wins.2-SNAPSHOT", "5.alpha-wins.1", MAJOR );
assertIncrement( "1.0-alpha-3-SNAPSHOT", "1.0-alpha-2-SNAPSHOT", SUBINCREMENTAL );
assertIncrement( "1.0-alpha-90-SNAPSHOT", "1.0-alpha-9-SNAPSHOT", SUBINCREMENTAL );
assertIncrement( "1.0-za-SNAPSHOT", "1.0-z-SNAPSHOT", SUBINCREMENTAL );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,21 @@ public void testSegmentCounting() throws Exception
@Test
public void testSegmentIncrementing() throws Exception
{
assertEquals( new DefaultArtifactVersion( "6" ).toString(),
assertEquals( new DefaultArtifactVersion( "6-SNAPSHOT" ).toString(),
instance.incrementSegment( new DefaultArtifactVersion( "5" ), MAJOR ).toString() );
assertEquals( new DefaultArtifactVersion( "6.0" ).toString(),
assertEquals( new DefaultArtifactVersion( "6.0-SNAPSHOT" ).toString(),
instance.incrementSegment( new DefaultArtifactVersion( "5.0" ), MAJOR ).toString() );
assertEquals( new DefaultArtifactVersion( "5.1" ).toString(),
assertEquals( new DefaultArtifactVersion( "5.1-SNAPSHOT" ).toString(),
instance.incrementSegment( new DefaultArtifactVersion( "5.0" ), MINOR ).toString() );
assertEquals( new DefaultArtifactVersion( "5.1.0" ).toString(),
assertEquals( new DefaultArtifactVersion( "5.1.0-SNAPSHOT" ).toString(),
instance.incrementSegment( new DefaultArtifactVersion( "5.0.1" ), MINOR ).toString() );
assertEquals( new DefaultArtifactVersion( "5.beta.0" ).toString(),
assertEquals( new DefaultArtifactVersion( "5.beta.0-SNAPSHOT" ).toString(),
instance.incrementSegment( new DefaultArtifactVersion( "5.alpha.1" ), MINOR ).toString() );
assertEquals( new DefaultArtifactVersion( "5.beta-0.0" ).toString(),
assertEquals( new DefaultArtifactVersion( "5.beta-0.0-SNAPSHOT" ).toString(),
instance.incrementSegment( new DefaultArtifactVersion( "5.alpha-1.1" ), MINOR ).toString() );
assertEquals( new DefaultArtifactVersion( "5.alpha-2.0" ).toString(),
assertEquals( new DefaultArtifactVersion( "5.alpha-2.0-SNAPSHOT" ).toString(),
instance.incrementSegment( new DefaultArtifactVersion( "5.alpha-1.1" ), INCREMENTAL ).toString() );
assertEquals( new DefaultArtifactVersion( "5.beta-0.0" ).toString(),
assertEquals( new DefaultArtifactVersion( "5.beta-0.0-SNAPSHOT" ).toString(),
instance.incrementSegment( new DefaultArtifactVersion( "5.alpha-wins.1" ), MINOR ).toString() );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,22 +105,22 @@ public void testSegmentCounting()
@Test
public void testSegmentIncrementing() throws Exception
{
assertEquals( new DefaultArtifactVersion( "6" ).toString(),
assertEquals( new DefaultArtifactVersion( "6-SNAPSHOT" ).toString(),
instance.incrementSegment( new DefaultArtifactVersion( "5" ), MAJOR ).toString() );
assertEquals( new DefaultArtifactVersion( "6.0" ).toString(),
assertEquals( new DefaultArtifactVersion( "6.0-SNAPSHOT" ).toString(),
instance.incrementSegment( new DefaultArtifactVersion( "5.0" ), MAJOR ).toString() );
assertEquals( new DefaultArtifactVersion( "5.1" ).toString(),
assertEquals( new DefaultArtifactVersion( "5.1-SNAPSHOT" ).toString(),
instance.incrementSegment( new DefaultArtifactVersion( "5.0" ), MINOR ).toString() );
assertEquals( new DefaultArtifactVersion( "5.1.0" ).toString(),
assertEquals( new DefaultArtifactVersion( "5.1.0-SNAPSHOT" ).toString(),
instance.incrementSegment( new DefaultArtifactVersion( "5.0.1" ), MINOR ).toString() );
assertEquals( new DefaultArtifactVersion( "5.beta.0" ).toString(),
assertEquals( new DefaultArtifactVersion( "5.beta.0-SNAPSHOT" ).toString(),
instance.incrementSegment( new DefaultArtifactVersion( "5.alpha.1" ), MINOR ).toString() );
assertEquals( new DefaultArtifactVersion( "5.alpha-2.0" ).toString(),
assertEquals( new DefaultArtifactVersion( "5.alpha-2.0-SNAPSHOT" ).toString(),
instance.incrementSegment( new DefaultArtifactVersion( "5.alpha-1.1" ), MINOR ).toString() );
assertEquals( new DefaultArtifactVersion( "5.alpha-1.2" ).toString(),
assertEquals( new DefaultArtifactVersion( "5.alpha-1.2-SNAPSHOT" ).toString(),
instance.incrementSegment( new DefaultArtifactVersion( "5.alpha-1.1" ), INCREMENTAL )
.toString() );
assertEquals( new DefaultArtifactVersion( "5.beta.0" ).toString(),
assertEquals( new DefaultArtifactVersion( "5.beta.0-SNAPSHOT" ).toString(),
instance.incrementSegment( new DefaultArtifactVersion( "5.alpha-wins.1" ), MINOR ).toString() );
}
}

0 comments on commit 45d70f0

Please sign in to comment.