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–10 unchanged (10 lines)
11import org.mockito.Mock;
12import org.mockito.Mockito;
13import org.mockito.Spy;
14import org.mockito.configuration.AnnotationEngine;
15import org.mockito.exceptions.Reporter;
16import org.mockito.exceptions.base.MockitoException;
17import org.mockito.internal.util.MockUtil;
18
19
20@SuppressWarnings({"unchecked"})
21public class SpyAnnotationEngine implements AnnotationEngine {
22
23 public Object createMockFor(Annotation annotation, Field field) {
…lines 24–42 unchanged (19 lines)
43
44 }
45 if (new MockUtil().isMock(instance)) {
46 // instance has been spied earlier
47 Mockito.reset(instance);
48 } else {
49 field.set(testClass, Mockito.spy(instance));
50 }
51 } catch (IllegalAccessException e) {
52 throw new MockitoException("Problems initiating spied field " + field.getName(), e);
53 } finally {
54 field.setAccessible(wasAccessible);
55 }
…lines 56–69 unchanged (14 lines)

After

…lines 1–12 unchanged (12 lines)
13import org.mockito.Spy;
14import org.mockito.configuration.AnnotationEngine;
15import org.mockito.exceptions.Reporter;
16import org.mockito.exceptions.base.MockitoException;
17import org.mockito.internal.util.MockUtil;
18
19import static org.mockito.Mockito.withSettings;
20
21@SuppressWarnings({"unchecked"})
22public class SpyAnnotationEngine implements AnnotationEngine {
23
24 public Object createMockFor(Annotation annotation, Field field) {
25 return null;
…lines 26–43 unchanged (18 lines)
44
45 }
46 if (new MockUtil().isMock(instance)) {
47 // instance has been spied earlier
48 Mockito.reset(instance);
49 } else {
50 field.set(testClass, Mockito.mock(instance.getClass(), withSettings()
51 .spiedInstance(instance)
52 .defaultAnswer(Mockito.CALLS_REAL_METHODS)
53 .name(field.getName())));
54 }
55 } catch (IllegalAccessException e) {
56 throw new MockitoException("Problems initiating spied field " + field.getName(), e);
57 } finally {
58 field.setAccessible(wasAccessible);
59 }
…lines 60–73 unchanged (14 lines)

Before

