|
16 | 16 |
|
17 | 17 | package de.danielbechler.diff |
18 | 18 |
|
19 | | -import de.danielbechler.diff.bean.NamedPropertyElement |
| 19 | +import de.danielbechler.diff.bean.BeanPropertyElement |
20 | 20 | import spock.lang.Specification |
21 | 21 |
|
22 | 22 | import static DiffNode.ROOT |
23 | 23 |
|
24 | 24 | /** |
25 | 25 | * @author Daniel Bechler |
26 | 26 | */ |
27 | | -class CategoryServiceTest extends Specification |
28 | | -{ |
29 | | - def categoryService = new CategoryService() |
30 | | - def accessor = Mock(PropertyAwareAccessor) |
31 | | - def nodePath = NodePath.buildWith("foo") |
32 | | - def nodeType = Alliance |
33 | | - def DiffNode node |
34 | | - def DiffNode rootNode |
35 | | - |
36 | | - def "setup"() |
37 | | - { |
38 | | - accessor.pathElement >> new NamedPropertyElement("foo") |
39 | | - rootNode = new DiffNode(ROOT, RootAccessor.instance, null) |
40 | | - node = new DiffNode(rootNode, accessor, nodeType) |
41 | | - } |
42 | | - |
43 | | - def "resolveCategories: should return categories configured via path"() |
44 | | - { |
45 | | - given: |
46 | | - categoryService.ofNode(nodePath).toBe("Stark", "Lannister") |
47 | | - |
48 | | - expect: |
49 | | - categoryService.resolveCategories(node) == ["Stark", "Lannister"] as Set |
50 | | - } |
51 | | - |
52 | | - def "resolveCategories: should return categories configured via type"() |
53 | | - { |
54 | | - given: |
55 | | - categoryService.ofType(nodeType).toBe("Stark", "Lannister") |
56 | | - |
57 | | - expect: |
58 | | - categoryService.resolveCategories(node) == ["Stark", "Lannister"] as Set |
59 | | - } |
60 | | - |
61 | | - def "resolveCategories: should return categories configured via node"() |
62 | | - { |
63 | | - given: |
64 | | - accessor.categories >> ["Stark", "Lannister"] |
65 | | - |
66 | | - expect: |
67 | | - categoryService.resolveCategories(node) == ["Stark", "Lannister"] as Set |
68 | | - } |
69 | | - |
70 | | - def "resolveCategories: should return combined categories configured via all possible options"() |
71 | | - { |
72 | | - given: |
73 | | - categoryService.ofNode(nodePath).toBe("A") |
74 | | - |
75 | | - and: |
76 | | - categoryService.ofType(nodeType).toBe("B") |
77 | | - |
78 | | - and: |
79 | | - accessor.categories >> ["C"] |
80 | | - |
81 | | - expect: |
82 | | - categoryService.resolveCategories(node) == ["A", "B", "C"] as Set |
83 | | - } |
84 | | - |
85 | | - def "resolveCategories: should not return categories of parent nodes"() |
86 | | - { |
87 | | - given: |
88 | | - accessor.categories >> ["B"] |
89 | | - |
90 | | - and: |
91 | | - categoryService.ofNode(NodePath.buildRootPath()).toBe("A") |
92 | | - |
93 | | - expect: |
94 | | - categoryService.resolveCategories(node) == ["B"] as Set |
95 | | - } |
96 | | - |
97 | | - def "resolveCategories: should return empty Set if no category is defined"() |
98 | | - { |
99 | | - given: |
100 | | - node = new DiffNode() |
101 | | - |
102 | | - expect: |
103 | | - categoryService.resolveCategories(node) == [] as Set |
104 | | - } |
105 | | - |
106 | | - class Alliance |
107 | | - { |
108 | | - } |
| 27 | +class CategoryServiceTest extends Specification { |
| 28 | + def categoryService = new CategoryService() |
| 29 | + def accessor = Mock(PropertyAwareAccessor) |
| 30 | + def nodePath = NodePath.buildWith("foo") |
| 31 | + def nodeType = Alliance |
| 32 | + def DiffNode node |
| 33 | + def DiffNode rootNode |
| 34 | + |
| 35 | + def "setup"() { |
| 36 | + accessor.pathElement >> new BeanPropertyElement("foo") |
| 37 | + rootNode = new DiffNode(ROOT, RootAccessor.instance, null) |
| 38 | + node = new DiffNode(rootNode, accessor, nodeType) |
| 39 | + } |
| 40 | + |
| 41 | + def "resolveCategories: should return categories configured via path"() { |
| 42 | + given: |
| 43 | + categoryService.ofNode(nodePath).toBe("Stark", "Lannister") |
| 44 | + |
| 45 | + expect: |
| 46 | + categoryService.resolveCategories(node) == ["Stark", "Lannister"] as Set |
| 47 | + } |
| 48 | + |
| 49 | + def "resolveCategories: should return categories configured via type"() { |
| 50 | + given: |
| 51 | + categoryService.ofType(nodeType).toBe("Stark", "Lannister") |
| 52 | + |
| 53 | + expect: |
| 54 | + categoryService.resolveCategories(node) == ["Stark", "Lannister"] as Set |
| 55 | + } |
| 56 | + |
| 57 | + def "resolveCategories: should return categories configured via node"() { |
| 58 | + given: |
| 59 | + accessor.categories >> ["Stark", "Lannister"] |
| 60 | + |
| 61 | + expect: |
| 62 | + categoryService.resolveCategories(node) == ["Stark", "Lannister"] as Set |
| 63 | + } |
| 64 | + |
| 65 | + def "resolveCategories: should return combined categories configured via all possible options"() { |
| 66 | + given: |
| 67 | + categoryService.ofNode(nodePath).toBe("A") |
| 68 | + |
| 69 | + and: |
| 70 | + categoryService.ofType(nodeType).toBe("B") |
| 71 | + |
| 72 | + and: |
| 73 | + accessor.categories >> ["C"] |
| 74 | + |
| 75 | + expect: |
| 76 | + categoryService.resolveCategories(node) == ["A", "B", "C"] as Set |
| 77 | + } |
| 78 | + |
| 79 | + def "resolveCategories: should not return categories of parent nodes"() { |
| 80 | + given: |
| 81 | + accessor.categories >> ["B"] |
| 82 | + |
| 83 | + and: |
| 84 | + categoryService.ofNode(NodePath.buildRootPath()).toBe("A") |
| 85 | + |
| 86 | + expect: |
| 87 | + categoryService.resolveCategories(node) == ["B"] as Set |
| 88 | + } |
| 89 | + |
| 90 | + def "resolveCategories: should return empty Set if no category is defined"() { |
| 91 | + given: |
| 92 | + node = new DiffNode() |
| 93 | + |
| 94 | + expect: |
| 95 | + categoryService.resolveCategories(node) == [] as Set |
| 96 | + } |
| 97 | + |
| 98 | + class Alliance { |
| 99 | + } |
109 | 100 | } |
0 commit comments