Repository navigation
Add unit tests to raise code coverage across all modules - #10
Merged
Merged
Conversation
Line coverage of the four published modules goes from 128/475 to 462/475, and the test count from 22 to 191. - flagship4j-javaflagr-core: 96% (was measured by no coverage report at all, only 2 tests). Covers every DefaultOpenFlagr overload and its fallback behaviour, the EffectiveVariant aliases and Jackson mapping, the OpenFlagrConfig builder, the exceptions and the model wire format. - flagship4j-openfeature-provider-javaflagr: 99% (had no tests). Covers the five evaluation types of OpenFlagrProvider, including the parse error and flag-not-found paths, and the OpenFeature context translation. - flagship4j-javaflagr-spring-boot-web-starter: 82% -> 98%. Adds BeanLocator, the FlagrEvalClientImpl failure branches, the random utilities, the bean factory methods and the configuration properties. - flagship4j-openfeature-spring-boot-starter: 100% (had no tests). Covers the auto-configuration beans, the property binding and the ConditionalOnMissingBean back off. Build changes: - Apply the jacoco plugin to the three modules that did not have it, so the coverage of every module is reported the same way as the web starter. - Add junit-jupiter and mockito 4.11.0 to the provider module, and spring-boot-starter-test to the openfeature starter. Mockito is kept on 4.x because the project targets Java 8. The only lines left uncovered are unreachable: the OpenFlagrNoFlagKeyException / OpenFlagrNoVariantException / Exception catch blocks in DefaultOpenFlagr.evaluateByDefaultVariantKey and the Exception catch block in FlagrEvalServiceImpl.evaluateByDefaultVariantKey are dead code, because the inner getEvaluationResult / getFlagrVariantKey already swallow every exception. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Raises the line coverage of the four published modules from 128/475 to 462/475 (97%) and the test count from 22 to 191. No production code is changed — this PR only adds tests and the build wiring needed to measure them.
flagship4j-javaflagr-coreflagship4j-openfeature-provider-javaflagrflagship4j-javaflagr-spring-boot-web-starterflagship4j-openfeature-spring-boot-starterWhat is covered
DefaultOpenFlagr— everyisFeatureFlagOn/getVariantKey/getVariantAttachment/evaluateoverload, driven throughMockWebServer, including the fallbacks for an unknown flag, an unassigned variant, a non-effective variant, a server error, a malformed body and a context that cannot be serialized.EffectiveVariant— allon/true/1andoff/false/0aliases, the blank and unknown value rejections, case-insensitiveisValid, and the Jackson round trip.OpenFlagrConfig— the hand-written builder overloads (String/URIendpoint,*Msand*Secondstimeouts), plus the Lombok accessors.OpenFlagrProvider— the boolean, string, integer, double and object evaluations, each with its success, parse-error and flag-not-found path, and the OpenFeature to OpenFlagr context translation.FlagrEvalClientImpl— the non-200, empty-body, refused-connection and truncated-response failure branches.BeanLocator,RandomUtils,SecureRandomUtils,FlagrEvalClientConfiguration, and the auto-configuration of the OpenFeature starter (bean registration, property binding,@ConditionalOnMissingBeanback off).Build changes
jacocoplugin to the three modules that did not have it, so every module reports coverage the same way the web starter already does.junit-jupiter:5.10.2andmockito 4.11.0to the provider module, andspring-boot-starter-testto the OpenFeature starter. Mockito stays on 4.x because the project targets Java 8.Notes for reviewers
Three things surfaced while writing these tests. None of them are fixed here, so that this PR stays test-only — happy to open follow-ups.
EvaluationContextExtensionMethodsnever skips an unset targeting key. It guards withif (source.getTargetingKey() != null), but the OpenFeature SDK reports an unset targeting key as an empty string, soentityId=\"\"is always sent.keepsOnlyTheFlagKeyAndAnEmptyEntityIdWhenTheSourceContextIsEmptypins the current behaviour with a comment explaining why.catchblocks. TheOpenFlagrNoFlagKeyException/OpenFlagrNoVariantException/Exceptionhandlers inDefaultOpenFlagr.evaluateByDefaultVariantKeyand theExceptionhandler inFlagrEvalServiceImpl.evaluateByDefaultVariantKeyare unreachable, because the innergetEvaluationResult/getFlagrVariantKeyalready swallow every exception. Those 12 lines are the entire remaining coverage gap; they were left alone rather than covered artificially.OpenFlagrProvider.getObjectEvaluationNPEs on a nullvariantAttachment(Structure.mapToStructure(null)).DefaultOpenFlagr's validation makes it unreachable today, but any otherOpenFlagrimplementation would hit it.Branch coverage sits at 53% because almost everything missing is Lombok-generated
equals/hashCode. Adding a rootlombok.configwithlombok.addLombokGeneratedAnnotation = truewould make JaCoCo skip generated methods and turn that number into something meaningful — left out as a reporting-policy decision for the maintainers.Test plan
./gradlew clean buildpasses../gradlew test --rerun-tasksrun three times, no flakes.NoSuchFieldError: JCTree$JCImport.qualid. CI already uses JDK 8, so it is unaffected.🤖 Generated with Claude Code