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
4 changes: 2 additions & 2 deletions japicmp/src/main/java/japicmp/versioning/VersionChange.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ public VersionChange(List<SemanticVersion> oldVersions, List<SemanticVersion> ne

public Optional<SemanticVersion.ChangeType> computeChangeType() throws JApiCmpException {
if (this.oldVersions.isEmpty()) {
if (ignoreMissingOldVersion) {
if (!ignoreMissingOldVersion) {
throw new JApiCmpException(JApiCmpException.Reason.IllegalArgument, "Could not extract semantic version for at least one old version. Please " +
"follow the rules for semantic versioning.");
} else {
return Optional.absent();
}
}
if (this.newVersions.isEmpty()) {
if (ignoreMissingNewVersion) {
if (!ignoreMissingNewVersion) {
throw new JApiCmpException(JApiCmpException.Reason.IllegalArgument, "Could not extract semantic version for at least one new version. Please " +
"follow the rules for semantic versioning.");
} else {
Expand Down
29 changes: 22 additions & 7 deletions japicmp/src/test/java/japicmp/versioning/VersionChangeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,36 @@ public void testTwoVersionsMajorChangeNotAllVersionsTheSameAndDifferentNumberofA
fail();
}

@Test
@Test(expected = JApiCmpException.class)
public void testMissingOldVersion() {
VersionChange vc = new VersionChange(Collections.singletonList(new SemanticVersion(1, 2, 3)), Collections.singletonList(new SemanticVersion(1, 2, 3)), true, false);
assertThat(vc.computeChangeType().get(), is(SemanticVersion.ChangeType.UNCHANGED));
VersionChange vc = new VersionChange(Collections.<SemanticVersion>emptyList(), Collections.singletonList(new SemanticVersion(1, 2, 3)), false, false);
vc.computeChangeType();
fail();
}

@Test
public void testIgnoreMissingOldVersion() {
VersionChange vc = new VersionChange(Collections.<SemanticVersion>emptyList(), Collections.singletonList(new SemanticVersion(1, 2, 3)), true, false);
assertThat(vc.computeChangeType().isPresent(), is(false));
}

@Test(expected = JApiCmpException.class)
public void testMissingNewVersion() {
VersionChange vc = new VersionChange(Collections.singletonList(new SemanticVersion(1, 2, 3)), Collections.singletonList(new SemanticVersion(1, 2, 3)), false, true);
assertThat(vc.computeChangeType().get(), is(SemanticVersion.ChangeType.UNCHANGED));
VersionChange vc = new VersionChange(Collections.singletonList(new SemanticVersion(1, 2, 3)), Collections.<SemanticVersion>emptyList(), false, false);
vc.computeChangeType();
fail();
}

@Test
public void testNoParameter() {
VersionChange vc = new VersionChange(new ArrayList<SemanticVersion>(), new ArrayList<SemanticVersion>(), false, false);
public void testIgnoreMissingNewVersion() {
VersionChange vc = new VersionChange(Collections.singletonList(new SemanticVersion(1, 2, 3)), Collections.<SemanticVersion>emptyList(), false, true);
assertThat(vc.computeChangeType().isPresent(), is(false));
}

@Test(expected = JApiCmpException.class)
public void testNoParameter() {
VersionChange vc = new VersionChange(Collections.<SemanticVersion>emptyList(), Collections.<SemanticVersion>emptyList(), false, false);
vc.computeChangeType();
fail();
}
}