MulePluginsCompatibilityValidator { protected boolean areMulePluginVersionCompatible(List<ArtifactCoordinates> dependencies) { Set<String> majors = dependencies.stream() .map(ArtifactCoordinates::getVersion) .map(VersionUtils::getMajor) .collect(Collectors.toSet()); return majors.size() <= 1; }  void validate(List<ArtifactCoordinates> mulePlugins);  }
@Test public void validateSameMulePluginTest() { dependencies.add(DEPENDENCY0); dependencies.add(DEPENDENCY0); assertThat("A mule plugin should be self-compatible", validator.areMulePluginVersionCompatible(dependencies), is(true)); }
@Test public void validateOrderMulePluginTest() { dependencies1 = new ArrayList<>(); dependencies1.add(DEPENDENCY0); dependencies1.add(DEPENDENCY1); dependencies2 = new ArrayList<>(); dependencies2.add(DEPENDENCY1); dependencies2.add(DEPENDENCY0); assertThat("Validation should order-independent", validator.areMulePluginVersionCompatible(dependencies1) == validator.areMulePluginVersionCompatible(dependencies2), is(true)); }
@Test public void validateDifferentMulePluginsTest() { dependencies.add(DEPENDENCY0); dependencies.add(DEPENDENCY1); dependencies1.add(DEPENDENCY1); dependencies1.add(DEPENDENCY2); dependencies2.add(DEPENDENCY0); dependencies2.add(DEPENDENCY2); assertThat("Validation should be valid for all elements of same version", validator.areMulePluginVersionCompatible(dependencies) && validator .areMulePluginVersionCompatible(dependencies1) == validator.areMulePluginVersionCompatible(dependencies2), is(true)); }
@Test public void areMulePluginVersionNotCompatibleTest() { dependencies.add(createDependency(0, "0.8.0", "mule-plugin")); dependencies.add(createDependency(1, "1.0.1", "mule-plugin")); assertThat("Mule plugins should be considered version compatible", validator.areMulePluginVersionCompatible(dependencies), is(false)); }
@Test public void areMulePluginVersionNotCompatibleAtLeastOneNotCompatibleTest() { dependencies.add(createDependency(0, "0.8.0", "mule-plugin")); dependencies.add(createDependency(1, "1.0.1", "mule-plugin")); dependencies.add(createDependency(2, "0.8.1", "mule-plugin")); assertThat("Mule plugins should be considered version compatible", validator.areMulePluginVersionCompatible(dependencies), is(false)); }
@Test public void areMulePluginVersionNotCompatibleWithAllNotCompatibleTest() { dependencies.add(createDependency(0, "0.8.0", "mule-plugin")); dependencies.add(createDependency(1, "1.0.1", "mule-plugin")); dependencies.add(createDependency(2, "2.0.1", "mule-plugin")); assertThat("Mule plugins should be considered version compatible", validator.areMulePluginVersionCompatible(dependencies), is(false)); }
@Test public void areMulePluginVersionCompatibleEmptyListTest() { assertThat("Mule plugins empty list should be considered version compatible", validator.areMulePluginVersionCompatible(dependencies), is(true)); }
@Test public void areMulePluginVersionCompatibleOneElementTest() { dependencies.add(createDependency(0, "1.0.0", "mule-plugin")); assertThat("Mule plugins unit list should be considered version compatible", validator.areMulePluginVersionCompatible(dependencies), is(true)); }
@Test public void areMulePluginVersionCompatibleMultipleElementsTest() { dependencies.add(createDependency(0, "1.0.0", "mule-plugin")); dependencies.add(createDependency(1, "1.0.1", "mule-plugin")); dependencies.add(createDependency(2, "1.1.0", "mule-plugin")); dependencies.add(createDependency(3, "1.1.1", "mule-plugin")); assertThat("Mule plugins should be considered version compatible", validator.areMulePluginVersionCompatible(dependencies), is(true)); }