Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,15 @@ public Restriction restrictionForSelectedSegment(ArtifactVersion lowerBound, Opt
ArtifactVersion nextVersion = selectedSegment
.filter(s -> s.isMajorTo(SUBINCREMENTAL))
.map(Segment::minorTo)
.filter(__ -> highestLowerBound != null)
.map(s -> (ArtifactVersion) new BoundArtifactVersion(highestLowerBound, s))
.orElse(highestLowerBound);
return new Restriction(
nextVersion,
false,
selectedSegment
.filter(MAJOR::isMajorTo)
.filter(__ -> highestLowerBound != null)
.map(s -> (ArtifactVersion) new BoundArtifactVersion(highestLowerBound, s))
.orElse(null),
false);
Expand All @@ -157,6 +159,7 @@ public Restriction restrictionForUnchangedSegment(
.orElse(null)
: selectedRestrictionUpperBound;
ArtifactVersion upperBound = unchangedSegment
.filter(__ -> selectedRestrictionUpperBound != null)
.map(s -> (ArtifactVersion) new BoundArtifactVersion(
selectedRestrictionUpperBound, s.isMajorTo(SUBINCREMENTAL) ? Segment.minorTo(s) : s))
.orElse(null);
Expand All @@ -174,7 +177,8 @@ public Restriction restrictionForUnchangedSegment(
@Override
public Restriction restrictionForIgnoreScope(ArtifactVersion lowerBound, Optional<Segment> ignored) {
ArtifactVersion highestLowerBound = getHighestLowerBound(lowerBound);
ArtifactVersion nextVersion = ignored.map(s -> (ArtifactVersion) new BoundArtifactVersion(highestLowerBound, s))
ArtifactVersion nextVersion = ignored.filter(__ -> highestLowerBound != null)
.map(s -> (ArtifactVersion) new BoundArtifactVersion(highestLowerBound, s))
.orElse(highestLowerBound);
return new Restriction(nextVersion, false, null, false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import static org.hamcrest.Matchers.arrayContaining;
import static org.hamcrest.Matchers.arrayWithSize;
import static org.hamcrest.Matchers.emptyArray;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasToString;
import static org.hamcrest.Matchers.is;
Expand Down Expand Up @@ -344,4 +345,34 @@ void testPredicate() {
assertThat(noSnapshots.getVersions(true), arrayWithSize(15));
assertThat(noSnapshots.getCurrentVersion(), nullValue());
}

@Test
void testRestrictionForUnchangedSegmentIfActualVersionNullAndUpperRestrictionNull() throws InvalidSegmentException {
ArtifactVersions versions = new ArtifactVersions(
new DefaultArtifact("default-group", "dummy-api", "(,2)", "foo", "bar", "jar", null),
Arrays.asList(versions("1.0.0")));
assertThat(
versions.restrictionForUnchangedSegment(null, Optional.of(MAJOR), false),
is(equalTo(new Restriction(null, false, null, false))));
}

@Test
void testRestrictionForSelectedSegmentIfLowerBoundNull() throws InvalidSegmentException {
ArtifactVersions versions = new ArtifactVersions(
new DefaultArtifact("default-group", "dummy-api", "(,)", "foo", "bar", "jar", null),
Arrays.asList(versions("1.0.0")));
assertThat(
versions.restrictionForSelectedSegment(null, Optional.of(MAJOR)),
is(equalTo(new Restriction(null, false, null, false))));
}

@Test
void testRestrictionForIgnoreScopeLowerBoundNull() throws InvalidSegmentException {
ArtifactVersions versions = new ArtifactVersions(
new DefaultArtifact("default-group", "dummy-api", "(,)", "foo", "bar", "jar", null),
Arrays.asList(versions("1.0.0")));
assertThat(
versions.restrictionForIgnoreScope(null, Optional.of(MAJOR)),
is(equalTo(new Restriction(null, false, null, false))));
}
}