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);
}
}
*/
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);
}
}