diff --git a/README.md b/README.md index 498f0ae..283da40 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# feature-flag +# option -![GitHub Workflow Status (branch)](https://img.shields.io/github/actions/workflow/status/KyoriPowered/feature-flag/build.yml?branch=trunk) [![MIT License](https://img.shields.io/badge/license-MIT-blue)](license.txt) [![Maven Central](https://img.shields.io/maven-central/v/net.kyori/feature-flag?label=stable)](https://search.maven.org/search?q=g:net.kyori%20AND%20a:feature-flag) ![Sonatype Nexus (Snapshots)](https://img.shields.io/nexus/s/net.kyori/feature-flag?label=dev&server=https%3A%2F%2Fs01.oss.sonatype.org) [![Javadoc](https://img.shields.io/badge/javadoc-all-green)](https://jd.advntr.dev/) +![GitHub Workflow Status (branch)](https://img.shields.io/github/actions/workflow/status/KyoriPowered/option/build.yml?branch=trunk) [![MIT License](https://img.shields.io/badge/license-MIT-blue)](license.txt) [![Maven Central](https://img.shields.io/maven-central/v/net.kyori/option?label=stable)](https://search.maven.org/search?q=g:net.kyori%20AND%20a:option) ![Sonatype Nexus (Snapshots)](https://img.shields.io/nexus/s/net.kyori/option?label=dev&server=https%3A%2F%2Fs01.oss.sonatype.org) [![Javadoc](https://img.shields.io/badge/javadoc-all-green)](https://jd.advntr.dev/) A small library for handling version-based feature configuration. @@ -10,6 +10,6 @@ We appreciate contributions of any type. For any new features or typo-fix/style All the adventure projects are built with Gradle, require at least JDK 8, and use a common checkstyle configuration. Please make sure all tests pass, license headers are updated, and checkstyle passes to help us review your contribution. -`feature-flag` is released under the terms of the [MIT License](license.txt). +`option` is released under the terms of the [MIT License](license.txt). [Discord]: https://discord.gg/MMfhJ8F diff --git a/build.gradle.kts b/build.gradle.kts index a9491f7..0c69a72 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -31,7 +31,7 @@ sourceSets { main { multirelease { alternateVersions(9) - moduleName("net.kyori.featureflag") + moduleName("net.kyori.option") requireAllPackagesExported() } } @@ -42,7 +42,7 @@ indraSonatype { } indra { - github("KyoriPowered", "feature-flag") { + github("KyoriPowered", "option") { ci(true) } mitLicense() @@ -56,7 +56,7 @@ indra { signWithKeyFromPrefixedProperties("kyori") configurePublications { pom { - url = "https://feature-flag.kyori.net" + url = "https://option.kyori.net" developers { developer { id = "kashike" diff --git a/gradle.properties b/gradle.properties index b9da59b..614e80c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ group=net.kyori version=1.0.0-SNAPSHOT -description=A small library for handling version-based feature configuration +description=A small library for handling version-based option configuration javadocPublishRoot=https://jd.advntr.dev/ diff --git a/license_header.txt b/license_header.txt index 493c5cf..26f2b40 100644 --- a/license_header.txt +++ b/license_header.txt @@ -1,4 +1,4 @@ -This file is part of feature-flag, licensed under the MIT License. +This file is part of option, licensed under the MIT License. Copyright (c) $YEAR KyoriPowered diff --git a/settings.gradle.kts b/settings.gradle.kts index 05d82b9..d876f1d 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -16,4 +16,4 @@ dependencyResolutionManagement { } } -rootProject.name = "feature-flag" +rootProject.name = "option" diff --git a/src/main/java/net/kyori/featureflag/package-info.java b/src/main/java/net/kyori/featureflag/package-info.java deleted file mode 100644 index bfd12d4..0000000 --- a/src/main/java/net/kyori/featureflag/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Feature flag system. - */ -package net.kyori.featureflag; diff --git a/src/main/java/net/kyori/featureflag/FeatureFlag.java b/src/main/java/net/kyori/option/Option.java similarity index 72% rename from src/main/java/net/kyori/featureflag/FeatureFlag.java rename to src/main/java/net/kyori/option/Option.java index 1a46503..6519fcc 100644 --- a/src/main/java/net/kyori/featureflag/FeatureFlag.java +++ b/src/main/java/net/kyori/option/Option.java @@ -1,5 +1,5 @@ /* - * This file is part of feature-flag, licensed under the MIT License. + * This file is part of option, licensed under the MIT License. * * Copyright (c) 2023 KyoriPowered * @@ -21,14 +21,14 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package net.kyori.featureflag; +package net.kyori.option; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** - * A representation of a feature that can be toggled to one of several values. + * A representation of a configurable option. * *

