From 0e3231774e88bf7c76855c13d952deeab7351f1d Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Mon, 12 Apr 2021 21:59:01 -0500 Subject: [PATCH] SONAR-14675 Community Edition should have an EditionProvider --- .../platform/PlatformEditionProvider.java | 20 +------- .../platform/PlatformEditionProviderTest.java | 47 +------------------ 2 files changed, 3 insertions(+), 64 deletions(-) diff --git a/sonar-core/src/main/java/org/sonar/core/platform/PlatformEditionProvider.java b/sonar-core/src/main/java/org/sonar/core/platform/PlatformEditionProvider.java index 0e5d68a9489..6ab15b1fb56 100644 --- a/sonar-core/src/main/java/org/sonar/core/platform/PlatformEditionProvider.java +++ b/sonar-core/src/main/java/org/sonar/core/platform/PlatformEditionProvider.java @@ -21,27 +21,9 @@ package org.sonar.core.platform; import java.util.Optional; -import static com.google.common.base.Preconditions.checkState; -import static org.sonar.core.platform.EditionProvider.Edition.COMMUNITY; - public class PlatformEditionProvider implements EditionProvider { - private static final EditionProvider[] NO_OTHER_PROVIDERS = new EditionProvider[0]; - private final EditionProvider[] otherEditionProviders; - - public PlatformEditionProvider() { - this(NO_OTHER_PROVIDERS); - } - - public PlatformEditionProvider(EditionProvider[] otherEditionProviders) { - this.otherEditionProviders = otherEditionProviders; - } - @Override public Optional get() { - checkState(otherEditionProviders.length <= 1, "There can't be more than 1 other EditionProvider"); - if (otherEditionProviders.length == 1) { - return otherEditionProviders[0].get(); - } - return Optional.of(COMMUNITY); + return Optional.of(Edition.COMMUNITY); } } diff --git a/sonar-core/src/test/java/org/sonar/core/platform/PlatformEditionProviderTest.java b/sonar-core/src/test/java/org/sonar/core/platform/PlatformEditionProviderTest.java index a6793840b81..038ab7143e8 100644 --- a/sonar-core/src/test/java/org/sonar/core/platform/PlatformEditionProviderTest.java +++ b/sonar-core/src/test/java/org/sonar/core/platform/PlatformEditionProviderTest.java @@ -19,57 +19,14 @@ */ package org.sonar.core.platform; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; -import static java.util.Optional.of; import static org.assertj.core.api.Assertions.assertThat; import static org.sonar.core.platform.EditionProvider.Edition.COMMUNITY; -import static org.sonar.core.platform.EditionProvider.Edition.DATACENTER; -import static org.sonar.core.platform.EditionProvider.Edition.DEVELOPER; public class PlatformEditionProviderTest { - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - @Test - public void returns_COMMUNITY_when_there_is_no_other_EditionProvider() { - ComponentContainer container = new ComponentContainer(); - ComponentContainer child = new ComponentContainer(container); - child.add(PlatformEditionProvider.class); - - assertThat(container.getComponentByType(PlatformEditionProvider.class)).isNull(); - PlatformEditionProvider platformEditionProvider = child.getComponentByType(PlatformEditionProvider.class); - assertThat(platformEditionProvider.get()).contains(COMMUNITY); - } - - @Test - public void returns_edition_from_other_EditionProvider_in_any_container() { - ComponentContainer container = new ComponentContainer(); - container.add((EditionProvider) () -> of(DATACENTER)); - ComponentContainer child = new ComponentContainer(container); - child.add(PlatformEditionProvider.class); - - assertThat(container.getComponentByType(PlatformEditionProvider.class)).isNull(); - PlatformEditionProvider platformEditionProvider = child.getComponentByType(PlatformEditionProvider.class); - assertThat(platformEditionProvider.get()).contains(DATACENTER); - } - @Test - public void get_fails_with_ISE_if_there_is_more_than_one_other_EditionProvider_in_any_container() { - ComponentContainer container = new ComponentContainer(); - container.add((EditionProvider) () -> of(DATACENTER)); - ComponentContainer child = new ComponentContainer(container); - child.add((EditionProvider) () -> of(DEVELOPER)); - child.add(PlatformEditionProvider.class); - - assertThat(container.getComponentByType(PlatformEditionProvider.class)).isNull(); - PlatformEditionProvider platformEditionProvider = child.getComponentByType(PlatformEditionProvider.class); - - expectedException.expect(IllegalStateException.class); - expectedException.expectMessage("There can't be more than 1 other EditionProvider"); - - platformEditionProvider.get(); + public void returns_COMMUNITY() { + assertThat(new PlatformEditionProvider().get()).contains(COMMUNITY); } } -- 2.39.5