{"action":"created","issue":{"url":"https://api.github.com/repos/mockito/mockito/issues/209","labels_url":"https://api.github.com/repos/mockito/mockito/issues/209/labels{/name}","comments_url":"https://api.github.com/repos/mockito/mockito/issues/209/comments","events_url":"https://api.github.com/repos/mockito/mockito/issues/209/events","html_url":"https://github.com/mockito/mockito/issues/209","id":76300294,"number":209,"title":"Mocks are not injected in Spring AOP proxies","user":{"login":"eulogi","id":5038312,"avatar_url":"https://avatars.githubusercontent.com/u/5038312?v=3","gravatar_id":"","url":"https://api.github.com/users/eulogi","html_url":"https://github.com/eulogi","followers_url":"https://api.github.com/users/eulogi/followers","following_url":"https://api.github.com/users/eulogi/following{/other_user}","gists_url":"https://api.github.com/users/eulogi/gists{/gist_id}","starred_url":"https://api.github.com/users/eulogi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eulogi/subscriptions","organizations_url":"https://api.github.com/users/eulogi/orgs","repos_url":"https://api.github.com/users/eulogi/repos","events_url":"https://api.github.com/users/eulogi/events{/privacy}","received_events_url":"https://api.github.com/users/eulogi/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/mockito/mockito/labels/wontfix","name":"wontfix","color":"ffffff"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-05-14T09:36:26Z","updated_at":"2015-09-18T09:22:53Z","closed_at":"2015-06-03T17:08:20Z","body":"Mocks are not injected in fields that are Spring AOP proxies. To solve it you can modify PropertyAndSetterInjection:\r\n\r\n    public boolean processInjection(Field injectMocksField, Object injectMocksFieldOwner, Set<Object> mockCandidates) {\r\n        // Set<Object> mocksToBeInjected = new HashSet<Object>(mockCandidates);\r\n        FieldInitializationReport report = initializeInjectMocksField(injectMocksField, injectMocksFieldOwner);\r\n\r\n        // for each field in the class hierarchy\r\n        boolean injectionOccurred = false;\r\n        Class<?> fieldClass = report.fieldClass();\r\n        Object fieldInstanceNeedingInjection = report.fieldInstance();\r\n        // Unwrap proxy to allow field injection\r\n        fieldInstanceNeedingInjection = unwrapProxy(fieldInstanceNeedingInjection);\r\n        fieldClass = fieldInstanceNeedingInjection.getClass();\r\n        while (fieldClass != Object.class) {\r\n            injectionOccurred |= injectMockCandidates(fieldClass, newMockSafeHashSet(mockCandidates), fieldInstanceNeedingInjection);\r\n            fieldClass = fieldClass.getSuperclass();\r\n        }\r\n        return injectionOccurred;\r\n    }\r\n\r\n\tpublic static Object unwrapProxy(Object bean) {\r\n\t\tif (AopUtils.isAopProxy(bean) && bean instanceof Advised) {\r\n\t\t\tAdvised advised = (Advised) bean;\r\n\t\t\ttry {\r\n\t\t\t\tbean = advised.getTargetSource().getTarget();\r\n\t\t\t} catch (Exception e) {\r\n\t\t\t\tLOG.error(\"Exception unwrapping proxy object\", e);\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn bean;\r\n\t}\r\n"},"comment":{"url":"https://api.github.com/repos/mockito/mockito/issues/comments/141393686","html_url":"https://github.com/mockito/mockito/issues/209#issuecomment-141393686","issue_url":"https://api.github.com/repos/mockito/mockito/issues/209","id":141393686,"user":{"login":"ningg","id":5243076,"avatar_url":"https://avatars.githubusercontent.com/u/5243076?v=3","gravatar_id":"","url":"https://api.github.com/users/ningg","html_url":"https://github.com/ningg","followers_url":"https://api.github.com/users/ningg/followers","following_url":"https://api.github.com/users/ningg/following{/other_user}","gists_url":"https://api.github.com/users/ningg/gists{/gist_id}","starred_url":"https://api.github.com/users/ningg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ningg/subscriptions","organizations_url":"https://api.github.com/users/ningg/orgs","repos_url":"https://api.github.com/users/ningg/repos","events_url":"https://api.github.com/users/ningg/events{/privacy}","received_events_url":"https://api.github.com/users/ningg/received_events","type":"User","site_admin":false},"created_at":"2015-09-18T09:22:53Z","updated_at":"2015-09-18T09:22:53Z","body":"I hope this feature can be included in mockito."}}