1

I'm trying to unit test a class which has something like this

Obj1 var = (Obj2) var2;

When I try to run unit test on these using mockito, I get an error from mockito saying it can't be typecasted from one form to another. How do I fix this?

lealceldeiro
  • 14,342
  • 6
  • 49
  • 80
raghuls_23
  • 11
  • 2
  • show your test class – Maciej Kowalski May 23 '19 at 08:31
  • There's nothing significant there. I just want to know if there is a way to overcome this limitation. The error message is "java.lang.ClassCastException: *.InvoiceItem$$EnhancerByMockitoWithCGLIB$$96e8b6e6 cannot be cast to *.InventoryInvoiceItem" – raghuls_23 May 23 '19 at 08:34
  • Possible duplicate of [Explanation of "ClassCastException" in Java](https://stackoverflow.com/questions/907360/explanation-of-classcastexception-in-java) – Roland Weisleder May 23 '19 at 08:39
  • You need to show at least the specific type used to create `var2` and how it is related to `Obj1`.... with the current code it's impossible to say for sure... we can just guess here... – lealceldeiro May 23 '19 at 13:45

0 Answers0