oluwasayo
10/13/2016, 6:56 AMpackage-private
access modifier and but the test in the same package (albeit in a different directory hierarchy per Maven). Since Kotlin doesn’t have package-private
, I tried its public
(default) but Weld doesn’t like CDI beans with public
fields.
Another thing was to try internal
but since the field had to be lateinit
so Kotlin knows CDI is going to inject it before use in production, the field ended up being compiled to public again and Weld complains.
I’ve seen this discussion (https://discuss.kotlinlang.org/t/automatic-visibility-relaxation-for-unit-tests/489/2) and this issue (https://youtrack.jetbrains.com/issue/KT-525) but it seems unattended.
I can’t use protected
because that would mean the test has to extend the SUT which doesn’t make sense. I also can’t put the test in the same file as the SUT and use private
as that would mean the test will be deployed to production.
Here is what I currently have:
@Inject
@Config @Key(“config.from.db")
internal open lateinit var apiKey: String
[ERROR] Caused by: org.jboss.weld.exceptions.DefinitionException: WELD-000075: Normal scoped managed bean implementation class has a public field: [EnhancedAnnotatedFieldImpl] @Inject @Key @Config public com.company.project.OurClass.apiKey"
Here is what I would normally have done in Java
@Inject
@Config @Key(“config.from.db”)
@VisibleForTesting
String apiKey;
How do I make this work?