mvysny / karibu-testing

Vaadin Server-Side Browserless Containerless Unit Testing
Apache License 2.0
105 stars 14 forks source link

Vaadin 23 issue with RadioButtonGroup #111

Closed chrisw73 closed 2 years ago

chrisw73 commented 2 years ago

Hi Martin!

I've just migrated to Vaadin 23 and run into a strange issue in a single KaribuTest. We have a view (created with vaadin designer) with a RadioButtonGroup on it which results in a NullPointerException as attached. The UI it self has no problem at all, just the karibu test failes...

From what I see the probelm occurs in the method presentationToModel in the RadioButtonGroup during instantiation by the Karibu MockInstantiator. The presentation is "foo" whilst the radioButtonGroup.keyMapper is null...

I can provide additional information, if needed.

Regards, Christoph

java.lang.IllegalArgumentException: Unable to create an instance of 'com.vaadin.flow.component.radiobutton.RadioButtonGroup'. The constructor threw an exception.

    at com.vaadin.flow.internal.ReflectTools.createProxyInstance(ReflectTools.java:515)
    at com.vaadin.flow.internal.ReflectTools.createInstance(ReflectTools.java:452)
    at com.vaadin.flow.di.DefaultInstantiator.create(DefaultInstantiator.java:139)
    at com.vaadin.flow.di.DefaultInstantiator.createComponent(DefaultInstantiator.java:73)
    at com.github.mvysny.kaributesting.v10.mock.MockInstantiator.createComponent(MockInstantiator.kt)
    at com.vaadin.flow.component.ComponentUtil.componentFromElement(ComponentUtil.java:444)
    at com.vaadin.flow.component.Component.from(Component.java:529)
    at com.vaadin.flow.component.template.internal.IdMapper.injectTemplateElement(IdMapper.java:172)
    at com.vaadin.flow.component.template.internal.IdMapper.attachExistingElementById(IdMapper.java:156)
    at com.vaadin.flow.component.template.internal.IdMapper.injectClientSideElement(IdMapper.java:108)
    at com.vaadin.flow.component.template.internal.IdMapper.mapComponentOrElement(IdMapper.java:79)
    at com.vaadin.flow.component.littemplate.LitTemplateInitializer.lambda$initChildElements$2(LitTemplateInitializer.java:108)
    at com.vaadin.flow.component.template.internal.ParserData.lambda$forEachInjectedField$0(ParserData.java:64)
    at java.base/java.util.HashMap.forEach(HashMap.java:1336)
    at java.base/java.util.Collections$UnmodifiableMap.forEach(Collections.java:1503)
    at com.vaadin.flow.component.template.internal.ParserData.forEachInjectedField(ParserData.java:63)
    at com.vaadin.flow.component.littemplate.LitTemplateInitializer.initChildElements(LitTemplateInitializer.java:107)
    at com.vaadin.flow.component.littemplate.LitTemplate.<init>(LitTemplate.java:96)
    at com.vaadin.flow.component.littemplate.LitTemplate.<init>(LitTemplate.java:81)
    at de.company.application.ui.AbstractBusinessView.<init>(AbstractBusinessView.java:37)
    at de.company.application.ui.TheView.<init>(TheView.java:48)
    at de.company.application.ui.TheViewTest.setup(TheViewTest.java:79)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:725)
    at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
    at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:149)
    at org.junit.jupiter.engine.extension.TimeoutExtension.interceptLifecycleMethod(TimeoutExtension.java:126)
    at org.junit.jupiter.engine.extension.TimeoutExtension.interceptBeforeEachMethod(TimeoutExtension.java:76)
    at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115)
    at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
    at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104)
    at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:98)
    at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.invokeMethodInExtensionContext(ClassBasedTestDescriptor.java:506)
    at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$synthesizeBeforeEachMethodAdapter$21(ClassBasedTestDescriptor.java:491)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeBeforeEachMethods$3(TestMethodTestDescriptor.java:171)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeBeforeMethodsOrCallbacksUntilExceptionOccurs$6(TestMethodTestDescriptor.java:199)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeBeforeMethodsOrCallbacksUntilExceptionOccurs(TestMethodTestDescriptor.java:199)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeBeforeEachMethods(TestMethodTestDescriptor.java:168)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:131)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:66)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:151)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
    at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1540)
    at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
    at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1540)
    at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
    at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
    at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35)
    at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
    at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54)
    at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:107)
    at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:88)
    at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:54)
    at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:67)
    at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:52)
    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:114)
    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:86)
    at org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:86)
    at org.junit.platform.launcher.core.SessionPerRequestLauncher.execute(SessionPerRequestLauncher.java:53)
    at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:71)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
    at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)
    at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)
Caused by: java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
    at com.vaadin.flow.internal.ReflectTools.createProxyInstance(ReflectTools.java:484)
    ... 92 more
Caused by: java.lang.NullPointerException
    at com.vaadin.flow.component.radiobutton.RadioButtonGroup.presentationToModel(RadioButtonGroup.java:106)
    at com.vaadin.flow.component.AbstractSinglePropertyField$TypeHandler.lambda$createReader$d15de0eb$1(AbstractSinglePropertyField.java:95)
    at com.vaadin.flow.component.AbstractSinglePropertyField.doSetModelValue(AbstractSinglePropertyField.java:358)
    at com.vaadin.flow.component.AbstractSinglePropertyField.<init>(AbstractSinglePropertyField.java:247)
    at com.vaadin.flow.component.radiobutton.GeneratedVaadinRadioGroup.<init>(GeneratedVaadinRadioGroup.java:486)
    at com.vaadin.flow.component.radiobutton.RadioButtonGroup.<init>(RadioButtonGroup.java:121)
chrisw73 commented 2 years ago

Issue solved. I'd just want you to know, that the issue occurrs when someone enters a value to the radio button group in the vaadin designer (in this case value="foo" ...

mvysny commented 2 years ago

Thank you so much for letting us know. Still, perhaps Karibu-Testing should also support this use-case. Is there a way to reproduce the issue in a simple project please?