program
block_comment "/*\r\n * Copyright (c) 2007 Mockito contributors\r\n * This prog"...
package_declaration
package "package"
scoped_identifier
scoped_identifier
scoped_identifier
identifier "org"
. "."
identifier "mockito"
. "."
identifier "internal"
. "."
identifier "configuration"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
identifier "java"
. "."
identifier "lang"
. "."
identifier "annotation"
. "."
identifier "Annotation"
; ";"
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 "org"
. "."
identifier "mockito"
. "."
identifier "Captor"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "org"
. "."
identifier "mockito"
. "."
identifier "Mock"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "org"
. "."
identifier "mockito"
. "."
identifier "Mockito"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "org"
. "."
identifier "mockito"
. "."
identifier "Spy"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
identifier "org"
. "."
identifier "mockito"
. "."
identifier "configuration"
. "."
identifier "AnnotationEngine"
; ";"
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
identifier "org"
. "."
identifier "mockito"
. "."
identifier "exceptions"
. "."
identifier "base"
. "."
identifier "MockitoException"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "org"
. "."
identifier "mockito"
. "."
identifier "internal"
. "."
identifier "util"
. "."
identifier "MockUtil"
; ";"
class_declaration
modifiers
annotation
@ "@"
identifier "SuppressWarnings"
annotation_argument_list
( "("
element_value_array_initializer
{ "{"
string_literal
" "\""
string_fragment "unchecked"
" "\""
} "}"
) ")"
public "public"
class "class"
identifier "SpyAnnotationEngine"
super_interfaces
implements "implements"
type_list
type_identifier "AnnotationEngine"
class_body
{ "{"
method_declaration (+22 nodes collapsed)
method_declaration
modifiers
annotation
@ "@"
identifier "SuppressWarnings"
annotation_argument_list
( "("
string_literal
" "\""
string_fragment "deprecation"
" "\""
) ")"
public "public"
void_type "void"
identifier "process"
formal_parameters
( "("
formal_parameter
generic_type
type_identifier "Class"
type_arguments
< "<"
wildcard
? "?"
> ">"
identifier "context"
, ","
formal_parameter
type_identifier "Object"
identifier "testClass"
) ")"
block
{ "{"
local_variable_declaration
array_type
type_identifier "Field"
dimensions
[ "["
] "]"
variable_declarator
identifier "fields"
= "="
method_invocation
identifier "context"
. "."
identifier "getDeclaredFields"
argument_list
( "("
) ")"
; ";"
enhanced_for_statement
for "for"
( "("
type_identifier "Field"
identifier "field"
: ":"
identifier "fields"
) ")"
block
{ "{"
if_statement
if "if"
parenthesized_expression
( "("
method_invocation
identifier "field"
. "."
identifier "isAnnotationPresent"
argument_list
( "("
class_literal
type_identifier "Spy"
. "."
class "class"
) ")"
) ")"
block
{ "{"
expression_statement (+37 nodes collapsed)
local_variable_declaration
boolean_type "boolean"
variable_declarator
identifier "wasAccessible"
= "="
method_invocation
identifier "field"
. "."
identifier "isAccessible"
argument_list
( "("
) ")"
; ";"
expression_statement
method_invocation
identifier "field"
. "."
identifier "setAccessible"
argument_list
( "("
true "true"
) ")"
; ";"
try_statement
try "try"
block
{ "{"
local_variable_declaration
type_identifier "Object"
variable_declarator
identifier "instance"
= "="
method_invocation
identifier "field"
. "."
identifier "get"
argument_list
( "("
identifier "testClass"
) ")"
; ";"
if_statement (+68 nodes collapsed)
if_statement
if "if"
parenthesized_expression
( "("
method_invocation
object_creation_expression
new "new"
type_identifier "MockUtil"
argument_list
( "("
) ")"
. "."
identifier "isMock"
argument_list
( "("
identifier "instance"
) ")"
) ")"
block
{ "{"
line_comment "// instance has been spied earlier\r"
expression_statement
method_invocation
identifier "Mockito"
. "."
identifier "reset"
argument_list
( "("
identifier "instance"
) ")"
; ";"
} "}"
else "else"
block
{ "{"
expression_statement
method_invocation
identifier "field"
. "."
identifier "set"
argument_list
( "("
identifier "testClass"
, ","
method_invocation
identifier "Mockito"
. "."
identifier "spy"
argument_list
( "("
identifier "instance"
) ")"
) ")"
; ";"
} "}"
} "}"
catch_clause (+35 nodes collapsed)
finally_clause
finally "finally"
block
{ "{"
expression_statement
method_invocation
identifier "field"
. "."
identifier "setAccessible"
argument_list
( "("
identifier "wasAccessible"
) ")"
; ";"
} "}"
} "}"
} "}"
} "}"
line_comment "//TODO duplicated elsewhere\r"
method_declaration (+84 nodes collapsed)
} "}"

After

