Hi Johan,
This is regarding the issue that i am facing in mocking a constructor.
I have two different constructors for a class with different arguments as below (though it doesn't make sense) :
public ClassA(Long relationshipId) {
this.relationshipId = relationshipId;
}
public ClassA(long relationshipId) {
this.relationshipId = Long.valueOf(relationshipId);
}
When i use the expectNew call as below to mock the object, it gives me the error as mentioned below
expectNew(ClassA.class,21L).andReturn(mockClassA)
Error:
org.powermock.reflect.exceptions.TooManyConstructorsFoundException: Several matching constructors found, please specify the argument parameter types so that PowerMock can determine which method you're referring to.
Matching constructors in class com.att.osd.framework.core.model.relation.DimRelationship were:
com.att.osd.framework.core.model.relation.ClassA( java.lang.Long.class )
com.att.osd.framework.core.model.relation.ClassA( long.class )
I read about this issue in the group and found that we can use suppressconstructor through one of your example stated below
suppress(constructor(EvilParent.class));
I am not able find the method "suppress(constructor())" can you please let me know where can i find it.
I couldn't find the method in MemberModifier, please refer to the attached image file.
I had to use anyObject(Shown below) as an aletrnate for the time being.
mockClassB.relateTo((ClassC)anyObject(),(ClassA)anyObject());
Also let me know if there is any other solution for the prob.
Thanks in Advance
Vikas.N