aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2021-04-12 21:59:01 -0500
committersonartech <sonartech@sonarsource.com>2021-04-14 20:03:29 +0000
commit0e3231774e88bf7c76855c13d952deeab7351f1d (patch)
tree629c112567110f8d461d6d55557c74b8d9adf10d /sonar-core
parenteca5700aeaaa1b3a6c40c77318d33e98a6dd23dd (diff)
downloadsonarqube-0e3231774e88bf7c76855c13d952deeab7351f1d.tar.gz
sonarqube-0e3231774e88bf7c76855c13d952deeab7351f1d.zip
SONAR-14675 Community Edition should have an EditionProvider
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/platform/PlatformEditionProvider.java20
-rw-r--r--sonar-core/src/test/java/org/sonar/core/platform/PlatformEditionProviderTest.java47
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<Edition> 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);
}
}