Bu test:Bir sınıf alır yapıcı ile nesne alay etmek nasıl?
Bunlar
public class ClassUnderTesting {
public void methodUnderTesting() {
new CollaboratorToBeMocked(InjectedAsTypeIntoCollaborator.class);
}
}
public class CollaboratorToBeMocked {
public CollaboratorToBeMocked(Class<InjectedAsTypeIntoCollaborator> clazz) {
}
public CollaboratorToBeMocked(InjectedIntoCollaborator someCollaborator) {
}
public CollaboratorToBeMocked() {
}
}
public class InjectedAsTypeIntoCollaborator {
}
public class InjectedIntoCollaborator {
}
Bu hata:
org.powermock.reflect.exceptions.TooManyConstructorsFoundException: Several matching constructors found, please specify the argument parameter types so that PowerMock can determine which method you're refering to.
Matching constructors in class CollaboratorToBeMocked were:
CollaboratorToBeMocked(InjectedIntoCollaborator.class)
CollaboratorToBeMocked(java.lang.Class.class)
Burada soru geliyor: PowerMock figürünü nasıl yapabilirim Hangi kurucu aramaya?
Sorunlu satırsuppress
. Hatanın nereden geldiğini budur.
CollaboratorToBeMocked (java.lang.Class.class) yapıcısını kaldırdığınızda ne olur? O zaman işe yarıyor mu? – Davidann
Yani, diğer yapıcıyı kaldırdığımda ... evet, InjectedIntoCollaborator ile kurucuyu kaldırırsam, – Belun