SemverIgnoreTransform implements DifferenceTransform<Element> { @Nullable @Override public Difference transform(@Nullable Element oldElement, @Nullable Element newElement, @Nonnull Difference difference) { if (!enabled) { return difference; } if (passThroughDifferences.contains(difference.code)) { return difference; } if (allowedSeverity == null) { return asBreaking(difference); } else if (allowedSeverity == DifferenceSeverity.BREAKING) { return null; } else { DifferenceSeverity diffSeverity = getMaxSeverity(difference); if (allowedSeverity.ordinal() - diffSeverity.ordinal() >= 0) { return null; } else { return asBreaking(difference); } } }  @Nonnull @Override Pattern[] getDifferenceCodePatterns(); @Nullable @Override Difference transform(@Nullable Element oldElement, @Nullable Element newElement,
                                                    @Nonnull Difference difference); @Override void close(); @Nullable @Override String getExtensionId(); @Nullable @Override Reader getJSONSchema(); @Override void initialize(@Nonnull AnalysisContext analysisContext);  }
@Test public void testDisabledByDefault() { DifferenceTransform<?> tr = getTestTransform("0.0.0", "0.0.1", "[{\"extension\": \"revapi.semver.ignore\", \"configuration\": {}}]"); Assert.assertSame(NON_BREAKING, tr.transform(null, null, NON_BREAKING)); Assert.assertSame(POTENTIALLY_BREAKING, tr.transform(null, null, POTENTIALLY_BREAKING)); Assert.assertSame(BREAKING, tr.transform(null, null, BREAKING)); }
@Test public void testDefaultSeverities() { String config = "[{\"extension\": \"revapi.semver.ignore\", \"configuration\": {\"enabled\": true}}]"; DifferenceTransform<?> tr = getTestTransform("0.0.0", "0.0.1", config); Assert.assertNull(tr.transform(null, null, NON_BREAKING)); Assert.assertTrue(isBreaking(tr.transform(null, null, POTENTIALLY_BREAKING))); Assert.assertTrue(isBreaking(tr.transform(null, null, BREAKING))); tr = getTestTransform("0.0.0", "0.1.0", config); Assert.assertNull(tr.transform(null, null, NON_BREAKING)); Assert.assertNull(tr.transform(null, null, POTENTIALLY_BREAKING)); Assert.assertNull(tr.transform(null, null, BREAKING)); tr = getTestTransform("0.0.0", "1.0.0", config); Assert.assertNull(tr.transform(null, null, NON_BREAKING)); Assert.assertNull(tr.transform(null, null, POTENTIALLY_BREAKING)); Assert.assertNull(tr.transform(null, null, BREAKING)); tr = getTestTransform("1.0.0", "1.0.1", config); Assert.assertTrue(isBreaking(tr.transform(null, null, NON_BREAKING))); Assert.assertTrue(isBreaking(tr.transform(null, null, POTENTIALLY_BREAKING))); Assert.assertTrue(isBreaking(tr.transform(null, null, BREAKING))); tr = getTestTransform("1.0.0", "1.1.0", config); Assert.assertNull(tr.transform(null, null, NON_BREAKING)); Assert.assertTrue(isBreaking(tr.transform(null, null, POTENTIALLY_BREAKING))); Assert.assertTrue(isBreaking(tr.transform(null, null, BREAKING))); tr = getTestTransform("1.0.0", "2.0.0", config); Assert.assertNull(tr.transform(null, null, NON_BREAKING)); Assert.assertNull(tr.transform(null, null, POTENTIALLY_BREAKING)); Assert.assertNull(tr.transform(null, null, BREAKING)); }
@Test public void testSeverityOverrides() { String config = "[{\"extension\": \"revapi.semver.ignore\", \"configuration\": {\"enabled\": true," + "\"versionIncreaseAllows\":{\"major\":\"potentiallyBreaking\",\"minor\":\"nonBreaking\",\"patch\": \"none\"}}}]"; DifferenceTransform<?> tr = getTestTransform("0.0.0", "0.0.1", config); Assert.assertTrue(isBreaking(tr.transform(null, null, NON_BREAKING))); Assert.assertTrue(isBreaking(tr.transform(null, null, POTENTIALLY_BREAKING))); Assert.assertTrue(isBreaking(tr.transform(null, null, BREAKING))); tr = getTestTransform("0.0.0", "0.1.0", config); Assert.assertNull(tr.transform(null, null, NON_BREAKING)); Assert.assertTrue(isBreaking(tr.transform(null, null, POTENTIALLY_BREAKING))); Assert.assertTrue(isBreaking(tr.transform(null, null, BREAKING))); tr = getTestTransform("0.0.0", "1.0.0", config); Assert.assertNull(tr.transform(null, null, NON_BREAKING)); Assert.assertNull(tr.transform(null, null, POTENTIALLY_BREAKING)); Assert.assertTrue(isBreaking(tr.transform(null, null, BREAKING))); tr = getTestTransform("1.0.0", "1.0.1", config); Assert.assertTrue(isBreaking(tr.transform(null, null, NON_BREAKING))); Assert.assertTrue(isBreaking(tr.transform(null, null, POTENTIALLY_BREAKING))); Assert.assertTrue(isBreaking(tr.transform(null, null, BREAKING))); tr = getTestTransform("1.0.0", "1.1.0", config); Assert.assertNull(tr.transform(null, null, NON_BREAKING)); Assert.assertTrue(isBreaking(tr.transform(null, null, POTENTIALLY_BREAKING))); Assert.assertTrue(isBreaking(tr.transform(null, null, BREAKING))); tr = getTestTransform("1.0.0", "2.0.0", config); Assert.assertNull(tr.transform(null, null, NON_BREAKING)); Assert.assertNull(tr.transform(null, null, POTENTIALLY_BREAKING)); Assert.assertTrue(isBreaking(tr.transform(null, null, BREAKING))); }
@Test public void testPassthrough() { String config = "[{\"extension\": \"revapi.semver.ignore\", \"configuration\": {\"enabled\": true, \"passThroughDifferences\": [\"potentiallyBreaking\"]}}]"; DifferenceTransform<?> tr = getTestTransform("1.0.0", "2.0.0", config); Assert.assertNull(tr.transform(null, null, NON_BREAKING)); Assert.assertSame(POTENTIALLY_BREAKING, tr.transform(null, null, POTENTIALLY_BREAKING)); Assert.assertNull(tr.transform(null, null, BREAKING)); }
@Test public void testNoOldVersion() { DifferenceTransform<?> tr = getTestTransform(null, "15", "[{\"extension\": \"revapi.semver.ignore\", \"configuration\": {\"enabled\": true}}]"); Assert.assertSame(NON_BREAKING, tr.transform(null, null, NON_BREAKING)); Assert.assertSame(POTENTIALLY_BREAKING, tr.transform(null, null, POTENTIALLY_BREAKING)); Assert.assertSame(BREAKING, tr.transform(null, null, BREAKING)); }
@Test public void testAppliesNameAndDescriptionChangesOnlyOnce() { DifferenceTransform<?> tr = getTestTransform("1.0.0", "1.0.1", "[{\"extension\": \"revapi.semver.ignore\", \"configuration\": {\"enabled\": true}}]"); Difference transformed = tr.transform(null, null, POTENTIALLY_BREAKING); Assert.assertNotNull(transformed); Difference transformed2 = tr.transform(null, null, transformed); Assert.assertEquals(transformed, transformed2); }