@@ -2,6 +2,9 @@ import PMKCoreLocation
2
2
import CoreLocation
3
3
import PromiseKit
4
4
import XCTest
5
+ #if os(iOS) || os(watchOS) || os(OSX)
6
+ import class Contacts. CNPostalAddress
7
+ #endif
5
8
6
9
class CLGeocoderTests : XCTestCase {
7
10
func test_reverseGeocodeLocation( ) {
@@ -54,6 +57,45 @@ class CLGeocoderTests: XCTestCase {
54
57
}
55
58
waitForExpectations ( timeout: 1 )
56
59
}
60
+
61
+ #if !os(tvOS) && swift(>=3.2)
62
+ @available ( iOS 11 . 0 , OSX 10 . 13 , watchOS 4 . 0 , * )
63
+ func test_geocodePostalAddress( ) {
64
+ class MockGeocoder : CLGeocoder {
65
+ override func geocodePostalAddress( _ postalAddress: CNPostalAddress , completionHandler: @escaping CLGeocodeCompletionHandler ) {
66
+ after ( . seconds( 0 ) ) . done {
67
+ completionHandler ( [ dummyPlacemark] , nil )
68
+ }
69
+ }
70
+ }
71
+
72
+ let ex = expectation ( description: " " )
73
+ MockGeocoder ( ) . geocodePostalAddress ( CNPostalAddress ( ) ) . done { x in
74
+ XCTAssertEqual ( x, [ dummyPlacemark] )
75
+ ex. fulfill ( )
76
+ }
77
+ waitForExpectations ( timeout: 1 )
78
+ }
79
+
80
+ @available ( iOS 11 . 0 , OSX 10 . 13 , watchOS 4 . 0 , * )
81
+ @available ( tvOS, unavailable)
82
+ func test_geocodePostalAddressLocale( ) {
83
+ class MockGeocoder : CLGeocoder {
84
+ override func geocodePostalAddress( _ postalAddress: CNPostalAddress , preferredLocale locale: Locale ? , completionHandler: @escaping CLGeocodeCompletionHandler ) {
85
+ after ( . seconds( 0 ) ) . done {
86
+ completionHandler ( [ dummyPlacemark] , nil )
87
+ }
88
+ }
89
+ }
90
+
91
+ let ex = expectation ( description: " " )
92
+ MockGeocoder ( ) . geocodePostalAddress ( CNPostalAddress ( ) , preferredLocale: nil ) . done { x in
93
+ XCTAssertEqual ( x, [ dummyPlacemark] )
94
+ ex. fulfill ( )
95
+ }
96
+ waitForExpectations ( timeout: 1 )
97
+ }
98
+ #endif
57
99
}
58
100
59
101
private let dummyPlacemark = CLPlacemark ( )
0 commit comments