Skip to content

Conversation

@ssharaev
Copy link
Member

@ssharaev ssharaev commented Jul 6, 2025

This PR

  • adds dedicated annotations BooleanFlag, StringFlag, IntegerFlag, and DoubleFlag for more specific and type-safe flag definitions in JUnit tests

Related Issues

Fixes #923

Notes

Not sure about tests, feedback on the test coverage is very welcome!

@ssharaev ssharaev requested a review from a team as a code owner July 6, 2025 17:35
@github-actions github-actions bot requested a review from aepfli July 6, 2025 17:36
@Test
@BooleanFlag(name = FLAG, value = true)
@BooleanFlag(name = FLAG, value = false)
void duplicatedTypedFlagsSimple() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use more descriptive names for your tests, maybe something like duplicateFlagKeyOverridesPreviousDeclaration

@chrfwow
Copy link
Contributor

chrfwow commented Jul 7, 2025

@ssharaev you will need to force push a commit that is signed off, otherwise the DCO check will not succeed

…lags in Junit5 extension

Signed-off-by: Sviatoslav Sharaev <[email protected]>
@ssharaev ssharaev force-pushed the feat/new-test-flags-annotations branch from d53dc31 to 6777d82 Compare July 14, 2025 04:20
}

@Test
@DoubleFlag(name = FLAG, value = 1.d)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@DoubleFlag(name = FLAG, value = 1.d)
@DoubleFlag(name = FLAG, value = FLAG_VALUE)

also for the other tests

Comment on lines +98 to +105
if (domainFlagNames.contains(flagName)) {
throw new IllegalArgumentException("Flag with name " + flagName + " already exists. "
+ "There shouldn't be @Flag and @" + value.getClass().getSimpleName() + "Flag with the same name!");
}

if (domainFlags.containsKey(flagName)) {
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of these checks is redundant. I think we could even remove the domainFlagNames set entirely, as it contains the same information as the domainFlags map.

@BooleanFlag(name = FLAG, value = false)
void duplicatedTypedFlagDoesntOverridePrevious() {
Client client = OpenFeatureAPI.getInstance().getClient();
assertThat(client.getBooleanValue(FLAG, false)).isTrue();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading the annotations I would have expected the last definition of FLAG to win and resolve to false.
Is this the same behavior as with multiple @Flag annotations?

@BooleanFlag(name = FLAG, value = true)
void existingSimpleTypedFlagIsRetrieved() {
Client client = OpenFeatureAPI.getInstance().getClient("testSpecific");
assertThat(client.getBooleanValue(FLAG, false)).isTrue();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this test do? FLAG is defined on Class and Method level, both with true.

@Test
@Flag(name = FLAG, value = "true")
@BooleanFlag(name = FLAG, value = true)
void simpleConfigDuplicateFlags() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, that defining FLAG twice as simple flag and type flag on the method level throws, an exception, but a simple flag FLAG on class level and a typed flag FLAG on method level does not throw.
See existingSimpleTypedFlagIsRetrieved() on L143

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just saw, this test class is disabled. Is this tech debt?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Junit5 extension] add dedicated Annotations for Number, Boolean and String flags

4 participants