unloggedio / unlogged-sdk

Unlogged SDK for recording code execution
https://unlogged.io
Apache License 2.0
152 stars 16 forks source link

class java.util.LinkedHashMap cannot be cast to class org.unlogged.demo.models.abstraction.PropertyDetails #81

Open TheAmg opened 2 weeks ago

TheAmg commented 2 weeks ago

Describe the bug

The above Exception is seen when running saved replays in unit mode/with mocks enabled on unlogged-spring-maven-demo. The methods where this is seen are - All the methods except the findAll method in PropertyControllerImpl.

Stack trace -

java.lang.ClassCastException: class java.util.LinkedHashMap cannot be cast to class org.unlogged.demo.models.abstraction.PropertyDetails (java.util.LinkedHashMap is in module java.base of loader 'bootstrap'; org.unlogged.demo.models.abstraction.PropertyDetails is in unnamed module of loader 'app')
    at org.unlogged.demo.controller.abstractions.PropertyControllerImpl.findById(PropertyControllerImpl.java:15)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
    at java.base/java.lang.reflect.Method.invoke(Method.java:580)
    at io.unlogged.AgentCommandExecutorImpl.executeCommandRaw(AgentCommandExecutorImpl.java:407)
    at io.unlogged.runner.UnloggedTestRunner.executeCandidate(UnloggedTestRunner.java:542)
    at io.unlogged.runner.UnloggedTestRunner.executeAndVerify(UnloggedTestRunner.java:472)
    at io.unlogged.runner.UnloggedTestRunner.fireTest(UnloggedTestRunner.java:254)
    at io.unlogged.runner.UnloggedTestRunner.executeByDescription(UnloggedTestRunner.java:145)
    at io.unlogged.runner.UnloggedTestRunner.executeByDescription(UnloggedTestRunner.java:153)
    at io.unlogged.runner.UnloggedTestRunner.run(UnloggedTestRunner.java:135)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
    at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
    at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:232)
    at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55)
java.lang.ClassCastException: class java.util.LinkedHashMap cannot be cast to class org.unlogged.demo.models.abstraction.PropertyDetails (java.util.LinkedHashMap is in module java.base of loader 'bootstrap'; org.unlogged.demo.models.abstraction.PropertyDetails is in unnamed module of loader 'app')
    at org.unlogged.demo.controller.abstractions.PropertyControllerImpl.findById(PropertyControllerImpl.java:15)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
    at java.base/java.lang.reflect.Method.invoke(Method.java:580)
    at io.unlogged.AgentCommandExecutorImpl.executeCommandRaw(AgentCommandExecutorImpl.java:407)
    at io.unlogged.runner.UnloggedTestRunner.executeCandidate(UnloggedTestRunner.java:542)
    at io.unlogged.runner.UnloggedTestRunner.executeAndVerify(UnloggedTestRunner.java:472)
    at io.unlogged.runner.UnloggedTestRunner.fireTest(UnloggedTestRunner.java:254)
    at io.unlogged.runner.UnloggedTestRunner.executeByDescription(UnloggedTestRunner.java:145)
    at io.unlogged.runner.UnloggedTestRunner.executeByDescription(UnloggedTestRunner.java:153)
    at io.unlogged.runner.UnloggedTestRunner.run(UnloggedTestRunner.java:135)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
    at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
    at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:232)
    at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55)

java.lang.ClassCastException: class java.util.LinkedHashMap cannot be cast to class org.unlogged.demo.models.abstraction.PropertyDetails (java.util.LinkedHashMap is in module java.base of loader 'bootstrap'; org.unlogged.demo.models.abstraction.PropertyDetails is in unnamed module of loader 'app')

    at org.unlogged.demo.controller.abstractions.PropertyControllerImpl.findById(PropertyControllerImpl.java:15)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
    at java.base/java.lang.reflect.Method.invoke(Method.java:580)
    at io.unlogged.AgentCommandExecutorImpl.executeCommandRaw(AgentCommandExecutorImpl.java:407)
    at io.unlogged.runner.UnloggedTestRunner.executeCandidate(UnloggedTestRunner.java:542)
    at io.unlogged.runner.UnloggedTestRunner.executeAndVerify(UnloggedTestRunner.java:472)
    at io.unlogged.runner.UnloggedTestRunner.fireTest(UnloggedTestRunner.java:254)
    at io.unlogged.runner.UnloggedTestRunner.executeByDescription(UnloggedTestRunner.java:145)
    at io.unlogged.runner.UnloggedTestRunner.executeByDescription(UnloggedTestRunner.java:153)
    at io.unlogged.runner.UnloggedTestRunner.run(UnloggedTestRunner.java:135)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
    at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
    at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:232)
    at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55)

Reproduction steps

  1. Clone and run the test runner on unlogged-spring-maven-demo
  2. The replay cases from PropertyControllerImpl will fail except findAll

Look for cases named as PropertyControllerImpl.{methodname} - normal mocked ...

Expected behavior

For the cases to pass with mocks being correctly picked up.

Additional context

No response