Keys must be unique among all feature flag instances.

* @@ -36,10 +36,10 @@ * @since 1.0.0 */ @ApiStatus.NonExtendable -public interface FeatureFlag { +public interface Option { /** - * Create a feature flag with a boolean value type. + * Create an option with a boolean value type. * *

Flag keys must not be reused between flag instances.

* @@ -48,12 +48,12 @@ public interface FeatureFlag { * @return the flag instance * @since 1.0.0 */ - static FeatureFlag booleanFlag(final String id, final boolean defaultValue) { - return FeatureFlagImpl.flag(id, Boolean.class, defaultValue); + static Option booleanOption(final String id, final boolean defaultValue) { + return OptionImpl.option(id, Boolean.class, defaultValue); } /** - * Create a feature flag with an enum value type. + * Create an option with an enum value type. * *

Flag keys must not be reused between flag instances.

* @@ -64,14 +64,14 @@ static FeatureFlag booleanFlag(final String id, final boolean defaultVa * @return the flag instance * @since 1.0.0 */ - static > FeatureFlag enumFlag(final String id, final Class enumClazz, final E defaultValue) { - return FeatureFlagImpl.flag(id, enumClazz, defaultValue); + static > Option enumOption(final String id, final Class enumClazz, final E defaultValue) { + return OptionImpl.option(id, enumClazz, defaultValue); } /** - * Get the flag id. + * Get the option id. * - *

This must be unique among feature flags.

+ *

This must be unique among options.

* * @return the flag id * @since 1.0.0 @@ -79,7 +79,7 @@ static > FeatureFlag enumFlag(final String id, final Class< @NotNull String id(); /** - * Get the type of the flag value. + * Get the type of the option value. * * @return the value type * @since 1.0.0 @@ -87,7 +87,7 @@ static > FeatureFlag enumFlag(final String id, final Class< @NotNull Class type(); /** - * Get a default value for the flag, if any is present. + * Get a default value for the option, if any is present. * * @return the default value * @since 1.0.0 diff --git a/src/main/java/net/kyori/featureflag/FeatureFlagImpl.java b/src/main/java/net/kyori/option/OptionImpl.java similarity index 82% rename from src/main/java/net/kyori/featureflag/FeatureFlagImpl.java rename to src/main/java/net/kyori/option/OptionImpl.java index 4560600..2b3f493 100644 --- a/src/main/java/net/kyori/featureflag/FeatureFlagImpl.java +++ b/src/main/java/net/kyori/option/OptionImpl.java @@ -1,5 +1,5 @@ /* - * This file is part of feature-flag, licensed under the MIT License. + * This file is part of option, licensed under the MIT License. * * Copyright (c) 2023 KyoriPowered * @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package net.kyori.featureflag; +package net.kyori.option; import java.util.Objects; import java.util.Set; @@ -31,25 +31,25 @@ import static java.util.Objects.requireNonNull; -final class FeatureFlagImpl implements FeatureFlag { +final class OptionImpl implements Option { private static final Set KNOWN_KEYS = ConcurrentHashMap.newKeySet(); private final String id; private final Class type; - private final @Nullable V defaultValue; // excluded from equality comparisons, it does not form part of the flag identity + private final @Nullable V defaultValue; // excluded from equality comparisons, it does not form part of the option identity - FeatureFlagImpl(final @NotNull String id, final @NotNull Class type, final @Nullable V defaultValue) { + OptionImpl(final @NotNull String id, final @NotNull Class type, final @Nullable V defaultValue) { this.id = id; this.type = type; this.defaultValue = defaultValue; } - static FeatureFlag flag(final String id, final Class type, final @Nullable T defaultValue) { + static Option option(final String id, final Class type, final @Nullable T defaultValue) { if (!KNOWN_KEYS.add(id)) { - throw new IllegalStateException("Key " + id + " has already been used. Feature flag keys must be unique."); + throw new IllegalStateException("Key " + id + " has already been used. Option keys must be unique."); } - return new FeatureFlagImpl<>( + return new OptionImpl<>( requireNonNull(id, "id"), requireNonNull(type, "type"), defaultValue @@ -75,7 +75,7 @@ static FeatureFlag flag(final String id, final Class type, final @Null public boolean equals(final @Nullable Object other) { if (this == other) return true; if (other == null || getClass() != other.getClass()) return false; - final FeatureFlagImpl that = (FeatureFlagImpl) other; + final OptionImpl that = (OptionImpl) other; return Objects.equals(this.id, that.id) && Objects.equals(this.type, that.type); } diff --git a/src/main/java/net/kyori/featureflag/FeatureFlagConfig.java b/src/main/java/net/kyori/option/OptionState.java similarity index 58% rename from src/main/java/net/kyori/featureflag/FeatureFlagConfig.java rename to src/main/java/net/kyori/option/OptionState.java index 5656dd9..6fc2ba1 100644 --- a/src/main/java/net/kyori/featureflag/FeatureFlagConfig.java +++ b/src/main/java/net/kyori/option/OptionState.java @@ -1,5 +1,5 @@ /* - * This file is part of feature-flag, licensed under the MIT License. + * This file is part of option, licensed under the MIT License. * * Copyright (c) 2023 KyoriPowered * @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package net.kyori.featureflag; +package net.kyori.option; import java.util.Map; import java.util.function.Consumer; @@ -34,76 +34,76 @@ * @since 1.0.0 */ @ApiStatus.NonExtendable -public interface FeatureFlagConfig { +public interface OptionState { /** - * Get an empty set of feature flags. + * Get an empty set of options. * - * @return the empty feature flag set + * @return the empty option state * @since 1.0.0 */ - static FeatureFlagConfig emptyFeatureFlagConfig() { - return FeatureFlagConfigImpl.EMPTY; + static OptionState emptyOptionState() { + return OptionStateImpl.EMPTY; } /** - * Create a builder for an unversioned feature flag set. + * Create a builder for an unversioned option state. * * @return the builder * @since 1.0.0 */ - static @NotNull Builder featureFlagConfig() { - return new FeatureFlagConfigImpl.BuilderImpl(); + static @NotNull Builder optionState() { + return new OptionStateImpl.BuilderImpl(); } /** - * Create a builder for a versioned feature flag set. + * Create a builder for a versioned option state. * * @return the builder * @since 1.0.0 */ - static @NotNull VersionedBuilder versionedFeatureFlagConfig() { - return new FeatureFlagConfigImpl.VersionedBuilderImpl(); + static @NotNull VersionedBuilder versionedOptionState() { + return new OptionStateImpl.VersionedBuilderImpl(); } /** - * Get whether a flag set contains a certain flag at all. + * Get whether this state contains a certain option at all. * - * @param flag the flag to check. - * @return whether the flag has been touched. + * @param option the option to check. + * @return whether the option has been touched. * @since 1.0.0 */ - boolean has(final @NotNull FeatureFlag flag); + boolean has(final @NotNull Option option); /** - * Get the value set for a certain flag. + * Get the value set for a certain option. * - * @param flag the flag to query - * @return the flag value + * @param option the option to query + * @return the option value * @param the value type * @since 1.0.0 */ - V value(final @NotNull FeatureFlag flag); + V value(final @NotNull Option option); /** - * A composite feature flag set. + * A composite option set. * *

By default, this returns results for the newest supported version.

* * @since 1.0.0 */ @ApiStatus.NonExtendable - interface Versioned extends FeatureFlagConfig { + interface Versioned extends OptionState { /** * The individual changes in each supported version. * * @return the child sets that exist * @since 1.0.0 */ - @NotNull Map childSets(); + @NotNull Map childStates(); /** - * Request a view of this feature flag set showing only flags available at versions up to and including {@code version}. + * Request a view of this option state showing only option values available at versions up to and including {@code version}. * * @param version the version to query * @return a limited view of this set @@ -113,62 +113,62 @@ interface Versioned extends FeatureFlagConfig { } /** - * A builder for feature flag sets. + * A builder for option states. * * @since 1.0.0 */ @ApiStatus.NonExtendable interface Builder { /** - * Set the value for a specific flag. + * Set the value for a specific option. * - * @param flag the flag to set the value for + * @param option the option to set the value for * @param value the value * @return this builder * @param the value type * @since 1.0.0 */ - @NotNull Builder value(final @NotNull FeatureFlag flag, final @NotNull V value); + @NotNull Builder value(final @NotNull Option option, final @NotNull V value); /** - * Apply all values from the existing feature flag set. + * Apply all values from the existing option state. * - * @param existing the existing set + * @param existing the existing state * @return this builder * @since 1.0.0 */ - @NotNull Builder values(final @NotNull FeatureFlagConfig existing); + @NotNull Builder values(final @NotNull OptionState existing); /** - * Create a completed feature flag config. + * Create a completed option state. * - * @return the built config + * @return the built state * @since 1.0.0 */ - @NotNull FeatureFlagConfig build(); + @NotNull OptionState build(); } /** - * A builder for versioned feature flag sets. + * A builder for versioned option states. * * @since 1.0.0 */ @ApiStatus.NonExtendable interface VersionedBuilder { /** - * Register feature flags for a specific version. + * Register options for a specific version. * * @param version the version to register - * @param versionBuilder the builder that will receive flags + * @param versionBuilder the builder that will receive options * @return this builder * @since 1.0.0 */ @NotNull VersionedBuilder version(final int version, final @NotNull Consumer versionBuilder); /** - * Create a completed versioned flag config. + * Create a completed versioned option state. * - * @return the built versioned config + * @return the built versioned state * @since 1.0.0 */ @NotNull Versioned build(); diff --git a/src/main/java/net/kyori/featureflag/FeatureFlagConfigImpl.java b/src/main/java/net/kyori/option/OptionStateImpl.java similarity index 60% rename from src/main/java/net/kyori/featureflag/FeatureFlagConfigImpl.java rename to src/main/java/net/kyori/option/OptionStateImpl.java index 9818110..c32d6d0 100644 --- a/src/main/java/net/kyori/featureflag/FeatureFlagConfigImpl.java +++ b/src/main/java/net/kyori/option/OptionStateImpl.java @@ -1,5 +1,5 @@ /* - * This file is part of feature-flag, licensed under the MIT License. + * This file is part of option, licensed under the MIT License. * * Copyright (c) 2023 KyoriPowered * @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package net.kyori.featureflag; +package net.kyori.option; import java.util.Collections; import java.util.IdentityHashMap; @@ -35,30 +35,30 @@ import static java.util.Objects.requireNonNull; -final class FeatureFlagConfigImpl implements FeatureFlagConfig { - static final FeatureFlagConfig EMPTY = new FeatureFlagConfigImpl(new IdentityHashMap<>()); - private final IdentityHashMap, Object> values; +final class OptionStateImpl implements OptionState { + static final OptionState EMPTY = new OptionStateImpl(new IdentityHashMap<>()); + private final IdentityHashMap, Object> values; - FeatureFlagConfigImpl(final IdentityHashMap, Object> values) { + OptionStateImpl(final IdentityHashMap, Object> values) { this.values = new IdentityHashMap<>(values); } @Override - public boolean has(final @NotNull FeatureFlag flag) { - return this.values.containsKey(requireNonNull(flag, "flag")); + public boolean has(final @NotNull Option option) { + return this.values.containsKey(requireNonNull(option, "flag")); } @Override - public V value(final @NotNull FeatureFlag flag) { - final V value = flag.type().cast(this.values.get(requireNonNull(flag, "flag"))); - return value == null ? flag.defaultValue() : value; + public V value(final @NotNull Option option) { + final V value = option.type().cast(this.values.get(requireNonNull(option, "flag"))); + return value == null ? option.defaultValue() : value; } @Override public boolean equals(final @Nullable Object other) { if (this == other) return true; if (other == null || getClass() != other.getClass()) return false; - final FeatureFlagConfigImpl that = (FeatureFlagConfigImpl) other; + final OptionStateImpl that = (OptionStateImpl) other; return Objects.equals(this.values, that.values); } @@ -75,28 +75,28 @@ public String toString() { } static final class VersionedImpl implements Versioned { - private final SortedMap sets; + private final SortedMap sets; private final int targetVersion; - private final FeatureFlagConfig filtered; + private final OptionState filtered; - VersionedImpl(final SortedMap sets, final int targetVersion, final FeatureFlagConfig filtered) { + VersionedImpl(final SortedMap sets, final int targetVersion, final OptionState filtered) { this.sets = sets; this.targetVersion = targetVersion; this.filtered = filtered; } @Override - public boolean has(final @NotNull FeatureFlag flag) { - return this.filtered.has(flag); + public boolean has(final @NotNull Option option) { + return this.filtered.has(option); } @Override - public V value(final @NotNull FeatureFlag flag) { - return this.filtered.value(flag); + public V value(final @NotNull Option option) { + return this.filtered.value(option); } @Override - public @NotNull Map childSets() { + public @NotNull Map childStates() { return Collections.unmodifiableSortedMap(this.sets.headMap(this.targetVersion + 1)); } @@ -105,10 +105,10 @@ public V value(final @NotNull FeatureFlag flag) { return new VersionedImpl(this.sets, version, flattened(this.sets, version)); } - public static FeatureFlagConfig flattened(final SortedMap versions, final int targetVersion) { - final Map applicable = versions.headMap(targetVersion + 1); - final FeatureFlagConfig.Builder builder = FeatureFlagConfig.featureFlagConfig(); - for (final FeatureFlagConfig child : applicable.values()) { + public static OptionState flattened(final SortedMap versions, final int targetVersion) { + final Map applicable = versions.headMap(targetVersion + 1); + final OptionState.Builder builder = OptionState.optionState(); + for (final OptionState child : applicable.values()) { builder.values(child); } @@ -144,31 +144,31 @@ public String toString() { } } - static final class BuilderImpl implements FeatureFlagConfig.Builder { - private final IdentityHashMap, Object> values = new IdentityHashMap<>(); + static final class BuilderImpl implements OptionState.Builder { + private final IdentityHashMap, Object> values = new IdentityHashMap<>(); @Override - public @NotNull FeatureFlagConfig build() { + public @NotNull OptionState build() { if (this.values.isEmpty()) return EMPTY; - return new FeatureFlagConfigImpl(this.values); + return new OptionStateImpl(this.values); } @Override - public @NotNull Builder value(final @NotNull FeatureFlag flag, final @NotNull V value) { + public @NotNull Builder value(final @NotNull Option option, final @NotNull V value) { this.values.put( - requireNonNull(flag, "flag"), + requireNonNull(option, "flag"), requireNonNull(value, "value") ); return this; } @Override - public @NotNull Builder values(final @NotNull FeatureFlagConfig existing) { - if (existing instanceof FeatureFlagConfigImpl) { - this.values.putAll(((FeatureFlagConfigImpl) existing).values); + public @NotNull Builder values(final @NotNull OptionState existing) { + if (existing instanceof OptionStateImpl) { + this.values.putAll(((OptionStateImpl) existing).values); } else if (existing instanceof VersionedImpl) { - this.values.putAll(((FeatureFlagConfigImpl) ((VersionedImpl) existing).filtered).values); + this.values.putAll(((OptionStateImpl) ((VersionedImpl) existing).filtered).values); } else { throw new IllegalArgumentException("existing set " + existing + " is of an unknown implementation type"); } @@ -176,17 +176,17 @@ static final class BuilderImpl implements FeatureFlagConfig.Builder { } } - static final class VersionedBuilderImpl implements FeatureFlagConfig.VersionedBuilder { - private final Map builders = new TreeMap<>(); + static final class VersionedBuilderImpl implements OptionState.VersionedBuilder { + private final Map builders = new TreeMap<>(); @Override - public FeatureFlagConfig.@NotNull Versioned build() { + public OptionState.@NotNull Versioned build() { if (this.builders.isEmpty()) { - return new VersionedImpl(Collections.emptySortedMap(), 0, FeatureFlagConfig.emptyFeatureFlagConfig()); + return new VersionedImpl(Collections.emptySortedMap(), 0, OptionState.emptyOptionState()); } - final SortedMap built = new TreeMap<>(); - for (final Map.Entry entry : this.builders.entrySet()) { + final SortedMap built = new TreeMap<>(); + for (final Map.Entry entry : this.builders.entrySet()) { built.put(entry.getKey(), entry.getValue().build()); } // generate 'flattened' latest element @@ -196,7 +196,7 @@ static final class VersionedBuilderImpl implements FeatureFlagConfig.VersionedBu @Override public @NotNull VersionedBuilder version(final int version, final @NotNull Consumer versionBuilder) { requireNonNull(versionBuilder, "versionBuilder") - .accept(this.builders.computeIfAbsent(version, $ -> new FeatureFlagConfigImpl.BuilderImpl())); + .accept(this.builders.computeIfAbsent(version, $ -> new OptionStateImpl.BuilderImpl())); return this; } } diff --git a/src/main/java/net/kyori/option/package-info.java b/src/main/java/net/kyori/option/package-info.java new file mode 100644 index 0000000..ed4360c --- /dev/null +++ b/src/main/java/net/kyori/option/package-info.java @@ -0,0 +1,4 @@ +/** + * Runtime option system. + */ +package net.kyori.option; diff --git a/src/main/java9/module-info.java b/src/main/java9/module-info.java index 6d45c73..3ef63f4 100644 --- a/src/main/java9/module-info.java +++ b/src/main/java9/module-info.java @@ -1,8 +1,8 @@ /** * Feature flag system. */ -module net.kyori.featureflag { +module net.kyori.option { requires static transitive org.jetbrains.annotations; - exports net.kyori.featureflag; + exports net.kyori.option; } diff --git a/src/test/java/net/kyori/featureflag/FeatureFlagConfigTest.java b/src/test/java/net/kyori/option/OptionConfigTest.java similarity index 73% rename from src/test/java/net/kyori/featureflag/FeatureFlagConfigTest.java rename to src/test/java/net/kyori/option/OptionConfigTest.java index a454deb..470fbc9 100644 --- a/src/test/java/net/kyori/featureflag/FeatureFlagConfigTest.java +++ b/src/test/java/net/kyori/option/OptionConfigTest.java @@ -1,5 +1,5 @@ /* - * This file is part of feature-flag, licensed under the MIT License. + * This file is part of option, licensed under the MIT License. * * Copyright (c) 2017-2023 KyoriPowered * @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package net.kyori.featureflag; +package net.kyori.option; import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.Test; @@ -30,31 +30,31 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -class FeatureFlagConfigTest { +class OptionConfigTest { enum TestEnum { ONE, TWO, THREE } - private static final FeatureFlag ONE = FeatureFlag.booleanFlag(key("one"), true); - private static final FeatureFlag TWO = FeatureFlag.booleanFlag(key("two"), false); - private static final FeatureFlag ENUM_FLAG = FeatureFlag.enumFlag(key("enum_flag"), TestEnum.class, TestEnum.ONE); + private static final Option ONE = Option.booleanOption(key("one"), true); + private static final Option TWO = Option.booleanOption(key("two"), false); + private static final Option ENUM_FLAG = Option.enumOption(key("enum_flag"), TestEnum.class, TestEnum.ONE); @Test void testEmpty() { - assertFalse(FeatureFlagConfig.emptyFeatureFlagConfig().has(ONE)); - assertFalse(FeatureFlagConfig.emptyFeatureFlagConfig().has(TWO)); - assertFalse(FeatureFlagConfig.emptyFeatureFlagConfig().has(ENUM_FLAG)); + assertFalse(OptionState.emptyOptionState().has(ONE)); + assertFalse(OptionState.emptyOptionState().has(TWO)); + assertFalse(OptionState.emptyOptionState().has(ENUM_FLAG)); } @Test void testEmptyEqualToBuilder() { - assertEquals(FeatureFlagConfig.emptyFeatureFlagConfig(), FeatureFlagConfig.featureFlagConfig().build()); + assertEquals(OptionState.emptyOptionState(), OptionState.optionState().build()); } @Test void testFixedValue() { - final FeatureFlagConfig set = FeatureFlagConfig.featureFlagConfig() + final OptionState set = OptionState.optionState() .value(ONE, false) .build(); @@ -65,7 +65,7 @@ void testFixedValue() { @Test void testDefaultValues() { - final FeatureFlagConfig set = FeatureFlagConfig.featureFlagConfig() + final OptionState set = OptionState.optionState() .build(); assertFalse(set.has(ONE)); @@ -76,7 +76,7 @@ void testDefaultValues() { @Test void testMixedTypes() { - final FeatureFlagConfig set = FeatureFlagConfig.featureFlagConfig() + final OptionState set = OptionState.optionState() .value(ONE, false) .value(ENUM_FLAG, TestEnum.THREE) .build(); @@ -88,12 +88,12 @@ void testMixedTypes() { @Test void testBuilderFromExisting() { - final FeatureFlagConfig existing = FeatureFlagConfig.featureFlagConfig() + final OptionState existing = OptionState.optionState() .value(ONE, false) .value(ENUM_FLAG, TestEnum.THREE) .build(); - final FeatureFlagConfig updated = FeatureFlagConfig.featureFlagConfig() + final OptionState updated = OptionState.optionState() .values(existing) .build(); @@ -102,7 +102,7 @@ void testBuilderFromExisting() { @Test void testVersionedBaseLevel() { - final FeatureFlagConfig.Versioned versioned = FeatureFlagConfig.versionedFeatureFlagConfig() + final OptionState.Versioned versioned = OptionState.versionedOptionState() .version(0, b -> b .value(TWO, true) .value(ENUM_FLAG, TestEnum.THREE)) @@ -118,7 +118,7 @@ void testVersionedBaseLevel() { @Test void testVersionLower() { - final FeatureFlagConfig.Versioned versioned = FeatureFlagConfig.versionedFeatureFlagConfig() + final OptionState.Versioned versioned = OptionState.versionedOptionState() .version(0, b -> b .value(TWO, true) .value(ENUM_FLAG, TestEnum.THREE)) @@ -136,7 +136,7 @@ void testVersionLower() { @Test void testVersionHigher() { - final FeatureFlagConfig.Versioned versioned = FeatureFlagConfig.versionedFeatureFlagConfig() + final OptionState.Versioned versioned = OptionState.versionedOptionState() .version(0, b -> b .value(TWO, true) .value(ENUM_FLAG, TestEnum.THREE)) @@ -155,7 +155,7 @@ void testVersionHigher() { @Test void testVersionBetweenSteps() { - final FeatureFlagConfig.Versioned versioned = FeatureFlagConfig.versionedFeatureFlagConfig() + final OptionState.Versioned versioned = OptionState.versionedOptionState() .version(0, b -> b .value(TWO, true) .value(ENUM_FLAG, TestEnum.THREE)) diff --git a/src/test/java/net/kyori/featureflag/FeatureFlagTest.java b/src/test/java/net/kyori/option/OptionTest.java similarity index 82% rename from src/test/java/net/kyori/featureflag/FeatureFlagTest.java rename to src/test/java/net/kyori/option/OptionTest.java index 70914da..af8066d 100644 --- a/src/test/java/net/kyori/featureflag/FeatureFlagTest.java +++ b/src/test/java/net/kyori/option/OptionTest.java @@ -1,5 +1,5 @@ /* - * This file is part of feature-flag, licensed under the MIT License. + * This file is part of option, licensed under the MIT License. * * Copyright (c) 2023 KyoriPowered * @@ -21,19 +21,19 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package net.kyori.featureflag; +package net.kyori.option; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertThrows; -public class FeatureFlagTest { +public class OptionTest { @Test void testMultipleOfKeysFails() { final String id = "test_flag"; - assertDoesNotThrow(() -> FeatureFlag.booleanFlag(id, false)); - assertThrows(IllegalStateException.class, () -> FeatureFlag.booleanFlag(id, false)); + assertDoesNotThrow(() -> Option.booleanOption(id, false)); + assertThrows(IllegalStateException.class, () -> Option.booleanOption(id, false)); } }