Clover Coverage Report - rice-shareddata-impl 2.0.0-SNAPSHOT
Coverage timestamp: Wed Dec 31 1969 19:00:00 EST
60   167   16   3.75
0   0   0.27   16
16     1  
1    
 
  CountyServiceImplTest       Line # 27 60 0% 16 76 0% 0.0
 
No Tests
 
1    /*
2    * Copyright 2006-2011 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10    * Unless required by applicable law or agreed to in writing, software
11    * distributed under the License is distributed on an "AS IS" BASIS,
12    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    * See the License for the specific language governing permissions and
14    * limitations under the License.
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   
 
27    class CountyServiceImplTest {
 
28  0 toggle private final shouldFail = new GroovyTestCase().&shouldFail
29   
 
30  0 toggle static sampleCounties = new HashMap<List<String>, CountyBo>()
 
31  0 toggle 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   
 
39  0 toggle @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    //no clue if CA has counties :-)
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   
 
56  0 toggle @Before
57    void setupBoServiceMockContext() {
58  0 businessObjectServiceMock = new MockFor(BusinessObjectService)
59   
60    }
61   
 
62  0 toggle @Before
63    void setupServiceUnderTest() {
64  0 countyServiceImpl = new CountyServiceImpl()
65  0 countyService = countyServiceImpl
66    }
67   
 
68  0 toggle void injectBusinessObjectServiceIntoCountryService() {
69  0 boService = businessObjectServiceMock.proxyDelegateInstance()
70  0 countyServiceImpl.setBusinessObjectService(boService)
71    }
72   
 
73  0 toggle @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   
 
83  0 toggle @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   
 
93  0 toggle @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   
 
103  0 toggle @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   
 
111  0 toggle @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   
 
119  0 toggle @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   
 
129  0 toggle @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   
 
139  0 toggle @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    //is this unmodifiable?
147  0 shouldFail(RuntimeException) {
148  0 values.add(CountyBo.to(sampleCounties[["CA", "MI", "shi"]]))
149    }
150  0 businessObjectServiceMock.verify(boService)
151    }
152   
 
153  0 toggle @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    //is this unmodifiable?
161  0 shouldFail(RuntimeException) {
162  0 values.add(CountyBo.to(sampleCounties[["CA", "MI", "shi"]]))
163    }
164   
165  0 businessObjectServiceMock.verify(boService)
166    }
167    }