Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I ignore lateinit var field? #90

Open
wickedev opened this issue Jan 12, 2022 · 2 comments
Open

How can I ignore lateinit var field? #90

wickedev opened this issue Jan 12, 2022 · 2 comments

Comments

@wickedev
Copy link

I have below classes. I want to create fixtures without lateinit var field , how can I achieve this?
Thank you for your awesome project

@Table("post")
data class Post(
    @Id override val id: ID,
    val title: String,
    val content: String,
    @Relation(User::class) val userId: ID,
) : Node {

    @Autowired lateinit var userRepository: UserRepository

    fun author(env: DataFetchingEnvironment): CompletableFuture<User> {
        return userRepository.findById(userId, env)
    }
}
@mattmook
Copy link
Member

There's no built in way currently... and perhaps it seems a little weird that the library tries to populate lateinit fields automatically anyway. So certainly I'll tweak the library so it doesn't automatically populate them.

Additionally you could also imagine the class having other properties defined that are not lateinit that may not be desirable to auto-populate and I think it would be great to have a way to "ignore" attempting to populate them.

@roeniss
Copy link

roeniss commented Jan 29, 2024

So certainly I'll tweak the library so it doesn't automatically populate them.

@mattmook Hi, can you provide the tweak? I'm also having the same issue that KotlinFixture kept trying to populate lateinit and got failed.

Unable to handle $MY_CLASS_FQCN
java.lang.UnsupportedOperationException: Unable to handle $MY_CLASS_FQCN
Unable to resolve class $MY_CLASS_FQCN
    Unable to populate class $MY_CLASS_FQCN
    Unable to instantiate class $MY_CLASS_FQCN using factory methods

	at com.appmattus.kotlinfixture.Fixture.create(KotlinFixture.kt:85)
	at $MY_TEST_CLASS_FQCN$1$1$2.invokeSuspend($MY_TEST_CLASS.kt:73)
	at $MY_TEST_CLASS_FQCN$1$1$2.invoke($MY_TEST_CLASS.kt)
	at $MY_TEST_CLASS_FQCN$1$1$2.invoke($MY_TEST_CLASS.kt)
	at io.kotest.engine.test.TestCaseExecutor$execute$innerExecute$1.invokeSuspend(TestCaseExecutor.kt:91)
	at io.kotest.engine.test.TestCaseExecutor$execute$innerExecute$1.invoke(TestCaseExecutor.kt)
	at io.kotest.engine.test.TestCaseExecutor$execute$innerExecute$1.invoke(TestCaseExecutor.kt)
	at io.kotest.engine.test.interceptors.CoroutineDebugProbeInterceptor.intercept(CoroutineDebugProbeInterceptor.kt:29)
	at io.kotest.engine.test.TestCaseExecutor$execute$3$1.invokeSuspend(TestCaseExecutor.kt:100)
	at io.kotest.engine.test.TestCaseExecutor$execute$3$1.invoke(TestCaseExecutor.kt)
	at io.kotest.engine.test.TestCaseExecutor$execute$3$1.invoke(TestCaseExecutor.kt)
	at io.kotest.engine.test.TestInvocationInterceptor$runBeforeTestAfter$executeWithBeforeAfter$1.invokeSuspend(TestInvocationInterceptor.kt:63)
	at io.kotest.engine.test.TestInvocationInterceptor$runBeforeTestAfter$executeWithBeforeAfter$1.invoke(TestInvocationInterceptor.kt)
	at io.kotest.engine.test.TestInvocationInterceptor$runBeforeTestAfter$executeWithBeforeAfter$1.invoke(TestInvocationInterceptor.kt)
	at io.kotest.engine.test.interceptors.InvocationTimeoutInterceptor$intercept$3.invokeSuspend(InvocationTimeoutInterceptor.kt:43)
	at io.kotest.engine.test.interceptors.InvocationTimeoutInterceptor$intercept$3.invoke(InvocationTimeoutInterceptor.kt)
	at io.kotest.engine.test.interceptors.InvocationTimeoutInterceptor$intercept$3.invoke(InvocationTimeoutInterceptor.kt)
	at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturnIgnoreTimeout(Undispatched.kt:100)
	at kotlinx.coroutines.TimeoutKt.setupTimeout(Timeout.kt:146)
	at kotlinx.coroutines.TimeoutKt.withTimeoutOrNull(Timeout.kt:103)
	...
	at kotlinx.coroutines.BuildersKt.withContext(Unknown Source)
	at io.kotest.engine.test.interceptors.CoroutineErrorCollectorInterceptor.intercept(CoroutineErrorCollectorInterceptor.kt:33)
	at io.kotest.engine.test.TestCaseExecutor$execute$3$1.invokeSuspend(TestCaseExecutor.kt:100)
	at io.kotest.engine.test.TestCaseExecutor$execute$3$1.invoke(TestCaseExecutor.kt)
	at io.kotest.engine.test.TestCaseExecutor$execute$3$1.invoke(TestCaseExecutor.kt)
	at io.kotest.engine.test.interceptors.CoroutineDispatcherFactoryInterceptor$intercept$4.invokeSuspend(coroutineDispatcherFactoryInterceptor.kt:57)
	at io.kotest.engine.test.interceptors.CoroutineDispatcherFactoryInterceptor$intercept$4.invoke(coroutineDispatcherFactoryInterceptor.kt)
	at io.kotest.engine.test.interceptors.CoroutineDispatcherFactoryInterceptor$intercept$4.invoke(coroutineDispatcherFactoryInterceptor.kt)
	at io.kotest.engine.concurrency.FixedThreadCoroutineDispatcherFactory$withDispatcher$4.invokeSuspend(FixedThreadCoroutineDispatcherFactory.kt:59)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:840)

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

No branches or pull requests

3 participants