Clover Coverage Report - rice-shareddata-impl 2.0.0-SNAPSHOT
Coverage timestamp: Wed Dec 31 1969 19:00:00 EST
51   141   14   3.64
0   0   0.27   14
14     1  
1    
 
  PostalCodeServiceImplTest       Line # 27 51 0% 14 65 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.postalcode
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.postalcode.PostalCodeService
26   
 
27    class PostalCodeServiceImplTest {
28   
 
29  0 toggle private final shouldFail = new GroovyTestCase().&shouldFail
30   
 
31  0 toggle static samplePostalCodes = new HashMap<List<String>, PostalCodeBo>()
 
32  0 toggle static samplePostalCodesPerCountry = new HashMap<String, List<PostalCodeBo>>()
33   
34    private def MockFor mockBoService
35    BusinessObjectService boService
36    PostalCodeServiceImpl postalCodeServiceImpl
37    PostalCodeService postalCodeService
38   
 
39  0 toggle @BeforeClass
40    static void createSamplePostalCodeBOs() {
41  0 def laingburgBo = new PostalCodeBo(active: true, countryCode: "US", stateCode: "MI", code: "48848",
42    cityName: "Laingburg")
43  0 def bevHillsBo = new PostalCodeBo(active: true, countryCode: "US", stateCode: "CA", code: "90210",
44    cityName: "Bev Hills")
45  0 def blubberBay = new PostalCodeBo(active: true, countryCode: "CA", stateCode: "BC", code: "604",
46    cityName: "Blubber Bay")
47  0 [laingburgBo, bevHillsBo, blubberBay].each {
48  0 samplePostalCodes[[it.code, it.countryCode].asImmutable()] = it
49    }
50  0 samplePostalCodesPerCountry["US"] = [laingburgBo, bevHillsBo]
51  0 samplePostalCodesPerCountry["CA"] = [blubberBay]
52    }
53   
 
54  0 toggle @Before
55    void setupBoServiceMockContext() {
56  0 mockBoService = new MockFor(BusinessObjectService)
57    }
58   
 
59  0 toggle @Before
60    void setupServiceUnderTest() {
61  0 postalCodeServiceImpl = new PostalCodeServiceImpl()
62  0 postalCodeService = postalCodeServiceImpl
63    }
64   
 
65  0 toggle void injectBusinessObjectServiceIntoCountryService() {
66  0 boService = mockBoService.proxyDelegateInstance()
67  0 postalCodeServiceImpl.setBusinessObjectService(boService);
68    }
69   
 
70  0 toggle @Test
71    void test_get_postal_code_null_countryCode() {
72  0 injectBusinessObjectServiceIntoCountryService()
73  0 shouldFail(RuntimeException) {
74  0 postalCodeService.getPostalCode(null, "48848")
75    }
76  0 mockBoService.verify(boService)
77    }
78   
 
79  0 toggle @Test
80    void test_get_postal_code_null_code() {
81  0 injectBusinessObjectServiceIntoCountryService()
82  0 shouldFail(RuntimeException) {
83  0 postalCodeService.getPostalCode("US", null)
84    }
85  0 mockBoService.verify(boService)
86    }
87   
 
88  0 toggle @Test
89    void test_get_postal_code_exists() {
90  0 mockBoService.demand.findByPrimaryKey(1..1) { clazz, map -> samplePostalCodes[map["countryCode"], [map["code"]]] }
91  0 injectBusinessObjectServiceIntoCountryService()
92  0 Assert.assertEquals(PostalCodeBo.to(samplePostalCodes[["US", "48848"]]), postalCodeService.getPostalCode("US", "48848"))
93  0 mockBoService.verify(boService)
94    }
95   
 
96  0 toggle @Test
97    void test_get_postal_code_does_not_exist() {
98  0 mockBoService.demand.findByPrimaryKey(1..1) { clazz, map -> samplePostalCodes[map["countryCode"], [map["code"]]] }
99  0 injectBusinessObjectServiceIntoCountryService()
100  0 Assert.assertNull(postalCodeService.getPostalCode("FOO", "BAR"))
101  0 mockBoService.verify(boService)
102    }
103   
 
104  0 toggle @Test
105    void test_find_all_postal_codes_in_country_null_countryCode() {
106  0 injectBusinessObjectServiceIntoCountryService()
107  0 shouldFail(RuntimeException) {
108  0 postalCodeService.findAllPostalCodesInCountry(null)
109    }
110  0 mockBoService.verify(boService)
111    }
112   
 
113  0 toggle @Test
114    void test_find_all_postal_codes_in_country_exists() {
115  0 mockBoService.demand.findMatching(1..1) { clazz, map -> samplePostalCodesPerCountry[map["countryCode"]] }
116  0 injectBusinessObjectServiceIntoCountryService()
117  0 def values = postalCodeService.findAllPostalCodesInCountry("US")
118  0 Assert.assertEquals(samplePostalCodesPerCountry["US"].collect { PostalCodeBo.to(it) }, values)
119   
120    //is this unmodifiable?
121  0 shouldFail(RuntimeException) {
122  0 values.add(PostalCodeBo.to(samplePostalCodes[["CA", "604"]]))
123    }
124  0 mockBoService.verify(boService)
125    }
126   
 
127  0 toggle @Test
128    void test_find_all_postal_codes_in_country_does_not_exist() {
129  0 mockBoService.demand.findMatching(1..1) { clazz, map -> samplePostalCodesPerCountry[map["countryCode"]] }
130  0 injectBusinessObjectServiceIntoCountryService()
131  0 def values = postalCodeService.findAllPostalCodesInCountry("FOO")
132  0 Assert.assertEquals([], values)
133   
134    //is this unmodifiable?
135  0 shouldFail(UnsupportedOperationException.class) {
136  0 values.add(PostalCodeBo.to(samplePostalCodes[["CA", "604"]]))
137    }
138   
139  0 mockBoService.verify(boService)
140    }
141    }