1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.kuali.rice.shareddata.impl.county |
18 |
|
|
19 |
|
import groovy.mock.interceptor.MockFor |
20 |
|
import org.junit.Assert |
21 |
|
import org.junit.Before |
22 |
|
import org.junit.BeforeClass |
23 |
|
import org.junit.Test |
24 |
|
import org.kuali.rice.kns.service.BusinessObjectService |
25 |
|
import org.kuali.rice.shareddata.api.county.CountyService |
26 |
|
|
|
|
| 0% |
Uncovered Elements: 76 (76) |
Complexity: 16 |
Complexity Density: 0.27 |
|
27 |
|
class CountyServiceImplTest { |
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
28 |
0
|
private final shouldFail = new GroovyTestCase().&shouldFail... |
29 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
30 |
0
|
static sampleCounties = new HashMap<List<String>, CountyBo>()... |
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
31 |
0
|
static sampleCountiesPerCountryState = new HashMap<List<String>, List<CountyBo>>()... |
32 |
|
|
33 |
|
private MockFor businessObjectServiceMock |
34 |
|
private BusinessObjectService boService |
35 |
|
CountyService countyService |
36 |
|
CountyServiceImpl countyServiceImpl |
37 |
|
|
38 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
39 |
0
|
@BeforeClass... |
40 |
|
static void createSamplePostalCodeBOs() { |
41 |
0
|
def shiBo = new CountyBo(active: true, countryCode: "US", stateCode: "MI", code: "shi", |
42 |
|
name: "Shiawassee ") |
43 |
0
|
def laBo = new CountyBo(active: true, countryCode: "US", stateCode: "CA", code: "la", |
44 |
|
name: "Los Angeles") |
45 |
|
|
46 |
0
|
def tiBo = new CountyBo(active: true, countryCode: "CA", stateCode: "BC", code: "ti", |
47 |
|
name: "Texada Island") |
48 |
0
|
[shiBo, laBo, tiBo].each { |
49 |
0
|
sampleCounties[[it.code, it.countryCode, it.stateCode].asImmutable()] = it |
50 |
|
} |
51 |
0
|
sampleCountiesPerCountryState[["US", "MI"].asImmutable()] = [shiBo] |
52 |
0
|
sampleCountiesPerCountryState[["US", "CA"].asImmutable()] = [laBo] |
53 |
0
|
sampleCountiesPerCountryState[["CA", "BC"].asImmutable()] = [tiBo] |
54 |
|
} |
55 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
56 |
0
|
@Before... |
57 |
|
void setupBoServiceMockContext() { |
58 |
0
|
businessObjectServiceMock = new MockFor(BusinessObjectService) |
59 |
|
|
60 |
|
} |
61 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
62 |
0
|
@Before... |
63 |
|
void setupServiceUnderTest() { |
64 |
0
|
countyServiceImpl = new CountyServiceImpl() |
65 |
0
|
countyService = countyServiceImpl |
66 |
|
} |
67 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
68 |
0
|
void injectBusinessObjectServiceIntoCountryService() {... |
69 |
0
|
boService = businessObjectServiceMock.proxyDelegateInstance() |
70 |
0
|
countyServiceImpl.setBusinessObjectService(boService) |
71 |
|
} |
72 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
4
-
|
|
73 |
0
|
@Test... |
74 |
|
void test_getCounty_null_countryCode() { |
75 |
0
|
injectBusinessObjectServiceIntoCountryService() |
76 |
|
|
77 |
0
|
shouldFail(RuntimeException) { |
78 |
0
|
countyService.getCounty(null, "MI", "48848") |
79 |
|
} |
80 |
0
|
businessObjectServiceMock.verify(boService) |
81 |
|
} |
82 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
4
-
|
|
83 |
0
|
@Test... |
84 |
|
void test_getPostalCode_null_stateCode() { |
85 |
0
|
injectBusinessObjectServiceIntoCountryService() |
86 |
|
|
87 |
0
|
shouldFail(RuntimeException) { |
88 |
0
|
countyService.getCounty("US", null, "48848") |
89 |
|
} |
90 |
0
|
businessObjectServiceMock.verify(boService) |
91 |
|
} |
92 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
4
-
|
|
93 |
0
|
@Test... |
94 |
|
void test_getPostalCode_null_code() { |
95 |
0
|
injectBusinessObjectServiceIntoCountryService() |
96 |
|
|
97 |
0
|
shouldFail(RuntimeException) { |
98 |
0
|
countyService.getCounty("US", "MI", null) |
99 |
|
} |
100 |
0
|
businessObjectServiceMock.verify(boService) |
101 |
|
} |
102 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
4
-
|
|
103 |
0
|
@Test... |
104 |
|
void test_get_county_exists() { |
105 |
0
|
businessObjectServiceMock.demand.findByPrimaryKey(1..1) { clazz, map -> sampleCounties[map["countryCode"], map["stateCode"], [map["code"]]] } |
106 |
0
|
injectBusinessObjectServiceIntoCountryService() |
107 |
0
|
Assert.assertEquals(CountyBo.to(sampleCounties[["US", "48848"]]), countyService.getCounty("US", "MI", "shi")) |
108 |
0
|
businessObjectServiceMock.verify(boService) |
109 |
|
} |
110 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
4
-
|
|
111 |
0
|
@Test... |
112 |
|
void test_get_county_does_not_exist() { |
113 |
0
|
businessObjectServiceMock.demand.findByPrimaryKey(1..1) { clazz, map -> sampleCounties[map["countryCode"], map["stateCode"], [map["code"]]] } |
114 |
0
|
injectBusinessObjectServiceIntoCountryService() |
115 |
0
|
Assert.assertNull(countyService.getCounty("FOO", "BAR", "BAZ")) |
116 |
0
|
businessObjectServiceMock.verify(boService) |
117 |
|
} |
118 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
4
-
|
|
119 |
0
|
@Test... |
120 |
|
void test_getAllPostalCodesInCountryAndState_null_countryCode() { |
121 |
0
|
injectBusinessObjectServiceIntoCountryService() |
122 |
|
|
123 |
0
|
shouldFail(RuntimeException) { |
124 |
0
|
countyService.findAllCountiesInCountryAndState(null, "MI") |
125 |
|
} |
126 |
0
|
businessObjectServiceMock.verify(boService) |
127 |
|
} |
128 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
4
-
|
|
129 |
0
|
@Test... |
130 |
|
void test_getAllPostalCodesInCountryAndState_null_stateCode() { |
131 |
0
|
injectBusinessObjectServiceIntoCountryService() |
132 |
|
|
133 |
0
|
shouldFail(RuntimeException) { |
134 |
0
|
countyService.findAllCountiesInCountryAndState("US", null) |
135 |
|
} |
136 |
0
|
businessObjectServiceMock.verify(boService) |
137 |
|
} |
138 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
4
-
|
|
139 |
0
|
@Test... |
140 |
|
void test_find_all_county_in_country_state_exists() { |
141 |
0
|
businessObjectServiceMock.demand.findMatching(1..1) { clazz, map -> sampleCountiesPerCountryState[map["countryCode"], map["stateCode"]] } |
142 |
0
|
injectBusinessObjectServiceIntoCountryService() |
143 |
0
|
def values = countyService.findAllCountiesInCountryAndState("US", "MI") |
144 |
0
|
Assert.assertEquals(sampleCountiesPerCountryState[["US", "MI"]].collect { CountyBo.to(it) }, values) |
145 |
|
|
146 |
|
|
147 |
0
|
shouldFail(RuntimeException) { |
148 |
0
|
values.add(CountyBo.to(sampleCounties[["CA", "MI", "shi"]])) |
149 |
|
} |
150 |
0
|
businessObjectServiceMock.verify(boService) |
151 |
|
} |
152 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
4
-
|
|
153 |
0
|
@Test... |
154 |
|
void test_find_all_county_in_country_state_does_not_exist() { |
155 |
0
|
businessObjectServiceMock.demand.findMatching(1..1) { clazz, map -> sampleCountiesPerCountryState[map["countryCode"], map["stateCode"]] } |
156 |
0
|
injectBusinessObjectServiceIntoCountryService() |
157 |
0
|
def values = countyService.findAllCountiesInCountryAndState("FOO", "BAR") |
158 |
0
|
Assert.assertEquals([], values) |
159 |
|
|
160 |
|
|
161 |
0
|
shouldFail(RuntimeException) { |
162 |
0
|
values.add(CountyBo.to(sampleCounties[["CA", "MI", "shi"]])) |
163 |
|
} |
164 |
|
|
165 |
0
|
businessObjectServiceMock.verify(boService) |
166 |
|
} |
167 |
|
} |