-3

I have a interface fly and a class duck which implements fly.

interface Fly {
  getWingSize();   
}

public class Duck implements Fly {
  @Override
  int getWingSize(){
    return 1;
  }
}

In my controller class, when I try to use the following:

Fly flyAnimal = Animal.getFlyingAnimal();
((Duck) flyAnimal).getWingSize();

It works fine, however in my junit, it gives a class cast exception. I am using powermockito.

mistack305
  • 27
  • 4

1 Answers1

1

In your code you are casting to concrete class (duck). In general, you would mock interfaces. Your test case might have mocked interface fly.

It should work fine if you replace ((duck) fly).getWingSize(); with fly.getWingSize();

Naresh Vavilala
  • 598
  • 4
  • 14