Code view:

A painting is a person's account of this edit as text, recorded independently of the node mapping - a rendering often has several equally defensible answers where the mapping has one. Deletions and insertions carry no position on the opposite side in a painting, so that panel draws no caret for them.

Before

…lines 1–6 unchanged (6 lines)
7import org.mockito.exceptions.Reporter;
8import org.mockito.internal.util.reflection.BeanPropertySetter;
9import org.mockito.internal.util.reflection.FieldSetter;
10
11import java.lang.reflect.Field;
12import java.util.Collection;
13
14/**
15 * This node returns an actual injecter which will be either :
16 *
17 * <ul>
18 * <li>an {@link OngoingInjecter} that do nothing if a candidate couldn't be found</li>
19 * <li>an {@link OngoingInjecter} that will try to inject the candidate trying first the property setter then if not possible try the field access</li>
20 * </ul>
21 */
22public class FinalMockCandidateFilter implements MockCandidateFilter {
23 public OngoingInjecter filterCandidate(final Collection<Object> mocks, final Field field, final Object fieldInstance) {
24 if(mocks.size() == 1) {
25 final Object matchingMock = mocks.iterator().next();
26
27 return new OngoingInjecter() {
28 public Object thenInject() {
29 try {
30 if (!new BeanPropertySetter(fieldInstance, field).set(matchingMock)) {
31 new FieldSetter(fieldInstance, field).set(matchingMock);
32 }
33 } catch (RuntimeException e) {
34 new Reporter().cannotInjectDependency(field, matchingMock, e);
35 }
36 return matchingMock;
37 }
38 };
39 }
40
41 return new OngoingInjecter() {
42 public Object thenInject() {
43 return null;
44 }
45 };
46
47 }
48}
49

After

…lines 1–6 unchanged (6 lines)
7import org.mockito.exceptions.Reporter;
8import org.mockito.internal.util.reflection.BeanPropertySetter;
9import org.mockito.internal.util.reflection.FieldSetter;
10
11import java.lang.reflect.Field;
12import java.util.Collection;
13import java.util.List;
14
15/**
16 * This node returns an actual injecter which will be either :
17 *
18 * <ul>
19 * <li>an {@link OngoingInjecter} that do nothing if a candidate couldn't be found</li>
20 * <li>an {@link OngoingInjecter} that will try to inject the candidate trying first the property setter then if not possible try the field access</li>
21 * </ul>
22 */
23public class FinalMockCandidateFilter implements MockCandidateFilter {
24 public OngoingInjecter filterCandidate(final Collection<Object> mocks, final Field field, List<Field> fields, final Object fieldInstance) {
25 if(mocks.size() == 1) {
26 final Object matchingMock = mocks.iterator().next();
27
28 return new OngoingInjecter() {
29 public Object thenInject() {
30 try {
31 if (!new BeanPropertySetter(fieldInstance, field).set(matchingMock)) {
32 new FieldSetter(fieldInstance, field).set(matchingMock);
33 }
34 } catch (RuntimeException e) {
35 new Reporter().cannotInjectDependency(field, matchingMock, e);
36 }
37 return matchingMock;
38 }
39 };
40 }
41
42 return new OngoingInjecter() {
43 public Object thenInject() {
44 return null;
45 }
46 };
47
48 }
49}
50

Before

program
block_comment "/*\n * Copyright (c) 2007 Mockito contributors\n * This progra"...
package_declaration
package "package"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "org"
. "."
identifier "mockito"
. "."
identifier "internal"
. "."
identifier "configuration"
. "."
identifier "injection"
. "."
identifier "filter"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
identifier "org"
. "."
identifier "mockito"
. "."
identifier "exceptions"
. "."
identifier "Reporter"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "org"
. "."
identifier "mockito"
. "."
identifier "internal"
. "."
identifier "util"
. "."
identifier "reflection"
. "."
identifier "BeanPropertySetter"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "org"
. "."
identifier "mockito"
. "."
identifier "internal"
. "."
identifier "util"
. "."
identifier "reflection"
. "."
identifier "FieldSetter"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
identifier "java"
. "."
identifier "lang"
. "."
identifier "reflect"
. "."
identifier "Field"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "java"
. "."
identifier "util"
. "."
identifier "Collection"
; ";"
block_comment "/**\n * This node returns an actual injecter which will be ei"...
class_declaration
modifiers
public "public"
class "class"
identifier "FinalMockCandidateFilter"
super_interfaces
implements "implements"
type_list
type_identifier "MockCandidateFilter"
class_body
{ "{"
method_declaration
modifiers
public "public"
type_identifier "OngoingInjecter"
identifier "filterCandidate"
formal_parameters
( "("
formal_parameter
modifiers
final "final"
generic_type
type_identifier "Collection"
type_arguments
< "<"
type_identifier "Object"
> ">"
identifier "mocks"
, ","
formal_parameter
modifiers
final "final"
type_identifier "Field"
identifier "field"
, ","
formal_parameter
modifiers
final "final"
type_identifier "Object"
identifier "fieldInstance"
) ")"
block (+175 nodes collapsed)
} "}"

After

program
block_comment "/*\n * Copyright (c) 2007 Mockito contributors\n * This progra"...
package_declaration
package "package"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "org"
. "."
identifier "mockito"
. "."
identifier "internal"
. "."
identifier "configuration"
. "."
identifier "injection"
. "."
identifier "filter"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
identifier "org"
. "."
identifier "mockito"
. "."
identifier "exceptions"
. "."
identifier "Reporter"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "org"
. "."
identifier "mockito"
. "."
identifier "internal"
. "."
identifier "util"
. "."
identifier "reflection"
. "."
identifier "BeanPropertySetter"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "org"
. "."
identifier "mockito"
. "."
identifier "internal"
. "."
identifier "util"
. "."
identifier "reflection"
. "."
identifier "FieldSetter"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
identifier "java"
. "."
identifier "lang"
. "."
identifier "reflect"
. "."
identifier "Field"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "java"
. "."
identifier "util"
. "."
identifier "Collection"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "java"
. "."
identifier "util"
. "."
identifier "List"
; ";"
block_comment "/**\n * This node returns an actual injecter which will be ei"...
class_declaration
modifiers
public "public"
class "class"
identifier "FinalMockCandidateFilter"
super_interfaces
implements "implements"
type_list
type_identifier "MockCandidateFilter"
class_body
{ "{"
method_declaration
modifiers
public "public"
type_identifier "OngoingInjecter"
identifier "filterCandidate"
formal_parameters
( "("
formal_parameter
modifiers
final "final"
generic_type
type_identifier "Collection"
type_arguments
< "<"
type_identifier "Object"
> ">"
identifier "mocks"
, ","
formal_parameter
modifiers
final "final"
type_identifier "Field"
identifier "field"
, ","
formal_parameter
generic_type
type_identifier "List"
type_arguments
< "<"
type_identifier "Field"
> ">"
identifier "fields"
, ","
formal_parameter
modifiers
final "final"
type_identifier "Object"
identifier "fieldInstance"
) ")"
block (+175 nodes collapsed)
} "}"