@@ -72,15 +72,15 @@ final class YumemiWeatherTests: XCTestCase {
7272 XCTAssertGreaterThanOrEqual ( Date ( ) . timeIntervalSince ( beginDate) , YumemiWeather . apiDuration)
7373 }
7474
75- func test_fetchWeather_jsonString_async ( ) {
75+ func test_fetchWeather_jsonString_callback ( ) {
7676 let parameter = """
7777{
7878 " area " : " tokyo " ,
7979 " date " : " 2020-04-01T12:00:00+09:00 "
8080}
8181"""
8282 let exp = expectation ( description: #function)
83- YumemiWeather . asyncFetchWeather ( parameter) { result in
83+ YumemiWeather . callbackFetchWeather ( parameter) { result in
8484 exp. fulfill ( )
8585 switch result {
8686 case . success( let jsonString) :
@@ -97,11 +97,44 @@ final class YumemiWeatherTests: XCTestCase {
9797 self . wait ( for: [ exp] , timeout: YumemiWeather . apiDuration + 0.1 )
9898 }
9999
100- static var allTests = [
100+ @available ( iOS 13 , macOS 10 . 15 , * )
101+ func test_fetchWeather_jsonString_async( ) async {
102+ let beginDate = Date ( )
103+ let parameter = """
104+ {
105+ " area " : " tokyo " ,
106+ " date " : " 2020-04-01T12:00:00+09:00 "
107+ }
108+ """
109+ do {
110+ let responseJson = try await YumemiWeather . asyncFetchWeather ( parameter)
111+ let dateFormatter = DateFormatter ( )
112+ dateFormatter. dateFormat = " yyyy-MM-dd'T'HH:mm:ssZZZZZ "
113+ let decoder = JSONDecoder ( )
114+ decoder. keyDecodingStrategy = . convertFromSnakeCase
115+ decoder. dateDecodingStrategy = . formatted( dateFormatter)
116+ _ = try decoder. decode ( Response . self, from: Data ( responseJson. utf8) )
117+ }
118+ catch let error as YumemiWeatherError {
119+ XCTAssertEqual ( error, YumemiWeatherError . unknownError)
120+ }
121+ catch {
122+ XCTFail ( )
123+ }
124+
125+ XCTAssertGreaterThanOrEqual ( Date ( ) . timeIntervalSince ( beginDate) , YumemiWeather . apiDuration)
126+ }
127+
128+ static var allNonConcurrentTests = [
101129 ( " test_fetchWeather " , test_fetchWeather) ,
102130 ( " test_fetchWeather_at " , test_fetchWeather_at) ,
103131 ( " test_fetchWeather_jsonString " , test_fetchWeather_jsonString) ,
104132 ( " test_fetchWeather_jsonString_sync " , test_fetchWeather_jsonString_sync) ,
133+ ( " test_fetchWeather_jsonString_callback " , test_fetchWeather_jsonString_callback) ,
134+ ]
135+
136+ @available ( iOS 13 , macOS 10 . 15 , * )
137+ static var allConcurrentTests = [
105138 ( " test_fetchWeather_jsonString_async " , test_fetchWeather_jsonString_async) ,
106139 ]
107140}
0 commit comments