private void setPotentialConstructor(Constructor constructor) { if (potentialConstructor == null) { potentialConstructor = constructor; }else{ /* * We've already found a constructor match before, this * means that PowerMock cannot determine which method to * expect since there are two methods with the same name * and the same number of arguments but one is using * wrapper types. */ throwExceptionWhenMultipleConstructorMatchesFound(new java.lang.reflect.Constructor[]{potentialConstructor.getJavaConstructor(), constructor.getJavaConstructor()}); } }
private boolean isVarArgConstructorFound() {return potentialConstructor!=null && potentialConstructor.isVarArg();}
private Set<Constructor> getDeclaredConstructorsWithoutPowerMockConstructor() { Set<Constructor> constructors = new HashSet<Constructor>(); for (java.lang.reflect.Constructor<?> constructor : unmockedType.getDeclaredConstructors()) { if (!isPowerMockConstructor(constructor.getParameterTypes())) { constructors.add(new Constructor(constructor)); } } return constructors; }
private void lookupPotentialConstructor() {Set<Constructor> constructors = getDeclaredConstructorsWithoutPowerMockConstructor(); for (Constructor constructor : constructors) { if (constructor.canBeInvokeWith(arguments)) { setPotentialConstructor(constructor); } // if a constructor is found and it has varargs parameters then the constructor will be used even if // other constructor is matcher the given arguments. It is done, because when Argument Matchers are used // arguments passed to the method are null value and it's imposable to determinate whether parameters // match to arguments or not. if (isVarArgConstructorFound()){ return; } } }
public java.lang.reflect.Constructor findConstructor() { lookupPotentialConstructor(); throwExceptionIfConstructorWasNotFound(); return potentialConstructor.getJavaConstructor(); }