@@ -18,17 +18,18 @@ package de.danielbechler.diff.introspection
18
18
19
19
import de.danielbechler.diff.access.PropertyAwareAccessor
20
20
import de.danielbechler.diff.mock.ObjectWithString
21
- import spock.lang.Specification
21
+ import spock.lang.Subject
22
22
23
23
import java.beans.BeanInfo
24
24
import java.beans.IntrospectionException
25
25
26
26
/**
27
27
* @author Daniel Bechler
28
28
*/
29
- public class StandardIntrospectorTest extends Specification {
29
+ class StandardIntrospectorTest extends AbstractIntrospectorSpecification {
30
30
31
- def introspector = new StandardIntrospector ()
31
+ @Subject
32
+ StandardIntrospector introspector = new StandardIntrospector ()
32
33
33
34
private Map<String , PropertyAwareAccessor > introspect (Class<?> type ) {
34
35
introspector. introspect(type). accessors. collectEntries {
@@ -38,74 +39,74 @@ public class StandardIntrospectorTest extends Specification {
38
39
39
40
def ' should return proper accessor for property' () {
40
41
when :
41
- def accessor = introspect(TypeWithOnlyOneProperty ). get(' value' )
42
+ def accessor = introspect(TypeWithOnlyOneProperty ). get(' value' )
42
43
then :
43
- accessor. propertyName == ' value'
44
+ accessor. propertyName == ' value'
44
45
and :
45
- def target = new TypeWithOnlyOneProperty ()
46
- accessor. get(target) == null
46
+ def target = new TypeWithOnlyOneProperty ()
47
+ accessor. get(target) == null
47
48
and :
48
- accessor. set(target, ' bar' )
49
- accessor. get(target) == ' bar'
49
+ accessor. set(target, ' bar' )
50
+ accessor. get(target) == ' bar'
50
51
and :
51
- accessor. excludedByAnnotation == false
52
+ accessor. excludedByAnnotation == false
52
53
and :
53
- accessor. categoriesFromAnnotation. isEmpty()
54
+ accessor. categoriesFromAnnotation. isEmpty()
54
55
}
55
56
56
57
def ' should return PropertyAwareAccessors for each property of the given class' () {
57
58
when :
58
- def accessors = introspect(TypeWithTwoProperties )
59
+ def accessors = introspect(TypeWithTwoProperties )
59
60
then :
60
- accessors. size() == 2
61
- accessors. get(' foo' ) != null
62
- accessors. get(' bar' ) != null
61
+ accessors. size() == 2
62
+ accessors. get(' foo' ) != null
63
+ accessors. get(' bar' ) != null
63
64
}
64
65
65
66
def ' should apply categories of ObjectDiffProperty annotation to accessor' () {
66
67
when :
67
- def accessor = introspect(TypeWithPropertyAnnotation ). get(' value' )
68
+ def accessor = introspect(TypeWithPropertyAnnotation ). get(' value' )
68
69
then :
69
- accessor. categoriesFromAnnotation. size() == 2
70
- accessor. categoriesFromAnnotation. containsAll([' category1' , ' category2' ])
70
+ accessor. categoriesFromAnnotation. size() == 2
71
+ accessor. categoriesFromAnnotation. containsAll([' category1' , ' category2' ])
71
72
}
72
73
73
74
def ' should apply exclusion of ObjectDiffProperty annotation to accessor' () {
74
75
when :
75
- def accessor = introspect(TypeWithPropertyAnnotation ). get(' value' )
76
+ def accessor = introspect(TypeWithPropertyAnnotation ). get(' value' )
76
77
then :
77
- accessor. excludedByAnnotation == true
78
+ accessor. excludedByAnnotation == true
78
79
}
79
80
80
81
def ' should throw exception when invoked without type' () {
81
82
when :
82
- introspector. introspect(null )
83
+ introspector. introspect(null )
83
84
then :
84
- thrown(IllegalArgumentException )
85
+ thrown(IllegalArgumentException )
85
86
}
86
87
87
88
def ' should skip default class properties' () {
88
89
expect :
89
- introspect(TypeWithNothingButDefaultProperties ). isEmpty()
90
+ introspect(TypeWithNothingButDefaultProperties ). isEmpty()
90
91
}
91
92
92
93
def ' should skip properties without getter' () {
93
94
expect :
94
- introspect(TypeWithPropertyWithoutGetter ). isEmpty()
95
+ introspect(TypeWithPropertyWithoutGetter ). isEmpty()
95
96
}
96
97
97
98
def ' should wrap IntrospectionException with RuntimeException' () {
98
99
given :
99
- introspector = new StandardIntrospector () {
100
- @Override
101
- protected BeanInfo getBeanInfo (final Class<?> type ) throws IntrospectionException {
102
- throw new IntrospectionException (type. getCanonicalName());
103
- }
104
- };
100
+ introspector = new StandardIntrospector () {
101
+ @Override
102
+ protected BeanInfo getBeanInfo (final Class<?> type ) throws IntrospectionException {
103
+ throw new IntrospectionException (type. getCanonicalName());
104
+ }
105
+ };
105
106
when :
106
- introspector. introspect(ObjectWithString . class);
107
+ introspector. introspect(ObjectWithString . class);
107
108
then :
108
- thrown(RuntimeException )
109
+ thrown(RuntimeException )
109
110
}
110
111
111
112
private class TypeWithNothingButDefaultProperties {
0 commit comments