rpuch commented on a change in pull request #460: URL: https://github.com/apache/ignite-3/pull/460#discussion_r753248995
########## File path: modules/api/src/test/java/org/apache/ignite/configuration/CoreDistributedConfigurationModuleTest.java ########## @@ -0,0 +1,100 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.configuration; + +import static com.github.npathai.hamcrestopt.OptionalMatchers.isPresent; +import static org.apache.ignite.configuration.annotation.ConfigurationType.DISTRIBUTED; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.anEmptyMap; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.is; + +import java.util.Optional; +import java.util.ServiceLoader; +import java.util.ServiceLoader.Provider; +import org.apache.ignite.configuration.schemas.runner.ClusterConfiguration; +import org.apache.ignite.configuration.schemas.store.DataStorageConfiguration; +import org.apache.ignite.configuration.schemas.table.HashIndexConfigurationSchema; +import org.apache.ignite.configuration.schemas.table.PartialIndexConfigurationSchema; +import org.apache.ignite.configuration.schemas.table.SortedIndexConfigurationSchema; +import org.apache.ignite.configuration.schemas.table.TablesConfiguration; +import org.apache.ignite.configuration.validation.ConfigurationModule; +import org.junit.jupiter.api.Test; + +/** + * Tests for {@link CoreDistributedConfigurationModule}. + */ +class CoreDistributedConfigurationModuleTest { + private final CoreDistributedConfigurationModule module = new CoreDistributedConfigurationModule(); + + @Test + void typeIsDistributed() { + assertThat(module.type(), is(DISTRIBUTED)); + } + + @Test + void hasClusterConfigurationRoot() { + assertThat(module.rootKeys(), hasItem(ClusterConfiguration.KEY)); + } + + @Test + void hasTablesConfigurationRoot() { + assertThat(module.rootKeys(), hasItem(TablesConfiguration.KEY)); + } + + @Test + void hasDataStorageConfigurationRoot() { + assertThat(module.rootKeys(), hasItem(DataStorageConfiguration.KEY)); + } + + @Test + void providesNoValidators() { + assertThat(module.validators(), is(anEmptyMap())); + } + + @Test + void providesNoInternalSchemaExtensions() { + assertThat(module.internalSchemaExtensions(), is(empty())); + } + + @Test + void providesHashIndexConfigurationSchemaAsPolymorphicExtension() { + assertThat(module.polymorphicSchemaExtensions(), hasItem(HashIndexConfigurationSchema.class)); + } + + @Test + void providesSortedIndexConfigurationSchemaAsPolymorphicExtension() { + assertThat(module.polymorphicSchemaExtensions(), hasItem(SortedIndexConfigurationSchema.class)); + } + + @Test + void providesPartialIndexConfigurationSchemaAsPolymorphicExtension() { + assertThat(module.polymorphicSchemaExtensions(), hasItem(PartialIndexConfigurationSchema.class)); + } + + @Test + void isLoadedByServiceLoader() { + Optional<ConfigurationModule> maybeModule = ServiceLoader.load(ConfigurationModule.class).stream() + .map(Provider::get) + .filter(module -> module instanceof CoreDistributedConfigurationModule) + .findAny(); + + assertThat(maybeModule, isPresent()); Review comment: The library is added to test scope and not to runtime, also the library is tiny (3 classes), so it does not seem to add a noticable overhead. As for the advantages of this approach, I think there are at least two of them: * A more general is that Hamcrest matchers allow to write assertions that are, basically, just a plain English (with some punctuation, alas), like `assertThat(result, is(42))`. Any human being will immediately understand what this means, even if they do not know anything about junit or Hamcrest. In our case, it's `assertThat(something, isPresent())` which is again plain English * Also, you are right, the error message for Matcher-based code is better, it's ``` Expected: is <Present> but: was <Empty> ``` while for the `assertTrue` case it would be ``` Expected :true Actual :false ``` In the first case, you only get one bit of information, in the second you also see some part of the context (that something was expected to present). So it seems to be that the Matcher-style assertion is justified here. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
