use of org.powermock.core.transformers.mock.MockGatewaySpy.MethodCall in project powermock by powermock.
the class ConstructorCallMockTransformerTest method should_provide_correct_constructor_param_and_arguments.
@Test
public void should_provide_correct_constructor_param_and_arguments() throws Exception {
assumeClassLoaderMode();
MockGatewaySpy.returnOnMethodCall(SUPPRESS);
Class<?> clazz = loadWithMockClassLoader(SuperClassCallSuperConstructor.class.getName());
final Constructor<?> constructor = clazz.getConstructor(String.class, String.class, double.class);
constructor.newInstance("name", "field", 100);
assertThatCorrectConstructorTypeProvided();
final MethodCall methodCall = MockGatewaySpy.constructorCalls().get(0);
assertThat(methodCall.args).as("Correct constructor arguments are provided").containsExactly("name", 100.0);
assertThat(methodCall.sig).as("Correct constructor signature is provided").containsExactly(String.class, double.class);
}
use of org.powermock.core.transformers.mock.MockGatewaySpy.MethodCall in project powermock by powermock.
the class ConstructorCallMockTransformerTest method should_provide_correct_constructor_param_and_arguments_when_cast_required.
@Test
public void should_provide_correct_constructor_param_and_arguments_when_cast_required() throws Exception {
assumeClassLoaderMode();
MockGatewaySpy.returnOnMethodCall(SUPPRESS);
final Class<?> clazz = loadWithMockClassLoader(SuperClassCallSuperConstructorWithCast.class.getName());
final Class<?> paramClass = loadWithMockClassLoader(ParameterInterface.class.getName());
final Object param = loadWithMockClassLoader(ParameterImpl.class.getName()).newInstance();
final Constructor<?> constructor = clazz.getConstructor(paramClass);
constructor.newInstance(param);
assertThatCorrectConstructorTypeProvided();
final MethodCall methodCall = MockGatewaySpy.constructorCalls().get(0);
assertThat(methodCall.args).as("Correct constructor arguments are provided").containsExactly(param);
assertThat(methodCall.sig).as("Correct constructor signature is provided").hasSize(1).extracting(new Extractor<Class<?>, Object>() {
@Override
public Object extract(final Class<?> input) {
return input.getName();
}
}).containsExactly(ParameterImpl.class.getName());
}
use of org.powermock.core.transformers.mock.MockGatewaySpy.MethodCall in project powermock by powermock.
the class ConstructorCallMockTransformerTest method assertThatCorrectConstructorTypeProvided.
private void assertThatCorrectConstructorTypeProvided() {
final MethodCall methodCall = MockGatewaySpy.constructorCalls().get(0);
assertThat(methodCall.type.getName()).as("Correct constructor type is provided").isEqualTo(SupperClassThrowsException.class.getName());
}
use of org.powermock.core.transformers.mock.MockGatewaySpy.MethodCall in project powermock by powermock.
the class ConstructorCallMockTransformerTest method should_provide_correct_constructor_param_and_arguments_when_parameters_vararg.
@Test
public void should_provide_correct_constructor_param_and_arguments_when_parameters_vararg() throws Exception {
assumeClassLoaderMode();
MockGatewaySpy.returnOnMethodCall(SUPPRESS);
final Class<?> clazz = loadWithMockClassLoader(SuperClassCallSuperConstructorWithVararg.class.getName());
final Class<?> paramClass = long[].class;
final Constructor<?> constructor = clazz.getConstructor(paramClass);
long[] params = { 1, 5, 6 };
constructor.newInstance(new Object[] { params });
assertThatCorrectConstructorTypeProvided();
final MethodCall methodCall = MockGatewaySpy.constructorCalls().get(0);
assertThat(methodCall.args).as("Constructor arguments have correct size").hasSize(1);
assertThat((long[]) methodCall.args[0]).as("Correct constructor arguments are provided").containsExactly(params);
assertThat(methodCall.sig).as("Correct constructor signature is provided").hasSize(1).containsExactly(long[].class);
}
Aggregations