program
block_comment "/*\r\n * Copyright (c) 2007 Mockito contributors\r\n * This prog"...
package_declaration
package "package"
scoped_identifier
scoped_identifier
scoped_identifier
identifier "org"
. "."
identifier "mockito"
. "."
identifier "internal"
. "."
identifier "configuration"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
identifier "java"
. "."
identifier "lang"
. "."
identifier "annotation"
. "."
identifier "Annotation"
; ";"
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 "org"
. "."
identifier "mockito"
. "."
identifier "Captor"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "org"
. "."
identifier "mockito"
. "."
identifier "Mock"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "org"
. "."
identifier "mockito"
. "."
identifier "Mockito"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "org"
. "."
identifier "mockito"
. "."
identifier "Spy"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
identifier "org"
. "."
identifier "mockito"
. "."
identifier "configuration"
. "."
identifier "AnnotationEngine"
; ";"
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
identifier "org"
. "."
identifier "mockito"
. "."
identifier "exceptions"
. "."
identifier "base"
. "."
identifier "MockitoException"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "org"
. "."
identifier "mockito"
. "."
identifier "internal"
. "."
identifier "util"
. "."
identifier "MockUtil"
; ";"
import_declaration
import "import"
static "static"
scoped_identifier
scoped_identifier
scoped_identifier
identifier "org"
. "."
identifier "mockito"
. "."
identifier "Mockito"
. "."
identifier "withSettings"
; ";"
class_declaration
modifiers
annotation
@ "@"
identifier "SuppressWarnings"
annotation_argument_list
( "("
element_value_array_initializer
{ "{"
string_literal
" "\""
string_fragment "unchecked"
" "\""
} "}"
) ")"
public "public"
class "class"
identifier "SpyAnnotationEngine"
super_interfaces
implements "implements"
type_list
type_identifier "AnnotationEngine"
class_body
{ "{"
method_declaration (+22 nodes collapsed)
method_declaration
modifiers
annotation
@ "@"
identifier "SuppressWarnings"
annotation_argument_list
( "("
string_literal
" "\""
string_fragment "deprecation"
" "\""
) ")"
public "public"
void_type "void"
identifier "process"
formal_parameters
( "("
formal_parameter
generic_type
type_identifier "Class"
type_arguments
< "<"
wildcard
? "?"
> ">"
identifier "context"
, ","
formal_parameter
type_identifier "Object"
identifier "testClass"
) ")"
block
{ "{"
local_variable_declaration
array_type
type_identifier "Field"
dimensions
[ "["
] "]"
variable_declarator
identifier "fields"
= "="
method_invocation
identifier "context"
. "."
identifier "getDeclaredFields"
argument_list
( "("
) ")"
; ";"
enhanced_for_statement
for "for"
( "("
type_identifier "Field"
identifier "field"
: ":"
identifier "fields"
) ")"
block
{ "{"
if_statement
if "if"
parenthesized_expression
( "("
method_invocation
identifier "field"
. "."
identifier "isAnnotationPresent"
argument_list
( "("
class_literal
type_identifier "Spy"
. "."
class "class"
) ")"
) ")"
block
{ "{"
expression_statement (+37 nodes collapsed)
local_variable_declaration
boolean_type "boolean"
variable_declarator
identifier "wasAccessible"
= "="
method_invocation
identifier "field"
. "."
identifier "isAccessible"
argument_list
( "("
) ")"
; ";"
expression_statement
method_invocation
identifier "field"
. "."
identifier "setAccessible"
argument_list
( "("
true "true"
) ")"
; ";"
try_statement
try "try"
block
{ "{"
local_variable_declaration
type_identifier "Object"
variable_declarator
identifier "instance"
= "="
method_invocation
identifier "field"
. "."
identifier "get"
argument_list
( "("
identifier "testClass"
) ")"
; ";"
if_statement (+68 nodes collapsed)
if_statement
if "if"
parenthesized_expression
( "("
method_invocation
object_creation_expression
new "new"
type_identifier "MockUtil"
argument_list
( "("
) ")"
. "."
identifier "isMock"
argument_list
( "("
identifier "instance"
) ")"
) ")"
block
{ "{"
line_comment "// instance has been spied earlier\r"
expression_statement
method_invocation
identifier "Mockito"
. "."
identifier "reset"
argument_list
( "("
identifier "instance"
) ")"
; ";"
} "}"
else "else"
block
{ "{"
expression_statement
method_invocation
identifier "field"
. "."
identifier "set"
argument_list
( "("
identifier "testClass"
, ","
method_invocation
identifier "Mockito"
. "."
identifier "mock"
argument_list
( "("
method_invocation
identifier "instance"
. "."
identifier "getClass"
argument_list
( "("
) ")"
, ","
method_invocation
method_invocation
method_invocation
method_invocation
identifier "withSettings"
argument_list
( "("
) ")"
. "."
identifier "spiedInstance"
argument_list
( "("
identifier "instance"
) ")"
. "."
identifier "defaultAnswer"
argument_list
( "("
field_access
identifier "Mockito"
. "."
identifier "CALLS_REAL_METHODS"
) ")"
. "."
identifier "name"
argument_list
( "("
method_invocation
identifier "field"
. "."
identifier "getName"
argument_list
( "("
) ")"
) ")"
) ")"
) ")"
; ";"
} "}"
} "}"
catch_clause (+35 nodes collapsed)
finally_clause
finally "finally"
block
{ "{"
expression_statement
method_invocation
identifier "field"
. "."
identifier "setAccessible"
argument_list
( "("
identifier "wasAccessible"
) ")"
; ";"
} "}"
} "}"
} "}"
} "}"
line_comment "//TODO duplicated elsewhere\r"
method_declaration (+84 nodes collapsed)
} "}"