|
1 | 1 | import 'dart:async'; |
2 | | -import 'dart:io'; |
3 | 2 | import 'package:flutter_test/flutter_test.dart'; |
4 | 3 | import 'package:cambridge_beer_festival/providers/beer_provider.dart'; |
5 | 4 | import 'package:cambridge_beer_festival/services/services.dart'; |
| 5 | +import 'package:http/http.dart' as http; |
6 | 6 | import 'package:cambridge_beer_festival/models/models.dart'; |
7 | 7 | import 'package:cambridge_beer_festival/domain/models/models.dart'; |
8 | 8 | import 'package:cambridge_beer_festival/domain/repositories/repositories.dart'; |
@@ -153,16 +153,16 @@ void main() { |
153 | 153 | ); |
154 | 154 | await provider.initialize(); |
155 | 155 |
|
156 | | - // Mock SocketException (no internet) |
| 156 | + // http.ClientException is thrown on network failures across all platforms |
157 | 157 | when(mockDrinkRepository.getDrinks(any)) |
158 | | - .thenThrow(const SocketException('Failed host lookup')); |
| 158 | + .thenThrow(http.ClientException('Failed host lookup')); |
159 | 159 |
|
160 | 160 | await provider.loadDrinks(); |
161 | 161 |
|
162 | 162 | expect(provider.error, isNotNull); |
163 | 163 | expect(provider.error, contains('No internet connection')); |
164 | 164 | expect(provider.error, contains('check your network')); |
165 | | - expect(provider.error, isNot(contains('SocketException'))); |
| 165 | + expect(provider.error, isNot(contains('ClientException'))); |
166 | 166 | expect(provider.error, isNot(contains('Failed host lookup'))); |
167 | 167 | }); |
168 | 168 |
|
@@ -315,15 +315,15 @@ void main() { |
315 | 315 | analyticsService: mockAnalyticsService, |
316 | 316 | ); |
317 | 317 |
|
318 | | - // Mock SocketException |
| 318 | + // http.ClientException is thrown on network failures across all platforms |
319 | 319 | when(mockFestivalRepository.getFestivals()) |
320 | | - .thenThrow(const SocketException('Network unreachable')); |
| 320 | + .thenThrow(http.ClientException('Network unreachable')); |
321 | 321 |
|
322 | 322 | await provider.loadFestivals(); |
323 | 323 |
|
324 | 324 | expect(provider.festivalsError, isNotNull); |
325 | 325 | expect(provider.festivalsError, contains('No internet connection')); |
326 | | - expect(provider.festivalsError, isNot(contains('SocketException'))); |
| 326 | + expect(provider.festivalsError, isNot(contains('ClientException'))); |
327 | 327 | }); |
328 | 328 |
|
329 | 329 | test('shows connection message for FestivalServiceException without status', |
|
0 commit comments