BoundedContextBuilder implements Logging { @CanIgnoreReturnValue public BoundedContextBuilder setTenantIndex(TenantIndex tenantIndex) { if (isMultitenant()) { checkNotNull(tenantIndex, "`%s` cannot be null in a multitenant `BoundedContext`.", TenantIndex.class.getSimpleName()); } this.tenantIndex = tenantIndex; return this; } BoundedContextBuilder(ContextSpec spec); private  BoundedContextBuilder(ContextSpec spec, SystemSettings systemFeatures); @Internal @VisibleForTesting static BoundedContextBuilder assumingTests(boolean multitenant); @Internal @VisibleForTesting static BoundedContextBuilder assumingTests(); ContextSpec spec(); BoundedContextName name(); boolean isMultitenant(); Optional<? extends TenantIndex> tenantIndex(); @CanIgnoreReturnValue BoundedContextBuilder enrichEventsUsing(EventEnricher enricher); Optional<EventEnricher> eventEnricher(); @CanIgnoreReturnValue BoundedContextBuilder setTenantIndex(TenantIndex tenantIndex); @CanIgnoreReturnValue BoundedContextBuilder addCommandDispatcher(CommandDispatcher commandDispatcher); @CanIgnoreReturnValue BoundedContextBuilder addCommandFilter(BusFilter<CommandEnvelope> filter); BoundedContextBuilder addCommandListener(Listener<CommandEnvelope> listener); @CanIgnoreReturnValue BoundedContextBuilder addEventDispatcher(EventDispatcher eventDispatcher); @CanIgnoreReturnValue BoundedContextBuilder addEventFilter(BusFilter<EventEnvelope> filter); BoundedContextBuilder addEventListener(Listener<EventEnvelope> listener); @CanIgnoreReturnValue BoundedContextBuilder add(Class<E> entityClass); @CanIgnoreReturnValue BoundedContextBuilder add(Repository<?, ?> repository); @CanIgnoreReturnValue BoundedContextBuilder removeCommandDispatcher(CommandDispatcher commandDispatcher); @CanIgnoreReturnValue BoundedContextBuilder removeEventDispatcher(EventDispatcher eventDispatcher); @CanIgnoreReturnValue BoundedContextBuilder remove(Class<E> entityClass); @CanIgnoreReturnValue BoundedContextBuilder remove(Repository<?, ?> repository); ImmutableList<Repository<?, ?>> repositories(); ImmutableList<CommandDispatcher> commandDispatchers(); ImmutableList<EventDispatcher> eventDispatchers(); @CanIgnoreReturnValue BoundedContextBuilder setAggregateRootDirectory(Supplier<AggregateRootDirectory> directory); SystemSettings systemFeatures(); BoundedContext build(); @Internal @VisibleForTesting BoundedContextBuilder testingCopy();  }
@Test @DisplayName("allow `TenantIndex` configuration") void setTenantIndex() { TenantIndex tenantIndex = new StubTenantIndex(); BoundedContextBuilder builder = BoundedContextBuilder .assumingTests() .setTenantIndex(tenantIndex); assertThat(builder.tenantIndex()) .hasValue(tenantIndex); }