I have Interface:
public interface Car{
public void drive();
}
Class which implements Car:
public class SuperCar implements Car{
@Override
public void drive(){
}
}
And Class which uses Car as a method argument
public class CarDealer{
public void sellCar( Car car)
}
I wan't to invoke sellCar method using getDeclaredMethod with SuperCar as a argument, but it doesn't find it because of different type of arguments( Car vs SuperCar)
public sellCarTest(){
SuperCar superCar = new SuperCar();
CarDealer carDealer = new CarDealer();
Class dealer = CarDealer.class;
Class[] args = Class[1];
args[0] = superCar.getClass();
Method m = dealer.getDeclaredMethod("sellCar", args);
m.setAccessible(true);
m.invoke(carDealer, superCar);
}
EDIT
Actually I've seen piece of code pasted in accepted answer, but it still didn't gave me correct answer.
I've found my answer here Testing private method using power mock which return list of Integers