| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 65 (65) |
Complexity: 14 |
Complexity Density: 0.27 |
|
| 27 |
|
class PostalCodeServiceImplTest { |
| 28 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 29 |
0
|
private final shouldFail = new GroovyTestCase().&shouldFail... |
| 30 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 31 |
0
|
static samplePostalCodes = new HashMap<List<String>, PostalCodeBo>()... |
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 32 |
0
|
static samplePostalCodesPerCountry = new HashMap<String, List<PostalCodeBo>>()... |
| 33 |
|
|
| 34 |
|
private def MockFor mockBoService |
| 35 |
|
BusinessObjectService boService |
| 36 |
|
PostalCodeServiceImpl postalCodeServiceImpl |
| 37 |
|
PostalCodeService postalCodeService |
| 38 |
|
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
| 39 |
0
|
@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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 54 |
0
|
@Before... |
| 55 |
|
void setupBoServiceMockContext() { |
| 56 |
0
|
mockBoService = new MockFor(BusinessObjectService) |
| 57 |
|
} |
| 58 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 59 |
0
|
@Before... |
| 60 |
|
void setupServiceUnderTest() { |
| 61 |
0
|
postalCodeServiceImpl = new PostalCodeServiceImpl() |
| 62 |
0
|
postalCodeService = postalCodeServiceImpl |
| 63 |
|
} |
| 64 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 65 |
0
|
void injectBusinessObjectServiceIntoCountryService() {... |
| 66 |
0
|
boService = mockBoService.proxyDelegateInstance() |
| 67 |
0
|
postalCodeServiceImpl.setBusinessObjectService(boService); |
| 68 |
|
} |
| 69 |
|
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
4
-
|
|
| 70 |
0
|
@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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
4
-
|
|
| 79 |
0
|
@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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
4
-
|
|
| 88 |
0
|
@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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
4
-
|
|
| 96 |
0
|
@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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
4
-
|
|
| 104 |
0
|
@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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
4
-
|
|
| 113 |
0
|
@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 |
|
|
| 121 |
0
|
shouldFail(RuntimeException) { |
| 122 |
0
|
values.add(PostalCodeBo.to(samplePostalCodes[["CA", "604"]])) |
| 123 |
|
} |
| 124 |
0
|
mockBoService.verify(boService) |
| 125 |
|
} |
| 126 |
|
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
4
-
|
|
| 127 |
0
|
@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 |
|
|
| 135 |
0
|
shouldFail(UnsupportedOperationException.class) { |
| 136 |
0
|
values.add(PostalCodeBo.to(samplePostalCodes[["CA", "604"]])) |
| 137 |
|
} |
| 138 |
|
|
| 139 |
0
|
mockBoService.verify(boService) |
| 140 |
|
} |
| 141 |
|
} |