public MockeryProxy(Class<?> mockingClass) { this.mockingClass = mockingClass; this.getInterceptorMetadata = new GetInterceptorMetadata(); this.getMockeryMetadata = new GetMockeryMetadata(); this.checkSupportType = new CheckSupportType(); }
@Override public void validateResponse(Object response) { interceptorMetadata.validate(response); Type typeMethod = method.getGenericReturnType(); Type adaptedTypeMethod = interceptorMetadata.adaptType(typeMethod); Object adaptedResponse = interceptorMetadata.adaptResponse(response); MockeryMetadata mockeryMethod = mockeryMetadata .fromMethod(providersClass, method, adaptedTypeMethod, null); checkSupportType.from(providersClass, method, mockeryMethod, adaptedTypeMethod); mockeryMethod.validate(adaptedResponse); }
GetTestClass(javax.lang.model.util.Types types) { this.instantiateInterface = new InstantiateInterface(); this.types = types; }
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (method.getDeclaringClass() == Object.class) { return method.invoke(this, args); } InterceptorMetadata interceptor = getInterceptorMetadata. with(mockingClass, method, args); try { applyValidationsToParams(method, args); Type adaptedTypeMethod = interceptor .adaptType(method.getGenericReturnType()); MockeryMetadata mockery = getMockeryMetadata .fromMethod(mockingClass, method, adaptedTypeMethod, args); checkSupportType.from(mockingClass, method, mockery, adaptedTypeMethod); Object response = mockery.legal(); return interceptor.onLegalMock(response); } catch (AssertionError e) { return interceptor.onIllegalMock(e); } }
@Override public <T> T getLegalForParam(int paramPosition) { Type type = method. getGenericParameterTypes()[paramPosition]; MockeryMetadata mockery = mockeryMetadata .fromParam(providersClass, method, null, paramPosition); checkSupportType.from(providersClass, method, mockery, type); return (T) mockery.legal(); }
private void applyValidationsToParams(Method method, Object[] args) { Type[] typeParams = method.getGenericParameterTypes(); for (int i = 0; i < typeParams.length; i++) { Type typeParam = typeParams[i]; MockeryMetadata mockery = getMockeryMetadata .fromParam(mockingClass, method, args, i); if (mockery == null) { String message = Messages.noMockeryFoundOnParam(mockingClass, method, i); throw new RuntimeException(message); } checkSupportType.from(mockingClass, method, mockery, typeParam); Object valueParam = args[i]; mockery.validate(valueParam); } }
@Override public <T> T getIllegalForParam(int paramPosition) { Type type = method. getGenericParameterTypes()[paramPosition]; MockeryMetadata mockery = mockeryMetadata .fromParam(providersClass, method, null, paramPosition); checkSupportType.from(providersClass, method, mockery, type); return (T) mockery.illegal(); }
@Before public void init() { checkSupportTypeUT = new CheckSupportType(); getMockeryMetadata = new GetMockeryMetadata(); }
@Before public void init() { robot = new RobotBuilder() .test(Providers.class) .onMethod("mocks") .build(); }
public MockeryMetadata fromMethod(Class<?> mockingClass, Method method, Type typeMethod, Object[] args) { Annotation[] annotationsMethod = method.getAnnotations(); MockeryMetadata mockery = mockeryMetadata(mockingClass, method, args, typeMethod, annotationsMethod); if (mockery == null) { String message = Messages .noMockeryFoundOnMethod(mockingClass, method); throw new RuntimeException(message); } return mockery; }
@Override public synchronized void init(ProcessingEnvironment env) { super.init(env); this.messager = env.getMessager(); this.filer = env.getFiler(); this.elementUtils = env.getElementUtils(); this.getTestClass = new GetTestClass(env.getTypeUtils()); this.brewJavaFile = new BrewJavaFile(); }
@TestInterceptor private interface Providers { String string(); }
public static Build test(Class<?> providersClass) { return new Build(providersClass); }
public Robot build() { return new RealRobot(providersClass, nameMethod); }
public MockeryMetadata fromParam(Class<?> mockingClass, Method method, Object[] args, int paramPosition) { Type typeParam = method.getGenericParameterTypes()[paramPosition]; Annotation[] annotationsParam = method.getParameterAnnotations()[paramPosition]; MockeryMetadata mockery = mockeryMetadata(mockingClass, method, args, typeParam, annotationsParam); return mockery; }
public DTOMockeryArgs() { instantiateInterface = new InstantiateInterface(); }
@TestInterceptor @Bypass private interface ProvidersMultipleInterceptor { String string(); }
public DTOMockery() { instantiateInterface = new InstantiateInterface(); }
public GetInterceptorMetadata() { this.instantiateInterface = new InstantiateInterface(); }
public GetMockeryMetadata() { this.instantiateInterface = new InstantiateInterface(); }